[osg-users] Problem with 2D and 3D text in the same scene
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 #include #include #include #include #include #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 osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Problem with 2D and 3D text in the same scene
Hi Frank, This is a bug. I take a look. more in next episode. Cheer David Callu 2009/2/18 > 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 > > > ___ > osg-users mailing list > osg-users@lists.openscenegraph.org > http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org > > ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Problem with 2D and 3D text in the same scene
Hi Frank Problem: osgText::Text and osgText::Text3D use the same font file. The first really load the file and obtain an osgText::Font object, the second use the cache created during the first load of the font file, and so obtain an osgText::Font object instead of osgText::Font3D object. To obtain an osgText::Font3D object, osgText::Text3D call osgDB::readObjectFile(...) with an option to specify the plugin we want an osgText::Font3D instead of osgText::Font. Generalised Problem: In osgDB::Registry, loaded file cache is referenced by the name of this file, so if I load a file with some options, and the cache already contain object for this filename, I obtain an object potentially not loaded with my options. Behaviours: Cache management is delegate to osgDB::Registry, but cache coherence (load a file with option then reuse it, deactivate the cache when load a specific file or don't cached the loaded file) is user's responsibility. Text3D case: Delegate the cache coherence of font file in osgText to the user is not a good idea. So to fix this I think to 2 solution: - never use the cache when load a font for a Text3D. Just because to load a Font3D, we use option in osgDB::readObjectFile() - move osgText::Font3D implementation in osgText::Font, suffix ex-Font3D method with "3D" in osgText::Font (so osgText::Font3D::getGlyph() become osgText::Font::getGlyph3D() ) And so Text and Text3D use the same osgText::Font object which contain 2D and 3D glyph. Thought, Robert, Other ? David Callu 2009/2/19 David Callu > Hi Frank, > > This is a bug. > I take a look. > > more in next episode. > Cheer > > David Callu > > 2009/2/18 > >> 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 >> >> >> ___ >> osg-users mailing list >> osg-users@lists.openscenegraph.org >> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org >> >> > ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Problem with 2D and 3D text in the same scene
Hi David, Thanks for looking into this problem. On Thu, Feb 19, 2009 at 1:08 PM, David Callu wrote: > Text3D case: > Delegate the cache coherence of font file in osgText to the user > is not a good idea. So to fix this I think to 2 solution: > - never use the cache when load a font for a Text3D. Just because > to load a Font3D, we use option in osgDB::readObjectFile() > - move osgText::Font3D implementation in osgText::Font, > suffix ex-Font3D method with "3D" in osgText::Font > (so osgText::Font3D::getGlyph() become osgText::Font::getGlyph3D() > ) > And so Text and Text3D use the same osgText::Font object which > contain > 2D and 3D glyph. I think merging the osgText::Font and Fon3D implementations would be the cleanest approach. Another, more hacky approach would be to postfix the font file name by .Text3D or something similar and then have the freetype plugin return Font3D when it detects this. Robert. Robert. ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Problem with 2D and 3D text in the same scene
Hi Robert I think merging the osgText::Font and Font3D implementations would be > the cleanest approach. > I think too ... but ... > > Another, more hacky approach would be to postfix the font file name by > .Text3D or something similar and then have the freetype plugin return > Font3D when it detects this. > This solution is really smart, it not break the scalability of osgText. I don't know which use can be done with a font except 2D or 3D glyph, but this keep the door open to other thing. osgText::Text3D have to ensure that name of font file is ended by .Text3D and font file cache coherence is not delegate to the user. I have try this solution and work fine. I prepare a submission if you prefer the second solution. Or implement the first one otherwise. As you want. David > Robert. > > Robert. > ___ > osg-users mailing list > osg-users@lists.openscenegraph.org > http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org > ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org