osg::ref_ptrviewer = new osgviewer::viewer;
osg::ref_ptrnode;
//申請乙個定時器
osg::timer* timer = new osg::timer;
osg::timer_t start_frame_time = 0;
osg::timer_t end_frame_time = 0;
float start_time;
float end_time;
//控制幀率使用的睡眠時間
float sleep_time = 0.0;
float last_sleep_time = 0.0;
//每幀的實際使用時間
float current_time = 0.0;
//每幀控制法
//float per_start_time = 0.0;
//float per_end_time = 0.0;
//計算幀率
int counts = 0;
//得到乙個tick值為多少second
std::cout << timer->getsecondspertick()<
//start_time = timer->tick();
start_time = viewer->elapsedtime();
timer->setstarttick();
node = osgdb::readnodefile("glider.osg");
std::cout<<"方法一:讀取模型的時間為:"tick();
end_time = viewer->elapsedtime();
std::cout<<"方法二:讀取模型的時間為:"viewer->addeventhandler(new printname);
viewer->addeventhandler(new osgviewer::helphandler);
viewer->addeventhandler(new osgviewer::statshandler);
viewer->addeventhandler(new osgviewer::windowsizehandler);
viewer->addeventhandler(new osgviewer::screencapturehandler);
viewer->setscenedata(node);
viewer->setcameramanipulator(new osgga::trackballmanipulator());
while(!viewer->done())
counts++;
viewer->frame();
//per_end_time = timer->tick();
//sleep_time =
1/35.0 - timer->delta_s(per_start_time, per_end_time);
if(sleep_time < 0)
openthreads::thread::microsleep(sleep_time*1000000);
//last_sleep_time = sleep_time;
if(counts == 3)
統計幀率的幾種方法
class cfpssta void cfpssta checkfps if flag 每5秒計算一次平均幀率,並清空數值,重新計數 下一次呼叫時,重設flag 其中m count在繪製函式後 第二種 class cfpssta2 void cfpssta2 checkfps 對繪製時間入佇列,每次...
OSG學習 osg概述以及學習方法等
osg 即openscenegraph的簡稱.是一款開源的場景圖形庫.同時它也是跨平台的.osg它基於場景圖的概念.利用了軟體開發當中的設計模式的理念,設計並提供了乙個基於opengl底層的物件導向的圖形開發框架.osg是完全由標準c 和opengl而寫的.充分利用stl和設計模式的特性,可以說是具...
19 osg中控制幀速例項
example1.cpp 定義控制台應用程式的入口點。include stdafx.h include include include include include include include using namespace std class testhandler public osgga...