Buffer object for glVertexPointer(...)

Hi,

I want to use vertex arrays for my application, but i can’t construct a buffer to call
glVertexPointer(…, java.nio.Buffer buffer)
with. Can anybody post code which creates a valid buffer object from a float array?

Thanks in advance
–Martin–

Hi,

You should use BufferUtils from jogl to set the native order to your buffers.

If you prefer to do it yourself, try something like this :

        ByteBuffer bb = ByteBuffer.allocateDirect ( 4 * points[i].length );
        
        bb.order ( ByteOrder.nativeOrder () );
        
      bb.asFloatBuffer ();

It should work

Yes, the critical bit is to use direct buffers, and to make sure you use native byte ordering. If you don’t JOGL complains loudly. Once you have that, it all works perfectly.

Check out this thread:

http://www.java-gaming.org/cgi-bin/JGNetForums/YaBB.cgi?board=jogl;action=display;num=1089966116

…and specifically this simple demo (contains a simple VBO example as well):

http://www.g0dmode.com/javastuff/jogl-tiledemo.zip

Cheers