jocheng's picture

Drawing points

Hello,

I'm drawing points with this code:

 GL.Color3(Color.DarkViolet);
   GL.PointSize(2.0f);
 
   GL.Begin(BeginMode.Points);
   foreach (Coord pt in this.pts)
   {
    GL.Vertex3(pt.X, pt.Y, pt.Z);
   }

Now I want to draw the points with vbo.
But I'm getting lost in the buffers ;-)


Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
jocheng's picture

What i have so far is this: (please verify this solution, because I can see the points but I'M not sure that I make everything right)

 int VBOid;
 
// buffer
GL.GenBuffers(1, out VBOid);
GL.BindBuffer(BufferTarget.ArrayBuffer, VBOid);
GL.BufferData(BufferTarget.ArrayBuffer, (IntPtr)(_points.Length * sizeof(float)), _points, BufferUsageHint.StaticDraw);    // vbo
GL.BindBuffer(BufferTarget.ArrayBuffer, 0);
 
// draw
GL.BindBuffer(BufferTarget.ArrayBuffer, VBOid);  
GL.VertexPointer(3, VertexPointerType.Float, sizeof(float) * 3, 0);
GL.EnableClientState(ArrayCap.VertexArray);
GL.DrawArrays(BeginMode.Points, 0, this.pts.Length);
GL.BindBuffer(BufferTarget.ArrayBuffer, 0);
JTalton's picture

I believe...

If _points is a Vector3[] then
GL.BufferData(BufferTarget.ArrayBuffer, (IntPtr)(_points.Length * Vector3.SizeInBytes), _points, BufferUsageHint.StaticDraw); //

If _points is a float[] then
GL.DrawArrays(BeginMode.Points, 0, this.pts.Length / 3);

jocheng's picture

Thank you for your comment.

_points is a float[] and this.pts.Length  == _points.Length / 3

c2woody's picture

GL.BufferData(BufferTarget.ArrayBuffer, (IntPtr)(_points.Length * sizeof(float)), _points, BufferUsageHint.StaticDraw);
The second parameter should be the stride of an element, which is the stride of a vertex (3 floats) so use * sizeof(float) * 3 there.

Best to test your code with 1 and 2 points to assure correctness.