0

I want to change vertex positions when key pressed. I use glMapBuffer to get buffer, but it always returns null. This is the code:

Creating vertex buffer:

    FloatBuffer verticesBuffer = FloatBuffer.allocate(vertices.length * 8);
    for (int i = 0; i < vertices.length; i++) {
        verticesBuffer.put(vertices[i].position.x);
        verticesBuffer.put(vertices[i].position.y);
        verticesBuffer.put(vertices[i].position.z);

        verticesBuffer.put(vertices[i].texCoord.x);
        verticesBuffer.put(vertices[i].texCoord.y);

        verticesBuffer.put(vertices[i].normal.x);
        verticesBuffer.put(vertices[i].normal.y);
        verticesBuffer.put(vertices[i].normal.z);

    }
    verticesBuffer.flip();
    gl.glGenBuffers(1, VBOVertices, 0);
    gl.glBindBuffer(gl.GL_ARRAY_BUFFER, VBOVertices[0]);
    gl.glBufferData(gl.GL_ARRAY_BUFFER, verticesBuffer.capacity() * 4, verticesBuffer, gl.GL_DYNAMIC_DRAW);

Getting the buffer:

    gl.glBindBuffer(gl.GL_ARRAY_BUFFER, VBOVertices[0]);
    ByteBuffer verticesByteBuffer = gl.glMapBuffer(gl.GL_ARRAY_BUFFER, gl.GL_WRITE_ONLY); //this is always null
    gl.glUnmapBuffer(gl.GL_ARRAY_BUFFER);
  • 1
    A return value of `NULL` is only half of the story. `glMapBuffer (...)` is supposed to set an error state when it returns `NULL`. You should call `glGetError (...)` to find out the source of the problem. Also, unless JOGL has done something really unusual to the standard OpenGL API specification, `glGenBuffers (...)` only takes 2 parameters. – Andon M. Coleman Dec 17 '13 at 21:57
  • Nevermind the comment about JOGL... you would think that if JOGL was going to deviate from the OpenGL specification they would make their documentation easier to browse. – Andon M. Coleman Dec 17 '13 at 22:03
  • Thanks for reply. Sorry for delay in response. glGetError returns "invalid operation", but it has nothing to do with mapping. I always get "invalid operation" error inside GLCanvases event methods ( eg. canvasKeyPressed(...) ), but there are no errors inside main loop. Any idea what causes them? – user1784182 Jan 03 '14 at 09:41
  • Ok, I was able to successfully change object's position but can't do it directly from swing's JFrame class. Don't quite understand why. Anyways, thank you very much for help. – user1784182 Jan 03 '14 at 10:11
  • Hi @user1784182, do you still need help? – elect Aug 12 '15 at 08:52

0 Answers0