c - opengl interleaving vbo not rendering to screen -


the opengl documentation interleave data , use stride , offset pack multiple vertex attributes 1 buffer.

the api reference here list format.

void glvertexattribpointer( gluint index,     glint size,     glenum type,     glboolean normalized,     glsizei stride,     const glvoid * pointer); 

i having trouble getting things render using format. can render scene using 3 separate buffers , putting data in there using 1 buffer rendering blank screen.

data structure.

typedef struct {     vec3 angles;     glshort vertex_count;     glfloat vertices[12];     glfloat colors[16];     glshort indices[6];     glfloat tex_coords[8]; } cg_sprite;  glgenvertexarrays(1, &big_vao); glgenbuffers(1, &big_vbo); glgenbuffers(1, &big_ibo);  glbindvertexarray(big_vao);  glbindbuffer(gl_array_buffer, big_vbo); glbufferdata(gl_array_buffer, big_vbo_size, big_v_buff, gl_stream_draw);  glbindbuffer(gl_element_array_buffer, big_ibo); glbufferdata(gl_element_array_buffer, big_ibo_total, big_i_buff,              gl_stream_draw);  glvertexattribpointer(0, 3, gl_float, gl_false, 9 * sizeof(glfloat),                       (glvoid*)0); glvertexattribpointer(1, 4, gl_float, gl_false, 9 * sizeof(glfloat),                       (glvoid*)(4 * sizeof(float))); glvertexattribpointer(2, 2, gl_float, gl_false, 9 * sizeof(glfloat),                       (glvoid*)(7 * sizeof(float)));   glbindbuffer(gl_array_buffer, 0); glbindbuffer(gl_element_array_buffer, 0); glbindvertexarray(0); 

after setting vbo that, in rendering loop. after translate, rotate , scale vertices on cpu, pack them giant buffers this:

cg_sprite_back_2_front(sprites, sprite_count); (int = 0; < sprite_count; i++) {     //--------------- start packing data buffers----------------     sp = sprites[i];      // v0     idx = 0;     big_v_buff[(i * 36) + idx++] = ov0.x;     big_v_buff[(i * 36) + idx++] = ov0.y;     big_v_buff[(i * 36) + idx++] = ov0.z;      big_v_buff[(i * 36) + idx++] = sp->quad->colors[0];     big_v_buff[(i * 36) + idx++] = sp->quad->colors[1];     big_v_buff[(i * 36) + idx++] = sp->quad->colors[2];     big_v_buff[(i * 36) + idx++] = sp->quad->colors[3];      big_v_buff[(i * 36) + idx++] = sp->quad->tex_coords[0];     big_v_buff[(i * 36) + idx++] = sp->quad->tex_coords[1];      // v1     big_v_buff[(i * 36) + idx++] = ov1.x;     big_v_buff[(i * 36) + idx++] = ov1.y;     big_v_buff[(i * 36) + idx++] = ov1.z;      big_v_buff[(i * 36) + idx++] = sp->quad->colors[4];     big_v_buff[(i * 36) + idx++] = sp->quad->colors[5];     big_v_buff[(i * 36) + idx++] = sp->quad->colors[6];     big_v_buff[(i * 36) + idx++] = sp->quad->colors[7];      big_v_buff[(i * 36) + idx++] = sp->quad->tex_coords[2];     big_v_buff[(i * 36) + idx++] = sp->quad->tex_coords[3];      // v2     big_v_buff[(i * 36) + idx++] = ov2.x;     big_v_buff[(i * 36) + idx++] = ov2.y;     big_v_buff[(i * 36) + idx++] = ov2.z;      big_v_buff[(i * 36) + idx++] = sp->quad->colors[8];     big_v_buff[(i * 36) + idx++] = sp->quad->colors[9];     big_v_buff[(i * 36) + idx++] = sp->quad->colors[10];     big_v_buff[(i * 36) + idx++] = sp->quad->colors[11];      big_v_buff[(i * 36) + idx++] = sp->quad->tex_coords[4];     big_v_buff[(i * 36) + idx++] = sp->quad->tex_coords[5];      // v3     big_v_buff[(i * 36) + idx++] = ov3.x;     big_v_buff[(i * 36) + idx++] = ov3.y;     big_v_buff[(i * 36) + idx++] = ov3.z;      big_v_buff[(i * 36) + idx++] = sp->quad->colors[12];     big_v_buff[(i * 36) + idx++] = sp->quad->colors[13];     big_v_buff[(i * 36) + idx++] = sp->quad->colors[14];     big_v_buff[(i * 36) + idx++] = sp->quad->colors[15];      big_v_buff[(i * 36) + idx++] = sp->quad->tex_coords[6];     big_v_buff[(i * 36) + idx++] = sp->quad->tex_coords[7];      idx = 0;     big_i_buff[(i * 6) + idx++] = * 4 + sp->quad->indices[0];     big_i_buff[(i * 6) + idx++] = * 4 + sp->quad->indices[1];     big_i_buff[(i * 6) + idx++] = * 4 + sp->quad->indices[2];      big_i_buff[(i * 6) + idx++] = * 4 + sp->quad->indices[3];     big_i_buff[(i * 6) + idx++] = * 4 + sp->quad->indices[4];     big_i_buff[(i * 6) + idx++] = * 4 + sp->quad->indices[5];     idx = 0;   } 

then render call

  glbindbuffer(gl_array_buffer, big_vbo);     glbufferdata(gl_array_buffer, big_vbo_total, big_v_buff, gl_stream_draw);      glbindbuffer(gl_element_array_buffer, big_ibo);     glbufferdata(gl_element_array_buffer, big_ibo_total, big_i_buff,                  gl_stream_draw);  gldrawelements(gl_triangles, sprite_count* 6, gl_unsigned_short, 0); 

this draws blanks screen. can't find out might going wrong.

ok kinda crazy. using gpuperf studio amd debug leads more confusion. took 2 screenshots of app running.

the profiler shows code should rendering whatever reason not.

here screenshots. enter image description here enter image description here

you can see debugger there's 2 triangles quad suppose be. have simplistic shader, data getting gpu reason it's not rendering correctly confusing.

now don't understand what's going on. have advise?

enter image description here

in addition calling glvertexattribpointer have enable vertex attribute using `glenablevertexattribarray. in addition, offset texture coordinates wrong. have start @ 8th element, not @ 7th.

glenablevertexattribarray(0); glvertexattribpointer(0, 3, gl_float, gl_false, 9 * sizeof(glfloat),                   (glvoid*)0); glenablevertexattribarray(1); glvertexattribpointer(1, 4, gl_float, gl_false, 9 * sizeof(glfloat),                   (glvoid*)(4 * sizeof(float))); glenablevertexattribarray(2); glvertexattribpointer(2, 2, gl_float, gl_false, 9 * sizeof(glfloat),                   (glvoid*)(8 * sizeof(float)));                             ^ 

next thing: if unbind gl_element_array_buffer while vao still bound, removed vao state. disable has happen in order:

glbindvertexarray(0); glbindbuffer(gl_element_array_buffer, 0); 

rendering: unbind vao after initializing vertex attribute pointers, if forgot bind before issuing draw call.

side-note: if data of vbo's not changing in every frame, should upload data once during initialization , not in every frame.


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -