Drawing more than one shape at once with VAO and VBOs

Started by pyraetos, January 06, 2013, 17:09:07

Previous topic - Next topic

pyraetos

Hi, what I'm trying to do is render two shapes at once using a Vertex Array Object and two Vertex Buffer Objects. I don't understand why only the first shape is actually showing up.

Here is the code, including comments to explain what I think is happening. Please let me know if the code logic I'm using is incorrect!

http://pastebin.com/JiTLV6c2

broumbroum

I think you have to look for the VBO extension, and thus ARBVertexBufferObject class, because you re mixing VAO with VBO in some way. Grab part of the code from my GLGeom.java file, and it should help you anyway. glgeom.glrender2D()
CU

broumbroum

Unsure if you correctly know what each of the Vertex Array functions do : e.g.
Quote
public static void render(Shape shape){
		//Safely converts homemade Shape object to GL-compatible FloatBuffer
		FloatBuffer buffer = shape.toFloatBuffer();
		//Selects previously created VAO
		glBindVertexArray(vertexArrayObjectID);
		//Creates a new VBO for our Shape to go in the VAO
		int id = glGenBuffers();
		vertexBufferObjectIDs.add(id);
here your rendering method is binding Vertex Array objects and creating a vertex buffer object to store vertices data. This process should occur once in the loading state of your scene.
Quote
//Selects the new VBO
		glBindBuffer(GL_ARRAY_BUFFER, id);
		//Loads up our Shape into the selected VBO
		glBufferData(GL_ARRAY_BUFFER, buffer, GL_STATIC_DRAW);
		/*
		 * Puts the VBO into the VAO using the amount of VBOs
		 * we have created minus one as the index
		 */
		glVertexAttribPointer(vertexBufferObjectIDs.size() - 1, 3, GL_FLOAT, false, 0, 0);		
	}
The Vertexattribpointer is incorrectly used, I think. You've meant
GL11.glEnableClientState(GL11.GL_VERTEX_ARRAY) which enables the VBO Buffer to be used as source of the Vertex Array when the buffer is bound..  (refer to songho.ca tutorials)

:)

The general process with OpenGL objects is globally this one :

  • Generate buffer names (as for textures);
  • Bind names and fill buffers to specific (client) targets (as GL_Texture_2D is, or GL_VERTEX_ARRAY as a client state);
  • Bind names (again) and render with specific attributes (as glVertex glColor, glDrawArrays, ...). 
Only the latter 3rd leap appears in a render Loop.
The 1st is a Init time and the 2nd occurs whenever an update of the data is required.

see you