Lighting Problem

Started by
1 comment, last by Xersist 22 years, 3 months ago
Anyone know what I could do to check to see what is wrong with the below? The OpenGL code is pretty much straight from Lesson 7 of NeHe''s tutorials. What happens is when the cube face that is facing the viewer turns away the "light" dims out, then when the cube face that was facing the viewer turns back toward the viewer again, the light fades back brighter. It''s like the light itself is turning off and on when the 1 cube face faces the viewer. But as you can see from the code below I don''t change any of the lights propteries. Below is the code I am using. I have included all the OpenGL code I am using besides what is needed to just create the window. The program you can see this happening is here. I did not include the image, you will get an error but the program will still run. Otherwise you can just supply your own image if you want.
  
GLfloat LightAmbient[]=		{ 0.5f, 0.5f, 0.5f, 1.0f };
GLfloat LightDiffuse[]=		{ 1.0f, 1.0f, 1.0f, 1.0f };
GLfloat LightPosition[]=	{ 0.0f, 0.0f, -2.0f, 1.0f };

//////////////////////////////////////////////////////////////////////

// Resize the application window.

//////////////////////////////////////////////////////////////////////

BOOL MyProgram::Resize(INT w, INT h)
{
	h == 0 ? h = 1 : h;												// Prevent A Divide By Zero Error

	glViewport(0, 0, (GLsizei)(w), (GLsizei)(h));					// Reset The Current Viewport

	glMatrixMode(GL_PROJECTION);									// Select The Projection Matrix

	glLoadIdentity();												// Reset The Projection Matrix

	gluPerspective(45.0f, (GLfloat)(w)/(GLfloat)(h), 0.1f, 100.0f);	// Calculate The Aspect Ratio Of The Window

							
	glMatrixMode(GL_MODELVIEW);										// Select The Modelview Matrix

	glLoadIdentity();												// Reset The Modelview Matrix

	
	return TRUE;
}

//////////////////////////////////////////////////////////////////////

// Initialize The Application After Window Is Created

// Called Each Time Window Is Created Including Fullscreen Switch

//////////////////////////////////////////////////////////////////////

BOOL MyProgram::Initialize()
{
	tex.Load("Data/wall01.bmp", GL_LINEAR, GL_LINEAR_MIPMAP_NEAREST, GL_REPEAT, GL_REPEAT);

	glEnable(GL_TEXTURE_2D);							// Enable Texture Mapping

	glShadeModel(GL_SMOOTH);							// Enable Smooth Shading

	glClearColor(0.0f, 0.0f, 0.0f, 0.0f);				// Black Background

	glClearDepth(1.0f);									// Depth Buffer Setup

	glEnable(GL_DEPTH_TEST);							// Enables Depth Testing

	glDepthFunc(GL_LEQUAL);								// The Type Of Depth Testing To Do

	glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);	// Really Nice Perspective Calculations


	glLightfv(GL_LIGHT1, GL_AMBIENT, LightAmbient);		// Setup The Ambient Light

	glLightfv(GL_LIGHT1, GL_DIFFUSE, LightDiffuse);		// Setup The Diffuse Light

	glLightfv(GL_LIGHT1, GL_POSITION,LightPosition);	// Position The Light

	glEnable(GL_LIGHT1);								// Enable Light One

	glEnable(GL_LIGHTING);

	return TRUE;
}

//////////////////////////////////////////////////////////////////////

// 5th. Render: Render The Scene

//////////////////////////////////////////////////////////////////////

void MyProgram::Render()
{
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);	// Clear The Screen And The Depth Buffer

	glLoadIdentity();									// Reset The View


	tex.Bind();

	glTranslatef(0.0f,0.0f,-10.0f);

	glRotatef(xrot,1.0f,0.0f,0.0f);
	glRotatef(yrot,0.0f,1.0f,0.0f);

	glBegin(GL_QUADS);
		// Front Face

		glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f,  1.0f);
		glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -1.0f,  1.0f);
		glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f,  1.0f,  1.0f);
		glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f,  1.0f,  1.0f);
		// Back Face

		glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f, -1.0f);
		glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f,  1.0f, -1.0f);
		glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f,  1.0f, -1.0f);
		glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f, -1.0f);
		// Top Face

		glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f,  1.0f, -1.0f);
		glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f,  1.0f,  1.0f);
		glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f,  1.0f,  1.0f);
		glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f,  1.0f, -1.0f);
		// Bottom Face

		glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f, -1.0f, -1.0f);
		glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f, -1.0f, -1.0f);
		glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f,  1.0f);
		glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f,  1.0f);
		// Right face

		glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -1.0f, -1.0f);
		glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f,  1.0f, -1.0f);
		glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f,  1.0f,  1.0f);
		glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f,  1.0f);
		// Left Face

		glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f, -1.0f);
		glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f,  1.0f);
		glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f,  1.0f,  1.0f);
		glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f,  1.0f, -1.0f);
	glEnd();

	++xrot;
	++yrot;
}
  
-X-
Advertisement
How could I say ?

For lighting, you have a few rules to know :

you might define the normals
you may define the normals
you should define the normals
you ''d better define the normals
you gotta define the normals
you have to define the normals
you need to define the normals
you must define the normals

understand ?
HOLY SCHINIKIES!!!!!!

Could of sworn I copied & pasted the lesson 7 code, and well I guess I was blinded by the light.

THANKS vincoof!!!!
-X-

This topic is closed to new replies.

Advertisement