|
// testNentw.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
/* 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>
//
int mytest;
bool test = false;
class TextCallBack : public osg::NodeCallback
{
public:
TextCallBack()
{
data_size = 1000;
data_index = 0;
last_update = 0;
int i;
for (i = 0 ; i < data_size ; i++)
{
data[i] = i;
sprintf(str[i],"%d",i);
}
test = true;
printf("\naisdhfjkaaaaaaa\n");
printf("%d\n",i);
//this_text = text;
};
virtual void operator()( osg::Node* node,
osg::NodeVisitor* nv )
{
if (test == true)
{
osg::Geode *geode=dynamic_cast<osg::Geode *>(node);
mytest++;
if(geode)
{
if (data_index < data_size&&(mytest%60==0))
{
//char string[256];
//sprintf(string, "%d", data[data_index++]);
//
sprintf(string, "%d", mytest);
//Sleep(1000);
for (int i = 0 ; i < geode->getNumDrawables() ; i++)
{
osgText::Text* this_text = (osgText::Text *)geode->getDrawable(i);
if (!this_text)
{
continue;
}
this_text->setText(str[data_index++]);
}
}
}
traverse( node, nv );
}
}
//printf("asdfasdg!");
protected:
int data[1000];
char str[1000][1000];
int data_size;
int data_index;
int last_update;
//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);
geode->setDataVariance(osg::Object:YNAMIC);
geode->setUpdateCallback(new TextCallBack());
viewer.setSceneData(root);
//viewer.setSceneData(osgDB::readNodeFile("cow.osg"));
/*while(!viewer.done())
{
viewer.frame();
}*/
viewer.run();
} |
|