![]() |
How to make texture transparent after SDL_RenderClear() | ![]() |
![]() |
How to make texture transparent after SDL_RenderClear() | ![]() |
Ivan Rubinson
Guest
![]() |
![]() |
Solution: Make an SDL_Surface*, do an SDL_SetColorKey, and then do an SDL_CreateTextureFromSurface
On Sat, Nov 30, 2013 at 11:50 AM, riptor wrote:
|
||||||||||||
|
![]() |
Re: How to make texture transparent after SDL_RenderClear() | ![]() |
lloyd_b
![]() |
![]() |
Try
Setting the Alpha for the draw color to 0 before the RenderClear should give you a blank, transparent canvas (provided the pixel format for that texture supports an alpha channel). |
||||||||||||||
|
![]() |
Re: How to make texture transparent after SDL_RenderClear() | ![]() |
riptor
![]() |
![]() |
I plan refreshing the temporary texture every frame and that means I'll have to createTextureFromSurface every frame. It will definitely degrade performance.
I tried SDL_SetRenderDrawColor(rend, 0, 0, 0, 0); , but it simply fills the texture with black color. Texture pixel format is SDL_PIXELFORMAT_ARGB8888.[/quote] |
||||||||||||||
|
![]() |
![]() |
riptor
![]() |
![]() |
I finally found the solution, it is easy but not intuitive and I think it is worth sharing.
Suppose we have SDL_Window win, SDL_Texture tex and SDL_Renderer ren We want to make tex fully transparent What we should do is
I tried using SDL_SetRenderDrawBlendMode but it didn't work. SDL_SetTextureBlendMode is the way to go ![]() |
||||||||||||
|
![]() |
![]() |
lloyd_b
![]() |
![]() |
I'm wondering whether that one should qualify as a bug. My personal opinion is that SDL_RenderClear() should arbitrarily set all pixels of the target to the specified value, regardless of what blend mode has been selected for that target. But after taking a quick look at the code, it doesn't appear SDL is doing anything involving blend mode in the relevant RenderClear functions. So this may be the result of some basic assumption in OpenGL/Direct3D/etc that I simply don't understand. |
||||||||||||||
|
![]() |
![]() |
riptor
![]() |
![]() |
Actually it looks like I didn't understand why my code worked. It doesn't matter which blend mode was set before SDL_RenderClear. But blend mode before SDL_RenderCopy matters and should be set to SDL_BLENDMODE_BLEND. So my code snippet shoul be rewritten like that.
|
||||||||||||||
|
![]() |
How to make texture transparent after SDL_RenderClear() | ![]() |
Joseph Carter
![]() |
![]() |
I believe SDL_RenderClear() failing to clear to transparent WAS
identified as a bug prior to 2.0.1 and corrected? Joseph On Sat, Nov 30, 2013 at 09:50:33AM +0000, riptor wrote:
_______________________________________________ SDL mailing list http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org |
||||||||||||||
|
![]() |
Re: How to make texture transparent after SDL_RenderClear() | ![]() |
riptor
![]() |
![]() |
Well, sdl 2.0.1 behaves the way I described, but I don't think it should be considered a bug.
|
||||||||||||||||
|