PDA

View Full Version : Help understanding glColorPointer.



rnodal
06-09-2008, 09:34 AM
Hello all:

I'm having problems in my application due to glColorPointer. So I have a couple questions about it so maybe I can understand what I'm doing wrong.

1- If I plan on having my color components in a one dimensionaly array what should my stride be?
GLfloat colors[] = {1.0, 0.5, 1.0, 1.0,
0.2, 1.0, 1.0, 1.0,
etc, etc};

2- How does opengl know when to stop picking color? Is it based on how many primitives I draw?

3- Are the colors being applied to each vertex or the whole primitive?

4- How many colors are you required to have in a color array if you want to render let's say 4 quads? I would say 4 but things are not working for me based on that reasoning.

Thanks a lot for your time!

-r

Zengar
06-09-2008, 09:51 AM
Colors are specified per-vertex. So if you draw N vertices, you need N color vectors. In case of an array, the stride is zero (if compiler doesn't do funny stuff with alignment).

rnodal
06-09-2008, 09:58 AM
Thanks for the answer. Just to confirm, If I want to draw 3 quads and I want all the quads to be white and solid. I would need 12 colors in my color array then? So the array would contain:
1.0, 1.0, 1.0, 1.0, repeated 12 more times? Thanks!

-r

Zengar
06-09-2008, 12:21 PM
If you set up your color array to use 4-component colors, then yes: you will need 48 floats (12 sets of 4 element vectors).

But when the color stays the same for all vertices, why even bother using color arrays? Just put glColor(1, 1, 1, 1) before the draw call --- the attribute will be then propagated to all vertices.

rnodal
06-09-2008, 02:14 PM
Well I will render more than 100 images and also some images will be duplicated and drawn with a different color so I think that is better so I don't have to make a call to glColor4f for every color. Thanks for the help I got the result that I wanted. The only problem left is this flickering that happens on the border of images that move. Neither multi sampling neither vsync can do anything about it.

-R