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

Thread: colors on a mesh of vertices.

Hybrid View

  1. #1
    Junior Member Newbie
    Join Date
    Jun 2001
    Location
    durgapur,west bengal, india
    Posts
    11

    colors on a mesh of vertices.

    Hi folks,
    I have created a mesh of vertices. I have also been able to color some reqd no. of. vertices in SMOOTH shading mode. But I want to color different vertices with different material properties , how can I do so???

  2. #2
    Senior Member OpenGL Pro
    Join Date
    Oct 2000
    Location
    Fargo, ND
    Posts
    1,797

    Re: colors on a mesh of vertices.

    Simple. Just set the material properties before you set each vertex.

    glBegin(GL_TRIANGLES);

    SetMaterialForVert1();
    glVertex3f(...);
    SetMaterialForVert2();
    glVertex3f(...);
    SetMaterialForVert3();
    glVertex3f(...);

    // etc.
    glEnd();
    Deiussum
    Software Engineer and OpenGL enthusiast

  3. #3
    Guest

    Re: colors on a mesh of vertices.

    You're also gonna have to work with vertex normals, which can be somewhat of a difficult task at first. Basically, first you calculate the surface normal of each face (the normalized cross product of 3 vertices of the faces). Then, you average the surface normals of adjacent surfaces to get a vertex normal. However, with sharp objects, you might not want the vertex normal to be generated, so you only average the surface normals if the dot product of the normals is >= the cosine of the angle of choice.

  4. #4
    Junior Member Newbie
    Join Date
    Jun 2001
    Location
    durgapur,west bengal, india
    Posts
    11

    Re: colors on a mesh of vertices.

    Thank you , for your contribution Its working fine after using vertex normals.

Posting Permissions

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