Sign in to follow this  
tomba

OpenGL lighting in opengl

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[i];j++) { glVertex3f(vertex[faces[i][j]-1][0],vertex[faces[i][j]-1][1],vertex[faces[i][j]-1][2]); } glEnd();

Share this post


Link to post
Share on other sites
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[i];j++) {
glNormal3f(normal[faces[i][j]-1][0],normal[faces[i][j]-1][1],normal[faces[i][j]-1][2]);
glVertex3f(vertex[faces[i][j]-1][0],vertex[faces[i][j]-1][1],vertex[faces[i][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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this