Lighting

Started by
13 comments, last by GrandMLee 22 years ago
I''m trying to set up three different light sources that can be toggled on and off. I''m using the NeHe tutorial as a basis. The problem is that even though I have commented out the tutorial''s standard light source, and initialized my own, it still shows up as being plane white (I have one red, one green, one blue) These light sources have different possitions (and this might be where I am having a problem) here is what I''ve got so far:
  
GLfloat RedAmbientLight[]=	{ 0.7f, 0.2f, 0.2f, 1.0f };
GLfloat RedDiffuseLight[]=	{ 1.0f, 0.0f, 0.0f, 1.0f };
GLfloat LightPosition1[]=	{ 1.0f, -1.0f, 1.0f, 1.0f };
GLfloat GreenAmbientLight[]=    { 0.2f, 0.7f, 0.2f, 1.0f };
GLfloat GreenDiffusetLight[]=   { 0.0f, 1.0f, 0.0f, 1.0f };
GLfloat LightPosition2[]=	{ 1.0f, 1.0f, 1.0f, 1.0f };
GLfloat BlueAmbientLight[]=	{ 0.2f, 0.2f, 0.7f, 1.0f };
GLfloat BlueDiffuseLight[]=	{ 0.0f, 0.0f, 1.0f, 1.0f };
GLfloat LightPosition3[]=	{ -1.0f, 0.0f, 1.0f, 1.0f };

glLightfv(GL_LIGHT2, GL_AMBIENT, RedAmbientLight);	
glLightfv(GL_LIGHT2, GL_DIFFUSE, RedDiffuseLight);
glLightfv(GL_LIGHT2, GL_POSITION,LightPosition1);
glEnable(GL_LIGHT2);		
glLightfv(GL_LIGHT3, GL_AMBIENT, GreenAmbientLight);	
glLightfv(GL_LIGHT3, GL_DIFFUSE, GreenDiffuseLight);
glLightfv(GL_LIGHT3, GL_POSITION,LightDiffusePosition2);
glEnable(GL_LIGHT3);
glLightfv(GL_LIGHT4, GL_AMBIENT, BlueAmbientLight);	
glLightfv(GL_LIGHT4, GL_DIFFUSE, BlueDiffuseLight);
glLightfv(GL_LIGHT4, GL_POSITION,LightPosition3);
glEnable(GL_LIGHT4);

glEnable(GL_LIGHTING);
  
does anyone see something wrong?
If at first you don't succeed, use profanity and try, try again.
Advertisement
Am I asking that stupid of a question?

If at once you don''t succeed, use pofanity and try, try again.
If at first you don't succeed, use profanity and try, try again.
quote:Original post by GrandMLee
Am I asking that stupid of a question?

If at once you don''t succeed, use pofanity and try, try again.


That code wouldn''t even compile!
Maybe you should try turning on less ambient light, make the ambient light level 0.2f for all of them or something. The combination of all the ambient light source might add up to 1 and therefore make it appear white.

Just A thought, probably won''t work

-Weasalmongler
how about not enabling them all... this would probably cause white light if the lighted vertices get lighted by all 3 lights...



KING CLAUDIUS Now, Hamlet, where''s Polonius?

HAMLET At supper.

KING CLAUDIUS At supper! where?

HAMLET Not where he eats, but where he is eaten
what about enableling GL_MATERIAL. I''m not 100% sure with this but i think you need glEnable(GL_MATERIAL) and also enable smooth shading so it looks good. If your light is too intense it will show up white. Just play around with things, it always takes an hour to get one thing done... compare your code to code that you know works
cha cha cha
This is done to a textured cube. Do you think that the face is lit by the different lights, only to be covered over by the texure? If that is the case, then why can I see a difference between the ambient and diffuse light sources? What does enabling material do to textures? Do you think I should enable smooth shading?
If at first you don't succeed, use profanity and try, try again.
I did the same thing playing around with the NEHE tutorials . Here''s the code I used for two lights:


  //variable declarationsGLfloat LightAmbient[]=	{ 0.5f, 0.5f, 0.5f, 1.0f }; //medium whiteGLfloat LightDiffuse[]=	{0.0f, 0.0f, 1.0f, 1.0f };  //blueGLfloat LightPosition[]={ -2.0f, 0.0f, 0.0f, 1.0f };//left of centerGLfloat LightDiffuse2[]={0.0f, 1.0f, 0.0f, 1.0f };   //greenGLfloat LightPosition2[]={ 2.0f, 0.0f, 0.0f, 1.0f }; //right of center......//in InitGL()        //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	//glLightfv(GL_LIGHT2, GL_AMBIENT, LightAmbient);		// Setup The Ambient Light	glLightfv(GL_LIGHT2, GL_DIFFUSE, LightDiffuse2);		// Setup The Diffuse Light	glLightfv(GL_LIGHT2, GL_POSITION,LightPosition2);	// Position The Light	glEnable(GL_LIGHT2);								// Enable Light One	  


Then in WinMain I call glDisable(GL_LIGHTING) or glEnable(GL_LIGHTING) when the user presses the L key - like in tutorial 7. If you comment out the "gllightfv(..GL_AMBIENT..)" lines like I did, your diffuse lights will probably show up better.
---------------Delphi 6 Personal Edition, free for non-commercial use.
I''m still getting plain white light.
here is what I have now.


  //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 };//GLfloat LightPosition1[]=	{ 1.0f, -1.0f, 1.0f, 1.0f };//GLfloat LightPosition2[]=	{ 1.0f, 1.0f, 1.0f, 1.0f };//GLfloat LightPosition3[]=	{ -1.0f, 0.0f, 1.0f, 1.0f };//GLfloat RedAmbientLight[]=	{ 0.7f, 0.2f, 0.2f, 1.0f };//GLfloat GreenAmbientLight[]={ 0.2f, 0.7f, 0.2f, 1.0f };GLfloat BlueAmbientLight[]=	{ 0.0f, 0.0f, 0.9f, 1.0f };//GLfloat RedDiffuseLight[]=	{ 1.0f, 0.0f, 0.0f, 1.0f };//GLfloat GreenDiffusetLight[]={ 0.0f, 1.0f, 0.0f, 1.0f };GLfloat BlueDiffuseLight[]=	{ 0.0f, 0.0f, 1.0f, 1.0f };.....	//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	//glLightfv(GL_LIGHT2, GL_AMBIENT, RedAmbientLight);		//glLightfv(GL_LIGHT2, GL_DIFFUSE, RedDiffuseLight);	//glLightfv(GL_LIGHT2, GL_POSITION,LightPosition1);	//glEnable(GL_LIGHT2);			//glLightfv(GL_LIGHT3, GL_AMBIENT, GreenAmbientLight);		//glLightfv(GL_LIGHT3, GL_DIFFUSE, GreenDiffuseLight);	//glLightfv(GL_LIGHT3, GL_POSITION,LightDiffusePosition2);	//glEnable(GL_LIGHT3);	glLightfv(GL_LIGHT4, GL_AMBIENT, BlueAmbientLight);		glLightfv(GL_LIGHT4, GL_DIFFUSE, BlueDiffuseLight);	glLightfv(GL_LIGHT4, GL_POSITION,LightPosition3);	glEnable(GL_LIGHT4);	  

If at first you don't succeed, use profanity and try, try again.
Did you say that these lights were being used on a textured cube and the cube appears white? If so the problem may be in the texturing part of the program, for example if the texture does not get mapped, then it is unlikely that a light source will work. Try reviewing you texturing part and check that it works correctly.

Have you tried positioning the light and enabling it each frame in the rendering loop. You could try this also. It shouldn''t need it but this did fix one of my lighting problems a while ago.

- Weasalmongler

This topic is closed to new replies.

Advertisement