Vertex Buffer problems

Started by tiagocoutinho, December 11, 2005, 20:10:30

Previous topic - Next topic

tiagocoutinho

Hi,

I am trying to draw a simple triangle with a vertex buffer but so far I haven't had any success. Can you tell me what  is missing in my code?

public class VertexBuffer {

	protected FloatBuffer memVBBuffer = null;
	
	private final float triangleVertices[] = { 
			1f, 1f, -0.5f, 
			-1f, -1f, -0.5f, 
			1f, -1f, -0.5f, 
			 };
	
	public VertexBuffer()
	{
                  memVBBuffer =BufferUtils.createFloatBuffer(9);
                  memVBBuffer.put(triangleVertices);
	}
	
	public void render() 
	{
		GL11.glEnableClientState( GL11.GL_VERTEX_ARRAY ); 
		GL11.glVertexPointer( 3, GL11.GL_FLOAT, memVBBuffer );
		GL11.glDrawArrays(GL11.GL_TRIANGLES, 0, 1 );
	}
}


The class that calls render performs a rotation around the y axis and I have tried displaying the triangle with direct glbegin(GL_TRIANGLE) with success.

Thank you in advance

tomb

I think the 3rd parameter to glDrawArrays is the number of vertices, not triangles. So it should be 3 not 1.