c++ - VAO problems with bind -


help find error.
suppose wrong bind. in "display" used vbo - works fine.
when used vao - black screen.

void createvao(gluint *_vid, gluint *_cid, gluint *_tid, gluint *_vao) { glgenvertexarrays(1, _vao); glbindvertexarray(*_vao);  glenableclientstate( gl_vertex_array ); glbindbuffer(gl_array_buffer, *_vid ); glvertexpointer( 3, gl_float, 0, 0 );  glbindvertexarray(0);  glbindbuffer(gl_array_buffer, 0); glbindbuffer(gl_element_array_buffer, 0); }   void createvbo(gluint *_vid, gluint *_cid, gluint *_tid) { glgenbuffers(1, _vid); glbindbuffer(gl_array_buffer, *_vid); glbufferdata(gl_array_buffer, sizeof(xyz) * cubeverticescount, cubepositions, gl_static_draw ); glbindbuffer(gl_array_buffer, 0); }   void display() { glclear(gl_color_buffer_bit);  glmatrixmode(gl_modelview); glloadidentity(); gltranslatef(0, 0, -800); glrotatef(rotate.angle_x, 1, 0, 0); glrotatef(rotate.angle_y, 0, 1, 0); glscalef(zoom,zoom,zoom);  // vao - dont work glcolor3f(1.0f,1.0f,1.0f); glbindvertexarray(vao); gldrawelements(gl_points, 0, gl_unsigned_int, null); glbindvertexarray(0);  // vbo - work //glenableclientstate( gl_vertex_array ); //glbindbuffer( gl_array_buffer, vid ); //glvertexpointer( 3, gl_float, 0, 0 ); //gldrawarrays(gl_points, 0, cubeverticescount); //gldisableclientstate(gl_vertex_array);  calculatefps(); glutswapbuffers(); } 

full source code. http://codepad.org/i87axdl4

i'm sorry lot of unnecessary code.

the vao doesn't have index buffer in it. gl_element_array_buffer part of vao's state. when bind vao, what's bound gl_element_array_buffer change vao's element array buffer.

you need bind element buffer in createvao, after binding vao (but before unbinding it).


Comments

Popular posts from this blog

Perl - how to grep a block of text from a file -

delphi - How to remove all the grips on a coolbar if I have several coolbands? -

javascript - Animating array of divs; only the final element is modified -