LWJGL Forum

Programming => Lightweight Java Gaming Library => Topic started by: Simpleton on November 01, 2004, 12:38:54

Title: Problem with Vertex Arrays (Newbie question)
Post by: Simpleton on November 01, 2004, 12:38:54
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. :(
Title: Problem with Vertex Arrays (Newbie question)
Post by: CaptainJester on November 01, 2004, 12:59:20
I think you need to rewind the buffer after you put your data.

pointer.put(vertices);
pointer.rewind();
Title: Problem with Vertex Arrays (Newbie question)
Post by: princec on November 01, 2004, 14:07:30
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 :)
Title: Problem with Vertex Arrays (Newbie question)
Post by: Simpleton on November 02, 2004, 07:46:56
Flipping the buffer, worked like a charm  :) . Thanks guys. Hopefully I can accelerate my LWJGL skills now.