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 ) )
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();