Results 1 to 5 of 5

Thread: Help understanding glColorPointer.

  1. #1
    Junior Member Newbie rnodal's Avatar
    Join Date
    Jun 2008
    Posts
    24

    Help understanding glColorPointer.

    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

  2. #2
    Senior Member OpenGL Pro Zengar's Avatar
    Join Date
    Sep 2001
    Location
    Germany
    Posts
    1,931

    Re: Help understanding glColorPointer.

    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).

  3. #3
    Junior Member Newbie rnodal's Avatar
    Join Date
    Jun 2008
    Posts
    24

    Re: Help understanding glColorPointer.

    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

  4. #4
    Senior Member OpenGL Pro Zengar's Avatar
    Join Date
    Sep 2001
    Location
    Germany
    Posts
    1,931

    Re: Help understanding glColorPointer.

    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.

  5. #5
    Junior Member Newbie rnodal's Avatar
    Join Date
    Jun 2008
    Posts
    24

    Re: Help understanding glColorPointer.

    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

Similar Threads

  1. glColorpointer
    By Janani in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 11-25-2009, 02:30 AM
  2. glColorPointer in linux
    By Janani in forum OpenGL: Linux
    Replies: 3
    Last Post: 11-25-2009, 02:27 AM
  3. glColorPointer
    By Connection in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 12-05-2008, 12:50 PM
  4. glColorPointer PROBLEM!!
    By robert_s in forum OpenGL: Advanced Coding
    Replies: 7
    Last Post: 01-18-2002, 05:31 PM
  5. glColorPointer & glDrawElements
    By mad666 in forum OpenGL: Advanced Coding
    Replies: 5
    Last Post: 05-26-2001, 04:43 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean