Buffer Error (Exception)

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Buffer Error (Exception)

Itun
    @Override
    public void display(GLAutoDrawable drawable) {
        GL2 gl = drawable.getGL().getGL2();
        int vertices[] = new int[] { 25, 25, 100, 325, 175, 25, 175, 325, 250,
                25, 325, 325 };
        float colors[] = new float[] { 1.0f, 0.2f, 0.2f, 0.2f, 0.2f, 1.0f,
                0.8f, 1.0f, 0.2f, 0.75f, 0.75f, 0.75f, 0.35f, 0.35f, 0.35f,
                0.5f, 0.5f, 0.5f };

        if (verticesBuf == null) {// IntBuffer tmpVerticesBuf
            verticesBuf = IntBuffer.allocate(vertices.length);
            verticesBuf.put(vertices);
        }
        if (colorsBuf == null) {
            colorsBuf = FloatBuffer.allocate(colors.length);
            colorsBuf.put(colors);
        }
        verticesBuf.rewind();
        colorsBuf.rewind();
        gl.glEnableClientState(GL2.GL_VERTEX_ARRAY);
        gl.glEnableClientState(GL2.GL_COLOR_ARRAY);

        gl.glVertexPointer(2, GL2.GL_INT, 0, verticesBuf);
        gl.glColorPointer(3, GL.GL_FLOAT, 0, colorsBuf);
        //update();
        //render(drawable);
    }

There are an exception in glVertexPointer.


Exception in thread "Timer-0" javax.media.opengl.GLException: javax.media.opengl.GLException: Argument "ptr" was not a direct buffer
        at com.jogamp.opengl.impl.awt.AWTThreadingPlugin.invokeOnOpenGLThread(AWTThreadingPlugin.java:101)
        at com.jogamp.opengl.impl.ThreadingImpl.invokeOnOpenGLThread(ThreadingImpl.java:192)
        at javax.media.opengl.Threading.invokeOnOpenGLThread(Threading.java:164)
        at javax.media.opengl.awt.GLCanvas.maybeDoSingleThreadedWorkaround(GLCanvas.java:594)
        at javax.media.opengl.awt.GLCanvas.display(GLCanvas.java:302)
        at com.jogamp.opengl.util.AnimatorImpl.display(AnimatorImpl.java:51)
        at com.jogamp.opengl.util.AnimatorBase.display(AnimatorBase.java:98)
        at com.jogamp.opengl.util.FPSAnimator$1.run(FPSAnimator.java:114)
        at java.util.TimerThread.mainLoop(Timer.java:512)
        at java.util.TimerThread.run(Timer.java:462)
Caused by: javax.media.opengl.GLException: Argument "ptr" was not a direct buffer
        at com.jogamp.opengl.impl.gl4.GL4bcImpl.glVertexPointer(GL4bcImpl.java:31116)
        at jogl.RenderLoop.display(RenderLoop.java:40)
        at com.jogamp.opengl.impl.GLDrawableHelper.display(GLDrawableHelper.java:140)
        at javax.media.opengl.awt.GLCanvas$DisplayAction.run(GLCanvas.java:660)
        at com.jogamp.opengl.impl.GLDrawableHelper.invokeGL(GLDrawableHelper.java:291)
        at javax.media.opengl.awt.GLCanvas$DisplayOnEventDispatchThreadAction.run(GLCanvas.java:677)
        at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:199)
        at java.awt.EventQueue.dispatchEvent(EventQueue.java:597)
        at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
        at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
        at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
        at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
Exception in thread "AWT-EventQueue-0" javax.media.opengl.GLException: Argument "ptr" was not a direct buffer
        at com.jogamp.opengl.impl.gl4.GL4bcImpl.glVertexPointer(GL4bcImpl.java:31116)
        at jogl.RenderLoop.display(RenderLoop.java:40)
        at com.jogamp.opengl.impl.GLDrawableHelper.display(GLDrawableHelper.java:140)
        at javax.media.opengl.awt.GLCanvas$DisplayAction.run(GLCanvas.java:660)
        at com.jogamp.opengl.impl.GLDrawableHelper.invokeGL(GLDrawableHelper.java:291)
        at javax.media.opengl.awt.GLCanvas.maybeDoSingleThreadedWorkaround(GLCanvas.java:596)
        at javax.media.opengl.awt.GLCanvas.display(GLCanvas.java:302)
        at javax.media.opengl.awt.GLCanvas.paint(GLCanvas.java:385)
        at sun.awt.RepaintArea.paintComponent(RepaintArea.java:248)
        at sun.awt.X11.XRepaintArea.paintComponent(XRepaintArea.java:56)
        at sun.awt.RepaintArea.paint(RepaintArea.java:224)
        at sun.awt.X11.XComponentPeer.handleEvent(XComponentPeer.java:695)
        at java.awt.Component.dispatchEventImpl(Component.java:4706)
        at java.awt.Component.dispatchEvent(Component.java:4460)
        at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
        at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
        at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
        at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
        at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
Reply | Threaded
Open this post in threaded view
|

Re: Buffer Error (Exception)

gouessej
Administrator
Hi!

Don't use indirect buffers, don't call IntBuffer.allocate nor FloatBuffer.allocate, rather use com.jogamp.common.nio.Buffers.newDirectIntBuffer and newDirectFloatBuffer. You should store your vertices into a float buffer, not into an int buffer as your array contains float values.
Julien Gouesse | Personal blog | Website