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. 解决在macOS下安装了python却没有pip命令的问题【经验总结】

    可以使用brew直接安装python,但是安装完成了之后没有pip命令. pip是常用的python包管理工具,类似于java的maven.第一反应brew install pip,却提示没这货. 可 ...

  2. vue 自定义全局组件

  3. fs模块

    fs.readdir(path, callback) 异步读取目录下文件 path - 文件路径. callback - 回调函数,回调函数带有两个参数err, files,err 为错误信息,fil ...

  4. kombu在redis中的键值名

    参考flower源码 取队列名,发送到求数量的函数中 queue_names = ControlHandler.get_active_queue_names() queues = yield brok ...

  5. 02-Elenment 引入使用

    快速上手 本节将介绍如何在项目中使用 Element. ¶使用 vue-cli@3 我们为新版的 vue-cli 准备了相应的 Element 插件,你可以用它们快速地搭建一个基于 Element 的 ...

  6. 普通页面引入React(使用和不使用JSX)

    1. 不使用JSX 优点: 不用配置有关JSX的编译. 依赖语法: React.createElement(component/type, props, ...chilidren); //第一个参数可 ...

  7. SQL server 中rowcount与@@rowcount 的使用

    rowcount的用法: rowcount的作用就是用来限定后面的sql在返回指定的行数之后便停止处理,比如下面的示例,set rowcount 10select * from 表A 这样的查询只会返 ...

  8. QShareMemory

    Qt提供了一种安全的共享内存的实现QSharedMemory,以便在多线程和多进程编程中安全的使用.比如说QQ的聊天的客户端,这里有个个性头象,当点击QQ音乐播放器的时候,启动QQ音乐播放器(启动一Q ...

  9. Linux存储在线管理(一)FC磁盘设备管理

    由 Jun_Tan 在 2013-1-28 上午12:08 上创建,最后由 Jun_Tan 在 2013-1-28 上午12:13 上修改 版本 1 Linux存储在线管理(一)FC磁盘设备管理 转载 ...

  10. Python中字符串与字节之间相互转换

    Python中字符串与字节之间相互转换 ​ a = b"Hello, world!" # bytes object b = "Hello, world!" # ...