Sign in to follow this  
Estauns

SpriteFlags.DoNotModifyRenderStates and everything stops drawing...

Recommended Posts

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).
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();
}

It's baffling why it happens - any experts have any idea?

Share this post


Link to post
Share on other sites
According to the MSDN documentation:
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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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:

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.

Share this post


Link to post
Share on other sites
*bump*

Sorry to have to bump this - but I still can't solve it. Google reveals a whopping 3 results for "DoNotModifyRenderState" and 2 of them are the MSDN itself.

I know it's Managed Code, but surely someone using the Interface has tried to override the render states.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this