Well, since it not a submission per say. Here is the sample source code that
John wanted me to so you all.
Enjoy! Comments welcome!!
...
Laters!
D Glenn
David Glenn
---
D Glenn 3D Computer Graphics amp; Media Systems.
www.dglenn.com
--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=46681#46681
// Suggested Revisions to osgText::Text class.
// John Markano 3/21/2012
//
// The code below includes suggested fixes for two problems in osgText::Text
// in the OpenSceneGraph 2.8.1 release:
// (1) Text in object coordinates may be rendered with the wrong size.
// If an application requests a font resolution that the font doesn't
// support, OpenSceneGraph uses the closest supported
// resolution. osgText::Text does not handle this situation properly.
// It uses the requested resolution in some calculations where the
// actual resolution is more appropriate.
// (2) Text in screen coordinates may not be scaled properly when a
// perspective projection is specified. In particular, the displayed text
// size may vary with the field of view when it should remain constant
// relative to the screen.
//
// A class TextImproved is defined below to correct these problems. This class
// inherits osgText::Text and replaces three virtual functions in the parent
// class:
// - computeLastCharacterOnLine (for the first issue above)
// - computeGlyphRepresentation (for the first issue above)
// - computePositions (for the second issue above)
//
// Each of these functions includes suggested changes to the original code.
// The original code is also left in place for comparison. The preprocessor
// variable USE_ORIGINAL_CODE can be set to a non-zero value to compile the
// original code instead of the improved code.
//
// An example program is also provided below to provide a before-and-after
// illustration of these changes. This example program splits the screen
// into four quadrants, where
// - The upper left quadrant contains black text generated by osgText::Text
// with screen coordinates specified. It changes size with the field of
// view, but its size should be fixed.
// - The upper right quadrant contains black text generated by the
// TextImproved class defined below. This text should, and does, appear
// with a constant height of around 100 pixels. (No reference scale is
// provided.)
// - The lower left quadrant contains red text generated by osgText::Text
// with object coordinates specified. It should be one unit tall, but
// its actual size varies depending on what the active font supports.
// In this example, it's less than half as tall as the requested size
// because the default font resolution of 32 is much higher than the
// supported (by DefaultFont) resolution of 12.
// - The lower right quadrant contains red text generated by the TextImproved
// class. It displays closer to the correct height of one unit.
//
// The example program allows the user to increase or decrease the field
// of view using keystrokes. Type '+' to increase the field of view, or '-'
// to decrease the field of view. The camera position is fixed, so this
// is the only available viewing parameter control.
//
// This code was developed and tested using Red Hat Enterprise Linux 5.5,
// Qt 4.5.2 and OpenSceneGraph 2.8.1.
//
// This fix uses an uppercase E to find the available font size. This is
// a kludge that is inappropriate for many fonts. A suggested
// improvement would be to add a function to osgText::Font (and the
// DefaultFont subclass) to return the supported font resolution that is
// closest to the requested resolution.
#include osg/Camera
#include osg/Geode
#include osg/Geometry
#include osg/GL
#include osg/Group
#include osg/Math
#include osg/Matrix
#include osg/Notify
#include osg/Vec3
#include osg/Vec3d
#include osgGA/GUIEventHandler
#include osgText/Text
#include osgViewer/Viewer
#define USE_ORIGINAL_CODE (0)
using namespace osg;
using namespace osgText;
class TextImproved : public osgText::Text
{
protected:
String::iterator computeLastCharacterOnLine(osg::Vec2 cursor, String::iterator
first,String::iterator last)
{
Font* activefont = getActiveFont();
if (!activefont) return last;
#if USE_ORIGINAL_CODE
float hr = _characterHeight/getFontHeight();
#else
// Use an upper case E to determine which font size is available
// near the requested font resolution.
// Then compute a scale factor to scale the font to the requested
// character height. Include a factor of 0.7 to allow lower
// case characters to drop below the base of capital letters.
Font::Glyph* glyphGenericUpper = activefont-getGlyph(_fontSize, 'E');
float hr = 0.7 * (glyphGenericUpper
? _characterHeight/glyphGenericUpper-t()
: _characterHeight/getFontHeight());
#endif
float wr = hr/_characterAspectRatio;
bool kerning = true;
unsigned int