Added support for glLightModel functionality via osg::LightModel.
This commit is contained in:
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\
|
||||
|
||||
Reference in New Issue
Block a user