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: colouring triangles

  1. #1
    Junior Member Newbie
    Join Date
    Dec 2004
    Location
    wales
    Posts
    12

    colouring triangles

    im trying to learn how to light up a triangle strip on a polygon mesh, and i cant seem to get it to work. im using the following...

    void faceStrip (CGPolyMesh *m, int faceIndex, int edgeIndex)
    {

    int i;
    CGFaceVertex *f;
    RGBAColor *cptr;

    // setup vertex array
    glEnableClientState(GL_VERTEX_ARRAY);
    glVertexPointer(3, GL_FLOAT, 0, m->V);

    glBegin(GL_TRIANGLES);

    for (f=m->Fv, i=0 ; i<m->noofFaces ; i++, f++)cptr = m->C + i; // i'th face colour in colour array
    glColor3f(cptr->r, cptr->g, cptr->b);

    glArrayElement(f->v1);
    glColor3f(1.0, 1.0, 0.0);
    glArrayElement(f->v2);
    glColor3f(1.0, 1.0, 0.0);
    glArrayElement(f->v3);
    glColor3f(1.0, 1.0, 0.0);





    }

    glEnd();

    glEnableClientState(GL_VERTEX_ARRAY);

    does any one know where im going wrong?

    thanx

    jofoxy

  2. #2
    Junior Member Newbie
    Join Date
    Dec 2004
    Location
    wales
    Posts
    12

    Re: colouring triangles

    where i say light i mean colour in red for example

  3. #3
    Senior Member OpenGL Guru knackered's Avatar
    Join Date
    Aug 2001
    Location
    UK
    Posts
    2,833

    Re: colouring triangles

    If you've got lighting enabled, glColor does nothing, you must manipulate the colour of the object by changing its material properties.
    However, you can still use glColor by using colormaterial:-
    Code :
    glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);
    glEnable(GL_COLOR_MATERIAL);
    This will make OpenGL change the ambient and diffuse attributes of the current material whenever you use glColor or equivalent.
    Knackered

  4. #4
    Junior Member Newbie
    Join Date
    Dec 2004
    Location
    wales
    Posts
    12

    Re: colouring triangles

    i dont mean light up i mean colour in red a triangle stip polygon

  5. #5
    Senior Member OpenGL Pro
    Join Date
    May 2000
    Location
    Naarn, Austria
    Posts
    1,102

    Re: colouring triangles

    Why do you call glColor3f(1.0, 1.0, 0.0) between your vertices? You would get only yellow polygons this way, because AFAIK with flat shading the color of the last vertex determines the color of the whole polygon. Or you might get color interpolation between your color and yellow if you activate smooth shading.

  6. #6
    Super Moderator OpenGL Guru dorbie's Avatar
    Join Date
    Jul 2000
    Location
    Bay Area, CA, USA
    Posts
    3,969

    Re: colouring triangles

    You need to post your question as an OpenGL question *ONCE* and you should stick to the beginners forum for now.

    If you don't get a reply in one thread don't post another two.

    Moving thread to beginners forum.

Posting Permissions

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