Discussion:
[SDL] Copy RGBA pixels directly to target texture without blending
stewambo
2017-03-16 15:11:01 UTC
Permalink
Hello,
I have a texture with static (or streaming) access and I need to render other stuff onto it, so I need to convert it to a target-texture. Therefor I just created an empty texture with SDL_TEXTUREACCESS_TARGET and set it as rendering target, but when i render my semi-transparent static/streaming texture onto it the black transparent background of the target-texture bleeds into the transparent part of my original texture

Original image:
[Image: Loading Image... ]

Left: original texture rendered directly;
Right: target-texture with original texture rendered ontop (obviously not the same, but darker)
[Image: Loading Image... ]

Code to create the image above:

Code:

SDL_Surface* surface = SDL_ConvertSurfaceFormat(IMG_Load("D:/Documents/Visual Studio 2015/Projects/SDLTest/resources/textures/gradientTexture.png"), SDL_PIXELFORMAT_RGBA8888, NULL);
SDL_Texture* staticTexture = SDL_CreateTextureFromSurface(renderer, surface);
SDL_Texture* targetTexture = SDL_CreateTexture( renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, 50, 50 );

SDL_SetRenderTarget(renderer, targetTexture);
SDL_SetTextureBlendMode(targetTexture, SDL_BLENDMODE_BLEND);
SDL_RenderCopy(renderer, staticTexture, NULL, NULL);
SDL_SetRenderTarget(renderer, NULL);

SDL_Rect rect0{ 50,50,50,50 };
SDL_RenderCopy(renderer, staticTexture, NULL, &rect0);
SDL_Rect rect1{ 100,50,50,50 };
SDL_RenderCopy(renderer, targetTexture, NULL, &rect1);




The solution to my problem in this topic (https://forums.libsdl.org/viewtopic.php?t=12064) was to set the background color of the target texture to one solid color, but here this doesn't work because the static texture is not a solid color...

So how can i get my target-texture to look exactly like my original texture, or is there a way to copy the RGBA information directly into the new texture without the need to render it using a blend mode?

Thanks :)
Sanette
2017-03-16 15:18:54 UTC
Permalink
have you tried SDL_BLENDMODE_NONE ?

(instead of SDL_BLENDMODE_BLEND)
Post by stewambo
Hello,
I have a texture with static (or streaming) access and I need to
render other stuff onto it, so I need to convert it to a
target-texture. Therefor I just created an empty texture with
SDL_TEXTUREACCESS_TARGET and set it as rendering target, but when i
render my semi-transparent static/streaming texture onto it the black
transparent background of the target-texture bleeds into the
transparent part of my original texture
Left: original texture rendered directly;
Right: target-texture with original texture rendered ontop (obviously
not the same, but darker)
SDL_Surface* surface =
SDL_ConvertSurfaceFormat(IMG_Load("D:/Documents/Visual Studio
2015/Projects/SDLTest/resources/textures/gradientTexture.png"),
SDL_PIXELFORMAT_RGBA8888, NULL);
SDL_Texture* staticTexture = SDL_CreateTextureFromSurface(renderer, surface);
SDL_Texture* targetTexture = SDL_CreateTexture( renderer,
SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, 50, 50 );
SDL_SetRenderTarget(renderer, targetTexture);
SDL_SetTextureBlendMode(targetTexture, SDL_BLENDMODE_BLEND);
SDL_RenderCopy(renderer, staticTexture, NULL, NULL);
SDL_SetRenderTarget(renderer, NULL);
SDL_Rect rect0{ 50,50,50,50 };
SDL_RenderCopy(renderer, staticTexture, NULL, &rect0);
SDL_Rect rect1{ 100,50,50,50 };
SDL_RenderCopy(renderer, targetTexture, NULL, &rect1);
The solution to my problem in this topic
<https://forums.libsdl.org/viewtopic.php?t=12064> was to set the
background color of the target texture to one solid color, but here
this doesn't work because the static texture is not a solid color...
So how can i get my target-texture to look exactly like my original
texture, or is there a way to copy the RGBA information directly into
the new texture without the need to render it using a blend mode?
Thanks Smile
_______________________________________________
SDL mailing list
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
--
sanette -- full_time_linux
leagor
2017-03-17 00:56:24 UTC
Permalink
frameTexture = SDL_CreateTexture(renderer, current_format,
SDL_TEXTUREACCESS_TARGET, w, h);

SDL_SetTextureBlendMode(frameTexture, SDL_BLENDMODE_NONE);
stewambo
2017-03-18 22:38:11 UTC
Permalink
Thanks to rtrussell (this thread (https://forums.libsdl.org/viewtopic.php?t=12361)) I tried the SDL_BLENDMODE_NONE again and found my mistake. Previously I always set the SDL_BLENDMODE_NONE for the target texture I wanted to render to, but I needed to set it for the static/streaming texture. Now it works perfectly fine.
Loading...