GLException: Argument "ptr" was not a direct buffer

I am a freshment !

int vertex[]={
25,25,
100,325,
175,25,
175,325,
250,25,
325,325,
};

IntBuffer ib=IntBuffer.allocate(vertex.length);
ib=ib.put(vertex);

gl.glEnableClientState(GL.GL_VERTEX_ARRAY);
gl.glVertexPointer(2, GL.GL_INT, 0, ib);

gl.glBegin…

But I got an exception:
Exception in thread “AWT-EventQueue-0” net.java.games.jogl.GLException: Argument “ptr” was not a direct buffer
at net.java.games.jogl.impl.windows.WindowsGLImpl.glColorPointer(WindowsGLImpl.java:2190)
at org.yourorghere.FirstCircleEventListener.drawGraph(FirstCircleEventListener.java:241)
at org.yourorghere.FirstCircleEventListener.display(FirstCircleEventListener.java:34)
at net.java.games.jogl.impl.GLDrawableHelper.display(GLDrawableHelper.java:74)
at net.java.games.jogl.GLCanvas$DisplayAction.run(GLCanvas.java:198)
at net.java.games.jogl.impl.GLContext.invokeGL(GLContext.java:268)
at net.java.games.jogl.GLCanvas.displayImpl(GLCanvas.java:186)
at net.java.games.jogl.GLCanvas.display(GLCanvas.java:74)

What’s wrong ?
And What can I do ?

Hi!

The error message is quite explicit. Do this:


import com.sun.opengl.util.BufferUtil;
...

int vertex[]={
            25,25,
            100,325,
            175,25,
            175,325,
            250,25,
            325,325,
        };

IntBuffer ib=BufferUtil.newIntBuffer(vertex.length);
ib.put(vertex);
ib.rewind();

gl.glEnableClientState(GL.GL_VERTEX_ARRAY);
gl.glVertexPointer(2, GL.GL_INT, 0, ib);

By default, your buffer was indirect. That was why it didn’t work. Good luck comrade.

Thank you very much ! Guy!

You’re welcome ;D

Do not hesitate to watch the source code of TUER if you want to know how to create VBOs, especially the package “drawer”.