Archived

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

alpha blending in direct3d question

This topic is 5706 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 am trying to implement alpha blending in Direct3D (7.0). What I ideally want is to give an alpha value that would correspond to the level of translucency. Say 0.0 would be totally clear and 1.0 would be totally visable, 0.5 partially visible with whatever lies behind the object partially visable (like say a stained glass window or something). To make a long story short, I can''t figure out how to do this. I''ve been messing around with the renderstate and texturestate options for hours. I suppose I could set the individual alpha values in the texture, but I want to be able to change them on the fly, so wouldn''t changing all the alpha values for a texture be very slow? Also, then I couldn''t use the same texture with different levels of translucency on different objects. It almost seems like 3ddevice->SetRenderState(D3DRENDERSTATE_TEXTUREFACTOR, color); is what I want, but this didn''t seem to work. So basically, is there even a way to do this? Thanks in advance!!!!!!

Share this post


Link to post
Share on other sites

I don''t have DX7 docs handy, but you''re right about setting the TEXTUREFACTOR. In rough pseudo code you also have to:
SRS=SetRenderState
STSS=SetTextureStageState

STSS(0,alpha1,tfactor)
STSS(0,alphaop,select arg 1)

STSS(0,color1,texture)
STSS(0,colorop,select arg 1)

SRS(alphablending, TRUE)


Stay Casual,

Ken
Drunken Hyena

Share this post


Link to post
Share on other sites
Thanks for the response!

So I tried doing that. This is the code I''m using:

if(SUCCEEDED(d3d_device->BeginScene()))
{
d3d_device->SetRenderState(D3DRENDERSTATE_ALPHABLENDENABLE, TRUE);

d3d_device->SetRenderState(D3DRENDERSTATE_TEXTUREFACTOR, D3DRGB(0.5f, 0.5f, 0.5f));

d3d_device->SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
d3d_device->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_SELECTARG1);

d3d_device->SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_TFACTOR);
d3d_device->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1);

d3d_device->SetTexture(0, lpTexture);
d3d_device->DrawPrimitive(D3DPT_TRIANGLESTRIP, D3DFVF_LVERTEX, &vertices, 4, 0);

d3d_device->SetRenderState(D3DRENDERSTATE_ALPHABLENDENABLE, FALSE);
}

But this isn''t working. It just draws the textures regularly. (I am just drawing three textured squares) Would this have something to do with how I created the textures or how lighting is set up? Or the types of vertices (LVERTEX) I''m using?

Any help would be most appreciated!

Share this post


Link to post
Share on other sites

quote:

d3d_device->SetRenderState(D3DRENDERSTATE_TEXTUREFACTOR, D3DRGB(0.5f, 0.5f, 0.5f));


Your not specifying the alpha value here, so it''s probably defaulting to full opaqueness. Since this is the D3D7 docs, I don''t know exactly the answer but there should be something like a D3DARGB macro. Alternately you can probably just give it as a hex value 0xAARRGGBB.



Stay Casual,

Ken
Drunken Hyena

Share this post


Link to post
Share on other sites