Dear Oliver,
Seeing that error my impression is that there is something wrong with
your OpenGL installation. However I seldom use Windows, so I may be wrong.
Can you check the program below with and without commenting the line
that enables the pbuffer and give the whole output?
The program should write a file called screenshot.png in the working
directory. That output image should be a white sphere over the default
background.

#include <osg/Geode>
#include <osg/ShapeDrawable>
#include <osgViewer/Viewer>
#include <osgGA/TrackballManipulator>
#include <osgDB/WriteFile>

int main(int argc, char *argv[])
{
    osg::ArgumentParser args(&argc, argv);
    osgViewer::Viewer viewer(args);
    osg::Camera *camera = viewer.getCamera();

    osg::ref_ptr<osg::GraphicsContext::Traits> traits = new
        osg::GraphicsContext::Traits;
    traits->width = 512;
    traits->height = 512;
    traits->pbuffer = true;
    traits->readDISPLAY();
    osg::GraphicsContext *gc =
        osg::GraphicsContext::createGraphicsContext(traits.get());
    camera->setGraphicsContext(gc);
    camera->setDrawBuffer(GL_FRONT);
    camera->setProjectionMatrixAsPerspective(22, 1, 0.1, 1000);
    camera->setViewport(new osg::Viewport(0, 0, 512, 512));

    osg::Geode *scene = new osg::Geode();
    osg::Shape *sphere = new osg::Sphere(osg::Vec3(), 1);
    scene->addDrawable(new osg::ShapeDrawable(sphere));
    viewer.setSceneData(scene);

    viewer.setCameraManipulator(new osgGA::TrackballManipulator());

    osg::Image *image = new osg::Image();
    camera->attach(osg::Camera::COLOR_BUFFER0, image);

    viewer.setThreadingModel(osgViewer::Viewer::SingleThreaded);
    viewer.realize();
    viewer.frame();

    osgDB::writeImageFile(*image, "screenshot.png");
}

Regards,
Juan

Dear Juan and Robert,

Thanks for the quick reply! I tried the code supplied by Juan but I'm
still getting the "Error: OpenGL version test failed, requires valid
graphics context." and subsequent errors (many "invalid operation").


As a second test I copied the complete osgViewer::setUpViewInWindow
and just added the line

Code:

traits->pbuffer = true;

to the Traits creation part. Without the line the code works but
displays a window, with the line I get the OpenGL errors.  For the
second case I get these Errors:

Code:

PixelBufferWin32::makeCurrentImplementation, wglMakeCurrent error:
Die angeforderte Ressource wird bereits verwendet.

Error: In Texture::Extensions::setupGLExtensions(..) OpenGL version
test failed, requires valid graphics context. Scaling image from
(256,256) to (0,0)

("Die angeforderte Ressource wird bereits verwendet." is german for
"The Requested Resource Is in Use".)


Is this a Win32 related problem or am I missing something?

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

Reply via email to