Skip to main content
GameDev.net gamedev.net
🔒 Locked

ALPHAOP madness

Started by Marc aka Foddex Apr 27, 2004 at 7:26 AM 3 replies 800+ views
Original Post
Marc aka Foddex
Marc aka Foddex
[I use DirectX 7!] Hi all, I''m kinda lost with the DirectX ALPHAOP render state. I''m used to OpenGL, where you can simply call functions like this:
//for alpha blending:

  glEnable(GL_BLEND);
  glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

//for alpha testing:

  glEnable(GL_ALPHA_TEST);
  glAlphaFunc(GL_EQUAL, reference_value);
With Direct3D I''ve found the following functions, which are pretty equal:
//for alpha blending:

  m_d3ddevice->SetRenderState( D3DRENDERSTATE_ALPHABLENDENABLE, TRUE );
  m_d3ddevice->SetRenderState( D3DRENDERSTATE_SRCBLEND,  D3DBLEND_SRCALPHA );
  m_d3ddevice->SetRenderState( D3DRENDERSTATE_DESTBLEND, D3DBLEND_INVSRCALPHA );

//for alpha testing:

  m_d3ddevice->SetRenderState( D3DRENDERSTATE_ALPHATESTENABLE, TRUE );
  m_d3ddevice->SetRenderState( D3DRENDERSTATE_ALPHAREF, reference_value);
  m_d3ddevice->SetRenderState( D3DRENDERSTATE_ALPHAFUNC, D3DCMP_EQUAL );
What I don''t understand though is that ALPHAOP stuff... how do I configure the ALPHAOP renderstate so that it works like OpenGL? In other words, is it possible to setup the ALPHAOP renderstate once, after which I can simply use the functions above to enable alpha testing/blending? I ask this, because I''ve found out that the following piece of code sets up the the ALPHAOP stuff for proper alpha blending:
  m_d3ddevice->SetTextureStageState(i, D3DTSS_ALPHAOP,   D3DTOP_SELECTARG1);
  m_d3ddevice->SetTextureStageState(i, D3DTSS_ALPHAARG1, D3DTA_DIFFUSE);
But the code for proper alpha testing is:
  m_d3ddevice->SetTextureStageState(i, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1 );
  m_d3ddevice->SetTextureStageState(i, D3DTSS_ALPHAARG1, D3DTA_TEXTURE );
  m_d3ddevice->SetTextureStageState(i, D3DTSS_ALPHAARG2, D3DTA_CURRENT );
Can this be combined? I want to be able to alpha test and alpha blend at the same time! I''m completely flabbergasted by the DX7 Help, which is not quite clear about all the different possibilities. Any help would be greatly appreciated! Marc
Endurion
Endurion
Should do the trick:


m_d3ddevice->SetTextureStageState(i, D3DTSS_ALPHAOP, D3DTOP_MODULATE);
m_d3ddevice->SetTextureStageState(i, D3DTSS_ALPHAARG1, D3DTA_TEXTURE);
m_d3ddevice->SetTextureStageState(i, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE);


Might do this as well:


m_d3ddevice->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_MODULATE );
m_d3ddevice->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_DIFFUSE );
m_d3ddevice->SetTextureStageState( 0, D3DTSS_COLORARG2, D3DTA_TEXTURE );


[edit: Show indexed sample code - get f***ed over with boldness, Want boldness, nought]


[edited by - Endurion on April 27, 2004 8:40:31 AM]
Fruny: Ftagn! Ia! Ia! std::time_put_byname! Mglui naflftagn std::codecvt eY'ha-nthlei!,char,mbstate_t>
Marc aka Foddex
Marc aka Foddex
Damn, I said it didn't work, but I was kinda blind. It works just fine Thanks a lot!!

[edited by - Marc aka Foddex on April 27, 2004 9:00:15 AM]
DrunkenHyena
DrunkenHyena
quote:

I ask this, because I''ve found out that the following piece of code sets up the the ALPHAOP stuff for proper alpha blending:
m_d3ddevice->SetTextureStageState(i, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1); m_d3ddevice->SetTextureStageState(i, D3DTSS_ALPHAARG1, D3DTA_DIFFUSE);
But the code for proper alpha testing is:
m_d3ddevice->SetTextureStageState(i, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1 ); m_d3ddevice->SetTextureStageState(i, D3DTSS_ALPHAARG1, D3DTA_TEXTURE ); m_d3ddevice->SetTextureStageState(i, D3DTSS_ALPHAARG2, D3DTA_CURRENT );



This is wrong. ALPHAOP determines where the alpha comes from, the renderstates say how it is used.

The first one sets the alpha to come from the DIFFUSE colour only. The second says the final alpha is the modulation of the texture alpha and the Current (lighting if lighting is on, otherwise DIFFUSE) colour.


Stay Casual,

Ken
Drunken Hyena
Stay Casual,KenDrunken Hyena</FON
Marc aka Foddex
Marc aka Foddex
DrunkenHyena, thanks for the explanation I''m not familiar with any such functionality in OpenGL, so I was kinda wondering what it did

Topic Locked

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

Sign in to reply to this topic.