Hi, I'm trying to draw many lines on the screen at the same time using OpenGL line strips and performance is slow, and it was suggested I use a vertex buffer. I'm new to vertex buffers - do I need a new one for each line I want to draw, or do I use a single buffer for all of the lines (they are not necessarily connected to each other)? At this point I have a list of lines (where each line is a list of vertices), but I'm not sure how to render these quickly. Any help would be appreciated.
EDIT: Here is my current code that gives an exception of: EDIT2: Rewinding the buffer before calling glVertexPointer fixed the exception since the put was advancing the buffer. This is now fixed.
java.lang.IndexOutOfBoundsException: Required 1 remaining elements in buffer, only had0
at com.sun.gluegen.runtime.BufferFactory.rangeCheck(BufferFactory.java:247)
at com.sun.opengl.impl.GLImpl.glVertexPointer(GLImpl.java:27937)
for (int i = 0; i < lines.size(); i++)
{
List<Vertex> v = lines.get(i);
DoubleBuffer buf = BufferUtil.newDoubleBuffer(v.size() * 3);
Iterator<Vertex> iter = v.iterator();
while (iter.hasNext())
{
Vertex vt = iter.next();
buf.put(new double[] { vt.x, vt.y, vt.z });
}
gl.glVertexPointer(3, GL.GL_DOUBLE, 0, buf);
gl.glEnableClientState(GL.GL_VERTEX_ARRAY);
gl.glDrawArrays(GL.GL_LINES, 0, v.size());
gl.glDisableClientState(GL.GL_VERTEX_ARRAY);
}
Hopefully this will provide some better insight into my problem (I know this code has issues, trying to learn here though).
Thanks, Jeff