2002-02-26 06:46:38 +08:00
|
|
|
#include <osg/GL>
|
|
|
|
#include <osg/LightModel>
|
|
|
|
|
|
|
|
using namespace osg;
|
|
|
|
|
|
|
|
|
|
|
|
LightModel::LightModel():
|
|
|
|
StateAttribute(),
|
|
|
|
_ambient(0.2f,0.2f,0.2f,1.0f),
|
|
|
|
_colorControl(LightModel::SINGLE_COLOR),
|
|
|
|
_localViewer(false),
|
|
|
|
_twoSided(false)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
LightModel::~LightModel()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2002-02-26 07:14:27 +08:00
|
|
|
// need to define if gl.h version < 1.2.
|
|
|
|
#ifndef GL_LIGHT_MODEL_COLOR_CONTROL
|
|
|
|
#define GL_LIGHT_MODEL_COLOR_CONTROL 0x81F8
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef GL_SINGLE_COLOR
|
|
|
|
#define GL_SINGLE_COLOR 0x81F9
|
|
|
|
#endif
|
|
|
|
|
2002-08-29 11:22:27 +08:00
|
|
|
#ifndef GL_SEPARATE_SPECULAR_COLOR
|
|
|
|
#define GL_SEPARATE_SPECULAR_COLOR 0x81FA
|
2002-02-26 07:14:27 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2002-02-26 06:46:38 +08:00
|
|
|
void LightModel::apply(State&) const
|
|
|
|
{
|
|
|
|
glLightModelfv(GL_LIGHT_MODEL_AMBIENT,_ambient.ptr());
|
2002-03-02 17:24:05 +08:00
|
|
|
|
2002-08-29 11:22:27 +08:00
|
|
|
static bool s_separateSpecularSupported = strcmp((const char *)glGetString(GL_VERSION),"1.2")>=0;
|
|
|
|
if (s_separateSpecularSupported)
|
2002-02-26 07:14:27 +08:00
|
|
|
{
|
2002-08-29 11:22:27 +08:00
|
|
|
if (_colorControl==SEPARATE_SPECULAR_COLOR)
|
2002-03-02 17:24:05 +08:00
|
|
|
{
|
2002-08-29 11:22:27 +08:00
|
|
|
glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL,GL_SEPARATE_SPECULAR_COLOR);
|
2002-03-02 17:24:05 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL,GL_SINGLE_COLOR);
|
|
|
|
}
|
2002-02-26 07:14:27 +08:00
|
|
|
}
|
|
|
|
|
2002-02-26 06:46:38 +08:00
|
|
|
glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER,_localViewer);
|
|
|
|
glLightModeli(GL_LIGHT_MODEL_TWO_SIDE,_twoSided);
|
|
|
|
}
|
|
|
|
|