[osg-users] Completely offscreen rendering using FBO?
Jad Killian
m.hasani at outlook.com
Mon Jan 28 02:07:04 PST 2019
Hi,
I would like to not have a window at all when rendering. I managed to get offscreen rendering to work fine with a pixel buffer like in the osgscreencapture example. Viewer setup code:
Code:
osgViewer::Viewer viewer;
unsigned int width = 1;
unsigned int height = 1;
bool pbufferOnly = false;
osg::ref_ptr<osg::GraphicsContext> pbuffer;
{
osg::ref_ptr<osg::GraphicsContext::Traits> traits = new osg::GraphicsContext::Traits;
traits->x = 0;
traits->y = 0;
traits->width = width;
traits->height = height;
traits->red = 8;
traits->green = 8;
traits->blue = 8;
traits->alpha = 8;
traits->windowDecoration = false;
traits->pbuffer = true;
traits->doubleBuffer = false;
traits->sharedContext = 0;
traits->readDISPLAY();
traits->setUndefinedScreenDetailsToDefaultScreen();
pbuffer = osg::GraphicsContext::createGraphicsContext(traits.get());
if (pbuffer.valid())
{
osg::notify(osg::NOTICE) << "Pixel buffer has been created successfully." << std::endl;
}
else
{
osg::notify(osg::NOTICE) << "Pixel buffer has not been created successfully." << std::endl;
}
}
if (pbuffer.valid())
{
osg::ref_ptr<osg::Camera> camera = new osg::Camera;
camera->setGraphicsContext(pbuffer.get());
camera->setViewport(new osg::Viewport(0, 0, width, height));
GLenum buffer = pbuffer->getTraits()->doubleBuffer ? GL_BACK : GL_FRONT;
camera->setDrawBuffer(buffer);
camera->setReadBuffer(buffer);
//camera->setFinalDrawCallback(new WindowCaptureCallback());
viewer.addSlave(camera.get(), osg::Matrixd(), osg::Matrixd());
viewer.realize();
However, on some devices I get the following error:
PixelBufferWin32::init(), Error: some wgl extensions not supported
So I thought maybe I should "upgrade" to FBOs. But I'm not sure how to do it. I know how to use FBOs to do Render-To-Texture, but I can't figure out how to use them instead of a window.
Cheers,
Jad[/code]
------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=75553#75553
More information about the osg-users
mailing list