OpenSceneGraph Forum Forum Index OpenSceneGraph Forum
Official forum which mirrors the existent OSG mailing lists. Messages posted here are forwarded to the mailing list and vice versa.
 
   FAQFAQ    SearchSearch    MemberlistMemberlist    RulesRules    UsergroupsUsergroups    RegisterRegister 
 Mail2Forum SettingsMail2Forum Settings  ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
   AlbumAlbum  OpenSceneGraph IRC ChatOpenSceneGraph IRC Chat   SmartFeedSmartFeed 

How to disable Antialiasing of an osg::Text


 
Post new topic   Reply to topic    OpenSceneGraph Forum Forum Index -> General
View previous topic :: View next topic  
Author Message
lq37
User


Joined: 04 Oct 2009
Posts: 93

PostPosted: Thu Mar 02, 2017 5:41 pm    Post subject:
How to disable Antialiasing of an osg::Text
Reply with quote

Hi,

In linux we are using osg::Text to display some chinese characters.Then
we find the osg::Text looks a little blur when the size of characters is small.Or,the Black characters seems a little gray when the character size is small.I have setFontSolution(128,128),it not help.

Then I find our old app which using QT to draw text,and with the same font,QT text looks better than osg::Text.

I find QT use QPaint to loading font and drawing text ,and It can enable or disable Antialiasing of text like below.


Code:
class Q_GUI_EXPORT QPainter
{
    Q_DECLARE_PRIVATE(QPainter)
    Q_GADGET
    Q_FLAGS(RenderHint RenderHints)

public:
    enum RenderHint {
        Antialiasing = 0x01,
        TextAntialiasing = 0x02,
        SmoothPixmapTransform = 0x04,
        HighQualityAntialiasing = 0x08,
        NonCosmeticDefaultPen = 0x10
    };



So my question is ,does osg can enable or disable Antialiasing to an osg::Text?Or any other way to make the text looks better when the character size is small?




...

Thank you!

Cheers,
Lv
Code:
Back to top
View user's profile Send private message
robertosfield
OSG Project Lead


Joined: 18 Mar 2009
Posts: 10791

PostPosted: Thu Mar 02, 2017 6:41 pm    Post subject:
How to disable Antialiasing of an osg::Text
Reply with quote

HI Lv,

osgText::Text renders into a 3D scene using OpenGL, which is quite
different than Qt rendering to a 2D window where font resolutions can
exactly matched to the pixels on screen, so you can't really compare
the two.

osgText::Text itself doesn't implement anti-aliasing, anti-aliasing is
a property of the GraphicsWindow that you've created. For the
blurriness you reporting it's unlikely to be an high level
anti-aliasing issue.

My guess is that it's more likely an issue of undersampling of the
glyph texture (magnification) if the size of glyph on screen is lower
than the font resolution, or possible magnification if the glyph on
screen is smaller than the font resolution. A 1:1 ratio will likely
minimize these effects.

You don't provide any guidance on how you are rendering so I can't
provide any more details than this.

Robert.

On 2 March 2017 at 17:41, Lv Qing <> wrote:
Quote:
Hi,

In linux we are using osg::Text to display some chinese characters.Then
we find the osg::Text looks a little blur when the size of characters is small.Or,the Black characters seems a little gray when the character size is small.I have setFontSolution(128,128),it not help.

Then I fond our old app which using QT to draw text,and with the same font,QT text looks better than osg::Text.

I fond QT use QPaint to loading font and drawing text ,and It can enable or disable Antialiasing of text like below.



Code:
class Q_GUI_EXPORT QPainter
{
Q_DECLARE_PRIVATE(QPainter)
Q_GADGET
Q_FLAGS(RenderHint RenderHints)

public:
enum RenderHint {
Antialiasing = 0x01,
TextAntialiasing = 0x02,
SmoothPixmapTransform = 0x04,
HighQualityAntialiasing = 0x08,
NonCosmeticDefaultPen = 0x10
};




So my question is ,does osg can enable or disable Antialiasing to an osg::Text?




...

Thank you!

Cheers,
Lv
Code:




------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=70395#70395








------------------
Post generated by Mail2Forum
Back to top
View user's profile Send private message
lq37
User


Joined: 04 Oct 2009
Posts: 93

PostPosted: Sun Mar 05, 2017 2:10 pm    Post subject:
Re: How to disable Antialiasing of an osg::Text
Reply with quote

robertosfield wrote:
HI Lv,

osgText::Text renders into a 3D scene using OpenGL, which is quite
different than Qt rendering to a 2D window where font resolutions can
exactly matched to the pixels on screen, so you can't really compare
the two.

osgText::Text itself doesn't implement anti-aliasing, anti-aliasing is
a property of the GraphicsWindow that you've created. For the
blurriness you reporting it's unlikely to be an high level
anti-aliasing issue.

My guess is that it's more likely an issue of undersampling of the
glyph texture (magnification) if the size of glyph on screen is lower
than the font resolution, or possible magnification if the glyph on
screen is smaller than the font resolution. A 1:1 ratio will likely
minimize these effects.

You don't provide any guidance on how you are rendering so I can't
provide any more details than this.

Robert.

On 2 March 2017 at 17:41, Lv Qing <> wrote:
Quote:
Hi,

In linux we are using osg::Text to display some chinese characters.Then
we find the osg::Text looks a little blur when the size of characters is small.Or,the Black characters seems a little gray when the character size is small.I have setFontSolution(128,128),it not help.

Then I fond our old app which using QT to draw text,and with the same font,QT text looks better than osg::Text.

I fond QT use QPaint to loading font and drawing text ,and It can enable or disable Antialiasing of text like below.



Code:
class Q_GUI_EXPORT QPainter
{
Q_DECLARE_PRIVATE(QPainter)
Q_GADGET
Q_FLAGS(RenderHint RenderHints)

public:
enum RenderHint {
Antialiasing = 0x01,
TextAntialiasing = 0x02,
SmoothPixmapTransform = 0x04,
HighQualityAntialiasing = 0x08,
NonCosmeticDefaultPen = 0x10
};




So my question is ,does osg can enable or disable Antialiasing to an osg::Text?




...

Thank you!

Cheers,
Lv
Code:




------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=70395#70395








------------------
Post generated by Mail2Forum




Thx! robert!

You mention A 1:1 ratio will likely minimize these effects.Which function excatly I should call?

ThX again!
Back to top
View user's profile Send private message
robertosfield
OSG Project Lead


Joined: 18 Mar 2009
Posts: 10791

PostPosted: Mon Mar 06, 2017 8:33 am    Post subject:
How to disable Antialiasing of an osg::Text
Reply with quote

Hi Lv,

Quote:
You mention A 1:1 ratio will likely minimize these effects.Which function excatly I should call?

There isn't a single function that you can use to do, as well, it's
impossible to implement in a general purpose 3d text implementation.
Only if you have screen aligned text can you start to think about
setting the font resolution (Text::setFontResolution(..) to match the
on screen resolution,

You haven't said anything about you are rendering your text really
can't provide any specific recommendations.

Robert.


------------------
Post generated by Mail2Forum
Back to top
View user's profile Send private message
lq37
User


Joined: 04 Oct 2009
Posts: 93

PostPosted: Tue Mar 14, 2017 5:07 pm    Post subject:
Reply with quote

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;
}





As you can see,I just use some routine method to read a font

font = osgText::readFontFile(*symbol->font()); // read font*/
t->setFontResolution(256,256); //set resolution


Thank you!

Cheers,
Lv
Back to top
View user's profile Send private message
robertosfield
OSG Project Lead


Joined: 18 Mar 2009
Posts: 10791

PostPosted: Tue Mar 14, 2017 5:29 pm    Post subject:
How to disable Antialiasing of an osg::Text
Reply with quote

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 <> wrote:
Quote:
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








------------------
Post generated by Mail2Forum
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    OpenSceneGraph Forum Forum Index -> General All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum

Similar Topics
Topic Author Forum Replies Posted
No new posts Text colors in shaders wernerM General 5 Fri Feb 24, 2017 12:00 pm View latest post
No new posts osgText::Text fix for GLES2 (OpenScen... Konstantin Submission 0 Tue Feb 14, 2017 6:37 pm View latest post
No new posts Version 3.5.6 osgText::Text bounding ... dcfennell General 0 Tue Jan 31, 2017 5:40 pm View latest post
No new posts Disable FFMpeg while building OSG? jiapei100 Build system [build] 1 Fri Jan 06, 2017 11:36 pm View latest post
No new posts Text following lines shaders with osg... kragnfroll General 1 Mon Jan 02, 2017 1:25 pm View latest post


Board Security Anti Bot Question MOD - phpBB MOD against Spam Bots
Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP