Alpha transparency in texture quads?

Started by
4 comments, last by Subconscious 20 years, 2 months ago
Alright, so I finally finished my texture quad engine (thanks to some help from people here) and it is fully optimized using dynamic vertex buffers. The frame rates are nearly 3 times higher than my D3DXSprite engine but I''m left with one last problem... How do I set the alpha transparency of the texture quad? With D3DXSprite, I would just change the alpha section of the color variable you pass to the Draw function... in my texture quad engine, my vertex format has a color to it, but when I set all the vertexes of a sprite to a color, it doesn''t take into account the alpha part of that color at all and draws them all at 100%. Is there anything special I have to do to get directx to look at the alpha part of the color set to my vertexes?
Advertisement
make sure alpha blend is on. If your FVF has color then set the alpha value of your vertexes (you have to lock them first). If your are doing alpha by binding a material you need to enable lighting. Also you need to set up you src and destination blend states and possibly texture stage (it prob defaults ok)
here are some key words for the dxsdk docs
D3DRS_SRCBLEND
D3DRS_DESTBLEND
D3DRS_ALPHABLENDENABLE
I know that you have to set those in order to alpha blend, right now I''m using:
pd3dDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);
pd3dDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
pd3dDevice->SetRenderState(D3DRS_DESTBLEND,D3DBLEND_INVSRCALPHA);

the alpha blending works fine when it''s part of the actual texture, but when I try to set the alpha transparency of a vertex, it doesn''t change it at all. I''ve looked through the sdk docs and they''re completley unhelpful with this...
You also need to tell the texture stages where to take the color and alpha from and how to mix the together.

Use
From DX8:

SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE );
SetTextureStageState( 0, D3DTSS_COLORARG2, D3DTA_DIFFUSE );
SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_MODULATE );

SetTextureStageState( 0, D3DTSS_ALPHAARG1, D3DTA_DIFFUSE );
SetTextureStageState( 0, D3DTSS_ALPHAARG2, D3DTA_TEXTURE );
SetTextureStageState( 0, D3DTSS_ALPHAOP, D3DTOP_MODULATE );

This tells D3D to take the color and alpha values from texture and from the vertex and modulate (multiply) them. This way you can also set the colors of your quads to tint your textures.

Fruny: Ftagn! Ia! Ia! std::time_put_byname! Mglui naflftagn std::codecvt eY'ha-nthlei!,char,mbstate_t>

thank you very much, that''s exactly what I needed
quote:
the alpha blending works fine when it''s part of the actual texture, but when I try to set the alpha transparency of a vertex, it doesn''t change it at all. I''ve looked through the sdk docs and they''re completley unhelpful with this...


Vertex colors are used when d3dlighting is off. When it''s on it uses the material that''s set instead. And you will have to do a
D3DTA_DIFFUSE for one of the alphaargs so that it gets used.

This topic is closed to new replies.

Advertisement