29 #include <boost/bind/bind.hpp>
30 #include <boost/function.hpp>
33 #include <osg/Geometry>
34 #include <osg/MatrixTransform>
38 #include "../common/WPathHelper.h"
39 #include "WGETextureHud.h"
44 m_maxElementWidth( 256 ),
46 m_viewport( new osg::Viewport() ),
47 m_coupleTexViewport( false )
49 getOrCreateStateSet()->setRenderBinDetails(
m_renderBin,
"RenderBin" );
64 m_hud->setMatrix( osg::Matrix::ortho2D( 0, screenWidth, 0, screenHeight ) );
67 unsigned int border = 5;
70 osg::Group* group =
static_cast< osg::Group*
>( node );
72 unsigned int nextX = border;
73 unsigned int nextY = border;
76 for(
size_t i = 0; i < group->getNumChildren(); ++i )
89 texMat->setMatrix( osg::Matrixd::scale(
static_cast< float >( screenWidth ) /
static_cast< float >( tex->
getRealWidth() ),
90 static_cast< float >( screenHeight )/
static_cast< float >( tex->
getRealHeight() ), 1.0 ) );
93 height =
static_cast< float >(
m_hud->
getMaxElementWidth() * screenHeight ) /
static_cast< float >( screenWidth );
100 if( nextY + height + border > screenHeight )
107 osg::Matrixd translate = osg::Matrixd::translate(
static_cast< double >( nextX ),
static_cast< double >( nextY ), 0.0 );
108 tex->setMatrix( scale * translate );
111 nextY += height + border;
115 traverse( node, nv );
137 bool hudEntryPredicate( osg::ref_ptr< osg::Texture > tex, osg::ref_ptr< osg::Node >
const& node )
153 boost::function< bool ( osg::ref_ptr< osg::Node >
const& ) > > TexCheck;
158 std::shared_ptr< WGEGroupNode::NodePredicate >(
159 new TexCheck( boost::bind( &hudEntryPredicate, texture, boost::placeholders::_1 ) )
175 osg::MatrixTransform(),
176 m_texture( texture ),
178 m_maxTextWidth( 256 )
180 setMatrix( osg::Matrixd::identity() );
181 setReferenceFrame( osg::Transform::ABSOLUTE_RF );
186 osg::Geode* geode =
new osg::Geode();
189 osg::ref_ptr< osg::Geometry > HUDBackgroundGeometry =
new osg::Geometry();
191 osg::ref_ptr< osg::Vec3Array > HUDBackgroundVertices =
new osg::Vec3Array;
192 HUDBackgroundVertices->push_back( osg::Vec3( 0, 0, -1 ) );
193 HUDBackgroundVertices->push_back( osg::Vec3( 1, 0, -1 ) );
194 HUDBackgroundVertices->push_back( osg::Vec3( 1, 1, -1 ) );
195 HUDBackgroundVertices->push_back( osg::Vec3( 0, 1, -1 ) );
197 osg::ref_ptr< osg::Vec3Array > HUDBackgroundTex =
new osg::Vec3Array;
198 HUDBackgroundTex->push_back( osg::Vec3( 0, 0, 0 ) );
199 HUDBackgroundTex->push_back( osg::Vec3( 1, 0, 0 ) );
200 HUDBackgroundTex->push_back( osg::Vec3( 1, 1, 0 ) );
201 HUDBackgroundTex->push_back( osg::Vec3( 0, 1, 0 ) );
203 osg::ref_ptr< osg::DrawElementsUInt > HUDBackgroundIndices =
new osg::DrawElementsUInt( osg::PrimitiveSet::POLYGON, 0 );
204 HUDBackgroundIndices->push_back( 0 );
205 HUDBackgroundIndices->push_back( 1 );
206 HUDBackgroundIndices->push_back( 2 );
207 HUDBackgroundIndices->push_back( 3 );
209 osg::ref_ptr< osg::Vec4Array > HUDcolors =
new osg::Vec4Array;
210 HUDcolors->push_back( osg::Vec4( 1.0f, 1.0f, 1.0f, 1.0f ) );
212 osg::ref_ptr< osg::Vec3Array > HUDnormals =
new osg::Vec3Array;
213 HUDnormals->push_back( osg::Vec3( 0.0f, 0.0f, 1.0f ) );
214 HUDBackgroundGeometry->setNormalArray( HUDnormals );
215 HUDBackgroundGeometry->setNormalBinding( osg::Geometry::BIND_OVERALL );
216 HUDBackgroundGeometry->addPrimitiveSet( HUDBackgroundIndices );
217 HUDBackgroundGeometry->setVertexArray( HUDBackgroundVertices );
218 HUDBackgroundGeometry->setColorArray( HUDcolors );
219 HUDBackgroundGeometry->setColorBinding( osg::Geometry::BIND_OVERALL );
220 HUDBackgroundGeometry->setTexCoordArray( 0, HUDBackgroundTex );
222 geode->addDrawable( HUDBackgroundGeometry );
225 osg::StateSet* state = geode->getOrCreateStateSet();
226 state->setTextureAttributeAndModes( 0, texture, osg::StateAttribute::ON );
227 state->setMode( GL_DEPTH_TEST, osg::StateAttribute::OFF );
228 state->setMode( GL_LIGHTING, osg::StateAttribute::PROTECTED );
229 state->setMode( GL_LIGHTING, osg::StateAttribute::OFF );
233 m_texMat->setMatrix( osg::Matrixd::identity() );
234 state->setTextureAttributeAndModes( 0,
m_texMat, osg::StateAttribute::ON );
244 state->setMode( GL_BLEND, osg::StateAttribute::PROTECTED );
245 state->setMode( GL_BLEND, osg::StateAttribute::OFF );
249 state->setMode( GL_BLEND, osg::StateAttribute::PROTECTED );
250 state->setMode( GL_BLEND, osg::StateAttribute::ON );
251 state->setRenderingHint( osg::StateSet::TRANSPARENT_BIN );
259 osg::ref_ptr< osg::Geode > textGeode =
new osg::Geode();
260 state = textGeode->getOrCreateStateSet();
261 state->setMode( GL_DEPTH_TEST, osg::StateAttribute::OFF );
262 addChild( textGeode );
265 m_label->setBackdropType( osgText::Text::OUTLINE );
266 m_label->setCharacterSize( 15 );
268 m_label->setAxisAlignment( osgText::Text::SCREEN );
269 m_label->setPosition( osg::Vec3( 0.02, 0.925, -1.0 ) );
270 m_label->setColor( osg::Vec4( 1.0, 1.0, 1.0, 1.0 ) );
271 textGeode->addDrawable(
m_label );
281 m_maxTextWidth = width;
282 m_label->setMaximumWidth( width - 20 );
287 return m_texture->getTextureWidth();
292 return m_texture->getTextureHeight();
Class to wrap around the osg Group node and providing a thread safe add/removal mechanism.
Callback which aligns and renders the textures.
WGETextureHud * m_hud
Pointer used to access members of the hud.
virtual void operator()(osg::Node *node, osg::NodeVisitor *nv)
operator () - called during the update traversal.
Class implementing one texture HUD entry representing a texture in the HUD.
osg::ref_ptr< osg::Texture2D > getTexture() const
Gets the texture associated with the entry.
~WGETextureHudEntry()
Destructor.
std::string m_name
The name for this HUD entry.
osgText::Text * m_label
The label text.
std::string getName() const
Returns the name of the entry.
unsigned int getRealHeight() const
Returns the real height of the contained texture.
osg::ref_ptr< osg::TexMat > getTextureMatrix() const
Get the texture matrix state for this entry.
unsigned int getRealWidth() const
Returns the real width of the contained texture.
WGETextureHudEntry(osg::ref_ptr< osg::Texture2D > texture, std::string name, bool transparency=false)
Constructor.
void setMaxTextWidth(float width)
Set maximum text width.
osg::ref_ptr< osg::TexMat > m_texMat
The texture matrix for this entry.
virtual ~WGETextureHud()
Destructor.
void removeTexture(osg::ref_ptr< WGETextureHudEntry > texture)
Remove the texture from the HUD.
osg::Viewport * m_viewport
The current viewport of.
void setViewport(osg::Viewport *viewport)
Sets the viewport of the camera housing this HUD.
void coupleViewportWithTextureViewport(bool couple=true)
Set the viewport to be used for textures too.
size_t getRenderBin() const
Returns the render bin used by the HUD.
unsigned int getMaxElementWidth() const
Gets the maximum width of a tex element.
void addTexture(osg::ref_ptr< WGETextureHudEntry > texture)
Adds the specified HUD element to the HUD.
unsigned int m_maxElementWidth
The maximum element width.
void setMaxElementWidth(unsigned int width)
Sets the new maximum width of a texture column.
bool m_coupleTexViewport
The viewport in texture space to allow viewing parts of the texture.
osg::ref_ptr< WGEGroupNode > m_group
The group Node where all those texture reside in.
size_t m_renderBin
The render bin to use.
WGETextureHud()
Default constructor.
static Fonts getAllFonts()
The paths to all fonts supported.
The actual class implementing the predicate evaluation.