[osg-users] Barenaked FBO-based-Viewer without window

Chris 'Xenon' Hanson xenon at alphapixel.com
Fri Apr 8 13:29:39 PDT 2011


  I'm doing some Render To Texture work right now, where I'm rendering to a texture that
is then utilized by some very basic (non-OSG) OpenGL code. I share contexts between OSG
and the basic OpenGL window so that I can rasterize the OSG-rendered texture onto a
fullscreen quad. I'm using plain OGL because it's in an environment that is not feasible
to directly call OSG from.

  I've made it work using PBuffers, but I'd like to do it properly with FBOs.

The common code looks like:

viewer = new osgViewer::Viewer;
osg::ref_ptr<osg::Camera> camera = viewer->getCamera();
// setup a texture to render to
RTTtexture = new osg::Texture2D;
RTTtexture->setTextureSize(tex_width, tex_height);
RTTtexture->setInternalFormat(GL_RGBA);
RTTtexture->setBorderWidth( 0 );
RTTtexture->setFilter(osg::Texture2D::MIN_FILTER,osg::Texture2D::LINEAR);
RTTtexture->setFilter(osg::Texture2D::MAG_FILTER,osg::Texture2D::LINEAR);

  PBuffer code looks like:

osg::ref_ptr<osg::GraphicsContext::Traits> traits = new osg::GraphicsContext::Traits;
traits->width = tex_width;
traits->height = tex_height;
traits->pbuffer = true;
traits->readDISPLAY();
osg::GraphicsContext *gc = osg::GraphicsContext::createGraphicsContext(traits.get());
camera->setGraphicsContext(gc);
camera->setRenderTargetImplementation(osg::Camera::PIXEL_BUFFER_RTT,
osg::Camera::FRAME_BUFFER);
camera->attach(osg::Camera::COLOR_BUFFER0, RTTtexture, 0, 0, false, samples, colorSamples);
viewer->realize();

  For FBO, I can skip most of that, and just

camera->setRenderTargetImplementation(osg::Camera::FRAME_BUFFER_OBJECT,
osg::Camera::FRAME_BUFFER);
camera->attach(osg::Camera::COLOR_BUFFER0, RTTtexture, 0, 0, false, samples, colorSamples);
viewer->realize();



  Unfortunately with the FBO, I always end up with something onscreen. Either a fullscreen
display or if I use setUpViewInWindow I get a window. I don't know how to get a completely
non-visible FBO.


  Any suggestions?


-- 
Chris 'Xenon' Hanson, omo sanza lettere. Xenon at AlphaPixel.com http://www.alphapixel.com/
  Digital Imaging. OpenGL. Scene Graphs. GIS. GPS. Training. Consulting. Contracting.
    "There is no Truth. There is only Perception. To Perceive is to Exist." - Xen


More information about the osg-users mailing list