Hi! I use JOGL 1.1.1.a. I can draw my cube using vbo but when I want to animate the cube I have a problem with change vertices position.
Init VBO
gl.glGenBuffers(bufferSize, IntBuffer.wrap(buffer));
verticesID = buffer[0];
gl.glBindBuffer(GL.GL_ARRAY_BUFFER, verticesID);
gl.glBufferData(GL.GL_ARRAY_BUFFER, BufferUtil.SIZEOF_FLOAT * vertices.capacity(), vertices, GL.GL_DYNAMIC_DRAW);
gl.glBindBuffer(GL.GL_ARRAY_BUFFER, 0);
normalsID = buffer[1];
gl.glBindBuffer(GL.GL_ARRAY_BUFFER, normalsID);
gl.glBufferData(GL.GL_ARRAY_BUFFER, BufferUtil.SIZEOF_FLOAT * normals.capacity(), normals, GL.GL_DYNAMIC_DRAW);
gl.glBindBuffer(GL.GL_ARRAY_BUFFER, 0);
gl.glEnableClientState(GL.GL_VERTEX_ARRAY);
gl.glEnableClientState(GL.GL_NORMAL_ARRAY);
Display and Update Vertices
gl.glPushMatrix();
gl.glMaterialfv(GL.GL_FRONT_AND_BACK, GL.GL_AMBIENT, material.getAmbient(), 0);
gl.glMaterialfv(GL.GL_FRONT_AND_BACK, GL.GL_DIFFUSE, material.getDiffuse(), 0);
gl.glMaterialfv(GL.GL_FRONT_AND_BACK, GL.GL_SPECULAR, material.getSpecular(), 0);
gl.glMaterialfv(GL.GL_FRONT_AND_BACK, GL.GL_EMISSION, material.getEmission(), 0);
gl.glMaterialfv(GL.GL_FRONT_AND_BACK, GL.GL_SHININESS, material.getShininess(), 0);
gl.glBindBuffer(GL.GL_ARRAY_BUFFER, verticesID);
gl.glVertexPointer(3, GL.GL_FLOAT, 0, 0);
gl.glBindBuffer(GL.GL_ARRAY_BUFFER, 0);
gl.glBindBuffer(GL.GL_ARRAY_BUFFER, normalsID);
gl.glNormalPointer(GL.GL_FLOAT, 0, 0);
gl.glBindBuffer(GL.GL_ARRAY_BUFFER, 0);
gl.glDrawArrays(GL.GL_QUADS, 0, 24);
gl.glBindBuffer(GL.GL_ARRAY_BUFFER, verticesID);
byteBuffer = gl.glMapBuffer(GL.GL_ARRAY_BUFFER, GL.GL_READ_WRITE);
if(bufferRW != null)
{
srcVertices = byteBuffer.asFloatBuffer();
vertices.rewind();
for(int i = 0; i < 24; i++)
{
vX = srcVertices.get();
vY = srcVertices.get();
vZ = srcVertices.get();
vertices.put(vX);
vertices.put(vY + 0.2f);
vertices.put(vZ);
}
}
gl.glUnmapBuffer(GL.GL_ARRAY_BUFFER);
gl.glBindBuffer(GL.GL_ARRAY_BUFFER, 0);
gl.glPopMatrix();
The cube should move up but nothing happens. What is wrong with my code ?