Hello, im trying to implement VBO’s but for 2 days i still have not found a solution.
Im sure its a simple mistake, but i cant seem to find it.
Between Init and Init buffer the buffer gets filled, all numbers are right.
The program crashes on this line:
glDrawArrays(GL_QUADS, 0, maxobjects);
Even a try / catch statement wont stop this crash, so i guess its a native crash.
Init:
public VBO_Object(int objects){
maxobjects = objects;
stride = (3 + 3 + 2) * 4 * objects; // 3 for vertex, 3 for colour and 2 for texture coordinates. * 4 for bytes
buffersize = (3 + 3 + 2) * objects;
buffer = new float[buffersize];
}
Init buffer
IntBuffer buffer = BufferUtils.createIntBuffer(1);
ARBVertexBufferObject.glGenBuffersARB(buffer);
id= buffer.get(0);
data = BufferUtils.createFloatBuffer(buffer.length);
data.put(buffer);
data.flip();
Draw call:
public void Draw(){
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_COLOR_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glBindBufferARB(GL_ARRAY_BUFFER_ARB, id);
glBufferDataARB(GL_ARRAY_BUFFER_ARB, data, GL_STATIC_DRAW_ARB);
glVertexPointer(3, GL_FLOAT, stride, /* offset **/0); // float at index 0
glColorPointer(3, GL_FLOAT, stride, /* offset **/(3*1) << 2); // float at index 3
glTexCoordPointer(2, GL_FLOAT, stride, /* offset **/(3*2) << 2); // float at index 6
glDrawArrays(GL_QUADS, 0, maxobjects);
glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0);
glDisableClientState(GL_COLOR_ARRAY);
glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
}