Tearing My Hair Out (Vertex Arrays)

Ive looked at all the definitions, the examples, etc on the web, and the red book… but still very very confused…

I have to draw objects onto the screen made of primitives. Some of these primitives I want to be different colors.

I have defined a global vertex array, and a global color array to store all the vertex and color values used in my opengl program.

My confusion is… can you use two arrays in the same function? e.g. drawitem() then use color and vertex arrays in the same function? I tried doing this, but the color function wouldnt work after the first call e.g. I enabled it, called the 0 array element, then disabled it, then enabled the vertex array, called the vertices then disabled it, tried to call another color element, but it was still the previous color???

Or am I going about this totaly wrong and should the color be in the DISPLAY function, and the vertex array calling be in the object function? and then I put the different colored objects into different functions?

I hope this makes some sense! but I am literally tearing my hair out here!!

Originally posted by <Chaoticjelly>:

the color function wouldnt work after the first call e.g. I enabled it, called the 0 array element, then disabled it, then enabled the vertex array, called the vertices then disabled it, tried to call another color element, but it was still the previous color???

Allow me to rescue you from incipient baldness. You say you “called the 0 array element” of the colour array, which makes no sense. You set up arrays for all the attributes you want your vertices to have, then call one of the drawing functions, which will pull data from ALL of the enabled arrays to actually draw vertices.

// setup:
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(whatever);
glEnableClientState(GL_COLOR_ARRAY);
glColorPointer(whatever);
// use:
glDrawArrays(whatever);