Jump to content

  • Log In with Google      Sign In   
  • Create Account

slimdx drawing a square


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 szpak234   Members   -  Reputation: 105

Like
0Likes
Like

Posted 13 December 2012 - 01:31 AM

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.

Sponsor:

#2 Gavin Williams   Members   -  Reputation: 664

Like
2Likes
Like

Posted 13 December 2012 - 05:20 AM

Draw(int vertexCount, int startVertexLocation)

... vertex count, not primitive count.

#3 szpak234   Members   -  Reputation: 105

Like
0Likes
Like

Posted 13 December 2012 - 09:39 AM

it was 1 am, now it's clear. Thx anyway




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS