PDA

View Full Version : Two Sided Lighting, need help



jerin3D
03-15-2002, 09:34 AM
Hi,
I rendered a 3D object with light in MFC window .I implemented a light that moves along with the viewpoint.Then the object's inside seems to be very dark. So i give glLightModeli( GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE);Then indside the object seems very white.Initally i specified color is yellow.Front face is yello and back face is white.Where i miss any initialization ??
The code written is given below:-

// initializing function

// Light0
GLfloat global_ambient[] = {0.1f, 0.1f, 0.1f, 1.0f};
GLfloat lit0_ambient[] = {0.2f, 0.2f, 0.2f, 1.0f};
GLfloat lit0_diffuse[] = {1.0f, 1.0f, 1.0f, 1.0f;
GLfloat lit0_specular[] ={1.0f, 1.0f, 1.0f, 1.0f};
GLfloat lit0_position[] ={1.0f, -1.0f, 0.0f, 1.0f};

glLightfv(GL_LIGHT0, GL_AMBIENT, lit0_ambient);
glLightfv(GL_LIGHT0, GL_DIFFUSE, lit0_diffuse);
glLightfv(GL_LIGHT0, GL_SPECULAR, lit0_specular);
glLightfv(GL_LIGHT0, GL_POSITION, lit0_position);

glLightModeli( GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE);
GLfloat mat_shininess[] = { 90.0 };
glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess);

glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);

glEnable( GL_COLOR_MATERIAL );
glColorMaterial (GL_FRONT, GL_AMBIENT_AND_DIFFUSE);

glClearDepth( 1.0f );
// enable depth testing
glEnable( GL_DEPTH_TEST );


//in the OnSize function ///
glViewport(0, 0, (GLsizei)cx, (GLsizei)cy);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(50, (GLdouble)cx/(GLdouble)cy, 0.001f, 100.0f);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glLightfv(GL_LIGHT0, GL_POSITION, lit0_position);

Sorry for bad English,
Thanks,
Jerry

tcobbs
03-15-2002, 11:05 AM
This REALLY belongs in the beginner forum, but your problem is that your material settings are all set to GL_FRONT. Change them to GL_FRONT_AND_BACK to have them effect both sides.

jerin3D
03-15-2002, 06:39 PM
Originally posted by tcobbs:
This REALLY belongs in the beginner forum, but your problem is that your material settings are all set to GL_FRONT. Change them to GL_FRONT_AND_BACK to have them effect both sides.


Many many thanks tcobbs !!!Yes,you are right.
I am really sorry for this post here.But it was very urgent,so i post here also.Then i feel that discussion forum is very very helpful.

Jerry