Archived

This topic is now archived and is closed to further replies.

Lighting colour changes when camera changes

This topic is 5021 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello all, got a weird little "bug" going on at the moment. If I change the orientation of my camera, the apparent colour of the lighting changes. I have normals generated in the same way that I would for Direct3D and are static, one for each vertex on the display list. I then have a single light configured as so:
float[] fAmbient 	= 	{ 0.0f, 	0.0f, 		0.0f, 		1.0f };	//dark grey
float[] fDiffuse 	= 	{ 0.25f, 	0.5f, 		1.0f, 		1.0f };	//mid-blue
//float[] fDirection 	= 	{ 0.0f, 	-1.0f, 		0.0f, 		0.0f }; //down light
float[] fDirection 	= 	{ 0.578f, 	-0.578f, 		0.578f, 		0.0f }; //down diagonal

//normalize the direction
float fLen = (float)Math.sqrt( (double)( fDirection[0] * fDirection[0] + fDirection[1] * fDirection[1] + fDirection[2] * fDirection[2] ) );
fDirection[0] /= fLen;
fDirection[1] /= fLen;
fDirection[2] /= fLen;

//set the parameters
gl.glLightfv( GL_LIGHT1, GL_AMBIENT, fAmbient );
gl.glLightfv( GL_LIGHT1, GL_DIFFUSE, fDiffuse );
gl.glLightfv( GL_LIGHT1, GL_POSITION, fDirection );
gl.glEnable( GL_LIGHT1 );
gl.glEnable( GL_LIGHTING );
 
I''m using an OpenGl->Java wrapper, because rules of the game dictate I have to use Java I''m fairly new to OpenGL (C++/D3D is my hometown!). I''ve read as much about lighting as I can, and I can''t see where my code is different enough to warrant such random results.. any help is greatly appreciated, Jack

Share this post


Link to post
Share on other sites
quote:
Check that your matrixmode set to GL_MODELVIEW when you specify your camera transform.


cheers for the idea, but it doesn''t seem to make any difference

I have (is psuedo code) the following:

Initialise
Matrix Mode ( Projection )
Load Identity
gluPerspective( ... )
Configure Lighting //the code from above
Matrix Mode ( ModelView )
Load Identity

Render
glClear( Color | Depth )
Matrix Mode( ModelView )
gluLookAt( ... )
RenderAllTerrain( )

is there anything obviously wrong with that structure. It''s a fairly simple 3D engine - nothing too fancy, no special features (no textures even!!); as such there''s not a lot of OpenGL code to get wrong

Jack

Share this post


Link to post
Share on other sites