Advertisement Jump to content
Sign in to follow this  

D3D9 - Rendering image to texture problem

This topic is 1041 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello guys, this is like second time when Im asking for help on forums. But Im totally newbie in DX or D3D programming, so please dont see me like an total idiot, I know I am.


So I have the following code :

pTEX = player->m_pRank->GetTexture(m_bRank+1);
-D3DX_PI / 2.0f);
ICON._41 = vCOORDS.x
ICON._42 = vCOORDS.y
ICON._43 = vCOORDS.z;
ICON._41 = (ICON._41 - 7.0f);
Device->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_SELECTARG1);
Device->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
Device->SetTextureStageState( 0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1);
Device->SetTextureStageState( 0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE);

Device->SetRenderState(D3DRS_BLENDOP, D3DBLEND_ONE);

Device->SetStreamSource( 0, m_vTRECTVB.GetVB(), 0, sizeof(PVERTEX));
Device->SetTransform( D3DTS_WORLD, &ICON);
    Device->SetTexture(0, pTEX);
Device->DrawPrimitive( D3DPT_TRIANGLESTRIP, 0, 2);

It works well, but there is one problem. Im rendering it from image, which has got transparent background. But when I render it to the texture (I can post the code), it renders it to square, and there begin the problem. When I rotate the camera to some light or effect, you can see throught it (the light) and the corners are clearly visible. Illustration image : So my question is : Is it possible to render the texture with totally transparent background or is it possible to render the image into the texture, without making square for it, so the texture will be just the image? Thanks for reply.

Edited by Tomas123

Share this post

Link to post
Share on other sites

Welcome to the forums!


First off your not an idiot. A lot of us are still learning here. Though some may disagree; the simple fact that your programming implies that you are capable of logical deduction, and flow control which would imply that you have a high level thought process organically accelerated by a human brain, haha.


That being said the first thing I would check are your renderStates.


without making square for it, so the texture will be just the image?


That's a great question.Your referring to Vectorized graphics which is the use of polygons to represent images/textures in graphics. But, I feel if you check over your RenderStates, or your underlying texture itself you'll find that complete transparency with a image is completely possible, and that the use of vectorized graphics for this one case is a little overkill imho



Edited by markypooch

Share this post

Link to post
Share on other sites

you are either:


A) not rendering the background to texture correctly (IE transparent), or


B) not drawing the resulting quad correctly with alpha test.


try it with a known good sprite texture to eliminate your draw call as the problem.


then look to your code that renders the background of the quad to texture. do you fill the whole quad, or just overwrite non-transparent pixels? if the former, are you setting background pixels correctly?  if the latter, do you correctly set the background to transparent first? does a blank background quad exhibit the same graphics artifacts? 


also remember that sprite textures (IE alpha tested) can have issues with non transparent pixels too close to the edge, and with mipmap filtering creating dark edges where it blends image with background, and also that alpha test of "alpha==255 => dont draw" doesn't always work, and it needs to be more like "alpha>128 => don't draw"

Share this post

Link to post
Share on other sites

Sadly it still isnt working :( btw. Im creating 32x32 empty texture with D3DPOOL_DEFAULT and then I set stream source on it and draw the image into the texture. Isnt problem there? And thanks for help, everyone.

Share this post

Link to post
Share on other sites

I found out that if I use ZENABLE in RenderState D3DRS_ZENABLE then it seems like its almost fixed (the sfxes are like up the texture), but then I can see the texture throught walls. I think that the problem could be maybe in rendering of SFXes? Because it happens just with SFXes, OBJs, other textures are ok. If someone could really help me with this, I can show you rendering of SFX and all the codes of creating textures to PM. Thanks everyone for help.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!