Archived

This topic is now archived and is closed to further replies.

Coder10000

DirectX: Textures & Alpha = ???

Recommended Posts

Hi, I''m trying to get a texture half translucent by using a triangle with a half translucent color (1.0, 1.0, 1.0, 0.5), but all I get is directx blending the texture with the triangle, just like rendering the texture into the backbuffer and then drawing the triangle without the texture. thanks

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Well sorry, I have no solution for that. I just want to say something to Kneelz and python_regious.
Coder10000 has a problem with DirectX. So I think either you help him with this problem or you don''t say anything. I think it is no solution to say that he should use a software renderer or OpenGL. Because that doesn''t solve his problem with DirectX. He learned DirectX, DirectX is used by many people and DirectX will stay for a long time, so why should he change to OpenGL ? Just because of one problem ? I really hate those kind of answers. It is as if the engine of your car is broken and the mechanic says that you should use a bike instead. So please, give an answer to his problem or don''t post.

Share this post


Link to post
Share on other sites
I''m not sure I understand what you are doing, but did you set up D3DRS_SRCBLEND / D3DRS_DSTBLEND render states?

< oscp.pochta.org >

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
The last poster is right. It has something to do with the DEST and SRC alpha settings. Sorry I can''t be more specific, but look those up in the SDK and you should figure it out.

Share this post


Link to post
Share on other sites
I''ve already lookup these settings. Setting them like this:

lpD3DDevice->SetRenderState (D3DRENDERSTATE_SRCBLEND, D3DBLEND_SRCALPHA);
lpD3DDevice->SetRenderState (D3DRENDERSTATE_DESTBLEND, D3DBLEND_INVSRCALPHA);

does nothing, because DirectX ignores the alpha value in the color of the triangle and the texture is completely opaque.

If I add: lpD3DDevice->SetTextureStageState (0, D3DTSS_ALPHAOP, D3DTOP_BLENDDIFFUSEALPHA);

DirectX blends the texture with the triangle and not with the backbuffer (like GL_BLEND mode in OpenGL, I know it works there using GL_MODULATE).

Do I have to change all alpha bits in the texture???

Coder10000

Share this post


Link to post
Share on other sites
Coder10000:
I''m not sure why you''re having problems. Maybe you''re leaving out some important information. I set up my program exactly as you described, and everything looks okay. Here are the only lines I had to change (in Visual Basic):

objD3DDev.SetTextureStageState 0, D3DRENDERSTATE_SRCBLEND, D3DBLEND_SRCALPHA
objD3DDev.SetTextureStageState 0, D3DRENDERSTATE_DESTBLEND, D3DBLEND_INVSRCALPHA
objD3DDev.SetTextureStageState 0, D3DTSS_ALPHAOP, D3DTOP_BLENDDIFFUSEALPHA

Maybe this is a silly question, but did you also set D3DRENDERSTATE_ALPHAENABLE to True?

I normally just use D3DBLEND_ONE for both SRC and DEST. You don''t need to set an ALPHAOP for this. It doesn''t work very well for things like colored glass, but it''s perfect for explosions and other flashy effects. Here''s how I do it:

objD3DDev.SetTextureStageState 0, D3DRENDERSTATE_SRCBLEND, D3DBLEND_ONE
objD3DDev.SetTextureStageState 0, D3DRENDERSTATE_DESTBLEND, D3DBLEND_ONE

Hope this helps.

Share this post


Link to post
Share on other sites
Code10000/
I don''t know whether that method will work, or can be made to work, I don''t know enough about alpha-blending, but all you need to make a triangle semi-transparent is-

g_pD3DDevice->SetRenderState ( D3DRS_ALPHABLENDENABLE, TRUE );
g_pD3DDevice->SetRenderState ( D3DRS_SRCBLEND, D3DBLEND_SRCCOLOR );
g_pD3DDevice->SetRenderState ( D3DRS_DESTBLEND, D3DBLEND_DESTCOLOR );

Once you''ve drawn it, turn alpha-blending off. Experiment with the arguments to get the effect you''re after.

python_regious/
I presume every time you see a post from someone having a problem with OpenGL you tell them to switch to D3D then? I agree with Anonymous Poster, you''re answer is unhelpful.

Share this post


Link to post
Share on other sites
Oops, just found a stupid bug in my engine. The result was that my engine didn''t switch textures. And I''m asking myself where the water has gone and why only see the environment map.

But still thanks ...

Share this post


Link to post
Share on other sites