Hi Guys,
I am new to OGL, I am currently working through the Nehe tutorials (great tutorials I must add). In an effort to learn vertex arrays, I have replaced the following code in lesson 2:
GL11.glBegin(GL11.GL_TRIANGLES);
GL11.glVertex3f( 0.0f, 1.0f, 0.0f);
GL11.glVertex3f(-1.0f,-1.0f, 0.0f);
GL11.glVertex3f( 1.0f,-1.0f, 0.0f);
GL11.glEnd();
with:
GL11.glEnableClientState(GL11.GL_VERTEX_ARRAY);
float[] vertices = {0.0f, 1.0f, 0.0f,-1.0f,-1.0f, 0.0f,1.0f,-1.0f, 0.0f};
FloatBuffer pointer = (new BufferUtils()).createFloatBuffer(9);
pointer.put(vertices);
GL11.glVertexPointer(3,0, pointer);
GL11.glDrawArrays(GL11.GL_TRIANGLES, 0, 9);
GL11.glDisableClientState(GL11.GL_VERTEX_ARRAY);
Unfortunately, the triangle is not being displayed. Please let me know what I am doing wrong. :(
I think you need to rewind the buffer after you put your data.
pointer.put(vertices);
pointer.rewind();
Need to flip() the buffer, not rewind. flip() sets the limit of the buffer. Get into the habit now! Or it'll confuse you later when you start using subsets of larger buffers.
Cas :)
Flipping the buffer, worked like a charm :) . Thanks guys. Hopefully I can accelerate my LWJGL skills now.