Hi Kris,
Unfortunatelly I cannot offer you a working code example. But I have few
observations that could help I believe. For sure you have an error in
glBindTexture call. It should be called with GL texture object id. You can
obtain it from your RTT texture with
getTextureObject(state->getContextID() );
Next I suppose that FBO_RENDER_TEXTURE_UNIT is a texture stage unit.
glActiveTexture is the GL function which sets texture stage. Even if you
call it there is another catch need to know, call it as
glActiveTexture( GL_TEXTURE0 + FBO_RENDER_TEXTURE_UNIT ) because GL enum
fror texture stages does not start from 0 like OSG stages do.
However, instead of using gl functions i suggest you use OSG equivalents
that would do all neccessary GL work for you and you would not risk
desyncing OSG state with GL state . Code may look like this :
void FBOFinalRenderCallback::operator () (osg::RenderInfo& renderInfo) const
{
osg::State * state = renderInfo.getState();
state->applyMode( GL_TEXTURE_RECTANGLE, true );
state->setActiveTextureUnit(FBO_RENDER_TEXTURE_UNIT);
renderTexture->apply(*state);
glGetTexImage(renderTexture->getTextureTarget(),
0,
renderTexture->getInternalFormat(),
renderTexture->getSourceType(),
data);
}
However, the best solution for you in my opinion would be using osg::Image
instead of osg::Texture as a RTT camera attachment. If osg::Image is
attached OSG automatically reads the image contents after draw. So you just
have the updated data in the image available all the time. See osgprerender
for example code. If you insist on using your own callback you may debug
this example and see how image contents are refreshed and use the original
OSG source as guidance for your code.
HTH & Cheers,
Wojtek
-----Oryginalna wiadomość-----
From: Kris Dale
Sent: Saturday, June 04, 2011 12:48 AM
To: [email protected]
Subject: [osg-users] Camera set to RTT, texture never changes
Happy Friday everyone.
Forgive me if this turns out to be a terribly trivial problem. I'm still a
rookie with GL/OSG/graphics in general.
I'm attempting to get a two camera system set up, one RTT. I'm attempting
to read the texture back into an unsigned char array during a callback each
frame. My scene graph is set up such that I have:
Code:
viewer
|_ setSceneData()
|_topNode(osg::Group)
|_FBOCamera(set to prerender)
|_SceneRoot(osg::Group)
I don't have any nodes added under the viewer's main camera currently.
The setup for my FBOCamera is:
Code:
primaryCamera->setFinalDrawCallback(new
FBOFinalRenderCallback(renderTexture));
FBOCamera->setClearColor(Vec4f(1., 1., 1., 1.));
FBOCamera->setClearMask(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
FBOCamera->setViewport(0, 0, WIDTH, HEIGHT);
//FBOCamera->setViewMatrixAsLookAt(Vec3d(0., 0., 0.), Vec3d(0., 1., 0.),
Vec3d(0., 0., 1.));
FBOCamera->setViewMatrix(Matrixd::identity());
//FBOCamera->setProjectionMatrixAsPerspective(60.,
(double)WIDTH/(double)HEIGHT, NEAR, FAR);
FBOCamera->setProjectionMatrix(Matrixd::identity());
FBOCamera->setRenderOrder(Camera::PRE_RENDER);
FBOCamera->setRenderTargetImplementation(Camera::FRAME_BUFFER_OBJECT);
FBOCamera->attach(Camera::BufferComponent(Camera::COLOR_BUFFER),
renderTexture);
The setup for my texture is:
Code:
StateSet *stateSet = topNode->getOrCreateStateSet();
stateSet->setTextureAttributeAndModes(FBO_RENDER_TEXTURE_UNIT,
renderTexture, StateAttribute::ON);
renderTexture->setTextureSize(WIDTH, HEIGHT);
renderTexture->setSourceFormat(GL_RGBA);
renderTexture->setInternalFormat(GL_RGBA8UI);
renderTexture->setSourceType(GL_UNSIGNED_BYTE);
renderTexture->setFilter(Texture2D::MIN_FILTER, Texture2D::NEAREST);
renderTexture->setFilter(Texture2D::MAG_FILTER, Texture2D::NEAREST);
renderTexture->setWrap(Texture::WRAP_S, Texture::CLAMP_TO_EDGE);
renderTexture->setWrap(Texture::WRAP_T, Texture::CLAMP_TO_EDGE);
renderTexture->setWrap(Texture::WRAP_R, Texture::CLAMP_TO_EDGE);
My callback gets a ref_ptr to the texture. Then each frame it:
Code:
glBindTexture(GL_TEXTURE_RECTANGLE, FBO_RENDER_TEXTURE_UNIT);
glGetTexImage(renderTexture->getTextureTarget(),
0,
renderTexture->getInternalFormat(),
renderTexture->getSourceType(),
data);
glBindTexture(GL_TEXTURE_RECTANGLE, 0);
PostCallbackValidateData(); // prints all the values in data to the
console
When I print data to the screen, all I get are the values I initially
populated data with. I never even get the clear color for the camera. What
I've written looks right when compared to other things I've seen done. What
am I missing here?
(As an aside: am I right in calling FBOCamera that? I presume that by
setting the camera to RTT, it's got to be using an FBO's GL_COLOR_BUFFER
behind the scenes, even if I don't explicitly generate the FBO.. I don't
know of any other way to RTT..)
Thanks all.
------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=40069#40069
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org