lighting in opengl

Started by
2 comments, last by tomba 16 years, 11 months ago
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();
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.
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();


- Thomas Cowellwebsite | journal | engine video

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. :)

This topic is closed to new replies.

Advertisement