DirectX: Textures & Alpha = ???

Started by
8 comments, last by Coder10000 23 years ago
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
Advertisement
Uhmm, don''t know.

I would suggest using a software renderer to avoid those problems!
Use opengl, it works in that.
If at first you don't succeed, redefine success.
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.
I''m not sure I understand what you are doing, but did you set up D3DRS_SRCBLEND / D3DRS_DSTBLEND render states?

< oscp.pochta.org >
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.
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
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.

GDNet+. It's only $5 a month. You know you want it.

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.
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 ...

This topic is closed to new replies.

Advertisement