[osg-users] How to disable Antialiasing of an osg::Text

Robert Osfield robert.osfield at gmail.com
Tue Mar 14 10:26:35 PDT 2017


Hi Lv,

It looks like you are position the text in a 3D scene and leaving it
to scale in object coordinates, which is fine, but it does mean that
the scale will and orientation will vary, this is very different
challenge for rendering clear text than rendering a fixed font to a
fixed 2D projection like you have with a typical Qt application.  You
simple can't compare fonts working in 3D and 2D domains.

That aside to get the best quality of text in a 3d scene you'll
typically want to aim for a font resolution around the on screen
resolution that the text will typically be rendered at, in full 3D
scene this scaling obviously varies so there won't be one ideal
resolution, you'll just have to pick the best one for your the size of
your text and the distances you view them at.

Disabling of placing text into the transparent bin could cause real
problems as the blending of the text could be broken.  Text is put in
the transparent bin to make sure it's rendered after the rest of the
3D scene to make sure that the transparent parts of the text are
correctly blending and the quads text doesn't interfere with with the
zbuffer.  I don't know whether this is affecting quality for you as
you don't say anything about what you by "decluttering".

Robert.

On 14 March 2017 at 17:07, Lv Qing <donlvqing at msn.com> wrote:
> Hi,
>
> Thx Robert!
>
>    I use one of osgEarth fuction to rendering my text.
>
>
>
> Code:
>
>
> osg::ref_ptr<osgText::Text> PowerPlaceNode::createPlaceNodeTextDrawable(const std::string& text,
>                 const TextSymbol* symbol, const osg::Vec3& positionOffset)
> {
>         osg::ref_ptr < osgText::Text > t = new osgText::Text();
>         osgText::String::Encoding text_encoding = osgText::String::ENCODING_UNDEFINED;
>         if (symbol && symbol->encoding().isSet())
>         {
>                 switch (symbol->encoding().value())
>                 {
>                 case TextSymbol::ENCODING_ASCII:
>                         text_encoding = osgText::String::ENCODING_ASCII;
>                         break;
>                 case TextSymbol::ENCODING_UTF8:
>                         text_encoding = osgText::String::ENCODING_UTF8;
>                         break;
>                 case TextSymbol::ENCODING_UTF16:
>                         text_encoding = osgText::String::ENCODING_UTF16;
>                         break;
>                 case TextSymbol::ENCODING_UTF32:
>                         text_encoding = osgText::String::ENCODING_UTF32;
>                         break;
>                 default:
>                         text_encoding = osgText::String::ENCODING_UTF8;
>                         break;   //editby lvqing 20140509
>                 }
>         }
>
>         t->setText(text, osgText::String::ENCODING_UTF8);
>
>
>         if (symbol && symbol->pixelOffset().isSet())
>         {
>                 t->setPosition(
>                                 osg::Vec3(positionOffset.x() + symbol->pixelOffset()->x(),
>                                                 positionOffset.y() + symbol->pixelOffset()->y(), positionOffset.z()));
>         }
>         else
>         {
>                 t->setPosition(positionOffset);
>         }
>
>         osgText::Font* font = 0L;
>         if (symbol && symbol->font().isSet())
>         {
>                 font = osgText::readFontFile(*symbol->font()); // read font*/
>         }
>
>         t->setFontResolution(256,256);
>
>         t->setAutoRotateToScreen(false);
>         t->setCharacterSizeMode(osgText::Text::OBJECT_COORDS);
>
>         if (symbol != NULL)
>         {
>                 if (symbol->size() != NULL)
>                 {
>                         t->setCharacterSize( symbol && symbol->size().isSet() ? *symbol->size() : 20.0f );
>                 }
>                 else
>                 {
>                         t->setCharacterSize( 20.0f );
>                 }
>         }
>
>         if (!font)
>                 font = Registry::instance()->getDefaultFont();
>         if (font)
>         {
>                 t->setFont(font);
>         }
>
>         t->setColor(symbol && symbol->fill().isSet() ? symbol->fill()->color() : Color::White);
>
>         if (symbol)
>         {
>                 // they're the same enum.
>                 osgText::Text::AlignmentType at = (osgText::Text::AlignmentType) symbol->alignment().value();
>                 t->setAlignment(at);
>         }
>
>         if (symbol && symbol->halo().isSet())
>         {
>                 t->setBackdropColor(symbol->halo()->color());
>                 t->setBackdropType(osgText::Text::OUTLINE);
>
>                 if (symbol->haloOffset() != NULL)
>                 {
>                         if (symbol->haloOffset().isSet())
>                         {
>                                 t->setBackdropOffset(*symbol->haloOffset(), *symbol->haloOffset());
>                         }
>                 }
>         }
>         else if (!symbol)
>         {
>                 // if no symbol at all is provided, default to using a black halo.
>                 t->setBackdropColor(osg::Vec4(.3, .3, .3, 1));
>                 t->setBackdropType(osgText::Text::OUTLINE);
>         }
>
>         // this disables the default rendering bin set by osgText::Font. Necessary if we're
>         // going to do decluttering.
>         // TODO: verify that it's still OK to share the font stateset (think so) or does it
>         // need to be marked DYNAMIC
>         if (t->getStateSet())
>                 t->getStateSet()->setRenderBinToInherit();
>         //osg::StateSet* stateSet = new osg::StateSet();
>         //t->setStateSet( stateSet );
>
>
> //#if 0 // OBE: the decluttering bin is now set higher up (in OrthoNode)
>
>         osg::StateSet* stateSet = t->getOrCreateStateSet();
>
>         if ( symbol && symbol->declutter().isSet() )
>         {
>                 Decluttering::setEnabled( stateSet, *symbol->declutter() );
>         }
>         else
>         {
>         //      stateSet->setRenderBinToInherit();
>                 stateSet->setMode(GL_LIGHTING,osg::StateAttribute::OFF);
>         }
>
>         t->setStateSet( stateSet );
>
>
>
>
> #if 0 // OBE: shadergenerator now takes care of all this
>         // add the static "isText=true" uniform; this is a hint for the annotation shaders
>         // if they get installed.
>         static osg::ref_ptr<osg::Uniform> s_isTextUniform = new osg::Uniform(osg::Uniform::BOOL, UNIFORM_IS_TEXT());
>         s_isTextUniform->set( true );
>         stateSet->addUniform( s_isTextUniform.get() );
> #endif
>
>         return t;
> }
>
>
>
>
>
>
>
> ...
>
> Thank you!
>
> Cheers,
> Lv
>
> ------------------
> Read this topic online here:
> http://forum.openscenegraph.org/viewtopic.php?p=70488#70488
>
>
>
>
>
> _______________________________________________
> osg-users mailing list
> osg-users at lists.openscenegraph.org
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org



More information about the osg-users mailing list