Skip to main content
gamedev.net
🔒 Locked

Panic! Alpha blend!

Started by Enselic 5 replies 500+ views
Original Post
Enselic
Enselic
I am getting nuts. I have searched GameDev, Google and browsed CodeSampler and yet my wanted alpha blend effect fails. What I have is a HUD with grey-scale ''char-quads'' i.e. polygons each with a char textured. The vertices for the char-quads have a diffuse value so I can make the chars whatever color I want (and also add alpha values I think). Now I want these chars to be slighly transparent to the "world" so I render the world then the HUD but how do I blend properly? I have tried several dest and source blend values and alpha testing here and alpha testing there but either the blend is way too much or there is no blend at all. ANY help apprichiated. ____________________ ____ ___ __ _ Enselic''s Corner - My site. Go test my game Spatra and see if you can beat it onto the Official Spatra Top 10. CodeSampler.com - Great site with source for specific tasks in DirectX and OpenGL.
Zimans
Zimans
To enable alpha blending:
ret = D3DDevice->SetRenderState (D3DRS_ALPHABLENDENABLE, TRUE);
ret = D3DDevice->SetRenderState (D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
ret = D3DDevice->SetRenderState (D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);

To allow the Alpha component of your Diffuse to control alpha level along with the textures alpha:
ret = D3DDevice->SetTextureStageState (0, D3DTSS_ALPHAOP, D3DTOP_MODULATE);
ret = D3DDevice->SetTextureStageState (0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE);
ret = D3DDevice->SetTextureStageState (0, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE);

-Zims
Enselic
Enselic
Thanks for the reply!

That worked precisely as I wanted with one exception; the black part of the char quad is not totally transparent any longer.

Anyone know how to fix that?



____________________ ____ ___ __ _
Enselic''s Corner - My site. Go test my game Spatra and see if you can beat it onto the Official Spatra Top 10.
CodeSampler.com - Great site with source for specific tasks in DirectX and OpenGL.
Enselic
Enselic
Well, if you can give me a link where I find the information I wanted I''d be glad. I knew that it says how to do indirectly but that another thing. And if I set alpha to 0 I won''t see a thing which is not what I want. I wonder if there is any way to let black parts disappear and other colors to follow the alpha on the diffuse data...


____________________ ____ ___ __ _
Enselic''s Corner - My site. Go test my game Spatra and see if you can beat it onto the Official Spatra Top 10.
CodeSampler.com - Great site with source for specific tasks in DirectX and OpenGL.
Enselic
Enselic
Got it working now. I simply added alpha data to the font-texture. And experimented with a few texture and rendering states.

Thanks for the help.


____________________ ____ ___ __ _
Enselic''s Corner - My site. Go test my game Spatra and see if you can beat it onto the Official Spatra Top 10.
CodeSampler.com - Great site with source for specific tasks in DirectX and OpenGL.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.