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 6 of 6

Thread: Coloring faces instead of vertices

  1. #1
    Intern Contributor
    Join Date
    Oct 2006
    Posts
    83

    Coloring faces instead of vertices

    Please Help,

    I am trying to use the glDrawElements() with glColorPointer() set to "color" elements/faces and not the individual vertices. Does anybody know if this is possible and if so, please help.

    For example, I have an ASCII file that has a section with X, Y, Z coordinates and Elements/face section with point/nodal connectivity. such that:

    NODE SECTION:
    Node1 X_coord Y_coord Z_coord
    Node2 X_coord Y_coord Z_coord
    ...
    ELEMENT SECTION:
    Element1 Node1 Node2 Node3 Element1_color
    Element2 Node3 Node4 Node5 Element2_color
    ...

    I have been setting the GLfloat colors[] array using R, G, B but it looks like the colors are determined on the vertices/nodes and not for the element/face which is what I would like.

    Any help/hints would be great.

  2. #2
    Advanced Member Frequent Contributor
    Join Date
    May 2005
    Location
    Prague, Czech Republic
    Posts
    924

    Re: Coloring faces instead of vertices

    All data specified using the gl*Pointer calls are per vertex. On GeForce 8 and better hw the functionality you seek can be implemented using geometry shaders however on any older hw you have to create new vertex for each unique combination of Node and element color. So the vertices might look something like:

    Code :
    X1, Y1, Z1, Element1_color
    X2, Y2, Z2, Element1_color
    X3, Y3, Z3, Element1_color
    X3, Y3, Z3, Element2_color
    X4, Y4, Z4, Element2_color
    X5, Y5, Z5, Element2_color

  3. #3
    Intern Contributor
    Join Date
    Oct 2006
    Posts
    83

    Re: Coloring faces instead of vertices

    Thanks Komat.

  4. #4
    Intern Contributor
    Join Date
    Oct 2006
    Posts
    83

    Re: Coloring faces instead of vertices

    One more question:

    What about shared vertices? Each element/face with have some shared nodes/vertices, how is this typically handled with OpenGL using glColorPointers?

    Thanks in advance.

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

    Re: Coloring faces instead of vertices

    For each vertex, you need to have a color and that's not going to change.
    Use index rendering (glDrawElements or glDrawRangeElements)
    and you will be able to reuse vertices that are identical (same vertex and color)
    ------------------------------
    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);

  6. #6
    Intern Contributor
    Join Date
    Oct 2006
    Posts
    83

    Re: Coloring faces instead of vertices

    Thank you, V-man.

    Do you know of a link or some quick and simple example(s) of face/element coloring using index rendering? I am using glDrawElements() but am new, so any help would be great.

Posting Permissions

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