LucaGanio
Topic Author
Posts: 6
Joined: 14 Dec 2014, 13:18

osg integration

22 Dec 2014, 09:07

Hello Noesis Team, I am trying the integration with OpenSceneGraph. I tried the example on the github page and it all works fine. But the example only focuses on the integration as an HUD, while I am interested in using Noesis as a part of the 3D scenegraph, e.g. on the side of a cube. Do you have any hint on what I should do to reach this goal?

Thank you.

Luca
 
LucaGanio
Topic Author
Posts: 6
Joined: 14 Dec 2014, 13:18

Re: osg integration

23 Dec 2014, 15:43

ok... I kinda found a solution to my problem. I will post some details here, so people can correct me if I did something wrong.

I create a Render to Texture osg::camera, with the following code:
osg::ref_ptr<osg::Camera> camera = new osg::Camera;
camera->setClearMask(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
camera->setClearColor(osg::Vec4(0.6f, 0.1f, 0.1f, 1.0f));
camera->setClearStencil(0);
camera->setReferenceFrame(osg::Transform::ABSOLUTE_RF);
camera->setViewMatrix(osg::Matrixd::identity());
camera->setViewport(0, 0, width, height);
camera->setRenderOrder(osg::Camera::PRE_RENDER);
camera->setRenderTargetImplementation(osg::Camera::FRAME_BUFFER_OBJECT);
camera->setProjectionMatrix(osg::Matrix::ortho2D(0.0, 1.0, 0.0, 1.0));

then I create a texture to render onto and I attach it to the camera:
osg::ref_ptr<osg::Texture2D> tex = makeColorTexture(width, height);

camera->attach(osg::Camera::PACKED_DEPTH_STENCIL_BUFFER, makeStencilTexture(width, height).get());
camera->attach(osg::Camera::COLOR_BUFFER, tex.get());

then I follow the example given in OSGBindings and I create a wrapper for noesis, add it as a drawable to a geode and add this geode to the camera.

next I create a quad and map the texture on it and add the quad as a child to the main scene.

I also add to change a thing in the wrapper given in OSGBindings.
I had to change from
fbo->glBindFramebuffer(GL_FRAMEBUFFER_EXT,0);
to
fbo->glBindFramebuffer(GL_FRAMEBUFFER_EXT, 2);
cause otherwise I was not getting anything rendered... don't know why and I don't understand if 2 is a random number or if there is any logic behind it.

Luca.
 
User avatar
jsantos
Site Admin
Posts: 2904
Joined: 20 Jan 2012, 17:18
Contact:

Re: osg integration

23 Dec 2014, 16:59

Good to know you have it working. If you also could provide a pull request to our github... :)
 if ( fbo )
{
    _uiRenderer->Render( renderCommands.offscreenCommands.GetPtr() );
    fbo->glBindFramebuffer( GL_FRAMEBUFFER_EXT, 0 );
}
Binding to 0 is working because that sample is rendering to the screen (default fbo, 0). If you had to change to 2 is probably because your OSG sample is using that handle for rendering. It shouldn't be hardcoded.

That part of the binding should be changed so that after doing renderer->Render() the following steps are done:
  • Restore context state
  • Set viewport
  • Restore previous FBO
 
LucaGanio
Topic Author
Posts: 6
Joined: 14 Dec 2014, 13:18

Re: osg integration

24 Dec 2014, 13:51

I have my code at work, but I will be back at work after xmas holidays... I will be happy to post a pull request on github with my code when I am back at work :)
I will also try to work out the other steps you suggest doing after the rendering and try to have it working
 
User avatar
jsantos
Site Admin
Posts: 2904
Joined: 20 Jan 2012, 17:18
Contact:

Re: osg integration

24 Dec 2014, 16:53

Thanks! We will also need help adapting the bindings to noesisGUI v1.2 because a few things changed in the API, apart from the new resources architecture.

Merry Christmas!

Who is online

Users browsing this forum: No registered users and 0 guests