I’m attempting to write a solar system using the C++ OpenGL API. I have a planet class, and I’m able to show all the planets, their orbits, etc. I also have a switch where I can change from the geocentric solar system to the heliocentric solar system. However, I’m having trouble controlling the lighting.
I’m able to get the heliocentric model to look (somewhat) correctly, by positioning GL_LIGHT0 to the origin
GLfloat LightPos[]={0,0,0,1};//Sun as light source
(which is where the Sun is placed).
However, since the light is located in the origin, no light is shining on the sun itself, so it looks severely unnatural (think of a light bulb lighting up a room even though it’s off).
My next issue is to get the light source to change from GL_LIGHT0 to GL_LIGHT1 when I switch from heliocentric to geocentric. I’m able to get the planets to change position, but here is how I’m switching between my light sources:
void keyboard(unsigned char key, int x, int y)
{
switch (key)
{
case 'l':
geocentric=!geocentric;
for(int i=0; i<7; i++)
planet[i]=new Planet(i,geocentric); //memory leak, I know
if(geocentric==true)
{
glDisable(GL_LIGHT0);
glEnable(GL_LIGHT1);
}//if
else if(geocentric==false)
{
glDisable(GL_LIGHT1);
glEnable(GL_LIGHT0);
}//else if
break;
}//switch
glutPostRedisplay();
}//keyboard
and I have the following in my main function:
glEnable(GL_LIGHTING);
if(!geocentric)glEnable(GL_LIGHT0);
else if(geocentric)glEnable(GL_LIGHT1);
and the following in display:
if(!geocentric)
glLightfv(GL_LIGHT0,GL_POSITION,LightPos);
else if(geocentric)
glLightfv(GL_LIGHT1,GL_POSITION,LightPos2); //LightPos2 is set to an arbitrary location on the x-axis for now, {20,0,0,1}
What am I doing wrong? I’ll gladly post my source code if anyone needs any more info. Would’ve done so in the first place, but I’m not 100% sure if this forum allows that sort of thing.
Thanks for any and all help in advance,
-Angel.