PDA

View Full Version : colors on a mesh of vertices.



omkar26
06-26-2001, 07:50 AM
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???

Deiussum
06-26-2001, 08:35 AM
Simple. Just set the material properties before you set each vertex.

glBegin(GL_TRIANGLES);

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

// etc.
glEnd();

06-27-2001, 03:13 PM
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.

omkar26
06-29-2001, 12:42 AM
Thank you , for your contribution Its working fine after using vertex normals.