Advertisement

Lighting problem

Started by March 03, 2002 01:56 PM
6 comments, last by cMADsc 22 years, 11 months ago
Greetings all, The problem I am have is when there is an object that can be rotated in my scene, only the front facing side is lit, the other sides seem rather dark. Could it be my normals calculation is off or something? Any suggestions to fix this is surely appreciated? Thx! ----------------------------- "There are ones that say they can and there are those who actually do." "...u can not learn programming in a class, you have to learn it on your own."
-----------------------------"There are ones that say they can and there are those who actually do.""...u can not learn programming in a class, you have to learn it on your own."
I''m not good in lighting but is your position not so placed that it''s only shining on the front side?

Are you using ambient or specular?
Advertisement
I''m not very good in lighting either

but it may be your normal calculations (again I dont know very much about lighting

can we see the code you are using to calculate them? Sometimes a sign error or a little mistake can cause everything to screw up
I am not good at lighting either.I have went back to the basic cubed and tried making a simple cube to see if I could find out the problem. Not successful yet. Only the code that pertains to the problem is included, hopefully


    [code]//globalsfloat ambient[]={0.40f, 0.40f, 0.40f, 1.0f};float diffuse[]={0.7f, 0.7f, 0.7f, 1.0f};float lightPos[] ={0.0f, 0.0f, 10.0f, 1.0f};     //draws the cube//only front face is actually properly litint RenderScene()//Does all the OpenGL drawing { 			 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);	glRotatef(xRot, 1.0f, 0.0f, 0.0f);	glRotatef(yRot, 0.0f, 1.0f, 0.0f);	glColor3f(1.0f, 0.0f, 0.0f);	glLightfv(GL_LIGHT0, GL_POSITION, lightPos);		DrawCube(0,0,0);		glLightfv(GL_LIGHT0, GL_POSITION, lightPos);			 return 0; }////////////////////////////////////////////////int SetupRC()//does any initialing that is needed{ 	glClearColor(0.0f, 0.0f, 0.0f, 1.0f);	glEnable(GL_DEPTH_TEST);	glFrontFace(GL_CCW);	glCullFace(GL_BACK);	glShadeModel(GL_FLAT);	glEnable(GL_LIGHTING);	glMaterialfv(GL_FRONT, GL_AMBIENT, matAmbient);	glMaterialfv(GL_FRONT, GL_DIFFUSE, matDiff);//	glLightfv(GL_LIGHT0, GL_AMBIENT, ambient);	glLightModelfv(GL_LIGHT_MODEL_AMBIENT, ambient);	glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse);	glLightfv(GL_LIGHT0, GL_POSITION, lightPos);	glEnable(GL_LIGHT0); 		glEnable(GL_COLOR_MATERIAL);	glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE);	return 0;}///////////////////////////////////////////////////////////void DrawCube(float xPos, float yPos, float zPos){	glPushMatrix();		glTranslatef(xPos, yPos, zPos);		glBegin(GL_POLYGON);		glNormal3f(0.0f, 1.0f, 0.0f);	// top face			glVertex3f(0.5f, 0.5f, 0.5f);				glVertex3f(0.5f, 0.5f, -0.5f);			glVertex3f(-0.5f, 0.5f, -0.5f);			glVertex3f(-0.5f, 0.5f, 0.5f);		glEnd();		glBegin(GL_POLYGON);		glNormal3f(0.0f, 0.0f, 1.0f);	// front face			glVertex3f(0.5f, 0.5f, 0.5f);				glVertex3f(-0.5f, 0.5f, 0.5f);			glVertex3f(-0.5f, -0.5f, 0.5f);			glVertex3f(0.5f, -0.5f, 0.5f);		glEnd();		glBegin(GL_POLYGON);		glNormal3f(1.0f, 0.0f, 0.0f);	// right face			glVertex3f(0.5f, 0.5f, 0.5f);				glVertex3f(0.5f, -0.5f, 0.5f);			glVertex3f(0.5f, -0.5f, -0.5f);			glVertex3f(0.5f, 0.5f, -0.5f);		glEnd();		glBegin(GL_POLYGON);		glNormal3f(-1.0f, 0.0f, 0.0f);	// left face			glVertex3f(-0.5f, 0.5f, 0.5f);				glVertex3f(-0.5f, 0.5f, -0.5f);			glVertex3f(-0.5f, -0.5f, -0.5f);			glVertex3f(-0.5f, -0.5f, 0.5f);		glEnd();	glBegin(GL_POLYGON);		glNormal3f(0.0f, -1.0f, 0.0f);	// bottom face			glVertex3f(-0.5f, -0.5f, 0.5f);			glVertex3f(-0.5f, -0.5f, -0.5f);			glVertex3f(0.5f, -0.5f, -0.5f);			glVertex3f(0.5f, -0.5f, 0.5f);			glEnd();		glBegin(GL_POLYGON);		glNormal3f(0.0f, 0.0f, -1.0f);	// back face			glVertex3f(0.5f, -0.5f, -0.5f);			glVertex3f(-0.5f, -0.5f, -0.5f);			glVertex3f(-0.5f, 0.5f, -0.5f);			glVertex3f(0.5f, 0.5f, -0.5f);			glEnd();	glPopMatrix();}[code]    



-----------------------------
"There are ones that say they can and there are those who actually do."

"...u can not learn programming in a class, you have to learn it on your own."



Edited by - cMADsc on March 3, 2002 5:38:52 PM
-----------------------------"There are ones that say they can and there are those who actually do.""...u can not learn programming in a class, you have to learn it on your own."
try this ...


  int RenderScene()//Does all the OpenGL drawing{glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);glLoadIdentity();glLightfv(GL_LIGHT0, GL_POSITION, lightPos);glRotatef(xRot, 1.0f, 0.0f, 0.0f);glRotatef(yRot, 0.0f, 1.0f, 0.0f);glColor3f(1.0f, 0.0f, 0.0f);DrawCube(0,0,0);return 0;}   


Edited by - Shag on March 3, 2002 5:49:09 PM

Edited by - Shag on March 3, 2002 5:49:39 PM
its the normals, dont ask me why but its always the normals
but seriously been a while since i was programming but they look wrong to me, cant remember how to calculate the damn things anymore but you should check up on them... and dont use GL_POLYGON its sloooooow use triangle strip or fan
Advertisement
Ok, I will try it out. Hope it works! Although, I did notice when I added the "glLoadIdentity()", in the function RenderScene, I had to increment the rotation of the cubed substanionally compared to before. Big difference.

without glLoadIdentity;
if(keys[VK_RIGHT])//right arrow key has been pushed
{
yRot+= 0.02f;//angle incremented
}
//////////////////////////////////////////////
with glLoadIdentity;
if(keys[VK_RIGHT])//right arrow key has been pushed
{
yRot+= 0.302f;//angle incremented
}

Edited by - cMADsc on March 3, 2002 6:03:44 PM
-----------------------------"There are ones that say they can and there are those who actually do.""...u can not learn programming in a class, you have to learn it on your own."
I went back and recalculated the normals and lighting problems are corrected!! Thanks again!!!!


-----------------------------
"There are ones that say they can and there are those who actually do."

"...u can not learn programming in a class, you have to learn it on your own."

-----------------------------"There are ones that say they can and there are those who actually do.""...u can not learn programming in a class, you have to learn it on your own."

This topic is closed to new replies.

Advertisement