Can anyone point me to any site which explains how to use vertex buffers in jogl, or even lwjgl, or even just a few lines of source code? Thanks
vertex buffer OBJECTS or vertex ARRAYS ?
Nehe lesson 45 is about vertex arrays and vbos. http://nehe.gamedev.net/data/lessons/lesson.asp?lesson=45
The only catch is that you can not send null as pointer into glVertexPointer(int size, int stride, FloatBuffer pointer) in lwjgl. Instead you have to use glVertexPointer(int size, int type, int stride, int buffer_offset). Besides from that the code is the same in java.
None of the platforms lesson 45 is implemented in are in java, all are C/C++ or VB. I’m trying to decipher the C++ one but it doesn’t even mention “glVertexBuffer” so I’m a little lost.
There is no glVertexBuffer. In directX there is CreateVertexBuffer(). The closest thing to that in opengl is vertex buffer objects. Wich is similar to vertex arrays except that the memory is managed by the driver.
To use vertex arrays you need to:
- Put your data in one or more FloatBuffers
- Tell opengl that your using vertex arrays by using GL.glEnableClientState
- Give opengl the pointer to your data in the FloatBuffer(s)
- Draw geometry by refering to the vertex array
// create FloatBuffer and store data in it
FloatBuffer vertexBuffer = ...;
float vs[] = {0, -100, -100, 0, -100, 100, 0, 100, 100, 0, 100, -100};
for (int i=0; i<vs.length; i++) {
vertexBuffer.put(vs[i]);
}
vertexBuffer.rewind();
// enable vertex array
GL.glEnableClientState(GL.GL_VERTEX_ARRAY);
// give pointer to data
GL.glVertexPointer(3, 0, vertexBuffer);
// draw
GL.glDrawArrays(GL.GL_QUADS, 0, 4);
You might want to look at the documentation to see what the various parameters mean. http://www.opengl.org/documentation/specs/man_pages/hardcopy/GL/html/gl/
what about glGenBuffersARB, glBindBufferARB, and glBufferDataARB? Do i need those?
i got an exception, that ‘ptr’ was not a direct pointer, when I called gl.glVertexPointer(3, 0, 1, buffer); I don’t really understand the arguments so I may have called it with the wrong params, since the jogl javadocs all just say “interface to C language function” without explaining anything
[quote]what about glGenBuffersARB, glBindBufferARB, and glBufferDataARB? Do i need those?
[/quote]
Those are vertex buffer object (vbo) functions. They can improve performance. But no, you don’t need then until you’ve got vertex arrays working.
There is no opengl javadoc. You have to look at the opengl documentation instead. It’s in the link I gave in my last post.
BTW. I think it should be “gl.glVertexPointer(3, GL_FLOAT, 0, buffer);”
[quote]i got an exception, that ‘ptr’ was not a direct pointer, when I called gl.glVertexPointer(3, 0, 1, buffer); I don’t really understand the arguments so I may have called it with the wrong params, since the jogl javadocs all just say “interface to C language function” without explaining anything
[/quote]
make sure your buffer is “direct”. in net.java.games.jogl.util.BufferUtils, there is a helper method to create the right kind of floatBuffers.
Jan
FloatBuffer fb = BufferUtils.newFloatBuffer(size);
fb.put( float[]); <- your vertex data
now you got a direct buffer
OK, now it accepts the FloatBuffer, but I get weird errors, like it would display the quads in the list for about 30 seconds and then just stop while still rendering the software-rendered polygons, so I tried tweaking a few things, then it didn’t display the vertex-arrayed ones ever, and now (the worst yet) it gives me a Heap at VM Abort.
Would it be possible for someone to post complete (non-pseudo) code that completely goes through the process of using vertex arrays (and whatever else is necessary) to hardware-render quads with texturing and vertex-coloring? I would really appreciate it.