CODE THAT WORKS WITH FVF:
Render()...
dev.SetRenderTarget(0,_backBuffer);
dev.SetTexture(0,_renderTexture);
dev.SetStreamSource(0, vertBuffer, 0);
dev.VertexFormat = CustomVertex.TransformedTextured.Format;
dev.Indices = ib; dev.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, 4, 0, 2);
CODE THAT I WOULD LIKE TO WORK WITH VERTEXDECLARATION!:
Constructor()...
VertexElement[] elements = new VertexElement[]
{
new VertexElement(0, 0, DeclarationType.Float4,
DeclarationMethod.Default,
DeclarationUsage.Position, 0),
new VertexElement(0, 16, DeclarationType.Float2,
DeclarationMethod.Default,
DeclarationUsage.TextureCoordinate, 0),
VertexElement.VertexDeclarationEnd
};
decl = new VertexDeclaration(dev, elements);
Render()...
dev.SetRenderTarget(0,_backBuffer);
dev.SetTexture(0,_renderTexture);
dev.SetStreamSource(0, vertBuffer, 0);
//dev.VertexFormat = CustomVertex.TransformedTextured.Format;
dev.VertexDeclaration = decl;
dev.Indices = ib; dev.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, 4, 0, 2);
Vertex Buffer
vertBuffer = new VertexBuffer(typeof(PositionTexVertex), 4, dev, Usage.None, PositionTexVertex.FVF, Pool.Managed);
PositionTexVertex[] vbData = (PositionTexVertex[]) vertBuffer.Lock(0, typeof(PositionTexVertex), LockFlags.None, 4);
vbData[0].Position = new Vector4(0, dev.Viewport.Height, 0.0f, 1);
vbData[0].UV = new Vector2(0,1);
vbData[1].Position = new Vector4(0, 0, 0.0f, 1);
vbData[1].UV = new Vector2(0,0);
vbData[2].Position = new Vector4(dev.Viewport.Width, 0, 0.0f, 1);
vbData[2].UV = new Vector2(1,0);
vbData[3].Position = new Vector4(dev.Viewport.Width, dev.Viewport.Height, 0.0f, 1);
vbData[3].UV = new Vector2(1,1);
//Unlock the vb before you can use it elsewhere
vertBuffer.Unlock();
PositionTexVertex struct
public struct PositionTexVertex
{
public Vector4 Position;
public Vector2 UV;
//public static readonly VertexFormats FVF = VertexFormats.Position | VertexFormats.Texture0;
public static readonly VertexFormats FVF = CustomVertex.TransformedTextured.Format;
}
Basically,
CustomVertex.TransformedTextured.Format works but when trying to switch over to a vertexdeclaration, information is no longer synchronized?
Should both VertexDeclaration and FVF be used at the same time?
Thanks, V.