Problem with Vertex Arrays (Newbie question)

Started by Simpleton, November 01, 2004, 12:38:54

Previous topic - Next topic

Simpleton

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. :(

CaptainJester

I think you need to rewind the buffer after you put your data.

pointer.put(vertices);
pointer.rewind();
The problems of this world cannot possibly be solved by skeptics or cynics whose horizons are limited by the obvious realities.  We need men and women who can dream of things that never were. - John Fitzgerald Kennedy(35th US President)
8)

princec

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 :)

Simpleton

Flipping the buffer, worked like a charm  :) . Thanks guys. Hopefully I can accelerate my LWJGL skills now.