# Copy RGBA pixels directly to target texture without blending

**URL:** <https://discourse.libsdl.org/t/copy-rgba-pixels-directly-to-target-texture-without-blending/22110>\
**Category:** SDL Development\
**Created:** [March 16, 2017, 3:11pm UTC](https://discourse.libsdl.org/t/copy-rgba-pixels-directly-to-target-texture-without-blending/22110 "2017-03-16T15:11:01Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![stewambo](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/s/9fc29f/32.png) [@stewambo](https://discourse.libsdl.org/u/stewambo)\
**Post date:** [March 16, 2017, 3:11pm UTC](https://discourse.libsdl.org/t/copy-rgba-pixels-directly-to-target-texture-without-blending/22110/1 "2017-03-16T15:11:01Z")

</div>

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: [http://i.imgur.com/5ByTcgv.png](http://i.imgur.com/5ByTcgv.png) ]

Left: original texture rendered directly;  
Right: target-texture with original texture rendered ontop (obviously not the same, but darker)  
[Image: [http://i.imgur.com/z7ukpYr.png](http://i.imgur.com/z7ukpYr.png) ]

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](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 🙂

---

<div class="post-metadata">

**Author:** ![Sanette](https://discourse.libsdl.org/user_avatar/discourse.libsdl.org/sanette/32/2749_2.png) [@Sanette](https://discourse.libsdl.org/u/Sanette)\
**Post date:** [March 16, 2017, 3:18pm UTC](https://discourse.libsdl.org/t/copy-rgba-pixels-directly-to-target-texture-without-blending/22110/2 "2017-03-16T15:18:54Z")

</div>

have you tried SDL\_BLENDMODE\_NONE ?

(instead of SDL\_BLENDMODE\_BLEND)

---

<div class="post-metadata">

**Author:** ![leagor](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/l/41988e/32.png) [@leagor](https://discourse.libsdl.org/u/leagor)\
**Post date:** [March 17, 2017, 12:56am UTC](https://discourse.libsdl.org/t/copy-rgba-pixels-directly-to-target-texture-without-blending/22110/3 "2017-03-17T00:56:24Z")

</div>

frameTexture = SDL\_CreateTexture(renderer, current\_format,  
SDL\_TEXTUREACCESS\_TARGET, w, h);

SDL\_SetTextureBlendMode(frameTexture, SDL\_BLENDMODE\_NONE);

---

<div class="post-metadata">

**Author:** ![stewambo](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/s/9fc29f/32.png) [@stewambo](https://discourse.libsdl.org/u/stewambo)\
**Post date:** [March 18, 2017, 10:38pm UTC](https://discourse.libsdl.org/t/copy-rgba-pixels-directly-to-target-texture-without-blending/22110/4 "2017-03-18T22:38:11Z")

</div>

Thanks to rtrussell (this thread ([https://forums.libsdl.org/viewtopic.php?t=12361](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.
