Sign in to follow this  

Easy transperancy

This topic is 4840 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm quite new to DirectX and have a question. Right now I'm using a texture that's usually 100% opaque, but I want to do it just 50% opaque in the middle of the execution. What's the easiest way to do this? (DirectX 9.0 SDK)

Share this post


Link to post
Share on other sites
Easiest way I would say is setting the renderstate to alpha enabled: D3DDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE).
But if you need more control of it, it's getting slightly more complicated. Depends on what you need, I guess

Share this post


Link to post
Share on other sites
?? You use it. It's just the renderstate you change:
Something like this, for example:

pD3DDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);
pD3DDevice->SetRenderState(D3DRS_ZENABLE, TRUE);
pD3DDevice->SetTexture(0, pTexture);

Share this post


Link to post
Share on other sites
Oops, sorry I get the point. You need to set a little more then that:

// alpha on
pD3DDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);
// choose a blending type
pD3DDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
pD3DDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_ONE);
// culling off (to look right through things)
pD3DDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE);

There's a lot more to find on these blending options in msdn, for example.

Share this post


Link to post
Share on other sites
Okay, as I said: I am new to DirectX =).
Is it really that easy?
Mustn't I set any alpha-data or anything like that to the texture, cause the texture is just loaded from a standard 24-bit .bmp-file?

Share this post


Link to post
Share on other sites
No, that why I posted this (easy) solution. You don't need to change the texture, just the renderstate. Doesn't it work?

Share this post


Link to post
Share on other sites
you will have to have some kind of alpha data somewhere. Either in the texture or in the vertices. When you fill your vertex buffer, set the vertex colors to have 50% alpha. Then you can uyse the texture states and the render states.

first use the texture states:

SetTextureState( 0, D3DTSS_COLOROP, D3DTOP_SELECTARG1 );
SetTextureState( 0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1 );
SetTextureState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE );
SetTextureState( 0, D3DTSS_ALPHAARG1, D3DTA_DIFFUSE );

The above tells d3d to take teh alpha from the vertices and the color from the texture.

Then enable alpha blending like the previous poster already mentioned, and you should be good to go.

Share this post


Link to post
Share on other sites
Well, maybe it's a good idea to post some of the code (loading texture, device creation..). Unfortunately I gotta go catch a train, so I won't be able to help you out for the next, say 8 hours. Maybe someone else..
-edit-
Oops, someone already did :)

Share this post


Link to post
Share on other sites

This topic is 4840 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this