opengl - Crash when glDrawArray and glDrawElements in one programme -


void init_cube(void){         makecube(cbr_points,cbr_normals);         glgenvertexarrays(1,&vaid_cube);         glbindvertexarray(vaid_cube);          glgenbuffers(1,&vbid_cube);         glbindbuffer(gl_array_buffer,vbid_cube);         glbufferdata(gl_array_buffer,sizeof(vec4)*cbr_points.size()+sizeof(vec3)*cbr_normals.size(),0,gl_static_draw);         glbuffersubdata(gl_array_buffer,0,cbr_points.size()*sizeof(vec4),cbr_points.data());         glbuffersubdata(gl_array_buffer,cbr_points.size()*sizeof(vec4),cbr_normals.size()*sizeof(vec3),cbr_normals.data());          gluint vposition = glgetattriblocation(g_idshader,"vposition");         glenablevertexattribarray(vposition);         glvertexattribpointer(vposition,4,gl_float,gl_false,0,buffer_offset(0));          gluint vnormal = glgetattriblocation(g_idshader,"vnormal");         glenablevertexattribarray(vnormal);         glvertexattribpointer(vnormal,3,gl_float,gl_false,0,buffer_offset(cbr_points.size()*sizeof(vec4))); }  void setvavbobject( void ) {     // set vao     glgenvertexarrays   ( 1, &g_vaid );     glbindvertexarray   ( g_vaid );      // set vertex position, normal , elements - vbo     glgenbuffers    ( 1, &g_vbidvertices );     glbindbuffer    ( gl_array_buffer, g_vbidvertices );     glbufferdata    ( gl_array_buffer, g_bunny.vertices.size() * sizeof(g_bunny.vertices[0]),   g_bunny.vertices.data(), gl_static_draw );      glgenbuffers    ( 1, &g_vbidnormals );     glbindbuffer    ( gl_array_buffer, g_vbidnormals );     glbufferdata    ( gl_array_buffer, g_bunny.normals.size() * sizeof(g_bunny.normals[0]), g_bunny.normals.data(), gl_static_draw );      // ex-todo: computing normal     // set indices buffer - flat shading not use indices      glgenbuffers ( 1, &g_ibidelements );     glbindbuffer ( gl_element_array_buffer, g_ibidelements );     glbufferdata ( gl_element_array_buffer,                         g_bunny.elements.size() * sizeof(g_bunny.elements[0]),                         g_bunny.elements.data(), gl_static_draw );       gluint vposition = glgetattriblocation( g_idshader, "vposition" );     glenablevertexattribarray( vposition );     glbindbuffer( gl_array_buffer, g_vbidvertices);     glvertexattribpointer( vposition, 4, gl_float, gl_false, 0, buffer_offset(0) );      gluint vnormal = glgetattriblocation( g_idshader, "vnormal" );     glenablevertexattribarray( vnormal );     glbindbuffer( gl_array_buffer, g_vbidnormals);     glvertexattribpointer( vnormal, 3, gl_float, gl_false, 0, buffer_offset(0) );  }  void displaybunny( void ) {     int size;      glbindbuffer ( gl_element_array_buffer, g_ibidelements );     glgetbufferparameteriv ( gl_element_array_buffer, gl_buffer_size, &size );     gldrawelements ( gl_triangles, size/sizeof(glushort), gl_unsigned_short, 0 ); }  void displaycube( void ) {     glbindvertexarray(vaid_cube);     glbindbuffer(gl_array_buffer,vbid_cube);     gldrawarrays(gl_triangles,0,cbr_points.size()); } 

i using obj file , vertex array, want show in 1 scene different method.

when use function discretely, shows nice, when use

displaybunny(); displaycube(); 

it comes errors. have choose 1 method show primitives?

enter image description here

glbindvertexarray(vaid_cube); 

there seems 1 of these conspicuously missing displaybunny.

also, gl_element_array_buffer part of vao's state. shouldn't keep re-binding every time render object. bind vao.


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -