[osg-users] Render to texture with GL3.
Nickolai Medvedev
raizel.dev at yandex.ru
Tue May 23 06:53:07 PDT 2017
I found problem. HUD-Camera does not work when i create OpenGL 3.3 core context. Only clear color is visible. If not create context, all is worked.
Code:
const int width(1920), height(1080);
const std::string version("3.3");
osg::ref_ptr< osg::GraphicsContext::Traits > traits = new osg::GraphicsContext::Traits();
traits->x = 0;
traits->y = 0;
traits->width = width;
traits->height = height;
traits->windowDecoration = true;
traits->doubleBuffer = true;
traits->vsync = false;
traits->glContextVersion = version;
traits->glContextFlags = GL_CONTEXT_FLAG_FORWARD_COMPATIBLE_BIT;
traits->glContextProfileMask = GL_CONTEXT_CORE_PROFILE_BIT;
osg::ref_ptr< osg::GraphicsContext > gc = osg::GraphicsContext::createGraphicsContext( traits.get() );
if( !gc.valid() )
{
osg::notify( osg::FATAL ) << "Unable to create OpenGL v" << version << " context." << std::endl;
return (1);
}
gc->realize();
gc->makeCurrent();
osgViewer::Viewer* viewer = new osgViewer::Viewer;
osg::Camera* cam = viewer->getCamera();
cam->setGraphicsContext( gc.get() );
cam->setComputeNearFarMode(osg::CullSettings::DO_NOT_COMPUTE_NEAR_FAR);
cam->setProjectionMatrix(osg::Matrix::perspective(45.0, (double)width/(double)height, 0.1, 100000.0) );
cam->setViewport(new osg::Viewport(0, 0, width, height));
//HUD-Camera created as in the example osghud
osg::ref_ptr<HUDCamera> hud_camera = new HUDCamera; //Inherited from osg::Camera
hud_camera->setGraphicsContext(gc.get());
hud_camera->setClearColor(osg::Vec4(0.0,0.0,0.0,1.0)); //Anyway, still see the classic blue osg color
hud_camera->addChild(RTTCamera::createScreenQuad(1.0f, 1.0f, 1920.0f, 1080.0f)); //Create geometry for TextureRectangle
Any ideas?
------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=70965#70965
More information about the osg-users
mailing list