Jump to content
  • Advertisement
Sign in to follow this  
Estauns

SpriteFlags.DoNotModifyRenderStates and everything stops drawing...

This topic is 4836 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
Advertisement
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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!