Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 5 of 5

Thread: glColorPointer and colors for whole triangle

  1. #1
    Junior Member Newbie
    Join Date
    Aug 2010
    Posts
    3

    glColorPointer and colors for whole triangle

    hello there!

    my vertex data (position and norms) is currently stored in a GL_ARRAY_BUFFER_ARB. the vertex ids (3 ids for one triangle) are hold in a GL_ELEMENT_ARRAY_BUFFER_ARB. The scene is drawn with glDrawElements().

    I now want to draw whole triangles (not single vertices!) in different RGBA colors. I've read about glColorPointer() but this seems to work only for coloring single vertices. Since the triangles share vertices this isn't possible for me.

    The scene I'm drawing is quite large, so I'd like to stick to my vertex buffer objects if possible.

    Maybe someone here can suggest a solution. That would be really nice.

    Cheers!

  2. #2
    Super Moderator OpenGL Guru
    Join Date
    Feb 2000
    Location
    Montreal, Canada
    Posts
    4,421

    Re: glColorPointer and colors for whole triangle

    You would have to use glColor4f or one of the other glColor and then call glDrawElements for every single triangle.

    As for glColorPointer, it is in the FAQ
    http://www.opengl.org/wiki/FAQ#Multi_indexed_rendering
    ------------------------------
    Sig: http://glhlib.sourceforge.net
    an open source GLU replacement library. Much more modern than GLU.
    float matrix[16], inverse_matrix[16];
    glhLoadIdentityf2(matrix);
    glhTranslatef2(matrix, 0.0, 0.0, 5.0);
    glhRotateAboutXf2(matrix, angleInRadians);
    glhScalef2(matrix, 1.0, 1.0, -1.0);
    glhQuickInvertMatrixf2(matrix, inverse_matrix);
    glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);
    glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);

  3. #3
    Senior Member OpenGL Guru
    Join Date
    May 2009
    Posts
    4,728

    Re: glColorPointer and colors for whole triangle

    Since the triangles share vertices this isn't possible for me.
    No, triangles do not share vertices. A vertex is a collection of data which includes the position, but is not only the position. Triangles that use the same vertex positions but different vertex colors do not share vertices.

    Therefore, you must break up your position list, such that each triangle uses its own vertex positions (not shared with other vertices), which can be paired up with different vertex colors.

  4. #4
    Member Regular Contributor
    Join Date
    May 2001
    Posts
    349

    Re: glColorPointer and colors for whole triangle

    Sounds like flat shading to me.
    glShadeModel(GL_FLAT);

  5. #5
    Senior Member OpenGL Guru
    Join Date
    May 2009
    Posts
    4,728

    Re: glColorPointer and colors for whole triangle

    Sounds like flat shading to me.
    That won't help. Because each triangle needs to have its own color. We're talking about vertex attribute data, not post-transform shader data.

    In order for flat shading to work as you suggest, you would have to be very, very careful about which colors you assign which triangles. Triangle strips are right out the window, and an optimized list would be difficult if not impossible to generate.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •