Added support for glLightModel functionality via osg::LightModel.
This commit is contained in:
parent
aaa0a42205
commit
e21af2adce
@ -193,6 +193,10 @@ SOURCE=..\..\src\osg\Light.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\src\osg\LightModel.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\src\osg\LightSource.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
@ -441,6 +445,10 @@ SOURCE=..\..\Include\Osg\Light
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\Include\Osg\LightModel
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\Include\Osg\LightSource
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
@ -162,6 +162,10 @@ SOURCE=..\..\..\src\osgPlugins\osg\Light.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\src\osgPlugins\osg\LightModel.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\src\osgPlugins\osg\LightSource.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
87
include/osg/LightModel
Normal file
87
include/osg/LightModel
Normal file
@ -0,0 +1,87 @@
|
||||
//C++ header - Open Scene Graph - Copyright (C) 1998-2001 Robert Osfield
|
||||
//Distributed under the terms of the GNU Library General Public License (LGPL)
|
||||
//as published by the Free Software Foundation.
|
||||
|
||||
#ifndef OSG_LIGHTMODEL
|
||||
#define OSG_LIGHTMODEL 1
|
||||
|
||||
#include <osg/StateAttribute>
|
||||
#include <osg/StateSet>
|
||||
#include <osg/Vec4>
|
||||
|
||||
namespace osg {
|
||||
|
||||
class SG_EXPORT LightModel : public StateAttribute
|
||||
{
|
||||
public :
|
||||
|
||||
LightModel();
|
||||
|
||||
/** Copy constructor using CopyOp to manage deep vs shallow copy.*/
|
||||
LightModel(const LightModel& lw,const CopyOp& copyop=CopyOp::SHALLOW_COPY):
|
||||
StateAttribute(lw,copyop),
|
||||
_ambient(lw._ambient),
|
||||
_colorControl(lw._colorControl),
|
||||
_localViewer(lw._localViewer),
|
||||
_twoSided(lw._twoSided) {}
|
||||
|
||||
|
||||
META_StateAttribute(LightModel, LIGHTMODEL);
|
||||
|
||||
/** return -1 if *this < *rhs, 0 if *this==*rhs, 1 if *this>*rhs.*/
|
||||
virtual int compare(const StateAttribute& sa) const
|
||||
{
|
||||
// check the types are equal and then create the rhs variable
|
||||
// used by the COMPARE_StateAttribute_Paramter macro's below.
|
||||
COMPARE_StateAttribute_Types(LightModel,sa)
|
||||
|
||||
// compare each paramter in turn against the rhs.
|
||||
COMPARE_StateAttribute_Parameter(_ambient)
|
||||
COMPARE_StateAttribute_Parameter(_colorControl)
|
||||
COMPARE_StateAttribute_Parameter(_localViewer)
|
||||
COMPARE_StateAttribute_Parameter(_twoSided)
|
||||
|
||||
return 0; // passed all the above comparison macro's, must be equal.
|
||||
}
|
||||
|
||||
|
||||
void setAmbientIntensity(const osg::Vec4& ambient) { _ambient = ambient; }
|
||||
const osg::Vec4& getAmbientIntensity() const { return _ambient; }
|
||||
|
||||
|
||||
enum ColorControl
|
||||
{
|
||||
SEPERATE_SPECULAR_COLOR,
|
||||
SINGLE_COLOR
|
||||
};
|
||||
|
||||
void setColorControl(const ColorControl cc) { _colorControl = cc; }
|
||||
inline const ColorControl getColorControl() const { return _colorControl; }
|
||||
|
||||
|
||||
void setLocalViewer(const bool localViewer) { _localViewer=localViewer; }
|
||||
inline const bool getLocalViewer() const { return _localViewer; }
|
||||
|
||||
|
||||
void setTwoSided(const bool twoSided) { _twoSided = twoSided; }
|
||||
inline const bool getTwoSided() const { return _twoSided; }
|
||||
|
||||
|
||||
|
||||
virtual void apply(State& state) const;
|
||||
|
||||
|
||||
protected :
|
||||
|
||||
virtual ~LightModel();
|
||||
|
||||
osg::Vec4 _ambient;
|
||||
ColorControl _colorControl;
|
||||
bool _localViewer;
|
||||
bool _twoSided;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
@ -131,6 +131,7 @@ class SG_EXPORT StateAttribute : public Object
|
||||
TEXENV,
|
||||
TEXGEN,
|
||||
TEXMAT,
|
||||
LIGHTMODEL,
|
||||
TRANSPARENCY,
|
||||
STENCIL,
|
||||
COLORMASK,
|
||||
|
@ -129,7 +129,6 @@ class OSGGLUT_EXPORT Viewer : public Window, public osgUtil::GUIActionAdapter
|
||||
int backface;
|
||||
int lighting;
|
||||
int flat_shade;
|
||||
int _two_sided_lighting;
|
||||
float frRate; // gwm Jul 2001 added convolved ('averaged') frame rate
|
||||
int _printStats; // gwm Jul 2001 change from bool
|
||||
struct { // gwm Jul 2001, added for display of statistics
|
||||
|
28
src/osg/LightModel.cpp
Normal file
28
src/osg/LightModel.cpp
Normal file
@ -0,0 +1,28 @@
|
||||
#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()
|
||||
{
|
||||
}
|
||||
|
||||
void LightModel::apply(State&) const
|
||||
{
|
||||
glLightModelfv(GL_LIGHT_MODEL_AMBIENT,_ambient.ptr());
|
||||
glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL,_colorControl);
|
||||
glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER,_localViewer);
|
||||
glLightModeli(GL_LIGHT_MODEL_TWO_SIDE,_twoSided);
|
||||
}
|
||||
|
@ -28,6 +28,7 @@ C++FILES = \
|
||||
Impostor.cpp\
|
||||
ImpostorSprite.cpp\
|
||||
Light.cpp\
|
||||
LightModel.cpp\
|
||||
LightSource.cpp\
|
||||
LineSegment.cpp\
|
||||
LineStipple.cpp\
|
||||
@ -98,6 +99,7 @@ TARGET_INCLUDE_FILES = \
|
||||
osg/ImpostorSprite\
|
||||
osg/LOD\
|
||||
osg/Light\
|
||||
osg/LightModel\
|
||||
osg/LightSource\
|
||||
osg/LineSegment\
|
||||
osg/LineStipple\
|
||||
|
@ -29,6 +29,7 @@
|
||||
#include <osg/LineSegment>
|
||||
#include <osg/PolygonMode>
|
||||
#include <osg/Texture>
|
||||
#include <osg/LightModel>
|
||||
#include <osg/ShadeModel>
|
||||
#include <osg/Notify>
|
||||
|
||||
@ -101,8 +102,6 @@ Viewer::Viewer()
|
||||
_viewFrustumCullingActive = true;
|
||||
_smallFeatureCullingActive = true;
|
||||
|
||||
_two_sided_lighting=0;
|
||||
|
||||
_useDisplayLists = true;
|
||||
|
||||
_saveFileName = "saved_model.osg";
|
||||
@ -359,8 +358,6 @@ float Viewer::draw(unsigned int viewport)
|
||||
{
|
||||
osg::Timer_t beforeDraw = _timer.tick();
|
||||
|
||||
glLightModeli(GL_LIGHT_MODEL_TWO_SIDE,_two_sided_lighting);
|
||||
|
||||
// do draw traversal.
|
||||
getViewportSceneView(viewport)->draw();
|
||||
|
||||
@ -943,7 +940,15 @@ void Viewer::keyboard(unsigned char key, int x, int y)
|
||||
break;
|
||||
|
||||
case 'T' :
|
||||
_two_sided_lighting = 1 - _two_sided_lighting;
|
||||
{
|
||||
osg::LightModel* lightmodel = dynamic_cast<LightModel*>(sceneView->getGlobalStateSet()->getAttribute(osg::StateAttribute::LIGHTMODEL));
|
||||
if (lightmodel)
|
||||
{
|
||||
lightmodel = new osg::LightModel;
|
||||
sceneView->getGlobalStateSet()->setAttribute(lightmodel);
|
||||
}
|
||||
lightmodel->setTwoSided(!lightmodel->getTwoSided());
|
||||
}
|
||||
break;
|
||||
|
||||
case 'w' :
|
||||
|
115
src/osgPlugins/osg/LightModel.cpp
Normal file
115
src/osgPlugins/osg/LightModel.cpp
Normal file
@ -0,0 +1,115 @@
|
||||
#include <osg/LightModel>
|
||||
|
||||
#include <osgDB/Registry>
|
||||
#include <osgDB/Input>
|
||||
#include <osgDB/Output>
|
||||
|
||||
using namespace osg;
|
||||
using namespace osgDB;
|
||||
|
||||
// forward declare functions to use later.
|
||||
bool LightModel_readLocalData(Object& obj, Input& fr);
|
||||
bool LightModel_writeLocalData(const Object& obj, Output& fw);
|
||||
|
||||
|
||||
// register the read and write functions with the osgDB::Registry.
|
||||
RegisterDotOsgWrapperProxy g_LightModelProxy
|
||||
(
|
||||
new osg::LightModel,
|
||||
"LightModel",
|
||||
"Object StateAttribute LightModel",
|
||||
&LightModel_readLocalData,
|
||||
&LightModel_writeLocalData
|
||||
);
|
||||
|
||||
|
||||
bool LightModel_readLocalData(Object& obj, Input& fr)
|
||||
{
|
||||
bool iteratorAdvanced = false;
|
||||
|
||||
LightModel& lightmodel = static_cast<LightModel&>(obj);
|
||||
|
||||
osg::Vec4 ambient;
|
||||
if (fr[0].matchWord("ambientIntensity") &&
|
||||
fr[1].getFloat(ambient[0]) &&
|
||||
fr[2].getFloat(ambient[1]) &&
|
||||
fr[3].getFloat(ambient[2]) &&
|
||||
fr[4].getFloat(ambient[3]))
|
||||
{
|
||||
lightmodel.setAmbientIntensity(ambient);
|
||||
fr+=5;
|
||||
iteratorAdvanced = true;
|
||||
}
|
||||
|
||||
if (fr[0].matchWord("colorControl"))
|
||||
{
|
||||
if (fr[1].matchWord("SEPERATE_SPECULAR_COLOR"))
|
||||
{
|
||||
lightmodel.setColorControl(osg::LightModel::SEPERATE_SPECULAR_COLOR);
|
||||
}
|
||||
else if (fr[1].matchWord("SINGLE_COLOR"))
|
||||
{
|
||||
lightmodel.setColorControl(osg::LightModel::SINGLE_COLOR);
|
||||
}
|
||||
}
|
||||
|
||||
int result;
|
||||
if (fr[0].matchWord("localViewer") && fr[1].getInt(result))
|
||||
{
|
||||
if (fr[1].matchWord("TRUE"))
|
||||
{
|
||||
lightmodel.setLocalViewer(true);
|
||||
fr+=2;
|
||||
iteratorAdvanced = true;
|
||||
}
|
||||
else if (fr[1].matchWord("FALSE"))
|
||||
{
|
||||
lightmodel.setLocalViewer(false);
|
||||
fr+=2;
|
||||
iteratorAdvanced = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (fr[0].matchWord("twoSided"))
|
||||
{
|
||||
if (fr[1].matchWord("TRUE"))
|
||||
{
|
||||
lightmodel.setTwoSided(true);
|
||||
fr+=2;
|
||||
iteratorAdvanced = true;
|
||||
}
|
||||
else if (fr[1].matchWord("FALSE"))
|
||||
{
|
||||
lightmodel.setTwoSided(false);
|
||||
fr+=2;
|
||||
iteratorAdvanced = true;
|
||||
}
|
||||
}
|
||||
|
||||
return iteratorAdvanced;
|
||||
}
|
||||
|
||||
bool LightModel_writeLocalData(const Object& obj,Output& fw)
|
||||
{
|
||||
const LightModel& lightmodel = static_cast<const LightModel&>(obj);
|
||||
|
||||
fw.indent() << "ambientIntensity " << lightmodel.getAmbientIntensity() << std::endl;
|
||||
|
||||
if (lightmodel.getColorControl()==osg::LightModel::SEPERATE_SPECULAR_COLOR)
|
||||
fw.indent() << "colorControl SEPERATE_SPECULAR_COLOR" << std::endl;
|
||||
else
|
||||
fw.indent() << "colorControl SINGLE_COLOR" << std::endl;
|
||||
|
||||
if (lightmodel.getLocalViewer())
|
||||
fw.indent() << "localViewer TRUE"<< std::endl;
|
||||
else
|
||||
fw.indent() << "localViewer FALSE"<< std::endl;
|
||||
|
||||
if (lightmodel.getTwoSided())
|
||||
fw.indent() << "twoSided TRUE"<< std::endl;
|
||||
else
|
||||
fw.indent() << "twoSided FALSE"<< std::endl;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -19,6 +19,7 @@ C++FILES = \
|
||||
Image.cpp\
|
||||
Impostor.cpp\
|
||||
Light.cpp\
|
||||
LightModel.cpp\
|
||||
LightSource.cpp\
|
||||
LineStipple.cpp\
|
||||
LineWidth.cpp\
|
||||
|
Loading…
Reference in New Issue
Block a user