opengl - C++ VBO rendering issue -
this code works it's supposed work, renders correctly (didn't post every piece of related code since think something's wrong these parts):
std::vector<gluint> vboid; std::vector< std::vector<glfloat> > verts;
...init:
verts[num].push_back(x); verts[num].push_back(y); //verts[num].push_back(0); // texture offset verts[num].push_back(0); verts[num].push_back(offset); verts[num].push_back(x + tile_size); verts[num].push_back(y); //verts[num].push_back(0); // texture offset verts[num].push_back(1); verts[num].push_back(offset); verts[num].push_back(x + tile_size); verts[num].push_back(y + tile_size); //verts[num].push_back(0); // texture offset verts[num].push_back(1); verts[num].push_back(offset + zsize); verts[num].push_back(x); verts[num].push_back(y + tile_size); //verts[num].push_back(0); // texture offset verts[num].push_back(0); verts[num].push_back(offset + zsize); ... glbindbuffer(gl_array_buffer, vboid[num]); glbufferdata(gl_array_buffer, verts[num].size() * sizeof(glfloat), verts[num].data(), gl_static_draw);
...render:
glbindbuffer(gl_array_buffer,vboid[num]); gltexcoordpointer(2,gl_float,sizeof(verts[num]),(void*)(sizeof(glfloat)*2)); glvertexpointer(2,gl_float,sizeof(verts[num]),0); glenableclientstate(gl_texture_coord_array); glenableclientstate(gl_vertex_array); gldrawarrays(gl_quads, 0, verts[num].size()); gldisableclientstate(gl_vertex_array); gldisableclientstate(gl_texture_coord_array);
but when try add z value modifying code, renders messed up:
...init
verts[num].push_back(x); verts[num].push_back(y); verts[num].push_back(0); // texture offset verts[num].push_back(0); verts[num].push_back(offset); verts[num].push_back(x + tile_size); verts[num].push_back(y); verts[num].push_back(0); // texture offset verts[num].push_back(1); verts[num].push_back(offset); verts[num].push_back(x + tile_size); verts[num].push_back(y + tile_size); verts[num].push_back(0); // texture offset verts[num].push_back(1); verts[num].push_back(offset + zsize); verts[num].push_back(x); verts[num].push_back(y + tile_size); verts[num].push_back(0); // texture offset verts[num].push_back(0); verts[num].push_back(offset + zsize); ... glbindbuffer(gl_array_buffer, vboid[num]); glbufferdata(gl_array_buffer, verts[num].size() * sizeof(glfloat), verts[num].data(), gl_static_draw);
...render:
glbindbuffer(gl_array_buffer,vboid[num]); gltexcoordpointer(2,gl_float,sizeof(verts[num]),(void*)(sizeof(glfloat)*3)); glvertexpointer(3,gl_float,sizeof(verts[num]),0); glenableclientstate(gl_texture_coord_array); glenableclientstate(gl_vertex_array); gldrawarrays(gl_quads, 0, verts[num].size()); gldisableclientstate(gl_vertex_array); gldisableclientstate(gl_texture_coord_array);
can explain i'm doing wrong here? why first codes work last ones don't?
i guess solved it.. code renders it's supposed to:
gltexcoordpointer(2,gl_float,sizeof(glfloat) * 5,(void*)(sizeof(glfloat) * 3)); glvertexpointer(3,gl_float,sizeof(glfloat) * 5,(void*)0); ... gldrawarrays(gl_quads, 0, verts[num].size() / 5);
but i'm unsure if it's correct, don't see artifacts don't know what's happening behind scenes.. help, if can confirm code correct please do
but understand here gltexcoordpointer(* 5, * 3) starts third array index (the first texture coordinate) , increases 5 (index * 5) elements forward each time. , glvertexpointer(* 5, 0) starts array index 0 , increases 5 each time. therefore:
verts[num].push_back(x); // index 0 verts[num].push_back(y); // index 1 verts[num].push_back(0); // index 2 // texture offset verts[num].push_back(0); // index 3 verts[num].push_back(offset); // index 4
i can add more stuff heh http://i.imgur.com/iemih6d.png
Comments
Post a Comment