上一章节:
本章节代码:
一、操作系接 口渲染流程
下面是一个osg,创建窗口是示例代码:
cpp
/**
运用OSG 创建窗口
**/
#include <windows.h>
#include <iostream>
#include <osgViewer/Viewer>
#include <osgViewer/api/Win32/GraphicsWindowWin32>
#include <osg/GraphicsContext>
int main()
{
// osgViewer::Viewer, 必须定义,前期准备均在其构造中完成
osgViewer::Viewer vierer;
// 窗口信息类
osg::ref_ptr<osg::GraphicsContext::Traits> traits = new osg::GraphicsContext::Traits;
traits->x = 100;
traits->y = 100;
traits->width = 800;
traits->height = 800;
traits->windowDecoration = true;
traits->doubleBuffer = true;
traits->sharedContext = 0;
osgViewer::GraphicsWindowWin32* gw = dynamic_cast<osgViewer::GraphicsWindowWin32*>(osg::GraphicsContext::createGraphicsContext(traits.get()));
if (gw != nullptr)
{
gw->realizeImplementation(); // 创建窗口
int a;
std::cin >> a;
}
else {
std::cout << "gw is null" << std::endl;
}
return 0;
}
运行结果:
