osg osgViewer::View::setUpViewInWindow()
void ViewerBase::frame(double simulationTime)
{
if (_done) return; // OSG_NOTICE<<std::endl<<"CompositeViewer::frame()"<<std::endl<<std::endl; if (_firstFrame)
{
viewerInit(); if (!isRealized())
{
realize();
} _firstFrame = false;
}
advance(simulationTime); eventTraversal();
updateTraversal();
renderingTraversals();
}
当前位置:osgViewer/View.cpp 第 575 行,osgViewer::View::setUpViewInWindow()这个函数有五个传入参数:窗口左上角坐标 x,y,宽度 width,高度 height,以及屏幕数 screenNum。它的作用顾名思义是根据给定的窗口参数来创建一个图形设备。
_displayType:显示器类型,默认为 MONITOR(监视器),此外还支持 POWERWALL(威力墙),REALITY_CENTER(虚拟实境中心)和 HEAD_MOUNTED_DISPLAY(头盔显示器)。
_stereoMode :立体显示模式,默认为 ANAGLYPHIC (互补色),此外还支持QUAD_BUFFER(四方体缓冲),HORIZONTAL_SPLIT(水平分割),VERTICAL_SPLIT(垂直分割),LEFT_EYE(左眼用),RIGHT_EYE(右眼用),HORIZONTAL_INTERLACE(水平交错),VERTICAL_INTERLACE(垂直交错),CHECKERBOARD(棋盘式交错,用于DLP 显示器)。
_eyeSeparation:双眼的物理距离,默认为 0.05。
_screenWidth,_screenHeight:屏幕的实际宽度和高度,分别默认设置为 0.325 和 0.26,目前它们影响的仅仅是视图采用透视投影时的宽高比。
_screenDistance:人眼到屏幕的距离,默认为 0.5。
_splitStereoHorizontalEyeMapping:默认为 LEFT_EYE_LEFT_VIEWPORT(左眼渲染左视口),也可设为 LEFT_EYE_RIGHT_VIEWPORT(左眼渲染右视口)。
_splitStereoHorizontalSeparation:左视口和右视口之间的距离(像素数),默认为 0。
_splitStereoVerticalEyeMapping:默认为 LEFT_EYE_TOP_VIEWPORT(左眼渲染顶视口),也可设为 LEFT_EYE_BOTTOM_VIEWPORT(左眼渲染底视口)。
_splitStereoVerticalSeparation:顶视口和底视口之间的距离(像素数),默认为 0。
_splitStereoAutoAdjustAspectRatio:默认为 true,用于屏幕分割之后对其宽高比进行补偿。
_maxNumOfGraphicsContexts:用户程序中最多可用的 GraphicsContext(图形设备上下文)数目,默认为 32 个。
_numMultiSamples:多重采样的子像素样本数,默认为 0。如果显示卡支持的话,打开多重采样可以大幅改善反走样(anti-aliasing)的效果。
此外还有很多可以设置的类变量,如_minimumNumberStencilBits(模板缓存的最小位数)等,其默认设置均在 osg::DisplaySettings::setDefaults 函数中完成,其中有些变量可能还没有作用。要注意的是,DisplaySettings 的作用仅仅是保存所有可能在系统显示中用到的数据,这个类本身并不会据此改变任何系统设置和渲染方式。
值得称道的是,DisplaySettings 可以很方便地从系统环境变量或者命令行参数中获取用户对显示设备的设置,详细的调用方法可以参阅 DisplaySettings::readEnvironmentalVariables和 DisplaySettings::readCommandLine 两个函数的内容,十分通俗易懂。
如果希望在用户程序中更改 DisplaySettings 中的显示设置,请务必在执行视景器的realize 函数之前,当然也就是仿真循环开始之前。这一点也是要切记的。
void View::setUpViewInWindow(int x, int y, int width, int height, unsigned int screenNum)
{
apply(new osgViewer::SingleWindow(x, y, width, height, screenNum));
}
void View::apply(ViewConfig* config)
{
if (config)
{
OSG_INFO<<"Applying osgViewer::ViewConfig : "<<config->className()<<std::endl;
config->configure(*this);
}
_lastAppliedViewConfig = config;
}
View::View():
_fusionDistanceMode(osgUtil::SceneView::PROPORTIONAL_TO_SCREEN_DISTANCE),
_fusionDistanceValue(1.0f)
{
// OSG_NOTICE<<"Constructing osgViewer::View"<<std::endl; _startTick = ; _frameStamp = new osg::FrameStamp;
_frameStamp->setFrameNumber();
_frameStamp->setReferenceTime();
_frameStamp->setSimulationTime(); _scene = new Scene; // make sure View is safe to reference multi-threaded.
setThreadSafeRefUnref(true); // need to attach a Renderer to the master camera which has been default constructed
getCamera()->setRenderer(createRenderer(getCamera())); setEventQueue(new osgGA::EventQueue); setStats(new osg::Stats("View"));
}
View::View(const osgViewer::View& view, const osg::CopyOp& copyop):
osg::Object(view, copyop),
osg::View(view,copyop),
osgGA::GUIActionAdapter(),
_startTick(),
_fusionDistanceMode(view._fusionDistanceMode),
_fusionDistanceValue(view._fusionDistanceValue)
{
_scene = new Scene; // need to attach a Renderer to the master camera which has been default constructed
getCamera()->setRenderer(createRenderer(getCamera())); setEventQueue(new osgGA::EventQueue); setStats(new osg::Stats("View"));
}
void SingleWindow::configure(osgViewer::View& view) const
{
osg::GraphicsContext::WindowingSystemInterface* wsi = osg::GraphicsContext::getWindowingSystemInterface();
if (!wsi)
{
OSG_NOTICE<<"SingleWindow::configure() : Error, no WindowSystemInterface available, cannot create windows."<<std::endl;
return;
} osg::DisplaySettings* ds = getActiveDisplaySetting(view); osg::ref_ptr<osg::GraphicsContext::Traits> traits = new osg::GraphicsContext::Traits(ds); traits->readDISPLAY();
if (traits->displayNum<) traits->displayNum = ; traits->screenNum = _screenNum;
traits->x = _x;
traits->y = _y;
traits->width = _width;
traits->height = _height;
traits->windowDecoration = _windowDecoration;
traits->overrideRedirect = _overrideRedirect;
traits->doubleBuffer = true;
traits->sharedContext = ; if (traits->width<= || traits->height<= )
{
osg::GraphicsContext::ScreenIdentifier si;
si.readDISPLAY(); // displayNum has not been set so reset it to 0.
if (si.displayNum<) si.displayNum = ; si.screenNum = _screenNum; unsigned int width, height;
wsi->getScreenResolution(si, width, height);
if (traits->width<=) traits->width = width;
if (traits->height<=) traits->height = height;
} osg::ref_ptr<osg::GraphicsContext> gc = osg::GraphicsContext::createGraphicsContext(traits.get()); view.getCamera()->setGraphicsContext(gc.get()); osgViewer::GraphicsWindow* gw = dynamic_cast<osgViewer::GraphicsWindow*>(gc.get());
if (gw)
{
OSG_INFO<<"SingleWindow::configure - GraphicsWindow has been created successfully."<<std::endl;
gw->getEventQueue()->getCurrentEventState()->setWindowRectangle(traits->x, traits->y, traits->width, traits->height );
}
else
{
OSG_NOTICE<<"SingleWindow::configure - GraphicsWindow has not been created successfully."<<std::endl;
return;
} double fovy, aspectRatio, zNear, zFar;
view.getCamera()->getProjectionMatrixAsPerspective(fovy, aspectRatio, zNear, zFar); double newAspectRatio = double(traits->width) / double(traits->height);
double aspectRatioChange = newAspectRatio / aspectRatio;
if (aspectRatioChange != 1.0)
{
view.getCamera()->getProjectionMatrix() *= osg::Matrix::scale(1.0/aspectRatioChange,1.0,1.0);
} view.getCamera()->setViewport(new osg::Viewport(, , traits->width, traits->height)); GLenum buffer = traits->doubleBuffer ? GL_BACK : GL_FRONT; view.getCamera()->setDrawBuffer(buffer);
view.getCamera()->setReadBuffer(buffer); if (ds->getKeystoneHint())
{
if (ds->getKeystoneHint() && !ds->getKeystoneFileNames().empty())
{
osgViewer::Keystone::loadKeystoneFiles(ds);
}
if (ds->getKeystones().empty()) ds->getKeystones().push_back(new Keystone); view.assignStereoOrKeystoneToCamera(view.getCamera(), ds);
}
else if (ds->getStereo() && ds->getUseSceneViewForStereoHint())
{
view.assignStereoOrKeystoneToCamera(view.getCamera(), ds);
}
}
osg osgViewer::View::setUpViewInWindow()的更多相关文章
- 《最长的一帧》 osg3.4 osgViewer::View::init() osgViewer::Viewer::getContexts()
开始:osgViewer/ViewerBase.cpp 389行,startThreading()函数,启动线程 void ViewerBase::startThreading() { if ...
- osgViewer::View::setUpViewOnSingleScreen()
void ViewerBase::frame(double simulationTime) { if (_done) return; // OSG_NOTICE<<std::endl< ...
- 探索未知种族之osg类生物---器官初始化三
当判断到viewer中没有一个graphicContext可用时,osg就会默认的进行一次对viewer的实现操作,这样可以保证osg以后可以安心的在屏幕上进行作画.那我们就来看看这个osgViewe ...
- OSG相机与视图
转自:http://blog.csdn.net/wang15061955806/article/details/51603083 相机与视图 osg::Camera类用来管理OSG中的模型—— ...
- osgViewer
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield * * This library is open source ...
- OSG开发概览
1 OSG基础知识 Ø OSG是Open Scene Graphic 的缩写,OSG于1997年诞生于以为滑翔机爱好者之手,Don burns 为了对滑翔机的飞行进行模拟,对openGL的库进行了封 ...
- OSG多屏显示问题
// testMultiScreen.cpp : Defines the entry point for the console application.// #include "stdaf ...
- OSG世界坐标转屏幕坐标(转载)
OSG世界坐标转屏幕坐标 #define M(row,col) m[col * 4 + row] void Transform_Point(double out[4], const double m[ ...
- OSG开发概览(转载)
OSG开发概览 1 OSG基础知识 Ø OSG是Open Scene Graphic 的缩写,OSG于1997年诞生于以为滑翔机爱好者之手,Don burns 为了对滑翔机的飞行进行模拟,对open ...
随机推荐
- Redis未授权访问漏洞复现及修复方案
首先,第一个复现Redis未授权访问这个漏洞是有原因的,在 2019-07-24 的某一天,我同学的服务器突然特别卡,卡到连不上的那种,通过 top,free,netstat 等命令查看后发现,CPU ...
- shell 文本替换 ---出现--- sed:-e 表达式 #1,字符 8:“s”的未知选项
需要替换的行为: monitor.url=http://192.168.25.100:8443/rest 查询资料得知,报错是因为替换的字符串包含有分隔符/ 所以这行改一下分隔符就可以解决问题了 ( ...
- P1168 中位数[堆 优先队列]
题目描述 给出一个长度为NNN的非负整数序列AiA_iAi,对于所有1≤k≤(N+1)/21 ≤ k ≤ (N + 1) / 21≤k≤(N+1)/2,输出A1,A3,…,A2k−1A_1, A_3 ...
- 本地python环境检查,插件检查及插件安装
电脑windows键+r 输入cmd 在python命令模式下 pip list --可以查看已安装的插件情况 或者用 pip freeze 也可以 卸载插件:pip uninstall *** ...
- Topshelf 使用
前言 在写后台代码的过程中,经常会遇到要写一些单独的服务.以前呢,直接用的是 .NET 下的 “Windows 服务” 控件开发的. 这个传统的控件开发起来很不方面,使用也不友好.发现有用 Topsh ...
- MySQL 中 关于 find_in_set 用法
在项目中用的是 EF.MySQL,在查询中用到某一个字段的值在某几个中.一开始想到的是 in. 但是,这个字段是 int 类型的,传入的参数需要用“,”分隔.这样传入的就是字符型的. 这样的结果是:本 ...
- html学习 菜鸟
1HTML 不是一种编程语言,而是一种标记语言 2只有 <body>区域才会在浏览器中显示. 3<!DOCTYPE>声明有助于浏览器中正确显示网页.doctype 声明是不区分 ...
- 带有EXE参数的启动
(一).先制作一个带启动参数的EXE文件. 步骤: 1.定义全局私有变量:private string[] s = new string[1]; //这里为了简单起见,只做一个 ...
- BUG----spark
我也想说很尴尬, 搞到显现 发现 原来是个版本的bug spark 1.6.0 有个BUG 希望更多人看到 Traceback (most recent call last): File &quo ...
- Educational Codeforces Round 76 (Rated for Div. 2) D题
题意: 给你n个关卡,每个关卡有一个怪物,怪物的攻击力为a[i],你有n个英雄,每个英雄有一个攻击力,和疲劳值,只要英雄的攻击力比怪物的高就算打过了,同时疲劳减一,一天只能出战一个英雄,一个英雄可以打 ...