D3DXSprite and alpha blend
When rendering alpha-blended sprites you send D3DXSPRITE_ALPHABLEND in the call to D3DXSprite->Begin(), sounds easy yes? So I thought that omitting this flag (using 0) would prevent alpha-blend from being used. Not as easy, if alpha blending has been enabled by some previous rendering the sprite will still render it as alphablended. Is this really the desired behaviour, having to manually disable alpha blend before the sprite Begin-End calls?
Give a man a fish and you feed him for a day.
Teach a man to fish and you feed him for a lifetime.
Yes, since alpha blending is set using SetRenderState().
If you set alpha blending prior to D3DXSprite render calls, it is possible, although improbable that D3DXSprite will turn it off after the call.
Direct3D is a pure state machine in that any state you set lasts until you 'un-set' it.
This is why you should turn alpha on, render all alpha objects, and then turn it off. This guarantees that render states won't be 'left over' in future calls.
You can also use state blocks to control render states. You think alpha blending is bad wait until you try using SetTextureStageState(). Those states are also left as-is in the next render so you must reset them to what you want prior to rendering your next object.
DirectX 10's non-FFP will solve most of this issue and shader's for DX9 already address this.
For now look into Direct3D render state blocks and effects.
Last edited by VirtualAce; 05-23-2006 at 04:57 AM.