Addd support for maximum screen text size into osgText when auto scale to
screen is active. Added osgautotransform demo.
This commit is contained in:
19
examples/osgautotransform/GNUmakefile
Normal file
19
examples/osgautotransform/GNUmakefile
Normal file
@@ -0,0 +1,19 @@
|
||||
TOPDIR = ../..
|
||||
include $(TOPDIR)/Make/makedefs
|
||||
|
||||
CXXFILES =\
|
||||
osgautotransform.cpp\
|
||||
|
||||
LIBS += -losgProducer -lProducer -losgText -losgProducer -lProducer -losgGA -losgDB -losgUtil -losg $(GL_LIBS) $(X_LIBS) $(OTHER_LIBS)
|
||||
|
||||
INSTFILES = \
|
||||
$(CXXFILES)\
|
||||
GNUmakefile.inst=GNUmakefile
|
||||
|
||||
EXEC = osgautotransform
|
||||
|
||||
INC += $(PRODUCER_INCLUDE_DIR) -I/usr/X11R6/include
|
||||
LDFLAGS += $(PRODUCER_LIB_DIR)
|
||||
|
||||
include $(TOPDIR)/Make/makerules
|
||||
|
||||
14
examples/osgautotransform/GNUmakefile.inst
Normal file
14
examples/osgautotransform/GNUmakefile.inst
Normal file
@@ -0,0 +1,14 @@
|
||||
TOPDIR = ../..
|
||||
include $(TOPDIR)/Make/makedefs
|
||||
|
||||
CXXFILES =\
|
||||
osgautotransform.cpp\
|
||||
|
||||
LIBS += -losgProducer -lProducer -losgText -losgProducer -lProducer -losgDB -losgText -losgUtil -losg $(GL_LIBS) $(X_LIBS) $(OTHER_LIBS)
|
||||
|
||||
EXEC = osgautotransform
|
||||
|
||||
INC += $(PRODUCER_INCLUDE_DIR) -I/usr/X11R6/include
|
||||
LDFLAGS += $(PRODUCER_LIB_DIR)
|
||||
|
||||
include $(TOPDIR)/Make/makerules
|
||||
245
examples/osgautotransform/osgautotransform.cpp
Normal file
245
examples/osgautotransform/osgautotransform.cpp
Normal file
@@ -0,0 +1,245 @@
|
||||
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2003 Robert Osfield
|
||||
*
|
||||
* This library is open source and may be redistributed and/or modified under
|
||||
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
|
||||
* (at your option) any later version. The full license is in LICENSE file
|
||||
* included with this distribution, and on the openscenegraph.org website.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* OpenSceneGraph Public License for more details.
|
||||
*/
|
||||
|
||||
#include <osgUtil/Optimizer>
|
||||
#include <osgDB/ReadFile>
|
||||
#include <osgProducer/Viewer>
|
||||
|
||||
#include <osg/Material>
|
||||
#include <osg/Geode>
|
||||
#include <osg/BlendFunc>
|
||||
#include <osg/Depth>
|
||||
#include <osg/Projection>
|
||||
#include <osg/AutoTransform>
|
||||
#include <osg/Geometry>
|
||||
|
||||
#include <osgText/Text>
|
||||
|
||||
osg::Node* createLabel(const osg::Vec3& pos, float size, const std::string& label)
|
||||
{
|
||||
osg::Geode* geode = new osg::Geode();
|
||||
|
||||
std::string timesFont("fonts/arial.ttf");
|
||||
|
||||
{
|
||||
osgText::Text* text = new osgText::Text;
|
||||
geode->addDrawable( text );
|
||||
|
||||
text->setFont(timesFont);
|
||||
text->setPosition(pos);
|
||||
text->setCharacterSize(size);
|
||||
text->setAlignment(osgText::Text::CENTER_CENTER);
|
||||
text->setText(label);
|
||||
|
||||
}
|
||||
|
||||
return geode;
|
||||
}
|
||||
|
||||
osg::Node* createLabel2(const osg::Vec3& pos, float size, const std::string& label)
|
||||
{
|
||||
osg::Geode* geode = new osg::Geode();
|
||||
|
||||
std::string timesFont("fonts/arial.ttf");
|
||||
|
||||
{
|
||||
osgText::Text* text = new osgText::Text;
|
||||
geode->addDrawable( text );
|
||||
|
||||
text->setFont(timesFont);
|
||||
text->setPosition(pos);
|
||||
text->setFontResolution(40,40);
|
||||
text->setCharacterSize(size);
|
||||
text->setAlignment(osgText::Text::CENTER_CENTER);
|
||||
text->setAutoRotateToScreen(true);
|
||||
text->setAutoScaleToScreen(true);
|
||||
text->setDrawMode(osgText::Text::TEXT_PIXMAP);
|
||||
text->setText(label);
|
||||
|
||||
}
|
||||
|
||||
return geode;
|
||||
}
|
||||
|
||||
osg::Node* createLabel3(const osg::Vec3& pos, float size, const std::string& label)
|
||||
{
|
||||
osg::Geode* geode = new osg::Geode();
|
||||
|
||||
std::string timesFont("fonts/arial.ttf");
|
||||
|
||||
{
|
||||
osgText::Text* text = new osgText::Text;
|
||||
geode->addDrawable( text );
|
||||
|
||||
text->setFont(timesFont);
|
||||
text->setPosition(pos);
|
||||
text->setFontResolution(40,40);
|
||||
text->setCharacterSize(size);
|
||||
text->setAlignment(osgText::Text::CENTER_CENTER);
|
||||
text->setAutoRotateToScreen(true);
|
||||
text->setAutoScaleToScreen(true);
|
||||
text->setText(label);
|
||||
|
||||
}
|
||||
|
||||
return geode;
|
||||
}
|
||||
|
||||
osg::Node* createAxis(const osg::Vec3& s, const osg::Vec3& e, int numReps)
|
||||
{
|
||||
osg::Group* group = new osg::Group;
|
||||
|
||||
osg::Vec3 dv = e-s;
|
||||
dv /= float(numReps-1);
|
||||
|
||||
osg::Vec3 pos = s;
|
||||
|
||||
bool useAuto = false;
|
||||
if (useAuto)
|
||||
{
|
||||
osg::Vec3Array* vertices = new osg::Vec3Array;
|
||||
|
||||
for(int i=0;i<numReps;++i)
|
||||
{
|
||||
osg::AutoTransform* at = new osg::AutoTransform;
|
||||
at->setPosition(pos);
|
||||
at->setAutoRotateToScreen(true);
|
||||
at->setAutoScaleToScreen(true);
|
||||
at->addChild(createLabel(osg::Vec3(0.0f,0.0f,0.0f),40.0f,"Test 2"));
|
||||
vertices->push_back(pos);
|
||||
pos += dv;
|
||||
|
||||
|
||||
group->addChild(at);
|
||||
}
|
||||
|
||||
osg::Vec4Array* colors = new osg::Vec4Array;
|
||||
colors->push_back(osg::Vec4(1.0f,1.0f,1.0f,1.0f));
|
||||
|
||||
osg::Geometry* geom = new osg::Geometry;
|
||||
geom->setVertexArray(vertices);
|
||||
geom->setColorArray(colors);
|
||||
geom->addPrimitiveSet(new osg::DrawArrays(GL_LINE_STRIP,0,vertices->size()));
|
||||
|
||||
osg::Geode* geode = new osg::Geode;
|
||||
geode->addDrawable(geom);
|
||||
|
||||
group->addChild(geode);
|
||||
}
|
||||
else
|
||||
{
|
||||
osg::Vec3Array* vertices = new osg::Vec3Array;
|
||||
|
||||
for(int i=0;i<numReps;++i)
|
||||
{
|
||||
group->addChild(createLabel3(osg::Vec3(pos),dv.length()*0.5f,"Test 2"));
|
||||
vertices->push_back(pos);
|
||||
pos += dv;
|
||||
|
||||
|
||||
}
|
||||
|
||||
osg::Vec4Array* colors = new osg::Vec4Array;
|
||||
colors->push_back(osg::Vec4(1.0f,1.0f,1.0f,1.0f));
|
||||
|
||||
osg::Geometry* geom = new osg::Geometry;
|
||||
geom->setVertexArray(vertices);
|
||||
geom->setColorArray(colors);
|
||||
geom->addPrimitiveSet(new osg::DrawArrays(GL_LINE_STRIP,0,vertices->size()));
|
||||
|
||||
osg::Geode* geode = new osg::Geode;
|
||||
geode->addDrawable(geom);
|
||||
|
||||
group->addChild(geode);
|
||||
}
|
||||
|
||||
return group;
|
||||
}
|
||||
|
||||
osg::Node* createScene()
|
||||
{
|
||||
osg::Group* root = new osg::Group;
|
||||
|
||||
int numReps = 3333;
|
||||
// int numReps = 10;
|
||||
root->addChild(createAxis(osg::Vec3(0.0,0.0,0.0),osg::Vec3(1000.0,0.0,0.0),numReps));
|
||||
root->addChild(createAxis(osg::Vec3(0.0,0.0,0.0),osg::Vec3(0.0,1000.0,0.0),numReps));
|
||||
root->addChild(createAxis(osg::Vec3(0.0,0.0,0.0),osg::Vec3(0.0,0.0,1000.0),numReps));
|
||||
|
||||
return root;
|
||||
}
|
||||
|
||||
int main( int argc, char **argv )
|
||||
{
|
||||
|
||||
// use an ArgumentParser object to manage the program arguments.
|
||||
osg::ArgumentParser arguments(&argc,argv);
|
||||
|
||||
// set up the usage document, in case we need to print out how to use this program.
|
||||
arguments.getApplicationUsage()->setDescription(arguments.getApplicationName()+" is the example which demonstrates how to do Head Up Displays.");
|
||||
arguments.getApplicationUsage()->setCommandLineUsage(arguments.getApplicationName()+" [options] [filename] ...");
|
||||
arguments.getApplicationUsage()->addCommandLineOption("-h or --help","Display this information");
|
||||
|
||||
|
||||
// construct the viewer.
|
||||
osgProducer::Viewer viewer(arguments);
|
||||
|
||||
// set up the value with sensible default event handlers.
|
||||
viewer.setUpViewer(osgProducer::Viewer::STANDARD_SETTINGS);
|
||||
|
||||
// get details on keyboard and mouse bindings used by the viewer.
|
||||
viewer.getUsage(*arguments.getApplicationUsage());
|
||||
|
||||
// if user request help write it out to cout.
|
||||
if (arguments.read("-h") || arguments.read("--help"))
|
||||
{
|
||||
arguments.getApplicationUsage()->write(std::cout);
|
||||
return 1;
|
||||
}
|
||||
|
||||
// any option left unread are converted into errors to write out later.
|
||||
arguments.reportRemainingOptionsAsUnrecognized();
|
||||
|
||||
// report any errors if they have occured when parsing the program aguments.
|
||||
if (arguments.errors())
|
||||
{
|
||||
arguments.writeErrorMessages(std::cout);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
// set the scene to render
|
||||
viewer.setSceneData(createScene());
|
||||
|
||||
// create the windows and run the threads.
|
||||
viewer.realize();
|
||||
|
||||
while( !viewer.done() )
|
||||
{
|
||||
// wait for all cull and draw threads to complete.
|
||||
viewer.sync();
|
||||
|
||||
// update the scene by traversing it with the the update visitor which will
|
||||
// call all node update callbacks and animations.
|
||||
viewer.update();
|
||||
|
||||
// fire off the cull and draw traversals of the scene.
|
||||
viewer.frame();
|
||||
|
||||
}
|
||||
|
||||
// wait for all cull and draw threads to complete before exit.
|
||||
viewer.sync();
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user