In the following code , I’m trying to draw the 3 Cartesian axis with 3 colors (red,blue,green) , the lines are drawing correctly , but the colors is incorrect . So how should I setup the color index array ? Many thanks!
auto draw_axis = [] {
struct {
float ary[3];
} axis[] = {
0.0f, 0.0f, 0.0f,
5.0f, 0.0f, 0.0f,
0.0f, 5.0f, 0.0f,
0.0f, 0.0f, 5.0f,
}, colors[] = {
1.0f,0.0f,0.0f,
0.0f,0.0f,1.0f,
0.0f,1.0f,0.0f,
};
unsigned char indices_vtx[] = {0,1,0,2,0,3};
unsigned char indices_clr[] = {0,0,1,1,2,2}; // not sure if this is correct
glVertexPointer(3,GL_FLOAT,sizeof(float)*3,(void*)axis);
glColorPointer(3,GL_FLOAT,sizeof(float)*3,(void*)colors);
glIndexPointer(GL_UNSIGNED_BYTE,0,(void*)indices_clr); // not sure if this is correct
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_COLOR_ARRAY);
glEnableClientState(GL_INDEX_ARRAY);
glLineWidth(2);
glDrawElements(GL_LINES,sizeof(indices_vtx),GL_UNSIGNED_BYTE,(void*)indices_vtx);
};