[osg-users] Render to texture ONLY?

Christian Buchner christian.buchner at gmail.com
Thu Aug 18 08:07:00 PDT 2016


On Windows, create a graphics context with the pbuffer flag set to true
and windowDecoration set to false.

        osg::ref_ptr<osg::GraphicsContext::Traits> traits = new
osg::GraphicsContext::Traits;
        traits->x = 0;
        traits->y = 0;
        traits->width = 640;
        traits->height = 480;
        traits->red = 8;
        traits->green = 8;
        traits->blue = 8;
        traits->alpha = 8;
        traits->windowDecoration = false;
        traits->pbuffer = true;
        traits->doubleBuffer = false; // or true as needed
        traits->sharedContext = 0;

        m_pbuffer =
osg::GraphicsContext::createGraphicsContext(traits.get());
        if (!m_pbuffer.valid())
        {
            osg::notify(osg::NOTICE) << "Pixel buffer has not been created
successfully. NOTE: update your dependencies folder if you see this error!"
<< std::endl;
            exit(1);
        }
        else
        {
            // Create an osgViewer running on top of a pbuffer graphics
context
            m_viewer = new osgViewer::Viewer();

            // in my case I use a slave camera with ortho projection
            // to render whatever is needed
            m_camera = new osg::Camera;
            m_camera->setGraphicsContext(m_pbuffer.get());
m_camera->setComputeNearFarMode(osg::Camera::DO_NOT_COMPUTE_NEAR_FAR);
            m_camera->setReferenceFrame(osg::Transform::ABSOLUTE_RF);
            m_camera->setViewMatrix(osg::Matrix());
            m_camera->setProjectionMatrix(osg::Matrix::ortho2D(0, 1.0, 0,
1.0));
            m_camera->setViewport(new osg::Viewport(0, 0, 640, 480));
            m_camera->setDrawBuffer(GL_FRONT);
            m_camera->setReadBuffer(GL_FRONT);
            m_viewer->addSlave(m_camera.get(), osg::Matrixd(),
osg::Matrixd());
            m_viewer->realize();


I do not know if the same would work on Linux, as pbuffers on Linux are an
optional extension that might not be supported.

I get this to render at arbitrary frame rates, entirely decoupled from the
screen's VBLANK interval.

Christian


2016-08-18 16:47 GMT+02:00 Chris Thomas <cthomas at soasta.com>:

> Hi,
>
> OK, I based my initial integration into my app on osgteapot.cpp. As with
> all the other examples, it os run via
>
> viewer.run();
>
> And this creates an output window in OSX (and I am assuming any other OS
> its run on). And thats the issue I have, I need OSG to run "headless", that
> is to say, producing no visible window in the OS.
>
> If OSG is rendering away, to a non visible buffer, I can then expose this
> to the user via my UI api (see above). Having this visible viewer, is the
> issue right now. Is there an option to run viewer with no visible
> display/window, or is there an alternative to viewer() ?
>
> Thank you!
>
> Cheers,
> Chris
>
> ------------------
> Read this topic online here:
> http://forum.openscenegraph.org/viewtopic.php?p=68420#68420
>
>
>
>
>
> _______________________________________________
> osg-users mailing list
> osg-users at lists.openscenegraph.org
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openscenegraph.org/pipermail/osg-users-openscenegraph.org/attachments/20160818/dbcd9b37/attachment-0003.htm>


More information about the osg-users mailing list