Discussion:
[Opensg-users] How to use StereoBufferViewport
Jörn Teuber
2014-11-25 14:48:18 UTC
Permalink
Hello everybody,

I have a seemingly simple problem with OpenSG 1.8 (yes, I have to use
that version...) which I don't know how to solve:
I want to use a zSpace Monitor to render in 3D, so I need quad buffered
stereo. No problem I thought, just use the StereoBufferedViewport with a
Camera with two ShearedStereoCameraDecorator. But it does give me any
3D. I still only get a 2D version of my scene even though the monitor is
clearly in 3D mode. I can even disable one of the buffers of the
Viewport to get a nice flickering window. What did I miss here?

Now a snippet of the relevant code I use (the original got some calls to
the zSpace API, but I don't think they matter here):

initialisation:
[...]

m_pCamera = osg::PerspectiveCamera::create();
osg::beginEditCP(m_pCamera);
m_pCamera->setBeacon(m_pCamBeacon);
m_pCamera->setFov(osg::deg2rad(60));
m_pCamera->setNear(0.1);
m_pCamera->setFar(100);
osg::endEditCP(m_pCamera);

osg::ShearedStereoCameraDecoratorPtr cameraDecoratorLeft,
cameraDecoratorRight;

cameraDecoratorLeft = osg::ShearedStereoCameraDecorator::create();
osg::beginEditCP(cameraDecoratorLeft);
cameraDecoratorLeft->setLeftEye(true);
cameraDecoratorLeft->setEyeSeparation( fEyeSeperation );
cameraDecoratorLeft->setDecoratee(m_pCamera);
cameraDecoratorLeft->setZeroParallaxDistance(
fZeroParallaxDist );
osg::endEditCP(cameraDecoratorLeft);

cameraDecoratorRight = osg::ShearedStereoCameraDecorator::create();
osg::beginEditCP(cameraDecoratorRight);
cameraDecoratorRight->setLeftEye(false);
cameraDecoratorRight->setEyeSeparation( fEyeSeperation );
cameraDecoratorRight->setDecoratee(m_pCamera);
cameraDecoratorRight->setZeroParallaxDistance(
fZeroParallaxDist );
osg::endEditCP(cameraDecoratorRight);

m_pViewport = osg::StereoBufferViewport::create();

osg::beginEditCP(m_pViewport);
m_pViewportLeft->setCamera( m_pCamera );
m_pViewportLeft->setBackground( background );
m_pViewportLeft->setRoot(pRoot);
m_pViewportLeft->setSize(0,0,1,1);
osg::endEditCP(m_pViewport);

m_pWindow = osg::GLUTWindow::create();
osg::beginEditCP(m_pWindow);
m_pWindow->setId(winid);
m_pWindow->addPort(m_pViewport);
m_pWindow->setSize( m_iWindowWidth, m_iWindowHeight);
m_pWindow->init();
osg::endEditCP(m_pWindow);


rendering: a simple
void render( osg::RenderAction* pRenderAction )
{
m_pWindow->render( pRenderAction );
}

Thank you so much for any help with this!
Best regards
Jörn Teuber
Gerrit Voß
2014-11-25 17:44:11 UTC
Permalink
Hi,

you have to replicate what you did for the camera decorators for the
viewports as well. So you need StereoBufferViewports, one for the left
eye with

svpleft->setLeftBuffer(true);
svpleft->setRightBuffer(false);
svpleft->setCamera(cameraDecoratorLeft);

and one for the right eye, with

svpright->setLeftBuffer(false);
svpright->setRightBuffer(true);
svpleft->setCamera(cameraDecoratorRight);

than add both viewports to the Window.

Source/System/Window/testStereoDecor.cpp has some examples for
reference.


kind regards
gerrit
Post by Jörn Teuber
Hello everybody,
I have a seemingly simple problem with OpenSG 1.8 (yes, I have to use
I want to use a zSpace Monitor to render in 3D, so I need quad buffered
stereo. No problem I thought, just use the StereoBufferedViewport with a
Camera with two ShearedStereoCameraDecorator. But it does give me any
3D. I still only get a 2D version of my scene even though the monitor is
clearly in 3D mode. I can even disable one of the buffers of the
Viewport to get a nice flickering window. What did I miss here?
Now a snippet of the relevant code I use (the original got some calls to
[...]
m_pCamera = osg::PerspectiveCamera::create();
osg::beginEditCP(m_pCamera);
m_pCamera->setBeacon(m_pCamBeacon);
m_pCamera->setFov(osg::deg2rad(60));
m_pCamera->setNear(0.1);
m_pCamera->setFar(100);
osg::endEditCP(m_pCamera);
osg::ShearedStereoCameraDecoratorPtr cameraDecoratorLeft,
cameraDecoratorRight;
cameraDecoratorLeft = osg::ShearedStereoCameraDecorator::create();
osg::beginEditCP(cameraDecoratorLeft);
cameraDecoratorLeft->setLeftEye(true);
cameraDecoratorLeft->setEyeSeparation( fEyeSeperation );
cameraDecoratorLeft->setDecoratee(m_pCamera);
cameraDecoratorLeft->setZeroParallaxDistance(
fZeroParallaxDist );
osg::endEditCP(cameraDecoratorLeft);
cameraDecoratorRight = osg::ShearedStereoCameraDecorator::create();
osg::beginEditCP(cameraDecoratorRight);
cameraDecoratorRight->setLeftEye(false);
cameraDecoratorRight->setEyeSeparation( fEyeSeperation );
cameraDecoratorRight->setDecoratee(m_pCamera);
cameraDecoratorRight->setZeroParallaxDistance(
fZeroParallaxDist );
osg::endEditCP(cameraDecoratorRight);
m_pViewport = osg::StereoBufferViewport::create();
osg::beginEditCP(m_pViewport);
m_pViewportLeft->setCamera( m_pCamera );
m_pViewportLeft->setBackground( background );
m_pViewportLeft->setRoot(pRoot);
m_pViewportLeft->setSize(0,0,1,1);
osg::endEditCP(m_pViewport);
m_pWindow = osg::GLUTWindow::create();
osg::beginEditCP(m_pWindow);
m_pWindow->setId(winid);
m_pWindow->addPort(m_pViewport);
m_pWindow->setSize( m_iWindowWidth, m_iWindowHeight);
m_pWindow->init();
osg::endEditCP(m_pWindow);
rendering: a simple
void render( osg::RenderAction* pRenderAction )
{
m_pWindow->render( pRenderAction );
}
Thank you so much for any help with this!
Best regards
Jörn Teuber
------------------------------------------------------------------------------
Download BIRT iHub F-Type - The Free Enterprise-Grade BIRT Server
from Actuate! Instantly Supercharge Your Business Reports and Dashboards
with Interactivity, Sharing, Native Excel Exports, App Integration & more
Get technology previously reserved for billion-dollar corporations, FREE
http://pubads.g.doubleclick.net/gampad/clk?id=157005751&iu=/4140/ostg.clktrk
_______________________________________________
Opensg-users mailing list
https://lists.sourceforge.net/lists/listinfo/opensg-users
--
Gerrit Voß
盖瑞客
---------------------------------------------------
Fraunhofer IDM @ NTU
南洋理工大学, Nanyang Technological University, (NTU)
新加坡, Singapore
--------------------------------------------------

If we communicate everything we ever think, speech
just becomes static. And all of us become bores.

J. Clarkson
Jörn Teuber
2014-11-26 09:49:04 UTC
Permalink
Thank you so much, that worked!

best regards,
Jörn
Post by Gerrit Voß
Hi,
you have to replicate what you did for the camera decorators for the
viewports as well. So you need StereoBufferViewports, one for the left
eye with
svpleft->setLeftBuffer(true);
svpleft->setRightBuffer(false);
svpleft->setCamera(cameraDecoratorLeft);
and one for the right eye, with
svpright->setLeftBuffer(false);
svpright->setRightBuffer(true);
svpleft->setCamera(cameraDecoratorRight);
than add both viewports to the Window.
Source/System/Window/testStereoDecor.cpp has some examples for
reference.
kind regards
gerrit
Post by Jörn Teuber
Hello everybody,
I have a seemingly simple problem with OpenSG 1.8 (yes, I have to use
I want to use a zSpace Monitor to render in 3D, so I need quad buffered
stereo. No problem I thought, just use the StereoBufferedViewport with a
Camera with two ShearedStereoCameraDecorator. But it does give me any
3D. I still only get a 2D version of my scene even though the monitor is
clearly in 3D mode. I can even disable one of the buffers of the
Viewport to get a nice flickering window. What did I miss here?
Now a snippet of the relevant code I use (the original got some calls to
[...]
m_pCamera = osg::PerspectiveCamera::create();
osg::beginEditCP(m_pCamera);
m_pCamera->setBeacon(m_pCamBeacon);
m_pCamera->setFov(osg::deg2rad(60));
m_pCamera->setNear(0.1);
m_pCamera->setFar(100);
osg::endEditCP(m_pCamera);
osg::ShearedStereoCameraDecoratorPtr cameraDecoratorLeft,
cameraDecoratorRight;
cameraDecoratorLeft = osg::ShearedStereoCameraDecorator::create();
osg::beginEditCP(cameraDecoratorLeft);
cameraDecoratorLeft->setLeftEye(true);
cameraDecoratorLeft->setEyeSeparation( fEyeSeperation );
cameraDecoratorLeft->setDecoratee(m_pCamera);
cameraDecoratorLeft->setZeroParallaxDistance(
fZeroParallaxDist );
osg::endEditCP(cameraDecoratorLeft);
cameraDecoratorRight = osg::ShearedStereoCameraDecorator::create();
osg::beginEditCP(cameraDecoratorRight);
cameraDecoratorRight->setLeftEye(false);
cameraDecoratorRight->setEyeSeparation( fEyeSeperation );
cameraDecoratorRight->setDecoratee(m_pCamera);
cameraDecoratorRight->setZeroParallaxDistance(
fZeroParallaxDist );
osg::endEditCP(cameraDecoratorRight);
m_pViewport = osg::StereoBufferViewport::create();
osg::beginEditCP(m_pViewport);
m_pViewportLeft->setCamera( m_pCamera );
m_pViewportLeft->setBackground( background );
m_pViewportLeft->setRoot(pRoot);
m_pViewportLeft->setSize(0,0,1,1);
osg::endEditCP(m_pViewport);
m_pWindow = osg::GLUTWindow::create();
osg::beginEditCP(m_pWindow);
m_pWindow->setId(winid);
m_pWindow->addPort(m_pViewport);
m_pWindow->setSize( m_iWindowWidth, m_iWindowHeight);
m_pWindow->init();
osg::endEditCP(m_pWindow);
rendering: a simple
void render( osg::RenderAction* pRenderAction )
{
m_pWindow->render( pRenderAction );
}
Thank you so much for any help with this!
Best regards
Jörn Teuber
------------------------------------------------------------------------------
Download BIRT iHub F-Type - The Free Enterprise-Grade BIRT Server
from Actuate! Instantly Supercharge Your Business Reports and Dashboards
with Interactivity, Sharing, Native Excel Exports, App Integration & more
Get technology previously reserved for billion-dollar corporations, FREE
http://pubads.g.doubleclick.net/gampad/clk?id=157005751&iu=/4140/ostg.clktrk
_______________________________________________
Opensg-users mailing list
https://lists.sourceforge.net/lists/listinfo/opensg-users
Loading...