Hi Sergey, I've just had a quick scan of your posts and my guess is that you haven't yet had any other replies as you are probably the first to have tried grafting the OSG into Blender. I don't personally know anything about the Blender even at the user level so can't comment on the Blender side of things. The best I can do is answer some high level questions on the OSG side.
Integrating the OSG via an GraphicsWindowEmbedded as you have done is probably one of the best routes forward. There are complications in having to keep the OpenGL state constistent between OSG and the 3rd Party OpenGL codes, this has been discussed a number of times over the years so have a look through the archives on the topic of integrating the OSG with 3rd Party OpenGL contexts/code. When using the GraphicsWindowEmbedded feature the osgViewer itself won't create or destroy any graphics context, it's actually a dummy osg::GraphicsContext used to trick osgViewer into implementing the rendering backend in a way that most of the standard osgViewer features will still work. The osgviewerSDL and osgviewerGLUT examples are probably the best places to learn about how to use this feature. Cheers, Robert. On Wed, Feb 16, 2011 at 12:05 AM, Sergey Kurdakov <sergey.fo...@gmail.com> wrote: > Hi all, > happy to report, that managed to render to fbo texture in Blender using osg. > what I had to do? > first I added convenience method to Viewer > GraphicsWindowEmbedded* Viewer::setUpViewerAsEmbeddedInWindowOrtho(int x, > int y, int width, int height) > { > setThreadingModel(SingleThreaded); > osgViewer::GraphicsWindowEmbedded* gw = new > osgViewer::GraphicsWindowEmbedded(x,y,width,height); > getCamera()->setViewport(new osg::Viewport(0,0,width,height)); > getCamera()->setGraphicsContext(gw); > _currentContext = gw; > _releaseContextAtEndOfFrameHint = false; > return gw; > } > as you might see - I have to set current context and also notify renderer > not to release context. > in Blender code I had > viewer = new osgViewer::Viewer(); > osg::ref_ptr<osg::Camera> camera = createOrthoCamera(WINDOW_WIDTH, > WINDOW_HEIGHT);; > viewer->setCamera(camera.get());//this is why I called my convenience method > Ortho > osgViewer::GraphicsWindowEmbedded* gw = > viewer->setUpViewerAsEmbeddedInWindowOrtho(0,0,512,512); > > then attached > osg::ref_ptr<osg::Image> fboImage = new osg::Image(); > fboImage->allocateImage( 512, 512, 1, GL_RGB, GL_UNSIGNED_BYTE); > camera->attach( osg::Camera::COLOR_BUFFER, fboImage); > osg::Camera::RenderTargetImplementation renderImplementation; > renderImplementation = osg::Camera::FRAME_BUFFER_OBJECT; > // tell the camera to use OpenGL frame buffer object where supported. > camera->setRenderTargetImplementation(renderImplementation); > viewer->setSceneData(t);//set my render data here > viewer->getCamera()->setPostDrawCallback(new > MyCameraPostDrawCallback(fboImage.get())); //save here a texture for Blender > viewer->getCamera()->getGraphicsContext()->realize(); > somewhere when I need I do > glPushAttrib( GL_ALL_ATTRIB_BITS ); > glMatrixMode(GL_TEXTURE); > glPushMatrix(); > viewer->renderingTraversals(); //frame() would also work > glMatrixMode(GL_TEXTURE); > glPopMatrix(); > glPopAttrib(); > there is also need to tell viewer not to release context upon destruction - > and this is what I do now. > But overall - this works OK. > > hope these hints would be useful for others. > Regards > Sergey > > > > _______________________________________________ > osg-users mailing list > osg-users@lists.openscenegraph.org > http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org > > _______________________________________________ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org