Loading 3D *.RAW CAD model

Hi all,
I am working with CAD models converted to *.RAW which has simplest format in terms of vertices. I am able to read the file and draw the triangles to form the 3D model but all the color or material I give is flat colored. Can any one suggest me how can make my CAD model look like a 3D object in real sense

Please excuse me I am new so I am not aware how to give the code separately I will make it brief

<code>
glEnable (GL_DEPTH_TEST);
glEnable (GL_LIGHTING);
glEnable (GL_LIGHT0);
glLightfv(GL_LIGHT0, GL_SPECULAR, whiteSpecularLight);
glLightfv(GL_LIGHT0, GL_AMBIENT, blackAmbientLight);
glLightfv(GL_LIGHT0, GL_DIFFUSE, whiteDiffuseLight);

glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,redDiffuseMaterial);
glMaterialfv(GL_FRONT_AND_BACK,GL_EMISSION,redDiffuseMaterial);
glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, mShininess);
objectfile = fopen(“C:\Users\RoBa\Desktop\sp.raw”, “r”);
while(!feof(objectfile))
{glBegin(GL_TRIANGLES);

glEnd();// Finished Drawing The Triangles}
fclose(objectfile);

</code>

Thank you in Advance !
Rohit

Do you set any normals? Without giving correct normals for your vertices lighting can not work properly.

[ code] in stead of <code> does the trick (without the space).

I do not know if normals are given in the file, but in order to make an object look like a 3d object it needs shading and for that you need normals.

To calculate the normal of a vertex, you calculate the normal of each triangle and attach it to the vertices.
The vector normal - (V2 - V1) x (V3 - V1), in which V1, V2 and V3 are in counter-clockwise order and the x is the crossproduct.

After calculating the normals, you can use them like this:


glBegin(GL_TRIANGLES);
  for each triangle:
    calculate normal;
    for each vertex:
      glNormal3f(normal.x, normal.y, normal.z);
      glVertex3f(vertex.x, vertex.y, vertex.z);
glEnd();