/* OpenSceneGraph example, osgwindows.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/ #include <osgDB/ReadFile>
#include <osgUtil/Optimizer>
#include <osgViewer/Viewer> #include <iostream> int main( int argc, char **argv )
{
// use an ArgumentParser object to manage the program arguments.
osg::ArgumentParser arguments(&argc,argv); // read the scene from the list of file specified commandline args.
osg::ref_ptr<osg::Node> loadedModel = osgDB::readRefNodeFiles(arguments); // if not loaded assume no arguments passed in, try use default mode instead.
if (!loadedModel) loadedModel = osgDB::readRefNodeFile("/home/ding/Downloads/OpenSceneGraph-Data/cow.osgt");
  //this path was modified because the OSG_FILE_PATH is not configed correctly in my computer!
  //so it is an alternative method // if no model has been successfully loaded report failure.
if (!loadedModel)
{
std::cout << arguments.getApplicationName() <<": No data loaded" << std::endl;
return ;
} // construct the viewer.
osgViewer::Viewer viewer; int xoffset = ;
int yoffset = ; // left window + left slave camera
{
osg::ref_ptr<osg::GraphicsContext::Traits> traits = new osg::GraphicsContext::Traits; traits->x = xoffset + ;
traits->y = yoffset + ;
traits->width = ;
traits->height = ;
traits->windowDecoration = true;
traits->doubleBuffer = true;
traits->sharedContext = ;
traits->readDISPLAY();
traits->setUndefinedScreenDetailsToDefaultScreen(); osg::ref_ptr<osg::GraphicsContext> gc = osg::GraphicsContext::createGraphicsContext(traits.get()); osg::ref_ptr<osg::Camera> camera = new osg::Camera;
camera->setGraphicsContext(gc.get());
camera->setViewport(new osg::Viewport(,, traits->width, traits->height));
GLenum buffer = traits->doubleBuffer ? GL_BACK : GL_FRONT;
camera->setDrawBuffer(buffer);
camera->setReadBuffer(buffer); // add this slave camera to the viewer, with a shift left of the projection matrix
viewer.addSlave(camera.get(), osg::Matrixd::translate(1.0,-1.0,0.0), osg::Matrixd());
} // right window + right slave camera
{
osg::ref_ptr<osg::GraphicsContext::Traits> traits = new osg::GraphicsContext::Traits;
traits->x = xoffset + ;
traits->y = yoffset + ;
traits->width = ;
traits->height = ;
traits->windowDecoration = true;
traits->doubleBuffer = true;
traits->sharedContext = ;
traits->readDISPLAY();
traits->setUndefinedScreenDetailsToDefaultScreen(); osg::ref_ptr<osg::GraphicsContext> gc = osg::GraphicsContext::createGraphicsContext(traits.get()); osg::ref_ptr<osg::Camera> camera = new osg::Camera;
camera->setGraphicsContext(gc.get());
camera->setViewport(new osg::Viewport(,, traits->width, traits->height));
GLenum buffer = traits->doubleBuffer ? GL_BACK : GL_FRONT;
camera->setDrawBuffer(buffer);
camera->setReadBuffer(buffer); // add this slave camera to the viewer, with a shift right of the projection matrix
viewer.addSlave(camera.get(), osg::Matrixd::translate(-1.0,-1.0,0.0), osg::Matrixd());
} // left_down window + right slave camera
{
osg::ref_ptr<osg::GraphicsContext::Traits> traits = new osg::GraphicsContext::Traits;
traits->x = xoffset + ;
traits->y = yoffset + ;
traits->width = ;
traits->height = ;
traits->windowDecoration = true;
traits->doubleBuffer = true;
traits->sharedContext = ;
traits->readDISPLAY();
traits->setUndefinedScreenDetailsToDefaultScreen(); osg::ref_ptr<osg::GraphicsContext> gc = osg::GraphicsContext::createGraphicsContext(traits.get()); osg::ref_ptr<osg::Camera> camera = new osg::Camera;
camera->setGraphicsContext(gc.get());
camera->setViewport(new osg::Viewport(,, traits->width, traits->height));
GLenum buffer = traits->doubleBuffer ? GL_BACK : GL_FRONT;
camera->setDrawBuffer(buffer);
camera->setReadBuffer(buffer); // add this slave camera to the viewer, with a shift right of the projection matrix
viewer.addSlave(camera.get(), osg::Matrixd::translate(1.0,1.0,0.0), osg::Matrixd());
} // right_down window + right slave camera
{
osg::ref_ptr<osg::GraphicsContext::Traits> traits = new osg::GraphicsContext::Traits;
traits->x = xoffset + ;
traits->y = yoffset + ;
traits->width = ;
traits->height = ;
traits->windowDecoration = true;
traits->doubleBuffer = true;
traits->sharedContext = ;
traits->readDISPLAY();
traits->setUndefinedScreenDetailsToDefaultScreen(); osg::ref_ptr<osg::GraphicsContext> gc = osg::GraphicsContext::createGraphicsContext(traits.get()); osg::ref_ptr<osg::Camera> camera = new osg::Camera;
camera->setGraphicsContext(gc.get());
camera->setViewport(new osg::Viewport(,, traits->width, traits->height));
GLenum buffer = traits->doubleBuffer ? GL_BACK : GL_FRONT;
camera->setDrawBuffer(buffer);
camera->setReadBuffer(buffer); // add this slave camera to the viewer, with a shift right of the projection matrix
viewer.addSlave(camera.get(), osg::Matrixd::translate(-1.0,1.0,0.0), osg::Matrixd());
}
// optimize the scene graph, remove redundant nodes and state etc.
osgUtil::Optimizer optimizer;
optimizer.optimize(loadedModel); // set the scene to render
viewer.setSceneData(loadedModel); return viewer.run();
}

The routine of each slave camera is alike. While the key point is this sentence:

viewer.addSlave(camera.get(), osg::Matrixd::translate(-1.0,1.0,0.0), osg::Matrixd());

This sentence set the viewpoint of slave camera,which translate the position of view point. Four slave camera view the common model in different direction, combine together.

the command to complie this program is following:

g++ -o osgwindows_1 osgwindows_1.cpp -losg -losgDB -losgViewer -lOpenThreads -losgUtil

After compling, just run it with:

sudo ./osgwindows_1

The outcome of above program is shown:

Like moniter constructed with four screen. Drag mouse in one window, the model will rotate in other three screen meanwhile. Great!

Learning OSG programing---osgwindows的更多相关文章

  1. Learning OSG programing---osgScribe

    Learning OSG programing---osgScribe Scribe可以翻译为素描,抄写等.本例通过在模型表面添加一层素描,来显示模型的骨架. 关键代码: osg::ref_ptr&l ...

  2. Learning OSG programing---Multi Camera in Multi window 在多窗口中创建多相机

    这个例子演示了在多个窗口中创建多个相机,函数的代码如下: void multiWindowMultipleCameras(osgViewer::Viewer& viewer,bool mult ...

  3. Learning OSG programing---Multi Camera in one window 在单窗口中创建多相机

    在学习OSG提供的例子osgCamera中,由于例子很长,涉及很多细节,考虑将其分解为几个小例子.本文介绍实现在一个窗口中添加多个相机的功能. 此函数接受一个Viewer引用类型参数,设置图形上下文的 ...

  4. Learning OSG programing---osgAnimation(3)

    接下来是用createModel函数创建模型: osg::ref_ptr<osg::Group> createModel(bool overlay, osgSim::OverlayNode ...

  5. Learning OSG programing---osgAnimation(2)

    osg::Node* createBase(const osg::Vec3& center,float radius) { ; ; *radius; *radius; osg::Vec3 v0 ...

  6. Learning OSG programing---osgAnimation(1)

    osg::AnimationPath* createAnimationPath(const osg::Vec3& center,float radius,double looptime) { ...

  7. Learning OSG programing---osgShape

    本例示范了osg中Shape ---- 基本几何元素的绘制过程.参照osg官方文档,Shape 类包含以下子类: 在示例程序中,函数createShapes函数用于生成需要绘制的几何形状. osg:: ...

  8. Learning OSG programing---osgClip

    OSG Clip例程剖析 首先是创建剪切节点的函数代码: osg::ref_ptr<osg::Node> decorate_with_clip_node(const osg::ref_pt ...

  9. Coursera Deep Learning 2 Improving Deep Neural Networks: Hyperparameter tuning, Regularization and Optimization - week3, Hyperparameter tuning, Batch Normalization and Programming Frameworks

    Tuning process 下图中的需要tune的parameter的先后顺序, 红色>黄色>紫色,其他基本不会tune. 先讲到怎么选hyperparameter, 需要随机选取(sa ...

随机推荐

  1. java中位运算和移位运算详解

    一.位运算 (1)按 位 与 & 如果两个相应的二进制形式的对应的位数都为1,则结果为1,记为同1为1,否则为0.首先我们看一下对正数的运算        分别看一下正数和负数的具体运算步骤 ...

  2. jenkinsapi和python打包工具的安装日志

    Successfully installed PyInstaller-3.3.1 altgraph-0.15 dis3-0.1.2 future-0.16.0 macholib-1.9 pefile- ...

  3. JavaScript常用字符串方法和属性

    一直以来  在喜马拉雅上听  陪你读书(JavaScript WEB前端)  主播沙翼 讲的很好  果断买了这本书  现在做个笔记 var str = ‘abcd’ str.charAt(0); // ...

  4. jsp常用代码

    1.头部 <%@ page language="java" import="java.util.*" pageEncoding="UTF-8&q ...

  5. 20180315-Python面向对象编程设计和开发

    1.在子类中调用父类的方法 在子类派生出的新方法中,往往需要重用父类的方法,我们有两种实现方式: 方式一:父类名.父类方法() Animal.__init__(self,name) 方式二:super ...

  6. 2018-8-10-win10-uwp-MetroLog-入门

    title author date CreateTime categories win10 uwp MetroLog 入门 lindexi 2018-08-10 19:16:53 +0800 2018 ...

  7. 02.LNMP架构-MySQL源码包编译部署详细步骤

    操作系统:CentOS_Server_7.5_x64_1804.iso 部署组件:Cmake+Boost+MySQL 操作步骤: 一.安装依赖组件 [root@localhost ~]# yum -y ...

  8. JAVA- 内部类及匿名内部类

    普通类,我们平时见到的那种类,就是一个后缀为.java的文件中,直接定义的类,比如 public Cat{ private String name; private int age; } 内部类, 内 ...

  9. python数字图像处理(五) 图像的退化和复原

    import cv2 import numpy as np import matplotlib.pyplot as plt import scipy import scipy.stats %matpl ...

  10. IText PDF简单示例

    package com.exe.learn.demo.itextpdf; import java.io.ByteArrayInputStream; import java.io.File; impor ...