Advertisement

Lighting Issues

Started by November 18, 2003 09:52 PM
6 comments, last by luridcortex 21 years, 3 months ago
Im trying to incorporate lighting into my code using the methods from the filtering and lighting tutorial. Im almost 100% ive got evrything set up properly, and i cant get the lighting to work at all! I want the lighting to be enabled by default so here is my init function:

int InitGL(GLvoid)										// All Setup For OpenGL Goes Here

{
	if (!LoadGLTextures())								// Jump To Texture Loading Routine ( NEW )

	{
		return FALSE;									// If Texture Didn''t Load Return FALSE

	}

	glEnable(GL_TEXTURE_2D);							// Enable Texture Mapping ( NEW )

	glShadeModel(GL_SMOOTH);							// Enable Smooth Shading

	glClearColor(0.0f, 0.0f, 0.0f, 0.5f);				// 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

	return TRUE;										// Initialization Went OK


	// SET UP LIGHTING

	glLightfv(GL_LIGHT1, GL_AMBIENT, LightAmbient);
	glLightfv(GL_LIGHT1, GL_DIFFUSE, LightDiffuse);
	glLightfv(GL_LIGHT1, GL_POSITION, LightPosition);

	glEnable(GL_LIGHTING);
	glEnable(GL_LIGHT1);
	

}
Does it matter where glEnable(GL_LIGHTING); is called? i tried moving it to the render function but then i got no light at all. Im using the same values for lighting as in the filtering tutorial:

// LIGHTING
GLfloat LightDiffuse[] = { 1.0f, 1.0f, 1.0f, 1.0f };		 // Direct Light
GLfloat LightAmbient[] = { 0.5f, 0.5f, 0.5f, 1.0f };		 // Fill Ligh
GLfloat LightPosition[] = { 0.0f, 0.0f, 2.0f, 1.0f };      // Position
 
You will also need to enable materials for your objects. Check out OpenGL materials stuff.
Advertisement
Yeah, that doesnt tell me much. What are materials??
you got your polygon normals set right?

[edited by - FlyingDemon on November 18, 2003 11:06:50 PM]
Bah.... i cant believe i missed that >:

thanks tho
bah.... got normals set up properly, still no dice.

where should glEnable(GL_LIGHTING) be called? once? each render pass?
Advertisement
You''re returning from your function before you actually enable lighting.

Also, if you''re using texturing, your TEXTURE_ENV_MODE must be MODULATE.

Last, you need to define a light position or vector for LIGHT1.

I suggest studying the pipeline for fragments as they pass out of vertex processing/interpolation (which is where OpenGL lighting comes from) and through texture application, color sum, fog, and framebuffer blending. There are many pieces to that process, and understanding them all is crucial.


Last, when someone says you need to set up materials (which is true) you should not reply saying "what are materials". You should do a web search for "OpenGL material" or just look for "material" in the index at the back of the OpenGL specification PDF file, which is downloadable from the front page of http://www.opengl.org/
enum Bool { True, False, FileNotFound };
Ok, its DEFINATLEY time for bed... check this out for a quick laugh:

int InitGL(GLvoid)										// All Setup For OpenGL Goes Here{	if (!LoadGLTextures())								// Jump To Texture Loading Routine ( NEW )	{		return FALSE;									// If Texture Didn''t Load Return FALSE	}	glEnable(GL_TEXTURE_2D);							// Enable Texture Mapping ( NEW )	glShadeModel(GL_SMOOTH);							// Enable Smooth Shading	glClearColor(0.0f, 0.0f, 0.0f, 0.5f);				// 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	return TRUE;										// SET UP LIGHTING	glLightfv(GL_LIGHT1, GL_AMBIENT, LightAmbient);	glLightfv(GL_LIGHT1, GL_DIFFUSE, LightDiffuse);	glLightfv(GL_LIGHT1, GL_POSITION, LightPosition);	glEnable(GL_LIGHT1);	glEnable(GL_LIGHTING);	}

This topic is closed to new replies.

Advertisement