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);
}
}
文字参考:王锐老师《最长的一帧》
代码参考:OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield    (osg3.4)

osg osgViewer::View::setUpViewInWindow()的更多相关文章

  1. 《最长的一帧》 osg3.4 osgViewer::View::init() osgViewer::Viewer::getContexts()

    开始:osgViewer/ViewerBase.cpp   389行,startThreading()函数,启动线程   void ViewerBase::startThreading() { if ...

  2. osgViewer::View::setUpViewOnSingleScreen()

    void ViewerBase::frame(double simulationTime) { if (_done) return; // OSG_NOTICE<<std::endl< ...

  3. 探索未知种族之osg类生物---器官初始化三

    当判断到viewer中没有一个graphicContext可用时,osg就会默认的进行一次对viewer的实现操作,这样可以保证osg以后可以安心的在屏幕上进行作画.那我们就来看看这个osgViewe ...

  4. OSG相机与视图

    转自:http://blog.csdn.net/wang15061955806/article/details/51603083 相机与视图     osg::Camera类用来管理OSG中的模型—— ...

  5. osgViewer

    /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield * * This library is open source ...

  6. OSG开发概览

    1 OSG基础知识 Ø OSG是Open Scene Graphic 的缩写,OSG于1997年诞生于以为滑翔机爱好者之手,Don burns  为了对滑翔机的飞行进行模拟,对openGL的库进行了封 ...

  7. OSG多屏显示问题

    // testMultiScreen.cpp : Defines the entry point for the console application.// #include "stdaf ...

  8. OSG世界坐标转屏幕坐标(转载)

    OSG世界坐标转屏幕坐标 #define M(row,col) m[col * 4 + row] void Transform_Point(double out[4], const double m[ ...

  9. OSG开发概览(转载)

    OSG开发概览 1 OSG基础知识 Ø OSG是Open Scene Graphic 的缩写,OSG于1997年诞生于以为滑翔机爱好者之手,Don burns  为了对滑翔机的飞行进行模拟,对open ...

随机推荐

  1. Jenkins配置文件

    https://github.com/zeyangli/Jenkins-docs 在Linux上的Jenkins 以rpm方式部署的配置文件在/etc/sysconfig/jenkins,可以定义Je ...

  2. 手写butterknife来剖析其原理

    基本使用: 对于butterknife库我想基本上都非常熟了,如今在项目中用它也用得非常之频繁了,不过为了学习的完整性,先来简单的回顾一下基本用法,先新建一个工程: 然后给textview增加一个点击 ...

  3. 【基础搜索】poj-2676-Sudoku(数独)--求补全九宫格的一种合理方案

      数独 时限:2000 MS   内存限制:65536K 提交材料共计: 22682   接受: 10675   特别法官 描述 数独是一个非常简单的任务.一个9行9列的正方形表被分成9个较小的3x ...

  4. ArcGIS + Python 批量裁剪、添加X/Y坐标脚本

    前言 前一段时间,同事拿来的数据范围太大,用不了那么多(只需要一个乡镇的,结果拿来区县的),太多了加载也是问题.所以就让我给处理下. 由于文件较多,手动裁剪的话,我一个一个用ArcGIS工具箱中的工具 ...

  5. SQL SERVER表压缩

    概述 SQL Server的主要性能取决于磁盘I/O效率,SQL Server .2008提供了数据压缩功能来提高磁盘I/O效率.表压缩意味着减小数据的磁盘占有量,所以压缩可以用在堆表.聚集索引的表. ...

  6. python - redis 的使用

    1.redis连接 redis提供两个类Redis和StrictRedis用于实现Redis的命令,StrictRedis用于实现大部分官方的命令,并使用官方的语法和命令,Redis是StrictRe ...

  7. Luogu 4751 动态DP 模板

    题面 动态求最大独立集 题解 树剖后用矩阵转移. 具体见Tweetuzki的洛谷博客 CODE #include <bits/stdc++.h> using namespace std; ...

  8. 入门指引之查看accesstoken

    1. 测试工具查看 https://mp.weixin.qq.com/debug/ 2. 代码获取: # -*- coding: utf-8 -*- # filename: basic.py impo ...

  9. 14 | count(*)这么慢,我该怎么办?

    在开发系统的时候,你可能经常需要计算一个表的行数,比如一个交易系统的所有变更记录总数.这时候你可能会想,一条select count(*) from t 语句不就解决了吗? 但是,你会发现随着系统中记 ...

  10. [Luogu] 封锁阳光大学

    https://www.luogu.org/problemnew/show/P1330 #include <cstdio> #include <cstring> #includ ...