|
/* OpenSceneGraph example, osganimate.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#include "stdafx.h"
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#include <osgUtil/Optimizer>
#include <osgDB/ReadFile>
#include <osgDB/WriteFile>
#include <osgDB/Registry>
#include <osgViewer/Viewer>
#include <osgViewer/ViewerEventHandlers>
#include <osg/Geode>
#include <osg/Camera>
#include <osg/ShapeDrawable>
#include <osg/Sequence>
#include <osg/PolygonMode>
#include <osg/io_utils>
#include <osgText/Font>
#include <osgText/Text>
class TextCallBack : public osg::NodeCallback
{
public:
TextCallBack(osgText::Text *text)
{
data_size = 1000;
data_index = 0;
for (int i = 0 ; i < data_size ; i++)
{
data[i] = i;
}
this_text = text;
};
virtual void operator()( osg::Node* node,
osg::NodeVisitor* nv )
{
char string[256];
sprintf(string, "%d", data[data_index++]);
this_text->setText(string);
Sleep(1000);
}
protected:
int data[1000];
int data_size;
int data_index;
osg::ref_ptr<osgText::Text> this_text;
};
osg::ref_ptr<osg::Node> createText()
{
osg::Group *node = new osg::Group;
osg::Geode *geode = new osg::Geode;
osgText::Text* text = new osgText::Text;
osgText::Font* font = osgText::readFontFile("fonts/arial.ttf");
osg::Vec4 layoutColor(1.0f,1.0f,0.0f,1.0f);
float layoutCharacterSize = 20.0f;
float windowHeight = 1024.0f;
float windowWidth = 1280.0f;
float margin = 50.0f;
node->addChild(geode);
text->setFont(font);
text->setColor(layoutColor);
text->setCharacterSize(layoutCharacterSize);
text->setPosition(osg::Vec3(margin,windowHeight-margin,0.0f));
text->setLayout(osgText::Text:EFT_TO_RIGHT);
text->setText("openscenegraph!");
geode->addDrawable(text);
return node;
}
void main()
{
osgViewer::Viewer viewer;
osg::Group *root = new osg::Group;
osg::Geode *geode = new osg::Geode;
osgText::Text* text = new osgText::Text;
osgText::Font* font = osgText::readFontFile("fonts/arial.ttf");
osg::Vec4 layoutColor(1.0f,1.0f,0.0f,1.0f);
float layoutCharacterSize = 20.0f;
float windowHeight = 1024.0f;
float windowWidth = 1280.0f;
float margin = 50.0f;
root->addChild(geode);
text->setFont(font);
text->setColor(layoutColor);
text->setCharacterSize(layoutCharacterSize);
text->setPosition(osg::Vec3(margin,windowHeight-margin,0.0f));
text->setLayout(osgText::Text::LEFT_TO_RIGHT);
text->setText("wangjunchao!");
geode->addDrawable(text);
root->setDataVariance(osg::Object:YNAMIC);
root->setUpdateCallback(new TextCallBack(text));
viewer.setSceneData(root);
viewer.run();
} |
|