Robert,
Sounds like the right solution. It works fine too! As expected it solves
my problem with squares around the text (LINE polygon mode) as well.
I noticed that you committed my test code in create3DText() in
osgtext.cpp, was this intentional? My comments state that it doesn't
work, but now it does, so...
/Andreas
Robert Osfield wrote:
Hi All,
Yesterday I looked into the issue of not being able to protect the
mode and attribute values set on the StateSet of a osgText::Text in
OpenSceneGraph-1.1. I expect the problem will have existed in prior
versions as well.
To fix the problem I changed the way that osgText::Text applies the
different textures that are required to provide all the different
characters used in each text string - typically it'll just be one
texture, but if you have high res characters then only a few
characters/glyphs might fit in each texture, so multiple textures will
be required. Originally the code was use StateSet per Texture, and
doing a state.apply(StateSet), and it was this apply that was
overwriting the protected values of the StateSet attached to the
osgText::Text drawable.
The solution I have adopted to refactor osgText::Font and
osgText::Text so that rather than applying a whole StateSet for each
texture, it just applies the Texture itself, leaving the rest of state
intact. This should also be faster as there will be less operations
going on.
One downside is that you now have to explicitly switch on GL_BLEND and
GL_TEXTURE_2D via the attached StateSet, or apply them inside the
Text::drawImplementation. Applying these modes via attached
conventional StateSet's is more flexible, and things work fine when
the text is used as normal part of the scene graph, state inheritance
and protection/overriding all work, so it'd seem quite a reasonable
solution.
However, Text is also used separate from the scene graph for things
like stats and help HUD's, these just do a text->draw() without worry
about doing a state.apply(text->getStateSet()) or explicitly enabling
GL_BLEND and GL_TEXTURE_2D. I could add this code in, or... explictly
add the enabling of GL_BLEND and GL_TEXURE_2D directly into
Text::drawImplementation, so it would force things to work in all
situtations.
Now, these two solutions are mutually exclusive, with either let
StateSet's do the enabling of GL_BLEND and GL_TEXTURE_2D, or will
encode this into Text::drawImplementation, and throw away any ability
override these modes off. Personally I can't see a reason for even
switching off texturing or blending on Text, as if you do they turn
out as white blocks, not much use to anyone.
With this in mind I have checked in to CVS the explicitly enabled of
GL_BLEND and GL_TEXTURE_2D into Text::drawImplemention(). This does
make any previous code that enables these modes or protecting the
enabling of these mode redundant, which means you'll just be able to
go ahead and delete these code blocks :-)
Thoughts?
As ever, I'd appreciate testing against your own applications.
Robert.
_______________________________________________
osg-users mailing list
[email protected]
http://openscenegraph.net/mailman/listinfo/osg-users
http://www.openscenegraph.org/
_______________________________________________
osg-users mailing list
[email protected]
http://openscenegraph.net/mailman/listinfo/osg-users
http://www.openscenegraph.org/