For now I have given up on trying to use core profile (my limited OpenGL 
knowledge is way obsolete), so I'm falling back to the previously mentioned 
workaround of rendering to a pbuffer and copying that back to the normal 2D 
engine.

Basing it around the osgscreencapture.cpp example, as if the --pbuffer-only 
option was used, it's working in the simplest case, but resizing the window 
does not work (only the original window size image is placed in the lower left 
of the resulting osg::Image, with the rest padded out with transparent pix).

I don't understand why, in the example, the following code is used 
(straightened out for the --pbuffer-only case):


Code:
    osg::ref_ptr<osg::GraphicsContext> pbuffer;
        osg::ref_ptr<osg::GraphicsContext::Traits> traits = new 
osg::GraphicsContext::Traits;
        ...
        traits->pbuffer = true;
        ...
        pbuffer = osg::GraphicsContext::createGraphicsContext(traits.get());
         
        ...

        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(mode, position, 
readBuffer));

        viewer.addSlave(camera.get(), osg::Matrixd(), osg::Matrixd());

        viewer.realize();

    return viewer.run();




So why is addSlave() then realize() necessary?

I tried simplifying it to just setting the pbuffer GraphicsContext directly on 
viewer.getCamera() (before realize()) but that results in a completely empty 
image.  But the normal viewer.getCamera() seems like a waste if I'm not using 
it.

It also fails if viewer.realize() is removed.

Anyway, the bigger problem is resizing.  In my viewer subclass, when the window 
is resized it calls resized() on the relevant GCs, which makes a bigger image 
but padded with transparent (I can't see on-screen in real time as yet, but 
instead it is writing the Image to a .png file).

FWIW, here is my code to set up the pbuffer GC and the resize method:


Code:
void MyViewer::embedInMemory(int x, int y, int width, int height)
{
    osg::ref_ptr<osg::Camera> camera = new osg::Camera;
    GLenum readBuffer = GL_BACK;
    WindowCaptureCallback::FramePosition position = 
WindowCaptureCallback::END_FRAME;
    WindowCaptureCallback::Mode mode = WindowCaptureCallback::READ_PIXELS;
    setThreadingModel(SingleThreaded);
    _gw = new GraphicsWindowMemory(x,y,width,height);
    camera->setViewport(new osg::Viewport(0,0,width,height));
    camera->setGraphicsContext(_gw);
    GLenum buffer = _gw->getTraits()->doubleBuffer ? GL_BACK : GL_FRONT;
    camera->setDrawBuffer(buffer);
    camera->setReadBuffer(buffer);
    camera->setFinalDrawCallback(new WindowCaptureCallback(mode, position, 
readBuffer));
    
    addSlave(camera.get(), osg::Matrixd(), osg::Matrixd());
    realize();
}

void MyViewer::reconfigure(int x, int y, int width, int height) 
{
    _queue.windowResize(x, y, width, height);  // osgGA::EventQueue & _queue
    if (_gw->isRealized()) {  // _gw is my GC created above
        _gw->makeCurrent();
    }
    _gw->resized(x, y, width, height);
    if (getCamera()->getGraphicsContext() && 
getCamera()->getGraphicsContext()->isRealized()) {
        getCamera()->getGraphicsContext()->resized(x, y, width, height);
        getCamera()->setViewport(new osg::Viewport(0,0,width,height));
        getCamera()->setProjectionMatrixAsPerspective(30.0f, 
static_cast<double>(width)/static_cast<double>(height), 1.0f, 10000.0f);
    }
}





Maybe you can point out the dumb mistake I have made.

[Sorry if the code has funny chars instead of spaces; it seems to be spaces in 
the text widget but preview looks a bit weird.]

Regards,
SJH

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=73969#73969





_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to