public override void Update()
{
if(_device == null)
return;
_device.Clear(Direct3D.ClearFlags.Target, Color.Aquamarine, 1.0F, 0);
_device.BeginScene();
_device.RenderState.Lighting = false;
_device.RenderState.AlphaBlendEnable = true;
_device.RenderState.AlphaSourceBlend = Direct3D.Blend.SourceAlpha;
_device.RenderState.AlphaDestinationBlend = Direct3D.Blend.InvSourceAlpha;
_device.RenderState.SourceBlend=Direct3D.Blend.SourceAlpha;
_device.RenderState.DestinationBlend=Direct3D.Blend.InvSourceAlpha;
try
{
_sprite.Begin(Direct3D.SpriteFlags.DoNotModifyRenderState);
}
catch
{
MessageBox.Show("Begin Exception");
}
for(int i = 0; i < 5; ++i)
{
_sprite.Draw2D(_texture, Rectangle.Empty, Rectangle.Empty, new Point(16, 16), 0, new Point(16, 16), Color.FromArgb(255, 255, 255, 255).ToArgb());
}
_sprite.End();
_device.EndScene();
_device.Present();
}
SpriteFlags.DoNotModifyRenderStates and everything stops drawing...
I need to take control of the renderstates to achieve some effects (blending for a particle system), but when I specify DoNotModifyRenderStates, all of my sprites just stop drawing. No exceptions or anything - anyone have any idea? If I change it to like SpriteFlags.None, then it works fine (all my stuff shows up).
It's baffling why it happens - any experts have any idea?
According to the MSDN documentation:
I would read this to assume that the sprite component will not set up any, even the basic, device states. That is, you take responsibility for configuring the device states.
My guess is that you're not doing this (looking at your code seems to back this up..) and consequently the device isn't in the correct state and nothing renders.
If you turn up the debug output (have you done this?) you might well find that it's warning you that it's not happy about something - or failing for a specific reason..
I'm not a MDX programmer (my copy of VStudio is too old [sad]) so the finer implementation details of the above quote don't mean much to me - but I'd suggest that's where you start looking [smile]
hth
Jack
Quote:Specifies no changes to the device render state when Sprite.Begin is called. The device is assumed to be in a valid state to draw vertices when the VertexElement.UsageIndex property equals 0 and VertexElement.DeclarationUsage is set to DeclarationUsage.Position, DeclarationUsage.TextureCoordinate, or DeclarationUsage.Color.
I would read this to assume that the sprite component will not set up any, even the basic, device states. That is, you take responsibility for configuring the device states.
My guess is that you're not doing this (looking at your code seems to back this up..) and consequently the device isn't in the correct state and nothing renders.
If you turn up the debug output (have you done this?) you might well find that it's warning you that it's not happy about something - or failing for a specific reason..
I'm not a MDX programmer (my copy of VStudio is too old [sad]) so the finer implementation details of the above quote don't mean much to me - but I'd suggest that's where you start looking [smile]
hth
Jack
Quote:I need to take control of the renderstates to achieve some effects (blending for a particle system)
Just re-read this bit and your source fragment... have you considered using SpriteFlags.AlphaBlend?? from looking at the documentation that might well do what you seem to be trying...
hth
Jack
Thanks jollyjeffers for pointing that out to me about the VertexDeclaration being needed. I've gone ahead and modified my code, but it's still not showing up. =/
Here's the new code:
Here's where I got the code from.
As far as AlphaBlend goes, I need to change the Desitnation blend to Blend.One from InvSourceAlpha, and I can't control the render states between the Begin and End call. I'm trying to get a particle 'glow' effect, so that stuff looks more intense.
Here's the new code:
try{ // Create the vertex element array. Direct3D.VertexElement[] elements = new Direct3D.VertexElement[] { new Direct3D.VertexElement(0, 0, Direct3D.DeclarationType.Float3, Direct3D.DeclarationMethod.Default, Direct3D.DeclarationUsage.Position, 0), new Direct3D.VertexElement(0, 12, Direct3D.DeclarationType.Float3, Direct3D.DeclarationMethod.Default, Direct3D.DeclarationUsage.Normal, 0), new Direct3D.VertexElement(0, 24, Direct3D.DeclarationType.Float2, Direct3D.DeclarationMethod.Default, Direct3D.DeclarationUsage.TextureCoordinate, 0), Direct3D.VertexElement.VertexDeclarationEnd }; // Use the vertex element array to create a vertex declaration. Direct3D.VertexDeclaration decl = new Direct3D.VertexDeclaration(_device, elements); _device.VertexDeclaration = decl; _sprite.Begin(Direct3D.SpriteFlags.DoNotModifyRenderState);}
Here's where I got the code from.
As far as AlphaBlend goes, I need to change the Desitnation blend to Blend.One from InvSourceAlpha, and I can't control the render states between the Begin and End call. I'm trying to get a particle 'glow' effect, so that stuff looks more intense.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement