LWJGL Forum

Programming => OpenGL => Topic started by: pyraetos on January 06, 2013, 17:09:07

Title: Drawing more than one shape at once with VAO and VBOs
Post by: pyraetos on January 06, 2013, 17:09:07
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
Title: Re: Drawing more than one shape at once with VAO and VBOs
Post by: broumbroum on January 07, 2013, 21:05:55
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() (http://sf3jswing.hg.sourceforge.net/hgweb/sf3jswing/sf3jswing/file/4a53f3595bd2/sf3jswing-jigaxtended/src/all/net/sf/jiga/xtended/impl/game/gl/geom/GLGeom.java#l1172)
CU
Title: Re: Drawing more than one shape at once with VAO and VBOs
Post by: broumbroum on January 08, 2013, 19:14:55
Unsure if you correctly know what each of the Vertex Array functions do : e.g.
Quotepublic 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 : 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