2012-03-22 01:36:20 +08:00
|
|
|
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
|
2003-01-22 00:45:36 +08:00
|
|
|
*
|
2012-03-22 01:36:20 +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
|
2003-01-22 00:45:36 +08:00
|
|
|
* (at your option) any later version. The full license is in LICENSE file
|
|
|
|
* included with this distribution, and on the openscenegraph.org website.
|
2012-03-22 01:36:20 +08:00
|
|
|
*
|
2003-01-22 00:45:36 +08:00
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2012-03-22 01:36:20 +08:00
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2003-01-22 00:45:36 +08:00
|
|
|
* 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>
|
2009-10-23 21:19:57 +08:00
|
|
|
|
2002-02-26 06:46:38 +08:00
|
|
|
#include <osg/GL>
|
|
|
|
#include <osg/LightModel>
|
2009-10-23 21:19:57 +08:00
|
|
|
#include <osg/Notify>
|
2002-02-26 06:46:38 +08:00
|
|
|
|
|
|
|
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
|
|
|
|
{
|
2009-10-23 21:19:57 +08:00
|
|
|
#ifdef OSG_GL_FIXED_FUNCTION_AVAILABLE
|
2009-10-25 19:52:01 +08:00
|
|
|
|
|
|
|
#ifdef OSG_GLES1_AVAILABLE
|
|
|
|
#define glLightModeli glLightModelx
|
|
|
|
#endif
|
|
|
|
|
2002-02-26 06:46:38 +08:00
|
|
|
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
|
|
|
}
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2009-10-25 19:52:01 +08:00
|
|
|
#ifndef OSG_GLES1_AVAILABLE
|
2002-02-26 06:46:38 +08:00
|
|
|
glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER,_localViewer);
|
2009-10-25 19:52:01 +08:00
|
|
|
#endif
|
|
|
|
|
2002-02-26 06:46:38 +08:00
|
|
|
glLightModeli(GL_LIGHT_MODEL_TWO_SIDE,_twoSided);
|
2009-10-23 21:19:57 +08:00
|
|
|
#else
|
2010-05-28 23:47:52 +08:00
|
|
|
OSG_NOTICE<<"Warning: LightModel::apply(State&) - not supported."<<std::endl;
|
2009-10-23 21:19:57 +08:00
|
|
|
#endif
|
2002-02-26 06:46:38 +08:00
|
|
|
}
|
|
|
|
|