Sign in to follow this  
szpaq234

slimdx drawing a square

Recommended Posts

I'm trying to render a square in SlimDX.
Code:
[CODE]
public class Square
{
public Buffer vertexBuffer;
public Square(Vector3 origin, float edge, Device device)
{
DataStream Vertices;
Vertices = new DataStream(12 * 5, true, true);
Vertices.Write(new Vector3(1, 1, 0));
Vertices.Write(new Vector3(-1, 1, 0));
Vertices.Write(new Vector3(-1, -1, 0));
Vertices.Write(new Vector3(1, -1, 0));
Vertices.Write(new Vector3(1, 1, 0));
Vertices.Position = 0;
vertexBuffer = new Buffer(device, Vertices, 12 * 5, ResourceUsage.Default, BindFlags.VertexBuffer, CpuAccessFlags.None, ResourceOptionFlags.None, 0);
Vertices.Close();
}
public void Draw(Device device)
{
device.ImmediateContext.InputAssembler.PrimitiveTopology = PrimitiveTopology.LineStrip;
device.ImmediateContext.InputAssembler.SetVertexBuffers(0, new VertexBufferBinding(vertexBuffer, 12, 0));
device.ImmediateContext.Draw(4, 0);
}
}
[/CODE]
However, only first four elements of DataStream Vertices are rendered. For square, it corresponds to 3 lines. I tried other PrimitiveTopology like TriangleList, TriangleStrip or PointList, they all behave the same - load only first 4 vertices no matter how big original DataStream is. I remember to create vertexBuffer with the same size as DataStream and tried to make it bigger as well.

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