D3D9 - Rendering image to texture problem

Started by
5 comments, last by Tomas123 8 years, 1 month ago

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 :


LPDIRECT3DTEXTURE9 pTEX = NULL;
pTEX = player->m_pRank->GetTexture(m_bRank+1);
 
 
D3DXMATRIX ICON;
D3DXMATRIX vROTACE;
 
D3DXMatrixScaling(
&vROTACE,
32,
32,
32);
 
D3DXMatrixRotationX(
&vROTACE,
-D3DX_PI / 2.0f);
ICON *= vROTACE;
 
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_ALPHABLENDENABLE,TRUE);
Device->SetRenderState(D3DRS_BLENDOP, D3DBLEND_ONE);
Device->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
Device->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
             

 
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 : http://prntscr.com/advv5q 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.

Advertisement

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

Marcus

Thank you, but which render states should I use? The texture is really transparent : http://prntscr.com/adwn2p But when I look at some SFXes or something like that, you can see the corners http://prntscr.com/adwnjj . And really thanks for answer, I appreciate it.

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"

Norm Barrows

Rockland Software Productions

"Building PC games since 1989"

rocklandsoftware.net

PLAY CAVEMAN NOW!

http://rocklandsoftware.net/beta.php

Your D3DRS_BLENDOP is set to D3DBLEND_ONE, but it can only be one of the following: https://msdn.microsoft.com/en-us/library/windows/desktop/bb172509%28v=vs.85%29.aspx

You most likely want D3DBLENDOP_ADD :)

.:vinterberg:.

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.

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.

This topic is closed to new replies.

Advertisement