I’m very sorry to be posting a lot of questions, but I can’t find almost anything about this problem…
I’m trying to change the data in VBO. The way I’m trying to do it, is glMapBuffer, change the values in that buffer and unmap it. But the problem is that glMapBuffer always returns null. I have read somewhere that this means some kind of an error, but I have no idea what it could be. Here is the code for the entire VBO class.
public class Batch {
public static final int target = GL_ARRAY_BUFFER;
public int id;
public int x, y, width, height;
public Batch(int x, int y, int width, int height) {
id = glGenBuffers();
FloatBuffer vertexBuffer = BufferUtils.createFloatBuffer(8);
vertexBuffer.put(x).put(y);
vertexBuffer.put(x + width).put(y);
vertexBuffer.put(x + width).put(y + height);
vertexBuffer.put(x).put(y + height);
vertexBuffer.flip();
glBindBuffer(target, id);
glBufferData(target, vertexBuffer, GL_STATIC_DRAW);
glBindBuffer(target, 0);
}
public void render() {
glColor3f(1, 1, 0);
glEnableClientState(GL_VERTEX_ARRAY);
glBindBuffer(target, id);
glVertexPointer(2, GL_FLOAT, 8, 0L);
glDrawArrays(GL_QUADS, 0, 4);
glDisable(GL_VERTEX_ARRAY);
glBindBuffer(target, 0);
}
public void set(float x, float y, float width, float height) {
glBindBuffer(target, id);
ByteBuffer buffer = glMapBuffer(target, GL_WRITE_ONLY, null);
System.out.println(buffer);
glBindBuffer(target, 0);
}
}