Jump to content
  • Advertisement
Sign in to follow this  
tomba

OpenGL lighting in opengl

This topic is 4050 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

i have a problem with lighting in opengl. I made two spheres which renders correctly. One was an import from Maya and other was the built in gluSphere() function. When i enable lighting the gluSphere renders the correct lighting. The imported sphere gives wrong lighting. Is there something i have to enable or disable? Does gluSphere render by doing something different? THe lighting does in circle around the sphere. The gluSphere has lighting shinning only on surface where the light position is. The imported sphere goes from bright to dark (right color, wrong surfaces) for the entire sphere. glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); glLoadIdentity(); glEnable(GL_DEPTH_TEST); glEnable(GL_LIGHTING); glEnable(GL_LIGHT2); glLightfv(GL_LIGHT2, GL_AMBIENT, greenLightColor); glLightfv(GL_LIGHT2, GL_DIFFUSE, greenLightColor); glLightfv(GL_LIGHT2, GL_SPECULAR, greenLightColor); m_pSphere = gluNewQuadric(); GLfloat flashLightPos[] = {0, sin(theta/360), cos(theta/360), 1.0 }; glLightfv(GL_LIGHT2, GL_POSITION, flashLightPos); theta +=1 % 360; gluLookAt(4,4, 4, 0,0,0, 1, 0, 0); glPushMatrix(); glTranslatef(2,0,0); gluSphere(m_pSphere,0.5f,20,20); glPopMatrix(); //Rendering from Maya: for (int i=0;i<totalF;i++) { glBegin(GL_QUADS); for (int j=0; j<faceSize;j++) { glVertex3f(vertex[faces[j]-1][0],vertex[faces[j]-1][1],vertex[faces[j]-1][2]); } glEnd();

Share this post


Link to post
Share on other sites
Advertisement
For each vertex, you need to provide normals, which are used by the lighting equation to shade the geometry. gluSphere is more than likely providing this information to the API when you call it.

Share this post


Link to post
Share on other sites
You need to supply the vertex normals (which are used in the lighting equation) while rendering the Maya mesh (using glNormal3f).


for (int i=0;i<totalF;i++) {
glBegin(GL_QUADS);
for (int j=0; j<faceSize;j++) {
glNormal3f(normal[faces[j]-1][0],normal[faces[j]-1][1],normal[faces[j]-1][2]);
glVertex3f(vertex[faces[j]-1][0],vertex[faces[j]-1][1],vertex[faces[j]-1][2]);
}
glEnd();



Share this post


Link to post
Share on other sites
thanks a lot everybody. I am really learning from a book. But i get curious and go out of the book. I think they cover this later on. So i'll read the whole book before asking anymore questions. :)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!