Ordering of lighting operations

I am writing a space trading simulation, and want to create an effect where the light always eminates from the position of the sun.

Basically, I have a skybox, depicting the starfield etc, and planets/ships inside the clipping plane, which should be lightsourced.

I want the starfield to not be affected by the lighting, so I switched off lighting before I drew the skybox…only to find the skybox now has a lovely red hue… ( if anyone can explain why I would appreciate it! my brain hurts when I start thinking of reasons why )

To recap:
I want the skybox to be full intensity,and unaffected by the lightsourcing.

I want the ships and planets to be affected by a diffuse light source, eminating from the direction of the sun.

What is the correct order of lighting operations to achieve this effect?

If anyone can give me a gentle nudge, I’m sure my brain will start working again.

dd
p.s
I’m implementing game logic in parallel to the graphics engine, hence the brain-ache.

>>I want the skybox to be full intensity,and unaffected by the lightsourcing.

You probably use GL_MODULATE and the lighting or the Gouraud shading with the current color (reddish?) add to the texture colors.
Use GL_DECAL for the skybox texture and every other coloring effect is replaced by the texture color. Switching off lighting might add performance. Depends on how many faces the skybox has.

as relic saiz i wouldnt even use DECAL though just leave it in MODULATE all the time.

setup camera
position directional light for sun
glDisable( GL_LIGHTING)
draw skybox
glEnable(LIGHTING)
draw everything else

Thanks for that, the skyboxes are now working just fine!!!

Next question:

I have positioned my lightsource at the point where the sun is. The planet has a light and dark side.

I move my ship towards the dark side of a planet. When I’m there, I orientate the ship to the planet, and suddenly, the planet is illuminated…

Where is the light coming from?

dd

Thanks for that, the skyboxes are now working just fine!!!

Next question:

I have positioned my lightsource at the point where the sun is. The planet has a light and dark side.

I move my ship towards the dark side of a planet. When I’m there, I orientate the ship to the planet, and suddenly, the planet is illuminated…

Where is the light coming from?

dd

Maybe you are setting the light position in the wrong place. If you need a light that is in a specific point in the world, you need to set it after you set the modelview matrix. The light position is also modified by the modelview matrix. If you set it before the modelview matrix is set, you get a lightposition that is relative the viewpoint.

I am using gluSphere for the planets…does this function create Normal vector information?

dd

Ok, been reading the red book…

This is what I have been doing:

// initialise light source
GLfloat diffuselight[]={ 0.6f, 0.6f, 0.6f, 0.5f };

glLightfv( GL_LIGHT0,GL_DIFFUSE,diffuselight );

… this is from my game main loop

// setup projection matrix
// setup modelview matrix

// setup positional light source
GLfloat lightPos[] = { 0.0f, 50.0f, 50.0f, 1.0f };

lightPos[0] =
universe->_currentSystem->_sunX;

lightPos[1] =
universe->_currentSystem->_sunY;

lightPos[2] =
universe->_currentSystem->_sunZ;

glLightfv( GL_LIGHT0,GL_POSITION,lightPos );
glEnable ( GL_LIGHTING );

// draw my objects

The planets are lightsourced, and there is a dark side and a light side.

I now move the ship to the dark side of the planets,stop and orientate towards the planet, and the lighting level increases…
i.e darkness becomes light…

dd

Thanks everyone…got this sorted now!!