c++ - "Access Violation Reading Location" with Vertex Buffer -
i trying convert following piece of code 1 uses vertex buffer:
glbegin (gl_quads); gltexcoord2fv (&_vertex[ci->index_list[7]].uv.x); glvertex3fv (&_vertex[ci->index_list[7]].position.x); glvertex3fv (&_vertex[ci->index_list[5]].position.x); glvertex3fv (&_vertex[ci->index_list[3]].position.x); glvertex3fv (&_vertex[ci->index_list[1]].position.x); glend ();
my faulty code partly looks this:
glfloat * p = (glfloat *) malloc(sizeof(glfloat)*14); //memcopies vertices p pointer memcpy(&p[counter+0], &_vertex[ci->index_list[7]].uv.x, sizeof(glfloat)*2); memcpy(&p[counter+2], &_vertex[ci->index_list[7]].position.x, sizeof(glfloat)*3); memcpy(&p[counter+5], &_vertex[ci->index_list[5]].position.x, sizeof(glfloat)*3); memcpy(&p[counter+8], &_vertex[ci->index_list[3]].position.x, sizeof(glfloat)*3); memcpy(&p[counter+11], &_vertex[ci->index_list[1]].position.x, sizeof(glfloat)*3); glgenbuffers(1, &vboid1); glbindbuffer(gl_array_buffer, vboid1); glbufferdata(gl_array_buffer, sizeof(glfloat)*14, p, gl_static_draw_arb); glenableclientstate(gl_texture_coord_array); glenableclientstate(gl_vertex_array); gltexcoordpointer(2, gl_float, sizeof(glfloat)*14, (glfloat*)0); glvertexpointer(3, gl_float, 0, 2+(glfloat*)0); gldrawarrays(gl_quads, 0, 1); gldisableclientstate(gl_texture_coord_array); gldisableclientstate(gl_vertex_array); glbindbuffer(gl_array_buffer, 0);
however, "access violation reading location" error on gldrawarrays line. ideas wrong here? new opengl/graphics , pretty sure i'm messing obvious.
this not going work. immediate mode allowed omit respecifying unchanged attributes between vertices. vertex arrays, cannot that. telling gl finds texcoords of i-th vertex @ byte offset 14*sizeof(glfloat)*i in buffer. first vertex, work, second, try access data beyond end of buffer.
you have duplicate data, every vertex has same attributes, in same layout. basically, need 1 vertex array per attribute, 1 entry every vertex, no matter value did change or not.
better view vertex not position (specified glvertex
command), complete n-tupel of relevant attributes. if any single component of any attribute differs, not considered same vertex anymore.
Comments
Post a Comment