Estauns Posted June 22, 2005 Posted June 22, 2005 Hi guys, I'm new here. I can normally struggle through these things, but this one has me stumped. I'm using the Sprite interface and I'm trying to take control of the render-states manually, so that I can set DestinationBlend to Blend.One, to get that neat 'intensity' effect when you're drawing a particle system. The kind of effect that makes one particle the default colour, but the more particles you add to the same spot, the brighter it is. Anyways, that's mostly irrelevant. Here's the code I'm using: 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.One; if(_renderList.Count > 0) { _renderList.Sort(_renderInformationComparer); 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); } catch { MessageBox.Show("Error with Sprite.Begin()"); } for(int i = 0; i < _renderList.Count; ++i) { RenderInformation renderInformation = (RenderInformation)_renderList[i]; _sprite.Draw2D(_textureManager.GetTexture(_device, renderInformation.Texture), Rectangle.Empty, Rectangle.Empty, new Point(16, 16), 0, new Point(renderInformation.X, renderInformation.Y), Color.FromArgb(255, 255, 255, 255).ToArgb()); } _sprite.End(); } _device.EndScene(); _device.Present(); _renderList.Clear(); I'm using the VertexElement / VertexDeclaration as described on these two pages: http://msdn.microsoft.com/archive/default.asp?url=/archive/en-us/directx9_m_dec_2004/directx/ref/ns/microsoft.directx.direct3d/e/spriteflags/spriteflags.asp 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. http://msdn.microsoft.com/archive/default.asp?url=/archive/en-us/directx9_m_dec_2004/directx/ref/ns/microsoft.directx.direct3d/s/vertexelement/vertexelement.asp _renderList is just my list for sorting my sprites, and it works fine if I change the SpriteFlags to something like AlphaBlend or None, but that doesn't let me control the render-states. Any advice here is very welcome. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.