[Question] Rendering to a osg::Texture2D using OpenSceneGraph in order to do some post-processing
I am using QT, C++ and obviously OpenSceneGraph. More specifically, I have a C++ class that derives from QOpenGLWidget. This class contains, among other variables, these two:
osg::ref_ptr<osg::Group> m_root;
osg::ref_ptr<osgViewer::Viewer> m_viewer;
The m_root variable contains all of my geometry and is a child of m_viewer.
m_viewer->setSceneData(m_root);
The viewer is also the camera owner.
m_viewer->setCamera(create_camera(width(), height()));
As far as I know, everything is well setup. The application correctly renders my geometry to the window, which the user can access and look at. Here is how I draw to the window:
void MyClass::paintGL()
{
m_viewer->frame();
}
I am trying to write the frame data to an osg::Texture2D instead of the screen, apply some post-processing shaders to it, and then draw that to the screen.
I have tried a lot of things so far, and none of them worked. AI does not help and the only information I found on google that talks about frame buffers or post-processing dates from 13 years ago and uses OSG 1.2. Please help.
Have a look at osgverse (https://github.com/xarray/osgverse). It contains full supports of PBR rendering and deferred / postprocessing passes, as well as Qt widget supports. If you wish to implement your own post effects, have a look at osgdeferred example first, which tells how to create a sub camera for RTT use.
Here's what you want @DeviantGames https://github.com/openscenegraph/OpenSceneGraph/blob/2e4ae2ea94595995c1fc56860051410b0c0be605/examples/osgmultiplerendertargets/osgmultiplerendertargets.cpp#L346