Hi I’m kind of new to using Dirext X and so far as I’m sure is common I’m finding the huge number of options to be quite staggering. One thing I’ve noticed is that keeping track of what options are on and which are off seems to be a huge problem for me so far. Take this following code for example:
device.RenderState.SourceBlend = Blend.SourceAlpha
device.RenderState.DestinationBlend = Blend.InvSourceAlpha
device.RenderState.AlphaBlendEnable = True
device.TextureState(0).AlphaOperation = TextureOperation.BlendDiffuseAlpha
device.Transform.World = PosMatrix
obj.DrawObject(device, Drawing.Color.FromArgb(100, obj.OverLayColor))
This seems to work great but when I next draw something I’m using the options I have set for the last thing I draw in my scene. What if I need different options? The question boils down to: Do I have to reset every option every time I change one to draw something?
Dim previousAlpha As Boolean = device.RenderState.AlphaBlendEnable
Dim SourceBlend As Blend = device.RenderState.SourceBlend
Dim DestinationBlend As Blend = device.RenderState.DestinationBlend
Dim AlphaOperation As TextureOperation = device.TextureState(0).AlphaOperation
device.RenderState.SourceBlend = Blend.SourceAlpha
device.RenderState.DestinationBlend = Blend.InvSourceAlpha
device.RenderState.AlphaBlendEnable = True
device.TextureState(0).AlphaOperation = TextureOperation.BlendDiffuseAlpha
device.Transform.World = PosMatrix
obj.DrawObject(device, Drawing.Color.FromArgb(100, obj.OverLayColor))
device.RenderState.AlphaBlendEnable = previousAlpha
device.RenderState.SourceBlend = SourceBlend
device.RenderState.DestinationBlend = DestinationBlend
device.TextureState(0).AlphaOperation = TextureOperation.BlendDiffuseAlpha
Or is there a better way?
Looking for any advice. Thank you.