Updates osghud demo.
Compile fixes for VisualStudio6.0 because its a hideous pile of junk and can't compile its way out of a paper bag.
This commit is contained in:
parent
fcbf1e200a
commit
e433b42bc0
@ -25,7 +25,6 @@
|
||||
#include <osgText/Text>
|
||||
|
||||
|
||||
|
||||
osg::Group* createHUDText()
|
||||
{
|
||||
|
||||
|
@ -133,40 +133,40 @@ public:
|
||||
Glyph();
|
||||
virtual ~Glyph();
|
||||
|
||||
unsigned int getGlyphCode() const { return _glyphCode; }
|
||||
unsigned int getGlyphCode() const;
|
||||
|
||||
void setFont(Font* font) { _font = font; }
|
||||
Font* getFont() const { return _font; }
|
||||
void setFont(Font* font);
|
||||
Font* getFont() const;
|
||||
|
||||
void setHorizontalBearing(const osg::Vec2& bearing) { _horizontalBearing=bearing; }
|
||||
const osg::Vec2& getHorizontalBearing() const { return _horizontalBearing; }
|
||||
void setHorizontalBearing(const osg::Vec2& bearing);
|
||||
const osg::Vec2& getHorizontalBearing() const;
|
||||
|
||||
void setHorizontalAdvance(float advance) { _horizontalAdvance=advance; }
|
||||
float getHorizontalAdvance() const { return _horizontalAdvance; }
|
||||
void setHorizontalAdvance(float advance);
|
||||
float getHorizontalAdvance() const;
|
||||
|
||||
void setVerticalBearing(const osg::Vec2& bearing) { _verticalBearing=bearing; }
|
||||
const osg::Vec2& getVerticalBearing() const { return _verticalBearing; }
|
||||
void setVerticalBearing(const osg::Vec2& bearing);
|
||||
const osg::Vec2& getVerticalBearing() const;
|
||||
|
||||
void setVerticalAdvance(float advance) { _verticalAdvance=advance; }
|
||||
float getVerticalAdvance() const { return _verticalAdvance; }
|
||||
void setVerticalAdvance(float advance);
|
||||
float getVerticalAdvance() const;
|
||||
|
||||
|
||||
void setTexture(GlyphTexture* texture) { _texture = texture; }
|
||||
GlyphTexture* getTexture() { return _texture; }
|
||||
const GlyphTexture* getTexture() const { return _texture; }
|
||||
void setTexture(GlyphTexture* texture);
|
||||
GlyphTexture* getTexture();
|
||||
const GlyphTexture* getTexture() const;
|
||||
|
||||
osg::StateSet* getStateSet() { return _texture?_texture->getStateSet():0; }
|
||||
const osg::StateSet* getStateSet() const { return _texture?_texture->getStateSet():0; }
|
||||
osg::StateSet* getStateSet();
|
||||
const osg::StateSet* getStateSet() const;
|
||||
|
||||
void setTexturePosition(int posX,int posY) { _texturePosX = posX; _texturePosY = posY; }
|
||||
int getTexturePositionX() const { return _texturePosX; }
|
||||
int getTexturePositionY() const { return _texturePosY; }
|
||||
void setTexturePosition(int posX,int posY);
|
||||
int getTexturePositionX() const;
|
||||
int getTexturePositionY() const;
|
||||
|
||||
void setMinTexCoord(const osg::Vec2& coord) { _minTexCoord=coord; }
|
||||
const osg::Vec2& getMinTexCoord() const { return _minTexCoord; }
|
||||
void setMinTexCoord(const osg::Vec2& coord);
|
||||
const osg::Vec2& getMinTexCoord() const;
|
||||
|
||||
void setMaxTexCoord(const osg::Vec2& coord) { _maxTexCoord=coord; }
|
||||
const osg::Vec2& getMaxTexCoord() const { return _maxTexCoord; }
|
||||
void setMaxTexCoord(const osg::Vec2& coord);
|
||||
const osg::Vec2& getMaxTexCoord() const;
|
||||
|
||||
void subload() const;
|
||||
|
||||
|
@ -55,46 +55,27 @@ void write_usage(std::ostream& out,const std::string& name)
|
||||
out << std::endl;
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// globals
|
||||
#define TEXT_POLYGON "Polygon Font - jygq"
|
||||
#define TEXT_OUTLINE "Outline Font - jygq"
|
||||
#define TEXT_TEXTURE "Texture Font - jygq"
|
||||
#define TEXT_BITMAP "Bitmap Font - jygq"
|
||||
#define TEXT_PIXMAP "Pixmap Font - jygq"
|
||||
|
||||
#define TEXT_COL_2D osg::Vec4(.9,.9,.9,1)
|
||||
#define TEXT_COL_3D osg::Vec4(.99,.3,.2,1)
|
||||
|
||||
|
||||
std::string timesFont("fonts/times.ttf");
|
||||
std::string arialFont("fonts/arial.ttf");
|
||||
|
||||
int gFontSize=18;
|
||||
int gFontSize1=24;
|
||||
osgText::Text::AlignmentType gAlignment=osgText::Text::LEFT_BOTTOM;
|
||||
|
||||
void set2dScene(osg::Group* rootNode)
|
||||
osg::Node* createHUD()
|
||||
{
|
||||
osg::Geode* geode = new osg::Geode();
|
||||
rootNode->addChild(geode);
|
||||
|
||||
osg::Vec3 position(150.0f,10.0f,0.0f);
|
||||
osg::Vec3 delta(90.0f,120.0f,0.0f);
|
||||
std::string timesFont("fonts/times.ttf");
|
||||
|
||||
// turn lighting off for the text and disable depth test to ensure its always ontop.
|
||||
osg::StateSet* stateset = geode->getOrCreateStateSet();
|
||||
stateset->setMode(GL_LIGHTING,osg::StateAttribute::OFF);
|
||||
stateset->setMode(GL_DEPTH_TEST,osg::StateAttribute::OFF);
|
||||
|
||||
osg::Vec3 position(150.0f,800.0f,0.0f);
|
||||
osg::Vec3 delta(0.0f,-120.0f,0.0f);
|
||||
|
||||
{
|
||||
osgText::Text* text = new osgText::Text;
|
||||
geode->addDrawable( text );
|
||||
|
||||
text->setFont(timesFont);
|
||||
text->setFontSize(gFontSize,gFontSize);
|
||||
text->setText("String 1");
|
||||
text->setText("Head Up Displays are simple :-)");
|
||||
text->setPosition(position);
|
||||
text->setDrawMode( osgText::Text::TEXT |
|
||||
osgText::Text::BOUNDINGBOX |
|
||||
osgText::Text::ALIGNMENT );
|
||||
text->setAlignment(gAlignment);
|
||||
|
||||
position += delta;
|
||||
}
|
||||
@ -105,13 +86,8 @@ void set2dScene(osg::Group* rootNode)
|
||||
geode->addDrawable( text );
|
||||
|
||||
text->setFont(timesFont);
|
||||
text->setFontSize(gFontSize,gFontSize);
|
||||
text->setText("String 1");
|
||||
text->setText("All you need to do is create your text in a subgraph.");
|
||||
text->setPosition(position);
|
||||
text->setDrawMode( osgText::Text::TEXT |
|
||||
osgText::Text::BOUNDINGBOX |
|
||||
osgText::Text::ALIGNMENT );
|
||||
text->setAlignment(gAlignment);
|
||||
|
||||
position += delta;
|
||||
}
|
||||
@ -122,16 +98,46 @@ void set2dScene(osg::Group* rootNode)
|
||||
geode->addDrawable( text );
|
||||
|
||||
text->setFont(timesFont);
|
||||
text->setFontSize(gFontSize,gFontSize);
|
||||
text->setText("String 1");
|
||||
text->setText("Disable depth test in this subgraph to ensure its always ontop.");
|
||||
text->setPosition(position);
|
||||
text->setDrawMode( osgText::Text::TEXT |
|
||||
osgText::Text::BOUNDINGBOX |
|
||||
osgText::Text::ALIGNMENT );
|
||||
text->setAlignment(gAlignment);
|
||||
|
||||
position += delta;
|
||||
}
|
||||
|
||||
{
|
||||
osgText::Text* text = new osgText::Text;
|
||||
geode->addDrawable( text );
|
||||
|
||||
text->setFont(timesFont);
|
||||
text->setText("Then place a osg::Projection node above the subgraph\nto create an othrograph projection.");
|
||||
text->setPosition(position);
|
||||
|
||||
position += delta;
|
||||
}
|
||||
|
||||
{
|
||||
osgText::Text* text = new osgText::Text;
|
||||
geode->addDrawable( text );
|
||||
|
||||
text->setFont(timesFont);
|
||||
text->setText("And add an osg::ModelViewMatrix set to ABSOLUTE to ensure\nit remains independent from any external model view matrices.");
|
||||
text->setPosition(position);
|
||||
|
||||
position += delta;
|
||||
}
|
||||
|
||||
// create the hud.
|
||||
osg::MatrixTransform* modelview_abs = new osg::MatrixTransform;
|
||||
modelview_abs->setReferenceFrame(osg::Transform::RELATIVE_TO_ABSOLUTE);
|
||||
modelview_abs->setMatrix(osg::Matrix::identity());
|
||||
modelview_abs->addChild(geode);
|
||||
|
||||
osg::Projection* projection = new osg::Projection;
|
||||
projection->setMatrix(osg::Matrix::ortho2D(0,1280,0,1024));
|
||||
projection->addChild(modelview_abs);
|
||||
|
||||
return projection;
|
||||
|
||||
}
|
||||
|
||||
struct MyCallback : public osg::NodeCallback
|
||||
@ -200,24 +206,9 @@ int main( int argc, char **argv )
|
||||
group->addChild(rootnode);
|
||||
rootnode = group;
|
||||
}
|
||||
|
||||
// create the hud.
|
||||
osg::Projection* projection = new osg::Projection;
|
||||
projection->setMatrix(osg::Matrix::ortho2D(0,1024,0,768));
|
||||
|
||||
osg::MatrixTransform* modelview_abs = new osg::MatrixTransform;
|
||||
modelview_abs->setReferenceFrame(osg::Transform::RELATIVE_TO_ABSOLUTE);
|
||||
modelview_abs->setMatrix(osg::Matrix::identity());
|
||||
|
||||
|
||||
set2dScene(modelview_abs);
|
||||
|
||||
projection->addChild(modelview_abs);
|
||||
// projection->setAppCallback(new MyCallback("App callback"));
|
||||
// projection->setCullCallback(new MyCallback("Cull callback"));
|
||||
|
||||
group->addChild(projection);
|
||||
|
||||
// add the HUD subgraph.
|
||||
group->addChild(createHUD());
|
||||
|
||||
// add a viewport to the viewer and attach the scene graph.
|
||||
viewer.addViewport( rootnode );
|
||||
|
@ -21,8 +21,6 @@
|
||||
|
||||
#include <osgDB/ReadFile>
|
||||
|
||||
//#include "CreateShadowedScene.h"
|
||||
|
||||
static bool s_ProfessionalServices = false;
|
||||
|
||||
class MyBillboardTransform : public osg::PositionAttitudeTransform
|
||||
@ -37,61 +35,30 @@ class MyBillboardTransform : public osg::PositionAttitudeTransform
|
||||
|
||||
bool computeLocalToWorldMatrix(osg::Matrix& matrix,osg::NodeVisitor* nv) const
|
||||
{
|
||||
|
||||
|
||||
if (_referenceFrame==RELATIVE_TO_PARENTS)
|
||||
osg::Quat billboardRotation;
|
||||
osgUtil::CullVisitor* cullvisitor = dynamic_cast<osgUtil::CullVisitor*>(nv);
|
||||
if (cullvisitor)
|
||||
{
|
||||
|
||||
osg::Quat billboardRotation;
|
||||
osgUtil::CullVisitor* cullvisitor = dynamic_cast<osgUtil::CullVisitor*>(nv);
|
||||
if (cullvisitor)
|
||||
{
|
||||
osg::Vec3 eyevector = cullvisitor->getEyeLocal()-_position;
|
||||
eyevector.normalize();
|
||||
|
||||
osg::Vec3 side = _axis^_normal;
|
||||
side.normalize();
|
||||
|
||||
float angle = atan2f(eyevector*_normal,eyevector*side);
|
||||
billboardRotation.makeRotate(osg::PI_2-angle,_axis);
|
||||
|
||||
}
|
||||
|
||||
|
||||
matrix.preMult(osg::Matrix::translate(-_pivotPoint)*
|
||||
osg::Matrix::rotate(_attitude)*
|
||||
osg::Matrix::rotate(billboardRotation)*
|
||||
osg::Matrix::translate(_position));
|
||||
}
|
||||
else // absolute
|
||||
{
|
||||
matrix = osg::Matrix::translate(-_pivotPoint)*
|
||||
osg::Matrix::rotate(_attitude)*
|
||||
osg::Matrix::translate(_position);
|
||||
osg::Vec3 eyevector = cullvisitor->getEyeLocal()-_position;
|
||||
eyevector.normalize();
|
||||
|
||||
osg::Vec3 side = _axis^_normal;
|
||||
side.normalize();
|
||||
|
||||
float angle = atan2f(eyevector*_normal,eyevector*side);
|
||||
billboardRotation.makeRotate(osg::PI_2-angle,_axis);
|
||||
|
||||
}
|
||||
|
||||
|
||||
matrix.preMult(osg::Matrix::translate(-_pivotPoint)*
|
||||
osg::Matrix::rotate(_attitude)*
|
||||
osg::Matrix::rotate(billboardRotation)*
|
||||
osg::Matrix::translate(_position));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool computeWorldToLocalMatrix(osg::Matrix& matrix,osg::NodeVisitor*) const
|
||||
{
|
||||
|
||||
if (_referenceFrame==RELATIVE_TO_PARENTS)
|
||||
{
|
||||
osg::Quat billboardRotation;
|
||||
matrix.postMult(osg::Matrix::translate(-_position)*
|
||||
osg::Matrix::rotate(billboardRotation.inverse())*
|
||||
osg::Matrix::rotate(_attitude.inverse())*
|
||||
osg::Matrix::translate(_pivotPoint));
|
||||
}
|
||||
else // absolute
|
||||
{
|
||||
matrix = osg::Matrix::translate(-_position)*
|
||||
osg::Matrix::rotate(_attitude.inverse())*
|
||||
osg::Matrix::translate(_pivotPoint);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void setAxis(const osg::Vec3& axis) { _axis = axis; }
|
||||
|
||||
@ -182,14 +149,7 @@ osg:: Node* createTextLeft(const osg::BoundingBox& bb)
|
||||
|
||||
|
||||
osg::StateSet* stateset = geode->getOrCreateStateSet();
|
||||
|
||||
// osg::BlendFunc *transp= new osg::BlendFunc();
|
||||
// transp->setFunction(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
|
||||
stateset->setMode(GL_LIGHTING,osg::StateAttribute::OFF);
|
||||
// stateset->setAttributeAndModes(transp,osg::StateAttribute::ON);
|
||||
// stateset->setTextureMode(0,GL_TEXTURE_2D,osg::StateAttribute::ON);
|
||||
// stateset->setRenderingHint(osg::StateSet::TRANSPARENT_BIN);
|
||||
|
||||
|
||||
//std::string font("fonts/times.ttf");
|
||||
@ -198,9 +158,10 @@ osg:: Node* createTextLeft(const osg::BoundingBox& bb)
|
||||
osgText::Text* text = new osgText::Text;
|
||||
|
||||
text->setFont(font);
|
||||
text->setFontSize(64,64);
|
||||
text->setFontSize(120,120);
|
||||
text->setAlignment(osgText::Text::RIGHT_CENTER);
|
||||
text->setAxisAlignment(osgText::Text::XZ_PLANE);
|
||||
text->setCharacterSize((bb.zMax()-bb.zMin())*0.8f);
|
||||
text->setPosition(bb.center()-osg::Vec3((bb.xMax()-bb.xMin()),-(bb.yMax()-bb.yMin())*0.5f,(bb.zMax()-bb.zMin())*0.3f));
|
||||
//text->setColor(osg::Vec4(0.37f,0.48f,0.67f,1.0f)); // Neil's orignal OSG colour
|
||||
text->setColor(osg::Vec4(0.20f,0.45f,0.60f,1.0f)); // OGL logo colour
|
||||
@ -218,7 +179,7 @@ osg:: Node* createTextLeft(const osg::BoundingBox& bb)
|
||||
subscript->setText("Professional Services");
|
||||
subscript->setAlignment(osgText::Text::RIGHT_CENTER);
|
||||
subscript->setAxisAlignment(osgText::Text::XZ_PLANE);
|
||||
subscript->setPosition(bb.center()-osg::Vec3((bb.xMax()-bb.xMin())*3.5f,-(bb.yMax()-bb.yMin())*0.3f,(bb.zMax()-bb.zMin())*0.7f));
|
||||
subscript->setPosition(bb.center()-osg::Vec3((bb.xMax()-bb.xMin())*3.5f,-(bb.yMax()-bb.yMin())*0.5f,(bb.zMax()-bb.zMin())*0.6f));
|
||||
subscript->setColor(osg::Vec4(0.0f,0.0f,0.0f,1.0f)); // black
|
||||
|
||||
geode->addDrawable( subscript );
|
||||
|
@ -291,9 +291,44 @@ void Font::GlyphTexture::apply(osg::State& state) const
|
||||
}
|
||||
}
|
||||
|
||||
// all the methods in Font::Glyph have been made non inline because VisualStudio6.0 is STUPID, STUPID, STUPID PILE OF JUNK.
|
||||
Font::Glyph::Glyph() {}
|
||||
Font::Glyph::~Glyph() {}
|
||||
|
||||
unsigned int Font::Glyph::getGlyphCode() const { return _glyphCode; }
|
||||
|
||||
void Font::Glyph::setFont(Font* font) { _font = font; }
|
||||
Font* Font::Glyph::getFont() const { return _font; }
|
||||
|
||||
void Font::Glyph::setHorizontalBearing(const osg::Vec2& bearing) { _horizontalBearing=bearing; }
|
||||
const osg::Vec2& Font::Glyph::getHorizontalBearing() const { return _horizontalBearing; }
|
||||
|
||||
void Font::Glyph::setHorizontalAdvance(float advance) { _horizontalAdvance=advance; }
|
||||
float Font::Glyph::getHorizontalAdvance() const { return _horizontalAdvance; }
|
||||
|
||||
void Font::Glyph::setVerticalBearing(const osg::Vec2& bearing) { _verticalBearing=bearing; }
|
||||
const osg::Vec2& Font::Glyph::getVerticalBearing() const { return _verticalBearing; }
|
||||
|
||||
void Font::Glyph::setVerticalAdvance(float advance) { _verticalAdvance=advance; }
|
||||
float Font::Glyph::getVerticalAdvance() const { return _verticalAdvance; }
|
||||
|
||||
void Font::Glyph::setTexture(GlyphTexture* texture) { _texture = texture; }
|
||||
Font::GlyphTexture* Font::Glyph::getTexture() { return _texture; }
|
||||
const Font::GlyphTexture* Font::Glyph::getTexture() const { return _texture; }
|
||||
|
||||
osg::StateSet* Font::Glyph::getStateSet() { return _texture?_texture->getStateSet():0; }
|
||||
const osg::StateSet* Font::Glyph::getStateSet() const { return _texture?_texture->getStateSet():0; }
|
||||
|
||||
void Font::Glyph::setTexturePosition(int posX,int posY) { _texturePosX = posX; _texturePosY = posY; }
|
||||
int Font::Glyph::getTexturePositionX() const { return _texturePosX; }
|
||||
int Font::Glyph::getTexturePositionY() const { return _texturePosY; }
|
||||
|
||||
void Font::Glyph::setMinTexCoord(const osg::Vec2& coord) { _minTexCoord=coord; }
|
||||
const osg::Vec2& Font::Glyph::getMinTexCoord() const { return _minTexCoord; }
|
||||
|
||||
void Font::Glyph::setMaxTexCoord(const osg::Vec2& coord) { _maxTexCoord=coord; }
|
||||
const osg::Vec2& Font::Glyph::getMaxTexCoord() const { return _maxTexCoord; }
|
||||
|
||||
void Font::Glyph::subload() const
|
||||
{
|
||||
GLenum errorNo = glGetError();
|
||||
@ -302,8 +337,6 @@ void Font::Glyph::subload() const
|
||||
osg::notify(osg::WARN)<<"before: detected OpenGL error '"<<gluErrorString(errorNo)<<std::endl;
|
||||
}
|
||||
|
||||
|
||||
|
||||
glPixelStorei(GL_UNPACK_ALIGNMENT,getPacking());
|
||||
|
||||
glTexSubImage2D(GL_TEXTURE_2D,0,
|
||||
|
@ -225,7 +225,8 @@ void Text::computeGlyphRepresentation()
|
||||
|
||||
_textureGlyphQuadMap.clear();
|
||||
|
||||
osg::Vec2 cursor(0.0f,0.0f);
|
||||
osg::Vec2 startOfLine(0.0f,0.0f);
|
||||
osg::Vec2 cursor(startOfLine);
|
||||
osg::Vec2 local(0.0f,0.0f);
|
||||
|
||||
unsigned int previous_charcode = 0;
|
||||
@ -243,6 +244,16 @@ void Text::computeGlyphRepresentation()
|
||||
{
|
||||
unsigned int charcode = *itr;
|
||||
|
||||
if (charcode=='\n')
|
||||
{
|
||||
if (horizontal) startOfLine.y() -= _fontHeight;
|
||||
else startOfLine.x() += _fontWidth;
|
||||
cursor = startOfLine;
|
||||
previous_charcode = 0;
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
Font::Glyph* glyph = activefont->getGlyph(charcode);
|
||||
if (glyph)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user