28 #include <boost/bind.hpp>
29 #include <boost/function.hpp>
33 #include <osg/Geometry>
34 #include <osg/MatrixTransform>
38 #include "../common/WPathHelper.h"
40 #include "WGETextureHud.h"
45 m_maxElementWidth( 256 ),
47 m_viewport( new osg::Viewport() ),
48 m_coupleTexViewport( false )
50 getOrCreateStateSet()->setRenderBinDetails(
m_renderBin,
"RenderBin" );
65 m_hud->setMatrix( osg::Matrix::ortho2D( 0, screenWidth, 0, screenHeight ) );
68 unsigned int border = 5;
71 osg::Group* group =
static_cast< osg::Group*
>( node );
73 unsigned int nextX = border;
74 unsigned int nextY = border;
77 for(
size_t i = 0; i < group->getNumChildren(); ++i )
90 texMat->setMatrix( osg::Matrixd::scale( static_cast< float >( screenWidth ) / static_cast< float >( tex->
getRealWidth() ),
91 static_cast< float >( screenHeight )/
static_cast< float >( tex->
getRealHeight() ), 1.0 ) );
94 height =
static_cast< float >(
m_hud->
getMaxElementWidth() * screenHeight ) / static_cast< float >( screenWidth );
101 if( nextY + height + border > screenHeight )
108 osg::Matrixd translate = osg::Matrixd::translate( static_cast< double >( nextX ), static_cast< double >( nextY ), 0.0 );
109 tex->setMatrix( scale * translate );
112 nextY += height + border;
116 traverse( node, nv );
138 bool hudEntryPredicate( osg::ref_ptr< osg::Texture > tex, osg::ref_ptr< osg::Node >
const& node )
154 boost::function< bool ( osg::ref_ptr< osg::Node >
const& ) > > TexCheck;
159 boost::shared_ptr< WGEGroupNode::NodePredicate >(
160 new TexCheck( boost::bind( &hudEntryPredicate, texture, _1 ) )
176 osg::MatrixTransform(),
177 m_texture( texture ),
179 m_maxTextWidth( 256 )
181 setMatrix( osg::Matrixd::identity() );
182 setReferenceFrame( osg::Transform::ABSOLUTE_RF );
187 osg::Geode* geode =
new osg::Geode();
190 osg::ref_ptr< osg::Geometry > HUDBackgroundGeometry =
new osg::Geometry();
192 osg::ref_ptr< osg::Vec3Array > HUDBackgroundVertices =
new osg::Vec3Array;
193 HUDBackgroundVertices->push_back( osg::Vec3( 0, 0, -1 ) );
194 HUDBackgroundVertices->push_back( osg::Vec3( 1, 0, -1 ) );
195 HUDBackgroundVertices->push_back( osg::Vec3( 1, 1, -1 ) );
196 HUDBackgroundVertices->push_back( osg::Vec3( 0, 1, -1 ) );
198 osg::ref_ptr< osg::Vec3Array > HUDBackgroundTex =
new osg::Vec3Array;
199 HUDBackgroundTex->push_back( osg::Vec3( 0, 0, 0 ) );
200 HUDBackgroundTex->push_back( osg::Vec3( 1, 0, 0 ) );
201 HUDBackgroundTex->push_back( osg::Vec3( 1, 1, 0 ) );
202 HUDBackgroundTex->push_back( osg::Vec3( 0, 1, 0 ) );
204 osg::ref_ptr< osg::DrawElementsUInt > HUDBackgroundIndices =
new osg::DrawElementsUInt( osg::PrimitiveSet::POLYGON, 0 );
205 HUDBackgroundIndices->push_back( 0 );
206 HUDBackgroundIndices->push_back( 1 );
207 HUDBackgroundIndices->push_back( 2 );
208 HUDBackgroundIndices->push_back( 3 );
210 osg::ref_ptr< osg::Vec4Array > HUDcolors =
new osg::Vec4Array;
211 HUDcolors->push_back( osg::Vec4( 1.0f, 1.0f, 1.0f, 1.0f ) );
213 osg::ref_ptr< osg::Vec3Array > HUDnormals =
new osg::Vec3Array;
214 HUDnormals->push_back( osg::Vec3( 0.0f, 0.0f, 1.0f ) );
215 HUDBackgroundGeometry->setNormalArray( HUDnormals );
216 HUDBackgroundGeometry->setNormalBinding( osg::Geometry::BIND_OVERALL );
217 HUDBackgroundGeometry->addPrimitiveSet( HUDBackgroundIndices );
218 HUDBackgroundGeometry->setVertexArray( HUDBackgroundVertices );
219 HUDBackgroundGeometry->setColorArray( HUDcolors );
220 HUDBackgroundGeometry->setColorBinding( osg::Geometry::BIND_OVERALL );
221 HUDBackgroundGeometry->setTexCoordArray( 0, HUDBackgroundTex );
223 geode->addDrawable( HUDBackgroundGeometry );
226 osg::StateSet* state = geode->getOrCreateStateSet();
227 state->setTextureAttributeAndModes( 0, texture, osg::StateAttribute::ON );
228 state->setMode( GL_DEPTH_TEST, osg::StateAttribute::OFF );
229 state->setMode( GL_LIGHTING, osg::StateAttribute::PROTECTED );
230 state->setMode( GL_LIGHTING, osg::StateAttribute::OFF );
234 m_texMat->setMatrix( osg::Matrixd::identity() );
235 state->setTextureAttributeAndModes( 0,
m_texMat, osg::StateAttribute::ON );
245 state->setMode( GL_BLEND, osg::StateAttribute::PROTECTED );
246 state->setMode( GL_BLEND, osg::StateAttribute::OFF );
250 state->setMode( GL_BLEND, osg::StateAttribute::PROTECTED );
251 state->setMode( GL_BLEND, osg::StateAttribute::ON );
252 state->setRenderingHint( osg::StateSet::TRANSPARENT_BIN );
260 osg::ref_ptr< osg::Geode > textGeode =
new osg::Geode();
261 state = textGeode->getOrCreateStateSet();
262 state->setMode( GL_DEPTH_TEST, osg::StateAttribute::OFF );
263 addChild( textGeode );
266 m_label->setBackdropType( osgText::Text::OUTLINE );
267 m_label->setCharacterSize( 15 );
269 m_label->setAxisAlignment( osgText::Text::SCREEN );
270 m_label->setPosition( osg::Vec3( 0.02, 0.925, -1.0 ) );
271 m_label->setColor( osg::Vec4( 1.0, 1.0, 1.0, 1.0 ) );
272 textGeode->addDrawable(
m_label );
282 m_maxTextWidth = width;
283 m_label->setMaximumWidth( width - 20 );
288 return m_texture->getTextureWidth();
293 return m_texture->getTextureHeight();
osg::ref_ptr< osg::Texture2D > getTexture() const
Gets the texture associated with the entry.
void setMaxTextWidth(float width)
Set maximum text width.
unsigned int getRealWidth() const
Returns the real width of the contained texture.
osg::Viewport * m_viewport
The current viewport of.
osg::ref_ptr< WGEGroupNode > m_group
The group Node where all those texture reside in.
osg::ref_ptr< osg::TexMat > m_texMat
The texture matrix for this entry.
static Fonts getAllFonts()
The paths to all fonts supported.
Class implementing one texture HUD entry representing a texture in the HUD.
unsigned int getMaxElementWidth() const
Gets the maximum width of a tex element.
virtual ~WGETextureHud()
Destructor.
bool m_coupleTexViewport
The viewport in texture space to allow viewing parts of the texture.
Callback which aligns and renders the textures.
WGETextureHud()
Default constructor.
size_t getRenderBin() const
Returns the render bin used by the HUD.
void setViewport(osg::Viewport *viewport)
Sets the viewport of the camera housing this HUD.
osg::ref_ptr< osg::TexMat > getTextureMatrix() const
Get the texture matrix state for this entry.
osgText::Text * m_label
The label text.
void setMaxElementWidth(unsigned int width)
Sets the new maximum width of a texture column.
void addTexture(osg::ref_ptr< WGETextureHudEntry > texture)
Adds the specified HUD element to the HUD.
~WGETextureHudEntry()
Destructor.
The actual class implementing the predicate evaluation.
Class to wrap around the osg Group node and providing a thread safe add/removal mechanism.
std::string getName() const
Returns the name of the entry.
unsigned int getRealHeight() const
Returns the real height of the contained texture.
void removeTexture(osg::ref_ptr< WGETextureHudEntry > texture)
Remove the texture from the HUD.
WGETextureHud * m_hud
Pointer used to access members of the hud.
void coupleViewportWithTextureViewport(bool couple=true)
Set the viewport to be used for textures too.
std::string m_name
The name for this HUD entry.
WGETextureHudEntry(osg::ref_ptr< osg::Texture2D > texture, std::string name, bool transparency=false)
Constructor.
size_t m_renderBin
The render bin to use.
unsigned int m_maxElementWidth
The maximum element width.
virtual void operator()(osg::Node *node, osg::NodeVisitor *nv)
operator () - called during the update traversal.