c++ - Multiple Vertex Array Objects: Proper way to display multiple primitives? -


i'm having hard time getting multiple vertex array objects render multiple primitives. opengl tutorials i've found online show using single vao, i'm not sure might doing wrong.

i'm using qt-opengl , trying render square , cube (on multiple vaos).

using following code, i'm getting 1 primitive displayed on screen (whichever 1 initialized second). can see either primitive when turn off initialization of other one, not @ same time.

data struct:

struct vbo : public qopenglbuffer {  };  struct vao : public qopenglvertexarrayobject {   vbo vbo[1]; }; enum { circle, rect, num_vaos }; enum { pos, num_vbos };  vao vao[num_vaos]; 

initialization:

static void init_objects() {   for(int = 0; < num_vaos; ++i) {     vao[i].create();   }    vao[circle].bind();    for(int = 0; < num_vbos; ++i) {     vao[circle].vbo[i].create();     vao[circle].vbo[i].setusagepattern( qopenglbuffer::staticdraw );   }    vao[circle].vbo[pos].bind();    vao[circle].vbo[pos].allocate(circle.getvertexdata(), circle.getnumvertices()*3*sizeof(float));    vao[circle].release();    // repeat rectangle instead of circle    vao[rect].bind();    for(int = 0; < num_vbos; ++i) {     vao[rect].vbo[i].create();     vao[rect].vbo[i].setusagepattern( qopenglbuffer::staticdraw );   }    vao[rect].vbo[pos].bind();    vao[rect].vbo[pos].allocate(circle.getvertexdata(), circle.getnumvertices()*3*sizeof(float));  } 

rendering code:

void game::paintgl() {   glclear(gl_color_buffer_bit | gl_depth_buffer_bit);   vao[rect].bind();   vao[rect].vbo[pos].bind();    qmatrix4x4 id;   game.setmvp( id );    game.setcolor( colour(0.0, 1.0, 0.0) );    gldrawelements(gl_triangles, rect.getsolidindices().size()*sizeof(unsigned int),     gl_unsigned_int, &(rect.getsolidindices()[0]));    glfinish();    vao[rect].release();    // circle:   vao[circle].bind();   vao[circle].vbo[pos].bind();    game.setmvp( id );    game.setcolor( colour(1.0, 0.0, 0.0) );    gldrawelements(gl_triangles, circle.getsolidindices().size()*sizeof(unsigned int),     gl_unsigned_int, &(circle.getsolidindices()[0]));   glflush(); } 

i've tried reading data buffers before rendering (they distinct , expect each primitive), know write occurred properly. i'm guessing might binding buffers wrong, or missing step while rendering.


Comments

Popular posts from this blog

node.js - Mongoose: Cast to ObjectId failed for value on newly created object after setting the value -

[C++][SFML 2.2] Strange Performance Issues - Moving Mouse Lowers CPU Usage -

ios - Possible to get UIButton sizeThatFits to work? -