This repository has been archived on 2024-01-06. You can view files and clone it, but cannot push or open issues or pull requests.
justhomework/OpenGL/lab4/main.cpp
2023-06-04 17:17:08 +08:00

40 lines
No EOL
1.1 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include <osgViewer/Viewer>
#include <osgDB/ReadFile>
#include <osgText/Text>
#include <osgGA/TrackballManipulator>
#include <chrono>
#include <osgGA/GUIEventAdapter>
#include <osgViewer/ViewerEventHandlers>
using namespace std;
using namespace chrono;
auto lastFT = system_clock::now();
auto FT = system_clock::now();
int main(int argc, char** argv)
{
// 创建一个OSG Viewer对象
osgViewer::Viewer viewer;
viewer.setUpViewInWindow(50, 50, 800, 600);
viewer.getCamera()->setClearColor(osg::Vec4(0.2, 0.2, 0.2, 1.0));
viewer.setCameraManipulator(new osgGA::TrackballManipulator);
viewer.addEventHandler(new osgViewer::StatsHandler);//查看帧数 s
// 创建一个OSG Node对象并加载OSG模型
osg::ref_ptr<osg::Node> model = osgDB::readNodeFile("clock.osgt");
// 将Node对象添加到OSG Viewer中
viewer.setSceneData(model);
// 启动OSG Viewer循环
while (!viewer.done())
{
auto thisFT = system_clock::now();
auto FT = duration_cast<microseconds>(thisFT - lastFT);
lastFT = thisFT;
viewer.frame();
}
return 0;
}