2006-07-18 23:21:48 +08:00
|
|
|
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
|
2003-01-22 00:45:36 +08:00
|
|
|
*
|
|
|
|
* This library is open source and may be redistributed and/or modified under
|
|
|
|
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
|
|
|
|
* (at your option) any later version. The full license is in LICENSE file
|
|
|
|
* included with this distribution, and on the openscenegraph.org website.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* OpenSceneGraph Public License for more details.
|
|
|
|
*/
|
2007-07-28 18:44:03 +08:00
|
|
|
#include <string.h>
|
2004-12-07 03:32:59 +08:00
|
|
|
#include <string>
|
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
|
|
|
|
2006-10-02 21:40:58 +08:00
|
|
|
static bool s_separateSpecularSupported = strncmp((const char*)glGetString(GL_VERSION),"1.2",3)>=0;
|
2002-08-29 11:22:27 +08:00
|
|
|
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
|
|
|
{
|
2005-11-17 21:35:53 +08:00
|
|
|
glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL,GL_SEPARATE_SPECULAR_COLOR);
|
2002-03-02 17:24:05 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2005-11-17 21:35:53 +08:00
|
|
|
glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL,GL_SINGLE_COLOR);
|
2002-03-02 17:24:05 +08:00
|
|
|
}
|
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);
|
|
|
|
}
|
|
|
|
|