Login  Register

Re: Problem moving a vertex with VBO

Posted by Goggy on Oct 19, 2015; 11:54am
URL: https://forum.jogamp.org/Solved-Problem-moving-a-vertex-with-VBO-tp4035503p4035513.html

Hi elect,
Thank you very much for your answer and for depthPeeling.
Looking at your code, especially when updateCamera is called, I have understood my mistake. Indeed, I called GL methods from the keyPressed callback. Now I just set a Boolean flag in this callback. When it is set to true, I call an UpdateVertex method from the display method, and it works

For the Community, I give here three versions of UpdateVertex, depending on how the updating is done.

        // A partial FloatBuffer is created and loaded
        private void UpdateVertex1(GL3 gl3) {
                float[] miniArray = new float[] { -0.5f };
                int miniArrayPosition = 0;
                FloatBuffer miniFloatBuffer = GLBuffers.newDirectFloatBuffer(miniArray);
                gl3.glBindBuffer(GL3.GL_ARRAY_BUFFER, VBO[0]);
                gl3.glBufferSubData(GL3.GL_ARRAY_BUFFER, miniArrayPosition * Float.BYTES, miniArray.length * Float.BYTES,
                                miniFloatBuffer);
                gl3.glBindBuffer(GL3.GL_ARRAY_BUFFER, 0);
        }

        // A new full FloatBuffer is created and loaded
        private void UpdateVertex2(GL3 gl3) {
                vertexData[0] = -0.5f;
                gl3.glBindBuffer(GL3.GL_ARRAY_BUFFER, VBO[0]);
                FloatBuffer myNewFloatBuffer = GLBuffers.newDirectFloatBuffer(vertexData);
                gl3.glBufferData(GL3.GL_ARRAY_BUFFER, numberBytesVertex, myNewFloatBuffer, GL3.GL_DYNAMIC_DRAW);
                gl3.glBindBuffer(GL3.GL_ARRAY_BUFFER, 0);
        }

        // The FloatBuffer is modified and fully reloaded
        private void UpdateVertex3(GL3 gl3) {
                gl3.glBindBuffer(GL3.GL_ARRAY_BUFFER, VBO[0]);
                myFloatBuffer.put(0, -0.5f);
                gl3.glBufferData(GL3.GL_ARRAY_BUFFER, numberBytesVertex, myFloatBuffer, GL3.GL_DYNAMIC_DRAW);
                gl3.glBindBuffer(GL3.GL_ARRAY_BUFFER, 0);
        }


Thank you once again, and I go on exploring JOGL...
Goggy