Hi guys, Im new here. I can normally struggle through these things, but this one has me stumped.
Im using the Sprite interface and Im 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 youre 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, thats mostly irrelevant.
Heres the code Im using:
Im using the VertexElement / VertexDeclaration as described on these two pages:
http://msdn.microsoft.com/archive/d...irectx.direct3d/e/spriteflags/spriteflags.asp
http://msdn.microsoft.com/archive/d...tx.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 doesnt let me control the render-states.
Any advice here is very welcome.
Im using the Sprite interface and Im 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 youre 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, thats mostly irrelevant.
Heres the code Im using:
Code:
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();
Im using the VertexElement / VertexDeclaration as described on these two pages:
http://msdn.microsoft.com/archive/d...irectx.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/d...tx.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 doesnt let me control the render-states.
Any advice here is very welcome.