Greetings,

I am experiencing problems rendering osgText::Text and osgText::Text3D
in the same scene. I have boiled it down to a nice bite-size chunk of
code which I have attached. I am running version 2.8.

Is this a bug?

Frank

#include <osgViewer/Viewer>

#include <osg/Group>
#include <osg/Camera>

#include <osgText/Font>
#include <osgText/Text>
#include <osgText/Text3D>

#if 1

// Can't see 3D text when both 2D and 3D use the same font...
char const * FontFile3D = "fonts/arial.ttf";
char const * FontFile2D = "fonts/arial.ttf";

#else

// but when they are different, things work fine.
char const * FontFile3D = "fonts/arial.ttf";
char const * FontFile2D = "fonts/times.ttf";

#endif

osg::ref_ptr< osg::Node > Create2DText()
  {
  osg::ref_ptr< osg::Camera > pCamera = new osg::Camera();
  pCamera->setReferenceFrame( osg::Transform::ABSOLUTE_RF );
  pCamera->setViewport( 0, 0, 800, 800 );
  pCamera->setProjectionMatrixAsOrtho2D( 0, 800, 0, 800 );
  pCamera->setViewMatrix( osg::Matrix::identity() );
  pCamera->setClearMask( GL_DEPTH_BUFFER_BIT );
  pCamera->getOrCreateStateSet()->setMode( GL_LIGHTING, osg::StateAttribute::OFF );

  osg::ref_ptr< osg::Geode > pGeode = new osg::Geode();
  pCamera->addChild( pGeode.get() );

  osg::ref_ptr< osgText::Text > pText = new osgText::Text;
  pText->setFont( FontFile2D );
  pText->setColor( osg::Vec4( 1.0f, 1.0f, 1.0f, 1.0f ) );
  pText->setCharacterSize( 42.0 );
  pText->setPosition( osg::Vec3( 100.0, 100.0 ,0.0f ) );

  pText->setText( "2D text" );
  pGeode->addDrawable( pText );

  return pCamera.get();
  }


osg::ref_ptr< osg::Node > Create3DText()
  {
  osg::ref_ptr< osg::Geode > pGeode = new osg::Geode;

  float characterSize  = 1.0f;
  float characterDepth = characterSize*0.2f;


  osg::ref_ptr< osgText::Text3D > pText = new osgText::Text3D();
  pText->setFont( FontFile3D );
  pText->setCharacterSize( characterSize );
  pText->setCharacterDepth( characterDepth );
  pText->setPosition( osg::Vec3( 0.0f, 0.0f, 0.0f ) );
  pText->setDrawMode( osgText::Text3D::TEXT );
  pText->setAxisAlignment( osgText::Text3D::XZ_PLANE );
  pText->setText( "3D Text" );
  pGeode->addDrawable( pText );

  osg::ref_ptr< osg::Group > pRoot = new osg::Group();
  pRoot->addChild( pGeode );

  return pRoot.get();
  }


int main( int argc, char * argv[] )
  {
  osgViewer::Viewer viewer;

  osg::ref_ptr< osg::Group > pGroup = new osg::Group();

  pGroup->addChild( Create2DText() );
  pGroup->addChild( Create3DText() );

  viewer.setSceneData( pGroup );

  viewer.run();
  }

_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to