Easy transperancy

Started by
9 comments, last by _0D_0A 19 years, 7 months ago
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)
Advertisement
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
Well, what do I do after setting D3DDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE) to actually make the texture more transperant?
?? 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);

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.
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?
No, that why I posted this (easy) solution. You don't need to change the texture, just the renderstate. Doesn't it work?
No, not really. I'm probably doing something wrong somewhere else in my code then.
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.
[size=2]aliak.net
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 :)

This topic is closed to new replies.

Advertisement