
VBO DrawArrays
Posted Saturday, 27 February, 2010 - 15:30 by russell inI want to draw a lot of lines by points using VBOs. I use following code:
public void DrawLineVBO(List<Point> points, Color color) { GL.Color3(color); int[] vertices = new int[points.Count * 2]; int i = 0; foreach (Point point in points) { vertices[i] = point.X; vertices[++i] = point.Y; i++; } GL.VertexPointer(2, VertexPointerType.Int, 0, vertices); GL.EnableClientState(EnableCap.VertexArray); GL.DrawArrays(BeginMode.Lines, 0, vertices.Length); GL.DisableClientState(EnableCap.VertexArray); }
If I call this code one time it works ok. But if I call this code many times (>10) I get AccessViolationException: "Attempted to read or write protected memory. This is often an indication that other memory is corrupt." How can I solve this problem?


Comments
Re: VBO DrawArrays
VBOs do not work like that. You need to perform the following steps:
GenBuffers)BindBufferandBufferData)BindBuffer,VertexPointer/NormalPointer/*Pointer,DrawArrays)You only need to perform steps 1 and 2 once, when you create the VBO. Step 3 should be done whenever you render.