void ON_GL( const ON_Light& light, GLenum light_index ) { ON_BOOL32 bPopModelViewMatrix = false; ON_BOOL32 bPopProjectionMatrix = false; switch ( light.CoordinateSystem() ) { case ON::world_cs: break; case ON::clip_cs: bPopProjectionMatrix = true; glMatrixMode(GL_PROJECTION); glPushMatrix(); glLoadIdentity(); // no break here case ON::camera_cs: bPopModelViewMatrix = true; glMatrixMode(GL_MODELVIEW); glPushMatrix(); glLoadIdentity(); break; case ON::screen_cs: break; } GLfloat ambient[4], diffuse[4], specular[4]; ON_GL( light.Ambient(), ambient ); ON_GL( light.Diffuse(), diffuse ); ON_GL( light.Specular(), specular ); glLightfv( light_index, GL_AMBIENT, ambient ); glLightfv( light_index, GL_DIFFUSE, diffuse ); glLightfv( light_index, GL_SPECULAR, specular ); ON_3dPoint loc = light.Location(); GLfloat f[4] = {(GLfloat)loc.x,(GLfloat)loc.y,(GLfloat)loc.z,(GLfloat)1.0}; glLightfv( light_index, GL_POSITION, f ); ON_3dVector dir = light.Direction(); f[0] = (GLfloat)dir.x; f[1] = (GLfloat)dir.y; f[2] = (GLfloat)dir.z; glLightfv( light_index, GL_SPOT_DIRECTION, f ); glLightf( light_index, GL_SPOT_EXPONENT, (GLfloat)(light.SpotExponent()*128.0) ); glLightf( light_index, GL_SPOT_CUTOFF, (GLfloat)light.SpotAngleRadians() ); ON_3dVector attenuation = light.Attenuation(); glLightf( light_index, GL_CONSTANT_ATTENUATION, (GLfloat)attenuation.x ); glLightf( light_index, GL_LINEAR_ATTENUATION, (GLfloat)attenuation.y ); glLightf( light_index, GL_QUADRATIC_ATTENUATION, (GLfloat)attenuation.z ); if ( light.IsEnabled() ) glEnable( light_index ); else glDisable( light_index ); if ( bPopProjectionMatrix ) { glMatrixMode(GL_PROJECTION); glPopMatrix(); } if ( bPopModelViewMatrix ) { glMatrixMode(GL_MODELVIEW); glPopMatrix(); } }