vertex arrays & colors

Started by
7 comments, last by DuckWizard 19 years, 11 months ago
When I use glDrawElements to draw a vertex array, the color array seems like it''s being ignored.

glEnableClientState(GL_COLOR_ARRAY);
glColorPointer(4, GL_FLOAT, 0, this->blend1);
where this->blend1 is an array of the same size as the vertex array of:

struct color4
{
   float r;
   float g;
   float b;
   float a;
}
What could I be missing? The vertex color is simply ignored - if I turn off texture maps everything is white. (even though to test it, I filled the color array with red). Thanks, -Jeremy
Advertisement
This is so strange - the colors are ignored when the vertex array is being drawn, but if I don''t reset the current color after the call to glDrawElements, then whatever I draw afterward is drawn in the color from the color array.

What''s going on here?!
Are you using texturing as well?

What is your TexEnv() set to?

And this is stupid, but make sure you are setting that stuff Before the glDrawElements() call. (I''ve done dumber things)



Waramp.

"Before you insult a man, walk a mile in his shoes.
That way, when you do insult him, you''ll be a mile away, and you''ll have his shoes."
Waramp.Before you insult a man, walk a mile in his shoes.That way, when you do insult him, you'll be a mile away, and you'll have his shoes.
I disabled texturing for the purposes of figuring out what''s going on. So no, I''m not using textures.

And I double checked, everything is being done in the right order :-)

I''m stumped.
hmmm.

so each of rgba is confined to be between 0 and 1 correct?

and blend1 is like
color4 blend1[500]; ?

and the blend1 has exactly as many elements as the vertex array? (ie, in this case, both have 500 elements?)

maybe try changing

glColorPointer(4, GL_FLOAT, 0, this->blend1);

to

glColorPointer(4, GL_FLOAT, 0, &this->blend1[0].r);


Waramp.

"Before you insult a man, walk a mile in his shoes.
That way, when you do insult him, you''ll be a mile away, and you''ll have his shoes."
Waramp.Before you insult a man, walk a mile in his shoes.That way, when you do insult him, you'll be a mile away, and you'll have his shoes.
are you using lighting?
Thanks for the tip - just to test it I turned off lighting and presto! Vertex colors are used. Is there any way I can get it to work with lighting?

Thanks,
-Jeremy
quote:Original post by DuckWizard
Thanks for the tip - just to test it I turned off lighting and presto! Vertex colors are used. Is there any way I can get it to work with lighting?

Yes, see glColorMaterial. If the default settings are what you want, just call glEnable with GL_COLOR_MATERIAL.

Smashing. Works flawlessly now.

Thanks for all of your help, everyone!

This topic is closed to new replies.

Advertisement