Archived

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

Jower

SetRenderState

Recommended Posts

Hey, I''m trying to do something like
LPDIRECT3DDEVICE9->SetRenderState(D3DRS_ALPHAFUNC, D3DCMP_EQUAL);
LPD3DXSPRITE->Draw(...);
LPDIRECT3DDEVICE9->SetRenderState(D3DRS_ALPHAFUNC, D3DCMP_NOTEQUAL);
LPD3DXSPRITE->Draw(...);
all with the same LPD3DXSPRITE and within the same Begin() End() and it dosen''t seem to work, it just uses the last one I set and draw with that. Isen''t there some way to change the renderstate during rendering ? Or do I have to do something like using multiple LPD3DXSPRITE''s ?

Share this post


Link to post
Share on other sites
Yes, you can change the state during rendering. Since you''re using the same sprite at the same position, it makes sense that the last one is what is shown since it overwrites the first one.

If you''re trying to do alpha blending, then there are a few more states you need to set up. You need to set things like the source color, destination color, where to get the alpha value from, etc... It''s all in the SDK docs.

neneboricua

Share this post


Link to post
Share on other sites
When you call Draw between Begin and End it does not actually draw anything, it simply batches the sprite to be drawn later. And when it draws later it uses the current settings. Try something like:


LPD3DXSPRITE->Begin()
LPDIRECT3DDEVICE9->SetRenderState(D3DRS_ALPHAFUNC, D3DCMP_EQUAL);
//Draw all sprites that use D3DCMP_EQUAL, many is better than few
LPD3DXSPRITE->Flush();
LPDIRECT3DDEVICE9->SetRenderState(D3DRS_ALPHAFUNC, D3DCMP_NOTEQUAL);
//Draw all sprites using D3DCMP_NOTEQUAL
LPD3DXSPRITE->End();


Flush forces the sprites to be rendered and End does an implicit Flush.


Stay Casual,

Ken
Drunken Hyena

[edited by - DrunkenHyena on April 20, 2004 1:42:42 PM]

Share this post


Link to post
Share on other sites