Setting color attribute for a VBO in OpenGL using the fixed function pipeline -
i want use vbo's , fixed function pipeline (i know should using shaders need use ffp...)
i have triangle being drawn, can't color attributes set-up correctly.
here create buffers
const glfloat vertexpositions[] = {10, 10, 0,10, -10, 0, -10, -10, 0}; const glfloat vertexcolours[] = {1,0,0,0,0,1, 0,1,0}; gluint positionsbufferobject; glgenbuffers(1, &positionsbufferobject); glbindbuffer(gl_array_buffer, positionsbufferobject); glbufferdata(gl_array_buffer, 9*sizeof(glfloat), vertexpositions, gl_static_draw); glfinish(); //wait until data transfered glvertexpointer( 3, gl_float, 0, (char *) null ); //attributes in bound buffer gluint colourbufferobject; glgenbuffers(1, &colourbufferobject); glbindbuffer(gl_array_buffer, colourbufferobject); glbufferdata(gl_array_buffer, 3 * sizeof(glfloat), vertexcolours, gl_static_draw); // set size , data of our vbo , set static_draw glfinish(); glcolorpointer( 3, gl_float, 0, (char *) null );//attributes in bound buffer
and draw;
glenableclientstate(gl_vertex_array); glenableclientstate(gl_color_array); gldrawarrays(gl_triangles, 0, 3); // draw first object
the triangle gets drawn, colors wrong, first vertex gets correct color (red) remaining 2 black;
i've tried messing around glvertexattribpointer different values of index, suspect won't have impact in ffp. going wrong?
glbufferdata(gl_array_buffer, 3 * sizeof(glfloat), vertexcolours, ...
should presumably pass 9 * sizeof(glfloat)
size
parameter.
since did vertexpositions
, looks cut-and-paste bug:)
Comments
Post a Comment