PDA

View Full Version : Crazy Shading I need help!

Raishael
03-04-2003, 09:37 PM
Hi everyone! I'm new here and stuff so just sayin' "Yo" to everyone first.

Okay now down to business http://www.opengl.org/discussion_boards/ubb/smile.gif Anyways... I am working on an OpenGL project for school actually. And our last project was to make a 3d neighborhood where the end house on the street would roll into the street and roll down the street. It wasnt too bad. Anyways, for our next project we had to build on that one. We have to add Smooth Shading to that using 3 light sources, Ambient, Diffuse, and Spectral. I am attempting to get this to work and am using the GLUT library. The Lighting seems to go crazy on the rolling house as it rolls where certain sides are not colored and certain sides are 1/2 colored and they keep flipping and changing. Does anyone know what I would be doing wrong. Also my stationary houses that I've set Normal vectors up for each wall, they seem to all be the color of the spectral light I have described below, I mean all that blue color dispite the angle they are facing from the light source. Either that or they are not colored at all, but never spectrally lit. some fragments of my code look like this...

This is what my typical polygon function is like... is this correct for shading, and how I implemented the normal vector?
void frontWall() {
glColor3f(0.0,0.0,1.0);
glBegin(GL_POLYGON);
glNormal3f(1,0,0);
glVertex3f(25,25,-25);
glVertex3f(25,25,25);
glVertex3f(25,-25,25);
glVertex3f(25,-25,-25);
glEnd();
}

Here's my shading for my Spectral shading... would anyone notice any problems with it?
GLfloat MatSpecular[] = {0.0,0.0,0.8,1.0};
GLfloat Light2Specular[] = {1.0,1.0,1.0,1.0};
GLfloat Light2Position[] = {1000, 0, 1000, 1};
glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, GL_TRUE);
(translations and rotations done here to give the neighborhood a 3d feel)
glMaterialfv(GL_FRONT,GL_SPECULAR,MatSpecular);
glLightfv(GL_LIGHT2,GL_SPECULAR,Light2Specular);
glLightfv(GL_LIGHT2,GL_POSITION,Light2Position);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT2);
(background neighborhood is drawn here)
(translate/rotate moving house)
(draw moving house)
(back to regular neighborhood matrix)
(forground neighborhood is drawn here)
(loops)

Any insite at all would be helpful.

fringe
03-05-2003, 12:51 AM
Hi ,

I haven't donw much lighting so I don't really know what is going on but have you made sure that the windings for all triangles are correct to make them face outwards. A good way to check is to turn of the lighting then enable back face culling.

Hope this helps allittle,

John