Copy RGBA pixels directly to target texture without blending

"stewambo" <[email protected]> Thu, 16 Mar 2017 15:11:01 +0000
Newsgroups gmane.comp.lib.sdl
Message-ID <[email protected]>
--===============2803949813339468663==
Content-Type: multipart/alternative;
	boundary="=_d725209685b8bc3ecdf2d2f381069c1a"

--=_d725209685b8bc3ecdf2d2f381069c1a
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 7bit

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 ]

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 ]

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 :)





--=_d725209685b8bc3ecdf2d2f381069c1a
Content-Type: text/html; charset="ISO-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<style type=3D"text/css">
<!--

/*
  The original subSilver Theme for phpBB version 2+
  Created by subBlue design
  http://www.subBlue.com

  NOTE: These CSS definitions are stored within the main page body so that =
you can use the phpBB2
  theme administration centre. When you have finalised your style you could=
 cut the final CSS code
  and place it in an external file, deleting this section to save bandwidth=
.
*/


 /* General page style. The scroll bar colours only visible in IE5.5+ */
body {
	background-color: #;
	font-family: ;
	font-size: 11;
	color: #;
}

/* General font families for common tags */
font,th,td,p { font-family:  }
p, td		{ font-size : 11; color : #; }
a:link,a:active,a:visited { color : #; }
a:hover		{ text-decoration: underline; color : #; }
hr	{ height: 0px; border: solid # 0px; border-top-width: 1px;}
h1,h2		{ font-family: "Trebuchet MS", Verdana, Arial, Helvetica, sans-serif=
; font-size : 22px; font-weight : bold; text-decoration : none; line-height=
 : 120%; color : #000000;}


/* This is the border line & background colour round the entire page */
.bodyline	{ background-color: #; border: 1px # solid; }


/* General text */
.gen { font-size : 12px; }
.genmed { font-size : 11px; }
.gensmall { font-size : 10px; line-height: 12px}
.gen,.genmed,.gensmall { color : #; }
a.gen,a.genmed,a.gensmall { color: #; text-decoration: none; }
a.gen:hover,a.genmed:hover,a.gensmall:hover	{ color: #; text-decoration: un=
derline; }


/* Forum title: Text and link to the forums used in: index.php */
.forumlink		{ font-weight: bold; font-size: 12px; color : #; }
a.forumlink 	{ text-decoration: none; color : #; }
a.forumlink:hover{ text-decoration: underline; color : #; }


/* The content of the posts (body of text) */
.postbody { font-size : 12px; line-height: 18px}
a.postlink:link	{ text-decoration: none; color : # }
a.postlink:visited { text-decoration: none; color : #; }
a.postlink:hover { text-decoration: underline; color : #}


/* Quote & Code blocks */
.code {
	font-family: ; font-size: 11px; color: #3FB753;
	background-color: #; border: #; border-style: solid;
	border-left-width: 1px; border-top-width: 1px; border-right-width: 1px; bo=
rder-bottom-width: 1px
}

.quote {
	font-family: ; font-size: 11px; color: #444444; line-height: 125%;
	background-color: #; border: #; border-style: solid;
	border-left-width: 1px; border-top-width: 1px; border-right-width: 1px; bo=
rder-bottom-width: 1px
}

-->
</style>
</head>
	<body>

	<div class=3D"postbody">Hello,<br />
I have a texture with static (or streaming) access and I need to render oth=
er stuff onto it, so I need to convert it to a target-texture. Therefor I j=
ust created an empty texture with SDL_TEXTUREACCESS_TARGET and set it as re=
ndering target, but when i render my semi-transparent static/streaming text=
ure onto it the black transparent background of the target-texture bleeds i=
nto the transparent part of my original texture <br />
<br />
Original image:<br />
<img src=3D"http://i.imgur.com/5ByTcgv.png" border=3D"0" /><br />
<br />
Left: original texture rendered directly; <br />
Right: target-texture with original texture rendered ontop (obviously not t=
he same, but darker)<br />
<img src=3D"http://i.imgur.com/z7ukpYr.png" border=3D"0" /><br />
<br />
Code to create the image above:<br />
<div align=3D"center"><table width=3D"90%" align=3D"center" cellspacing=3D"=
1" cellpadding=3D"2" border=3D"0" class=3D"code"><br />=0D<tr> <br />=0D	<t=
d class=3D"code_header" align=3D"left">Code:</td><br />=0D</tr><br />=0D<tr=
><br />=0D	<td class=3D"code" align=3D"left"><br />
SDL_Surface* surface =3D SDL_ConvertSurfaceFormat&#40;IMG_Load&#40;"D&#58;/=
Documents/Visual Studio 2015/Projects/SDLTest/resources/textures/gradientTe=
xture.png"&#41;, SDL_PIXELFORMAT_RGBA8888, NULL&#41;;<br />
SDL_Texture* staticTexture =3D SDL_CreateTextureFromSurface&#40;renderer, s=
urface&#41;;<br />
SDL_Texture* targetTexture =3D SDL_CreateTexture&#40; renderer, SDL_PIXELFO=
RMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, 50, 50 &#41;; <br />
<br />
SDL_SetRenderTarget&#40;renderer, targetTexture&#41;; <br />
SDL_SetTextureBlendMode&#40;targetTexture, SDL_BLENDMODE_BLEND&#41;;<br />
SDL_RenderCopy&#40;renderer, staticTexture, NULL, NULL&#41;;<br />
SDL_SetRenderTarget&#40;renderer, NULL&#41;;<br />
<br />
SDL_Rect rect0&#123; 50,50,50,50 &#125;;<br />
SDL_RenderCopy&#40;renderer, staticTexture, NULL, &rect0&#41;;<br />
SDL_Rect rect1&#123; 100,50,50,50 &#125;;<br />
SDL_RenderCopy&#40;renderer, targetTexture, NULL, &rect1&#41;;<br />
</td><br />=0D	</tr><br />=0D</table></div><br />
<br />
The solution to my problem in <a href=3D"https://forums.libsdl.org/viewtopi=
c.php?t=3D12064" target=3D"_blank">this topic</a> 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...<br />
<br />
<span style=3D"font-style: italic"><span style=3D"font-weight: bold">So how=
 can i get my target-texture to look exactly like my original texture, or i=
s there a way to copy the RGBA information directly into the new texture wi=
thout the need to render it using a blend mode?<br />
<br />
Thanks <img src=3D"http://forums.libsdl.org/images/smiles/icon_smile.gif" a=
lt=3D"Smile" border=3D"0" /></span></span></div>
	</body>
</html>

--=_d725209685b8bc3ecdf2d2f381069c1a--

--===============2803949813339468663==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
SDL mailing list
[email protected]
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

--===============2803949813339468663==--