Hi,
I tried to fix it a few more times, but I can't. It's working for color but not 
for the depth buffer.
When I execute the following code I get the variables texture2D and depth 
filled with white color. I draw the image and the texture on a rectangle.

Thanks for help,
jojo


Code:
osgViewer::Viewer* v = new osgViewer::Viewer;
    v->setCameraManipulator(new osgGA::TrackballManipulator());
    v->getCameraManipulator()->setHomePosition(getCameraPosition2(), 
getLookAtPoint(), getUpVector());
    osg::ref_ptr<osg::GraphicsContext::Traits> traits = new 
osg::GraphicsContext::Traits;
    traits->target = osg::Camera::FRAME_BUFFER_OBJECT;
    traits->x =0;
    traits->y = 0;
    traits->width = 720;
    traits->height = 576;
    traits->windowDecoration = false;
    traits->doubleBuffer = false;
    traits->sharedContext = 0;
    traits->pbuffer = true;

    osg::GraphicsContext* _gc= 
osg::GraphicsContext::createGraphicsContext(traits.get());

    v->getCamera()->setGraphicsContext(_gc);

    osg::Camera* camera = v->getCamera();

    camera->setViewport(new osg::Viewport(0,0,720,576));
    double fovy, aspectRatio, zNear, zFar;
    camera->getProjectionMatrixAsPerspective(fovy, aspectRatio, zNear, zFar);
    std::cout<< fovy << " " << aspectRatio<< " " << zNear << " " << zFar<<"\n";
    fovy+=41.0;
    camera->setProjectionMatrixAsPerspective(fovy, aspectRatio, zNear, zFar);
    std::cout<< fovy << " " << aspectRatio<< " " << zNear << " " << zFar<<"\n";
    v->setSceneData(osgDB::readNodeFile("Scene1.osg"));
    v->setDataVariance(osg::Object::DYNAMIC);
    v->setThreadingModel(osgViewer::Viewer::SingleThreaded);
    v->realize();
    osg::ref_ptr<osg::Image> depth = new osg::Image;
    osg::ref_ptr<osg::Image> color = new osg::Image;
    color->allocateImage(720, 576, 1, GL_RGBA, GL_UNSIGNED_BYTE);
    depth->allocateImage(720, 576, 1, GL_DEPTH_COMPONENT, GL_FLOAT);
    camera->attach(osg::Camera::COLOR_BUFFER, color.get());
    camera->attach(osg::Camera::DEPTH_BUFFER, depth.get());

    osg::ref_ptr<osg::Texture2D> texture2D = new osg::Texture2D;
    texture2D->setTextureSize(720, 576);
    texture2D->setInternalFormat(GL_DEPTH_COMPONENT);
    texture2D->setFilter(osg::Texture2D::MIN_FILTER,osg::Texture2D::LINEAR);
    texture2D->setFilter(osg::Texture2D::MAG_FILTER,osg::Texture2D::LINEAR);

    camera->attach(osg::Camera::DEPTH_BUFFER, texture2D.get(), 0, 0, false);

//    camera->attach(osg::Camera::DEPTH_BUFFER, depth.get(),0,0);


        v->frame();



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





_______________________________________________
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to