HI Bram,
It's hard to guess at what the exact problem is without testing the problem
first hand with the full code. The best I can do is problem general
comments.
In general if the result is different then I'd suspect that the state
inherited down the the leaves of the scene graph (in this case
osgText::Text drawables) is different. You don't say how you have placed
your Camera's in the Viewer/Scene graph so there is no way for use to know
what state might be inherited in the instances you mention.
The only other general comment I can make is that by default osg::Camera's
don't set any override for OpenGL defaults so you have to apply the
defaults you want if they are different from OpenGL defaults or what has
been applied from above (if there is any state above.) In osg::StateSet
there is a convenience method to help with this:
/** Set all the modes to on or off so that it defines a
complete state, typically used for a default global state.*/
void setGlobalDefaults();
You code snippets don't include this so it could be that it's simply that
the default state isn't what is required. Adding a:
camera->getOrCreateStateSet()->setGlobalDefaults();
May be appropriate.
I have to stress, this are just general guesses, I really don't know enough
about how you have set up the whole scene graph and viewer to know exactly
what's going wrong so am having to guess at what these missing bits of
information might be.
Robert.
On 20 July 2014 16:11, Bram Vaessen <[email protected]> wrote:
> Hi,
>
> I'm having a small issue with the osgText::Text that I can't figure out.
>
> There is difference in how bright the text looks when I compare a
> osgText::Text drawn on screen, and the same one, but then drawn on a
> framebuffer, and then (the buffer) drawn on screen. Should be exactly the
> same right, if the bg color is the same?
>
> I attached a small part of a screenshot to show the difference. Other
> things that I draw on the framebuffer do not appear darker, so it seems to
> be related to osgText::Text.
>
> Here are some parts of the code:
>
> camera for gui on screen:
>
>
> Code:
> osg::ref_ptr<osg::Camera> camera = new osg::Camera();
> camera->setViewport(new osg::Viewport(0,0,width,height));
> camera->setClearMask(GL_DEPTH_BUFFER_BIT);
> camera->setReferenceFrame(osg::Transform::ABSOLUTE_RF);
>
> camera->setComputeNearFarMode(osg::CullSettings::DO_NOT_COMPUTE_NEAR_FAR);
> camera->setRenderOrder(osg::Camera::POST_RENDER,0);
> camera->setProjectionMatrixAsOrtho2D(0,width,height,0);
> //camera->setViewMatrix(camera->getViewMatrix() *
> osg::Matrixd::scale(1,-1.f,1));
> camera->getOrCreateStateSet()->setMode(GL_BLEND,
> osg::StateAttribute::ON); //blend
> camera->getOrCreateStateSet()->setMode(GL_DEPTH_TEST,
> osg::StateAttribute::OFF);
> camera->getOrCreateStateSet()->setMode(GL_ALPHA_TEST,
> osg::StateAttribute::OFF);
> camera->getOrCreateStateSet()->setMode(GL_LIGHTING,
> osg::StateAttribute::OFF | osg::StateAttribute::PROTECTED);
> camera->getOrCreateStateSet()->setMode(GL_FOG,
> osg::StateAttribute::OFF);
>
>
>
> camera for rendering to a framebuffer:
>
>
> Code:
> osg::ref_ptr<osg::Camera> camera = new osg::Camera();
> camera->setViewport(new osg::Viewport(0,0,width,height));
> camera->setClearMask(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
> camera->setReferenceFrame(osg::Transform::ABSOLUTE_RF);
> camera->setClearColor(osg::Vec4(0,0,0,0));
> camera->setRenderOrder(osg::Camera::PRE_RENDER,0);
> camera->setProjectionMatrixAsOrtho2D(0,width,height,0);
> camera->getOrCreateStateSet()->setMode(GL_BLEND,
> osg::StateAttribute::ON); //blend
> camera->getOrCreateStateSet()->setMode(GL_LIGHTING,
> osg::StateAttribute::OFF);
> camera->getOrCreateStateSet()->setMode(GL_DEPTH_TEST,
> osg::StateAttribute::OFF);
> camera->getOrCreateStateSet()->setMode(GL_ALPHA_TEST,
> osg::StateAttribute::OFF);
>
> camera->setRenderTargetImplementation(osg::Camera::FRAME_BUFFER_OBJECT);
>
> camera->attach(osg::Camera::BufferComponent(osg::Camera::COLOR_BUFFER0),
> texture);
>
>
>
>
> texture used for framebuffer:
>
>
> Code:
> osg::ref_ptr<osg::TextureRectangle> rect = new osg::TextureRectangle;
> rect->setTextureSize(width, height);
> rect->setInternalFormat(GL_RGBA32F_ARB);
> rect->setSourceFormat(GL_RGBA);
> rect->setSourceType(GL_FLOAT);
>
> rect->setFilter(osg::TextureRectangle::MIN_FILTER,osg::TextureRectangle::NEAREST);
>
> rect->setFilter(osg::TextureRectangle::MAG_FILTER,osg::TextureRectangle::NEAREST);
>
>
>
> quad used to render the framebuffer onscreen:
>
>
> Code:
> osg::ref_ptr<osg::Geode> geode = new osg::Geode();
> geode->getOrCreateStateSet()->setMode(GL_LIGHTING,
> osg::StateAttribute::OFF);
> osg::ref_ptr<osg::Geometry> geom = new osg::Geometry();
> geom->setSupportsDisplayList(false);
> osg::ref_ptr<osg::Vec3Array> vertices = new osg::Vec3Array;
> osg::ref_ptr<osg::Vec2Array> texcoords = new osg::Vec2Array;
> vertices->push_back(osg::Vec3d(0,0,0));
> texcoords->push_back(osg::Vec2(0,height));
> vertices->push_back(osg::Vec3d(0,height,0));
> texcoords->push_back(osg::Vec2(0,0));
> vertices->push_back(osg::Vec3d(width,height,0));
> texcoords->push_back(osg::Vec2(width,0));
> vertices->push_back(osg::Vec3d(width,0,0));
> texcoords->push_back(osg::Vec2(width,height));
> osg::ref_ptr<osg::Vec4Array> colors = new osg::Vec4Array;
> colors->push_back(color);
> geom->setVertexArray(vertices);
> geom->setTexCoordArray(0,texcoords);
> geom->setColorArray(colors);
> geom->setColorBinding(osg::Geometry::BIND_OVERALL);
> geom->addPrimitiveSet(new
> osg::DrawArrays(osg::PrimitiveSet::QUADS,0,vertices->size()));
> geode->addDrawable(geom);
>
>
>
> Does anyone have an idea what could cause this? I've looked at the source
> of osgText::Text, but it seems very complicated, and it also uses a custom
> rendering so it doesn't seem to be affected much by the render states (for
> example I don't think you can turn blending off trough the stateset when
> rendering text?), so I have no clue at this point...
>
>
> Thank you!
>
> Cheers,
> Bram
> Code:
>
>
>
>
> ------------------
> Read this topic online here:
> http://forum.openscenegraph.org/viewtopic.php?p=60357#60357
>
>
>
>
> Attachments:
> http://forum.openscenegraph.org//files/textproblem_940.png
>
>
> _______________________________________________
> 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