• Advertisement
Sign in to follow this  

slimdx drawing a square

This topic is 1867 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'm trying to render a square in SlimDX.
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);
}
}

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

  • Advertisement