I am currently working on a 2d Top-down RPG written in Java 1.6 using LWJGL. I implemented the use of VBO in my game, and now I support two of them: one for these vertices and one for texture cords.
Everything works fine, except that I still don't have a logical way to update objects. As an example, if I want a certain tile to change its texture (change the texture coordinates inside VBO to show a different area of ββthe texture sheet), I donβt see a way to just change the texture coordinates corresponding to this one tile. All I can think of right now is to fill the buffers with all the data needed for each loop, and load them with glBufferData for each frame. It works, but it does not seem to be the best way to do this (or does it?).
Now there is a glBufferSubData command that will not allocate new memory, but will only change the part that I will say so that it changes. The thing is, I donβt know how to track the area that needs to be changed (offset). LWJGL offers glBufferSubData (target, offset, data); A command that requires only the start of the buffer. Is an offset something like an index?
So, if I first load these buffers into VBO and then want to change the second value of the second float []:
FloatBuffer vertexData = BufferUtils.createFloatBuffer(amountOfVertices * vertexSize);
vertexData.put(new float[]{100, 100, 300, 100, 300, 300, 100, 300});
vertexData.put(new float[]{400, 100, 600, 100, 600, 300, 400, 300});
vertexData.flip();
I would generate new data, put it inside a small FloatBuffer and load it using glBufferSubData (GL_VERTEX_ARRAY, 10, newFloatBuffer) ;? 10 is because I want to change the values ββfrom the tenth old value.
It is right? Is there a better way to do this? And again: is it okay if I reload all the data in every frame?