I can’t seem to get specular lighting to turn on in my little
OGL program. Well, it looks off to me. Take a look here: http://users.bestweb.net/~jandl/snapshot1.png
Note (in the above pic):
red == (+) x-axis
green == (+) y-axis
blue == (+) z-axis
The axes are about 10 units long.
Also, the direction of the lighting (as seen in the pic) seems
a bit different than what I’ve specified in the code – not
sure if this is related. Here’s the relevant code:
glClearColor( 0.0 , 0.0 , 0.0 , 0.0 );
glShadeModel( GL_SMOOTH ); // Yes, this is redundant.
glDepthFunc( GL_LESS ); // Yes, this is redundant.
glPolygonMode( GL_FRONT , GL_FILL ); // Yes, this is redundant.
glPolygonMode( GL_BACK , GL_LINE );
// The material:
// Bright specular reflections.
float mat_specular[] = { 1.0 , 1.0 , 1.0 , 1.0 };
int mat_shininess[] = { 100 } ; // Very shiny.
// Material is mostly green, that is to say, the ambient and
// diffuse light reflected off of the material is mostly green.
float mat_amb_and_diffuse[] = { 0.0 , 0.8 , 0.2 , 1.0 };
glMaterialfv( GL_FRONT_AND_BACK , GL_SPECULAR , mat_specular );
glMaterialiv( GL_FRONT_AND_BACK , GL_SHININESS , mat_shininess );
glMaterialfv( GL_FRONT_AND_BACK , GL_AMBIENT_AND_DIFFUSE ,
mat_amb_and_diffuse );
// The light:
float light_ambient[] = { 0.2 , 0.2 , 0.2 , 1.0 };
float white_light[] = { 1.0 , 1.0 , 1.0 , 1.0 };
glLightfv( GL_LIGHT0 , GL_AMBIENT , light_ambient ); // redundant
glLightfv( GL_LIGHT0 , GL_DIFFUSE , white_light ); // redundant
glLightfv( GL_LIGHT0 , GL_SPECULAR , white_light ); // redundant
// This one’s funny… The light doesn’t seem to be shining in the
// -1,-1,-1 direction but rather the -1,-1,0 dir… ******
float light_dir[] = { -1.0 , -1.0 , -1.0 , 0.0 }; // Directional.
glLightfv( GL_LIGHT0 , GL_POSITION , light_dir );
glLightModeli( GL_LIGHT_MODEL_LOCAL_VIEWER , GL_TRUE );
glLightModeli( GL_LIGHT_MODEL_TWO_SIDE , GL_TRUE );
// And finally, enable everything.
glEnable( GL_LIGHTING );
glEnable( GL_LIGHT0 );
glEnable( GL_DEPTH_TEST );
Also, in my reshape callback I’ve got:
glViewport( 0 , 0 , static_cast<GLsizei>( w ) ,
static_cast<GLsizei>( h ) );
glMatrixMode( GL_PROJECTION );
glLoadIdentity();
// args: fovy, aspect, near, far
gluPerspective( 40.0 , 1.0 , 5.0 , 45.0 );
glMatrixMode( GL_MODELVIEW );
glLoadIdentity();
gluLookAt( 20.0 , 20.0 , 20.0 , // camera location
0.0 , 0.0 , 0.0 , // looking at
0.0 , 1.0 , 0.0 ); // which way up is
Thanks,
—j
[This message has been edited by jmg (edited 04-24-2002).]