i have pretty basic opengl application vertices of single triangle in vao. vertex attributes "p" position , "c" color. shader basic. doesn't transform positions , interpolates colors of 3 vertices on triangle.
the problem occurs when accessing attributes. if position @ location 0 , color @ 1, shader somehow swaps attributes (interpreting color position , vice versa). if color @ 0 , position @ 1, works expected.
i can't figure out, wrong , appreciate help. here code:
... glint loc_p = 0, loc_c = 1; // works not // glint loc_p = 1, loc_c = 0; // works glbindattriblocation(shader1, loc_p, "p"); glbindattriblocation(shader1, loc_c, "c"); glvertexattribpointer(loc_p, 4, gl_float, false, 8*sizeof(glfloat), (glvoid*)0); glvertexattribpointer(loc_c, 4, gl_float, false, 8*sizeof(glfloat), (glvoid*)(4*sizeof(glfloat))); { glclear(gl_color_buffer_bit | gl_depth_buffer_bit); // render shader 1 glbindvertexarray(vao); gluseprogram(shader1); glenablevertexattribarray(loc_p); glenablevertexattribarray(loc_c); gldrawarrays(gl_triangles, 0, 3); } while(running);
vertex shader:
#version 430 in vec4 p; in vec4 c; out vec4 fcol; void main() { fcol = c; gl_position = p; }
fragment shader:
#version 430 in vec4 fcol; void main() { gl_fragcolor = fcol; }
you have link shader program using gllinkprogram
after calling glbindattriblocation
. opengl website:
any attribute binding occurs after program object has been linked not take effect until next time program object linked.
Comments
Post a Comment