From fa0333b6fe23c62d25bc6b8dd9d26e43cfc0bf62 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Tue, 6 May 2003 18:04:27 +0000 Subject: [PATCH] Aded extra constructors to BlendFunc and Depth to help set them up convieniently. Added a background quad to osghud. --- examples/osghud/osghud.cpp | 57 ++++++++++++++++++++++++++++++++++++-- include/osg/BlendFunc | 2 ++ include/osg/Depth | 42 +++++++++++++++------------- src/osg/BlendFunc.cpp | 11 ++++++-- src/osg/Depth.cpp | 14 ++++------ 5 files changed, 92 insertions(+), 34 deletions(-) diff --git a/examples/osghud/osghud.cpp b/examples/osghud/osghud.cpp index ba7929c18..f6683ab1c 100644 --- a/examples/osghud/osghud.cpp +++ b/examples/osghud/osghud.cpp @@ -20,6 +20,7 @@ #include #include #include +#include #include #include @@ -29,12 +30,13 @@ osg::Node* createHUD() { osg::Geode* geode = new osg::Geode(); - std::string timesFont("fonts/times.ttf"); + std::string timesFont("fonts/arial.ttf"); // turn lighting off for the text and disable depth test to ensure its always ontop. osg::StateSet* stateset = geode->getOrCreateStateSet(); stateset->setMode(GL_LIGHTING,osg::StateAttribute::OFF); - stateset->setMode(GL_DEPTH_TEST,osg::StateAttribute::OFF); + //stateset->setMode(GL_DEPTH_TEST,osg::StateAttribute::OFF); + stateset->setAttribute(new osg::Depth(osg::Depth::LESS,0.0,0.0001)); osg::Vec3 position(150.0f,800.0f,0.0f); osg::Vec3 delta(0.0f,-120.0f,0.0f); @@ -94,7 +96,46 @@ osg::Node* createHUD() text->setText("And add an osg::ModelViewMatrix set to ABSOLUTE to ensure\nit remains independent from any external model view matrices."); position += delta; - } + } + + + + { + osg::BoundingBox bb; + for(unsigned int i=0;igetNumDrawables();++i) + { + bb.expandBy(geode->getDrawable(i)->getBound()); + } + + osg::Geometry* geom = new osg::Geometry; + + osg::Vec3Array* vertices = new osg::Vec3Array; + float depth = bb.zMin()-0.1; + vertices->push_back(osg::Vec3(bb.xMin(),bb.yMax(),depth)); + vertices->push_back(osg::Vec3(bb.xMin(),bb.yMin(),depth)); + vertices->push_back(osg::Vec3(bb.xMax(),bb.yMin(),depth)); + vertices->push_back(osg::Vec3(bb.xMax(),bb.yMax(),depth)); + geom->setVertexArray(vertices); + + osg::Vec3Array* normals = new osg::Vec3Array; + normals->push_back(osg::Vec3(0.0f,0.0f,1.0f)); + geom->setNormalArray(normals); + geom->setNormalBinding(osg::Geometry::BIND_OVERALL); + + osg::Vec4Array* colors = new osg::Vec4Array; + colors->push_back(osg::Vec4(1.0f,1.0,0.8f,0.2f)); + geom->setColorArray(colors); + geom->setColorBinding(osg::Geometry::BIND_OVERALL); + + geom->addPrimitiveSet(new osg::DrawArrays(GL_QUADS,0,4)); + + osg::StateSet* stateset = geom->getOrCreateStateSet(); + stateset->setMode(GL_BLEND,osg::StateAttribute::ON); + //stateset->setAttribute(new osg::PolygonOffset(1.0f,1.0f),osg::StateAttribute::ON); + stateset->setRenderingHint(osg::StateSet::TRANSPARENT_BIN); + + geode->addDrawable(geom); + } // create the hud. osg::MatrixTransform* modelview_abs = new osg::MatrixTransform; @@ -167,6 +208,16 @@ int main( int argc, char **argv ) // create the windows and run the threads. viewer.realize(); + // set all the sceneview's up so that their left and right add cull masks are set up. + for(osgProducer::OsgCameraGroup::SceneHandlerList::iterator itr=viewer.getSceneHandlerList().begin(); + itr!=viewer.getSceneHandlerList().end(); + ++itr) + { + osgUtil::SceneView* sceneview = itr->get(); + sceneview->setComputeNearFarMode(osgUtil::CullVisitor::DO_NOT_COMPUTE_NEAR_FAR); + } + + while( !viewer.done() ) { // wait for all cull and draw threads to complete. diff --git a/include/osg/BlendFunc b/include/osg/BlendFunc index 9ab3e1971..bd3169f76 100644 --- a/include/osg/BlendFunc +++ b/include/osg/BlendFunc @@ -25,6 +25,8 @@ class SG_EXPORT BlendFunc : public StateAttribute BlendFunc(); + BlendFunc(GLenum source, GLenum destination); + /** Copy constructor using CopyOp to manage deep vs shallow copy.*/ BlendFunc(const BlendFunc& trans,const CopyOp& copyop=CopyOp::SHALLOW_COPY): StateAttribute(trans,copyop), diff --git a/include/osg/Depth b/include/osg/Depth index 5b3eb5f27..9b603be90 100644 --- a/include/osg/Depth +++ b/include/osg/Depth @@ -25,15 +25,28 @@ class SG_EXPORT Depth : public StateAttribute public : - Depth(); + enum Function + { + NEVER = GL_NEVER, + LESS = GL_LESS, + EQUAL = GL_EQUAL, + LEQUAL = GL_LEQUAL, + GREATER = GL_GREATER, + NOTEQUAL = GL_NOTEQUAL, + GEQUAL = GL_GEQUAL, + ALWAYS = GL_ALWAYS + }; + + + Depth(Function func=LESS,double zNear=0.0, double zFar=1.0,bool writeMask=true); /** Copy constructor using CopyOp to manage deep vs shallow copy.*/ Depth(const Depth& dp,const CopyOp& copyop=CopyOp::SHALLOW_COPY): StateAttribute(dp,copyop), _func(dp._func), - _depthWriteMask(dp._depthWriteMask), _zNear(dp._zNear), - _zFar(dp._zFar) {} + _zFar(dp._zFar), + _depthWriteMask(dp._depthWriteMask) {} META_StateAttribute(osg, Depth, DEPTH); @@ -59,27 +72,11 @@ class SG_EXPORT Depth : public StateAttribute modes.push_back(GL_DEPTH_TEST); } - enum Function - { - NEVER = GL_NEVER, - LESS = GL_LESS, - EQUAL = GL_EQUAL, - LEQUAL = GL_LEQUAL, - GREATER = GL_GREATER, - NOTEQUAL = GL_NOTEQUAL, - GEQUAL = GL_GEQUAL, - ALWAYS = GL_ALWAYS - }; - inline void setFunction(Function func) { _func = func; } inline Function getFunction() const { return _func; } - inline void setWriteMask(bool mask) { _depthWriteMask = mask; } - - inline bool getWriteMask() const { return _depthWriteMask; } - inline void setRange(double zNear, double zFar) { _zNear = zNear; @@ -89,6 +86,11 @@ class SG_EXPORT Depth : public StateAttribute inline double getZNear() const { return _zNear; } inline double getZFar() const { return _zFar; } + inline void setWriteMask(bool mask) { _depthWriteMask = mask; } + + inline bool getWriteMask() const { return _depthWriteMask; } + + virtual void apply(State& state) const; protected: @@ -96,11 +98,11 @@ class SG_EXPORT Depth : public StateAttribute virtual ~Depth(); Function _func; - bool _depthWriteMask; double _zNear; double _zFar; + bool _depthWriteMask; }; } diff --git a/src/osg/BlendFunc.cpp b/src/osg/BlendFunc.cpp index c75f520ac..90f0be33a 100644 --- a/src/osg/BlendFunc.cpp +++ b/src/osg/BlendFunc.cpp @@ -14,12 +14,17 @@ using namespace osg; -BlendFunc::BlendFunc() +BlendFunc::BlendFunc(): + _source_factor(SRC_ALPHA), + _destination_factor(ONE_MINUS_SRC_ALPHA) { - _source_factor = SRC_ALPHA; - _destination_factor = ONE_MINUS_SRC_ALPHA; } +BlendFunc::BlendFunc(GLenum source, GLenum destination): + _source_factor(source), + _destination_factor(destination) +{ +} BlendFunc::~BlendFunc() { diff --git a/src/osg/Depth.cpp b/src/osg/Depth.cpp index 0a60d20c5..52ffb7e9f 100644 --- a/src/osg/Depth.cpp +++ b/src/osg/Depth.cpp @@ -14,16 +14,14 @@ using namespace osg; -Depth::Depth() +Depth::Depth(Function func,double zNear, double zFar,bool writeMask): + _func(func), + _zNear(zNear), + _zFar(zFar), + _depthWriteMask(writeMask) { - _func = LESS; - _depthWriteMask = true; - - _zNear = 0.0; - _zFar = 1.0; } - Depth::~Depth() { } @@ -31,7 +29,7 @@ Depth::~Depth() void Depth::apply(State&) const { glDepthFunc((GLenum)_func); - glDepthMask((GLboolean)_depthWriteMask); glDepthRange(_zNear,_zFar); + glDepthMask((GLboolean)_depthWriteMask); }