Hi,
I'm developing a 3d scene editor. The problem is I'm not able to give light to the entire scene following the camera (I do not use gluLookAt). Please look at the screenshot; you will see that the building is partially enlightned while the upper part is dark:
http://cpsed.sourceforge.net/
These are the settings I use for light:
void GLWidget::initializeGL()
{
glClearColor( 0.4 , 0.4 , 0.4 , 1.0 );
glMatrixMode ( GL_MODELVIEW );
glLoadIdentity();
glEnable (GL_RESCALE_NORMAL);
glDepthFunc (GL_LEQUAL);
glEnable (GL_COLOR_MATERIAL);
glEnable (GL_DEPTH_TEST);
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, 700.0f, 1.0f };
glLightfv(GL_LIGHT0, GL_AMBIENT, LightAmbient);
glLightfv(GL_LIGHT0, GL_DIFFUSE, LightDiffuse);
glLightfv(GL_LIGHT0, GL_POSITION,LightPosition);
glEnable(GL_LIGHT0);
glEnable(GL_LIGHTING);
mode = GL_RENDER;
}
and this is the drawing routine:
void GLWidget::paintGL()
{
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
glMatrixMode( GL_MODELVIEW );
glLoadIdentity();
SetCamera();
for ( std::map< GLuint , string >::iterator i= GlWindowClass->DisplayList.begin(); i != GlWindowClass->DisplayList.end(); i++)
{
unsigned int index = i->first;
glPushMatrix();
if ( mode == GL_SELECT ) glPushName ( index );
glTranslatef ( Model [ index-1 ].x , Model [ index-1 ].y , Model [ index-1 ].z );
glRotatef ( Model [ index-1 ].xrot , 1.0f , 0.0f , 0.0f );
glRotatef ( Model [ index-1 ].yrot , 0.0f , 1.0f , 0.0f );
glRotatef ( Model [ index-1 ].zrot , 0.0f , 0.0f , 1.0f );
glScalef ( Model [ index-1 ].sx , Model [ index-1 ].sy , Model [ index-1 ].sz );
glCallList ( index );
if ( mode == GL_SELECT ) glPopName ();
glPopMatrix();
}
}
Follows the set camera:
void GLWidget::SetCamera()
{
glTranslatef ( Tx, Ty, Depth );
glRotatef ( AngleX, 1, 0, 0 );
glRotatef ( AngleY, 0, 1, 0 );
glRotatef ( AngleZ, 0, 0, 1 );
}
What is wrong ?
Colossus