Aded extra constructors to BlendFunc and Depth to help set them up convieniently.
Added a background quad to osghud.
This commit is contained in:
parent
06054d9520
commit
fa0333b6fe
@ -20,6 +20,7 @@
|
||||
#include <osg/BlendFunc>
|
||||
#include <osg/Depth>
|
||||
#include <osg/Projection>
|
||||
#include <osg/PolygonOffset>
|
||||
#include <osg/MatrixTransform>
|
||||
|
||||
#include <osgText/Text>
|
||||
@ -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);
|
||||
@ -96,6 +98,45 @@ osg::Node* createHUD()
|
||||
position += delta;
|
||||
}
|
||||
|
||||
|
||||
|
||||
{
|
||||
osg::BoundingBox bb;
|
||||
for(unsigned int i=0;i<geode->getNumDrawables();++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;
|
||||
modelview_abs->setReferenceFrame(osg::Transform::RELATIVE_TO_ABSOLUTE);
|
||||
@ -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.
|
||||
|
@ -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),
|
||||
|
@ -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;
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -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()
|
||||
{
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user