[osg-users] osgText::Text Drawing order

260 views
Skip to first unread message

Andre Simoes

unread,
Dec 14, 2009, 9:06:45 AM12/14/09
to OpenSceneGraph Users
Hello There.

I've been reading alot of e-mails regarding drawing of objects in sequence, like a simple OpenGL program that draws each Geometry independently of its complexibility and cost to the GPU.

And for now I'm working in an OSG scenario in which I'm doing a toolkit that generates widgets in 2D Orthographic mode. Almost all of the components are being drawn with LIGHTING disabled because they are unecessary for the case. And with or without RenderBin::TRAVERSAL_ORDER option enabled I can add a widget as a child of other widget without problems by using osg::Group::insertChild( 0, child ).

The problem is when I try to draw osgText::Texts inside components as children. They simply not appear on the screen.
- if i create them and set their StateSet as setGlobalDefaults the text appears as a Child of other widgets ( But in this case i loose color and background transparency control of the text and is something i would not like to loose ).
- If i draw them without a widget on the screen the Text appears.

After that I thought that TRAVERSAL_ORDER could solve the problem. But TRAVERSAL_ORDER is not solving the problem.

I'm doing on the initial part of my code before creating any X Window with osgViewer::View... :

int main( void )
{
        using namespace osgUtil;
        RenderBin::setDefaultRenderBinSortMode( RenderBin::TRAVERSAL_ORDER );
        RenderBin::SortMode s = RenderBin::getDefaultRenderBinSortMode();

        /// window init
       /// widget init

       return viewer.run();
}

My questions are:
- Am I looking to the right option (RenderBin::TRAVERSAL_ORDER ) ?
- Am I setting TRAVERSAL_ORDER in the right way ?

Sorry to ask but i already lost one week searching for documentation about this problem and no good results.

Kind Regards
Andre

Robert Osfield

unread,
Dec 14, 2009, 10:54:28 AM12/14/09
to OpenSceneGraph Users
Hi Andre,

I'm finding it difficult to guess what your after/what problems your
seeing. The best I can do is say as a general note, one would
typically use control the rendering order via
StateSet::setRenderingDetails(..) from within the scene graph rather
attempting to set globals.

Robert.

> _______________________________________________
> osg-users mailing list
> osg-...@lists.openscenegraph.org
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
>
>
_______________________________________________
osg-users mailing list
osg-...@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Andre Simoes

unread,
Dec 14, 2009, 2:48:36 PM12/14/09
to OpenSceneGraph Users
Hello Robert.

Sorry about the bad explanation of my problem.

I think is better to start from scratch and just explain the problem to you.

I'm making a widget system, on Ortho2D,  that separates levels of parents from childs by osg::Groups ( osg::PositionAttitudeTransform, osg::Switch ... )

- The children  position is always related to the bottom top vertex of the parent ( i.e,  a text inside a box ).

          ---------------------
          |                    |
          |                    |
          |text (at 0,0)   |
          ----------------------
  box at (20,20)

- Children have to be drawn on top of the parent ( the parent area can be hidden by the child but the child cannot be hidden by the parent drawing ).
( i.e white child text on a black box )

|----------------------- |
|------------------------|
|------------------------|
|---WHITE TEXT--|
|------------------------|
------------------------

 My problem is to always make all kinds of Geometries that are on the leafs of my tree as the top most visible.

For example: If i have a tree in the following sequence

root -> Rectangle1
        child -> Rectangle2
                 child ->  Triangle3

OpenGL should draw Rectangle1 than Rectangle2 and on the end Triangle3 to the FrameBuffer.
On the monitor:  Triangle2 will be above Triangle1 and Triangle3 will be above Triangle2  (in case those are being drawn at the same place ).

---------------------------------
|      --------------------      |
|     |         / \        |     |
|     |        /   \       |     |
|     |       /      \     |     |
|     |       ---------    |     |
|     |     Triangle3  |     |
|     ---------------------     |
|   Rectangle2            |
|     (below triangle3)   |
--------------------------------
Rectangle1 ( goes below everyone )

I've made some separate tests and noticed that if my geometries have just the same StateSet configuration ( i.e all geometries with StateSet::setGlobalDefault )  I can make this result on the frame buffer.
But when i add a osgText::Text element for example as:

root -> Rectangle1
        child -> Rectangle2
                      child-> osgText::Text

-----------------------------------------
|     --------------------------------   |
|     |   "no osgText::Text" |   |       
|     |          inside            |   |
|     |_________________ |   |
|                                        |
|_______________________|

The text will only appear if i make _child_text->getOrCreateStateSet()->setGlobalDefaults(); that makes me to loose transparency and other configurations for the osgText::Text component.

Screen shots from my current diagram block configuration and my scene

I've already tried to use "setRenderBinDetails"  ( version 2.9.5 ) and worked... But if  I simply use setRenderBinDetails i will have to rebuild all the binNum for every visual on my graph after a simply insertChild because they will be not in the right draw order.
For our system this is not good. Because the number of components that my co-workers generally draw are very large and it would take very long to rebuild the number for the graphs just because of a removal or an insertion of component.

Is there anything that i could use to ensure that they will always be processed in the order that they are being added as child bypassing the state set configuration ?

Regards
Andre

2009/12/14 Robert Osfield <robert....@gmail.com>

Robert Osfield

unread,
Dec 15, 2009, 4:24:02 AM12/15/09
to OpenSceneGraph Users
Hi Andre,

Text by default will drop into the transparent bin so this is likely
the reason why it's ordering is not exactly what you expect it. Text
has to be in the transparent bin to ensure correct blending.

Also I don't of if you are aware but rendering order only controls
which item depends upon the current setting of the depth buffer - i.e.
is depth test on, and what is rejected (normally more distance
fragements are discarded) and the depth of the object. If you switch
off depth test or the fragments have the same depth and fragements of
the same depth pass the depth test will rendering order make a
difference.

In you case you don't specify what you are doing with the depth test
or depth buffer, it's also difficult to guess at what level of
understanding you have about depth buffers and depth test.

Robert.

Andre Simoes

unread,
Dec 14, 2009, 1:17:02 PM12/14/09
to OpenSceneGraph Users
Hello Robert.

Sorry about the bad explanation of my problem.

I think is better to start from scratch and just explain the problem to you.

I'm making a widget system, on Ortho2D,  that separates levels of parents from childs by osg::Groups ( osg::PositionAttitudeTransform, osg::Switch ... )
There are two png files attached (a block diagram and its osg scene ) that gives a better idea of this groups....
I've already tried to use "setRenderBinDetails"  ( version 2.9.5 ) and worked... But if  I simply use setRenderBinDetails i will have to rebuild all the binNum for every visual on my graph after a simply insertChild because they will be not in the right draw order.
For our system this is not good. Because the number of components that my co-workers generally draw are very large and it would take very long to rebuild the number for the graphs just because of a removal or an insertion of component.

Is there anything that i could use to ensure that they will always be processed in the order that they are being added as child bypassing the state set configuration ?

Regards
Andre

2009/12/14 Robert Osfield <robert....@gmail.com>
Hi Andre,
text_default.png
osg_problem.png

Robert Osfield

unread,
Dec 15, 2009, 5:27:00 AM12/15/09
to OpenSceneGraph Users
Hi Andre,

Block diagrams won't help as that most likely not at issue. What are
you doing with the depth buffer/depth test? What you are doing the
with the depth of each of the objects?

Robert.

Trajce Nikolov

unread,
Dec 15, 2009, 6:03:16 AM12/15/09
to OpenSceneGraph Users
Andre,

could you send some test code so we can do some tests and help you ?

Nick

http://www.linkedin.com/in/tnick
Sent from Gümüşsuyu, İstanbul, Turkey

Andre Simoes

unread,
Dec 15, 2009, 6:11:35 AM12/15/09
to OpenSceneGraph Users
Hi Robert.

In reality I'm not doing anything with the depth buffer since i never used depth for a 2D projection in pure OpenGL programs.

For a simple OpenGL program I just draw components in sequence. As an example like this:

void draw( void )
{
 ......
for( int i = 0; i < number_of_components; ++i )
{
        glEnable() // for all necessary capacities of a geometry
           glBegin()
                   //// draw vertexes
           glEnd();
        glDisable()  // for all necessary capacities
}

}

The component[  number_of_componet - 1 ] in this case is always the top-most visible no matter if it has blending or anything else.

-----------------

Hello Trajce Nikolov, sorry not to have a piece of code here because its from the company.

But I'll reproduce the same error in a simple example to send you in c++ for everyone to check as soon as possible.

--------------

Regards
Andre

2009/12/15 Robert Osfield <robert....@gmail.com>

Robert Osfield

unread,
Dec 15, 2009, 6:21:39 AM12/15/09
to OpenSceneGraph Users
Hi Andre,

On Tue, Dec 15, 2009 at 11:11 AM, Andre Simoes <andrer...@gmail.com> wrote:
> Hi Robert.
>
> In reality I'm not doing anything with the depth buffer since i never used
> depth for a 2D projection in pure OpenGL programs.

So.... you disable depth test?

If you have depth test on then you will be using the depth buffer even
with 2D projections.. as 2D projections are really no different rather
3D projections in OpenGL, everything in reality is 3D, everything has
depth even it's flat and depth value of 0, and if depth test is on
then each fragment will be tested against the depth buffer.

> For a simple OpenGL program I just draw components in sequence. As an
> example like this:

Again as I've been saying for the last three emails, depth test is the
key and still you haven't provide any information about it.

Robert.

Andre Simoes

unread,
Dec 15, 2009, 10:15:36 AM12/15/09
to OpenSceneGraph Users
Hello Robert.

I never thought of  the Depth buffer application under a 2D orthographic mode.

After adding
    osg::StateSet *ss = getOrCreateStateSet();
    ss->setRenderingHint( osg::StateSet::TRANSPARENT_BIN );
    ss->setMode( GL_DEPTH_TEST, osg::StateAttribute::ON );

         to all my geometries osgText::Texts are being correctly displayed.

Thanks
Andre

2009/12/15 Robert Osfield <robert....@gmail.com>
Hi Andre,

Andre Simoes

unread,
Dec 15, 2009, 12:00:52 PM12/15/09
to OpenSceneGraph Users
Hi Robert.

Sorry to post again.

But even using the ss->setRenderingHint( osg::StateSet::TRANSPARENT_BIN ) for all geometries a cannot guarantee that the Texts will be on screen.

- When I add to much components (nothing more than rects with texts inside) on the screen my texts just simply fade away.
- If i add a small quantity widgets with texts inside and one widget with LineStipple, all Texts fade away too.

As a test,  just to see the osgText::Texts,  i've made a second configuration that looses the transparency of them but at least they are showing on screen if their respective colors:
       _text->getOrCreateStateSet()->setMode( GL_DEPTH, osg::StateAttribute::OFF );
       _text->getOrCreateStateSet()->setRenderingHint( osg::StateSet::DEFAULT_BIN );

I'll restart to create the widget System using your first hint as base ( setRenderBinDetails( number_as_draw_order, "" )  ).

Scene results together with code:

Regards
Andre

2009/12/15 Andre Simoes <andrer...@gmail.com>

Robert Osfield

unread,
Dec 15, 2009, 12:31:05 PM12/15/09
to OpenSceneGraph Users
Hi Andre,

I'm afraid I can't dedicate all my support time to just understanding
what you are doing wrong and trying to help you - I have other work to
do. What you want to do is possible. osgWidget does it, why not go
look at it. I have tried by best to point you in the right direction,
but this is as far as I can go.

Perhaps others can help you.

Robert.

Trajce Nikolov

unread,
Dec 15, 2009, 12:52:48 PM12/15/09
to OpenSceneGraph Users
Andre,

can you post some code samples?

Nick

http://www.linkedin.com/in/tnick
Sent from Gümüşsuyu, İstanbul, Turkey

Reply all
Reply to author
Forward
0 new messages