[osg-users] Dual screen support on Linux using TwinView

155 views
Skip to first unread message

Michael

unread,
Nov 17, 2008, 10:06:27 PM11/17/08
to osg-...@lists.openscenegraph.org
Hi

I am developing a program using OpenSceneGraph as the renderer. This program needs support for dual screens; I am using composite viewer to setup different views into the scenegraph, with each view appearing on a separate screen (the outputs will be driving projectors).

My X configuration is setup using TwinView; so as far as X is concerned there is only one screen. Can OpenSceneGraph do what I need to do with this configuration (ie get screen info from xinerama) or do I need to configure X so that each monitor is on a different Xscreen? I'd rather not reconfigure X if possible.

Cheers
Michael Marner

Robert Osfield

unread,
Nov 18, 2008, 4:07:46 AM11/18/08
to OpenSceneGraph Users
Hi Michael,

The OSG does support two displays attached to a single graphics card,
and will work either with X set up with a separate X screen per
physical display or a single screen spanning both displays. For best
performance it's best to set up a single X screen across both displays
as this will just require the OSG to open up a single graphics
context, which is a far more efficient use of the GPU than opening up
two graphics contexts that content for time and space on the GPU.

Depending upon how you set up the window manager you may find that you
windows are resized automatically to just come up on a single display,
if this happens it's because the window manager is overriding the
window sizes that you ask for when create your graphics context and
the way to solve it is to set the
GaphicsContext::Traits::overrideRedirect to true when creating your
graphics contexts.

Robert.

> _______________________________________________
> osg-users mailing list
> osg-...@lists.openscenegraph.org
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
>
>
_______________________________________________
osg-users mailing list
osg-...@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Michael

unread,
Nov 19, 2008, 7:09:19 PM11/19/08
to OpenSceneGraph Users
Hey Robert

Thanks for the reply. So I've been doing some testing and I'm not sure exactly how I set this up. Here is some more info on my setup:

xorg.conf:

Section "Device"
    Identifier     "Device0"
    Driver         "nvidia"
    VendorName     "NVIDIA Corporation"
    BoardName      "GeForce 8600 GT"
    Option         "TwinView" "1"
    Option         "NoLogo" "true"
    Option         "TwinViewXineramaInfoOrder" "DFP, CRT"
    Option         "TwinViewOrientation" "DFP LeftOf CRT"
    Option         "metamodes" "DFP: 1024x768 +0+0, CRT: 1024x768 +1920+0"
EndSection


So, I have two monitors setup using TwinView. Therefore there is a single X screen with a resolution of 2048x768.

Now, what I would like is essentially 2 full screen windows, one on each monitor. How do I do this with OpenSceneGraph? Below is the basic code I am trying:

// our composite viewer
ref_ptr<osgViewer::CompositeViewer> viewer = new osgViewer::CompositeViewer;
ref_ptr<osg::GraphicsContext::Traits> traits = new osg::GraphicsContext::Traits;

// scenegraph root
ref_ptr<Node> node = new Node();

// do this twice, once for each screen
for (int i=0;i<2;i++)
{
    // the first view will be on screen 0, the second on screen 1
    traits->screenNum = i;
    traits->x = 0;
    traits->y = 0;
    traits->width = 1024;
    traits->height = 768;
    traits->windowDecoration = false;
    traits->doubleBuffer = true;
    traits->overrideRedirect = true;

    // create the graphics context
    osg::ref_ptr<osg::GraphicsContext> gc = osg::GraphicsContext::createGraphicsContext(traits.get());

    // add the view to our composite viewer
    osgViewer::View* v = new osgViewer::View;
    v->setSceneData(node);
    v->getCamera()->setGraphicsContext(gc.get());

    viewer->addView(v);
}

This fails on the second display because OSG can't connect to screen 0:1, because there is only 1 xscreen. Clearly I am doing this wrong, but I'm not sure of the correct way. Something like this?

1. Create a single GraphicsContext on screen 0, with width=2048 (both displays)
2. Create my views, and somehow tell each one to only render on half of the context?

Any help with this would be greatly appreciated.

Cheers
Michael

Benoit Gagnon

unread,
Nov 19, 2008, 8:21:40 PM11/19/08
to OpenSceneGraph Users
I believe you simply have to offset the X and Y locations of your graphic contexts and leave the screen identifier to 0. The width and height should be 1024x768 for both contextes.

Robert Osfield

unread,
Nov 20, 2008, 4:08:10 AM11/20/08
to OpenSceneGraph Users
Hi Michael,

On Thu, Nov 20, 2008 at 12:09 AM, Michael <michael.t...@gmail.com> wrote:
> This fails on the second display because OSG can't connect to screen 0:1,
> because there is only 1 xscreen. Clearly I am doing this wrong, but I'm not
> sure of the correct way.

If you have only only X screen then you'll only be able to open up a
window on that one... so you'll need to use the screenNum set to 0 fro
both contexts, or....

> Something like this?
> 1. Create a single GraphicsContext on screen 0, with width=2048 (both
> displays)
> 2. Create my views, and somehow tell each one to only render on half of the
> context?

If you a grabbing the whole of both displays I would create a single
graphics context that goes across both physical displays. Otherwise
you'll need to create two graphics contexts on the same X11 screenNum
but with the second window starting at a xpos of 1024.

Now what to do about the views depends upon you actual needs. Do you
have two separate logical views of doing you have single view that is
just made up of two cameras (like looking out of two adjacent
real-world windows that share the same view). If you have only single
view, then do the two halves of it but up against each other or do
they overlap?

Could you have a bash at explain what you are specifically trying to
achieve as the advice to give is different for all the different
cases.

Robert.

Michael

unread,
Nov 20, 2008, 6:52:37 PM11/20/08
to OpenSceneGraph Users
Hey Robert

We have 2 separate logical views (I guess). Essentially we have 2 projectors that can each be placed at any location and orientation in the room and they project onto objects in the room. This is not a tiled display, and we are not worried about overlap. We are also doing some render to texture operations which is why we have different views. Each monitor output is driving a single projector. So, we have 2 projectors and a couple of RTT cameras.

The projectors have their own projection and view matrices, but share the same scene graph data for drawing. One of the projectors does shadow removal for the other one, so we need to control the render order. So, we need each monitor output to drive one of our views for the projector, using the 1 graphics context.

I appreciate the help (and patience!)

Cheers
Michael

Robert Osfield

unread,
Nov 21, 2008, 4:40:56 AM11/21/08
to OpenSceneGraph Users
HI Michael,

Does you two "views" move together, i.e. they look different
directions but as the viewpoint moves around both projector outputs
should update relative to this? If this is the case they you have one
View but with two slave Cameras each with a project and view offset
from the View's master Camera.

If two projector outputs are wholly independent w.r.t viewpoint, and
require same camera controls such as seprate CameraManipulator then
you do have a case which is logically two different views.

Robert.

Michael

unread,
Nov 25, 2008, 7:57:43 PM11/25/08
to OpenSceneGraph Users
Hi Robert

Thanks for the clarrification. After reading through the OpenSceneGraph API docs we definitely require two views. So to summarise

2 monitors (projectors)
1 View on each monitor
1 XScreen, and therefore 1 context (if possible).

Sorry for not giving all this information up front but I have only written about 1/3 of the codebase, so I have to go fishing through the code. I appreciate the help!

Thanks
Michael

Robert Osfield

unread,
Nov 26, 2008, 4:28:35 AM11/26/08
to OpenSceneGraph Users
Hi Michael,

On Wed, Nov 26, 2008 at 12:57 AM, Michael <michael.t...@gmail.com> wrote:
> Thanks for the clarrification. After reading through the OpenSceneGraph API
> docs we definitely require two views. So to summarise
>
> 2 monitors (projectors)
> 1 View on each monitor
> 1 XScreen, and therefore 1 context (if possible).

Yep this would be a sensible set up. With setting up the single
context you may need to set the Traits::overrideRedirect to true to
prevent the window manage resizing the window to just once physical
screen. Then create the graphics context, then when you set the each
View's master Camera you just assign the same created graphics context
so that both Cameras share things single window.

The osgcompositeview has code that shares a single context between
multiple views so have a look at it.

Michael

unread,
Nov 30, 2008, 2:16:40 AM11/30/08
to OpenSceneGraph Users
Hi Robert

Thanks a lot for your help. This will do exactly what I need.

Cheers
Michael
Reply all
Reply to author
Forward
0 new messages