OpenSceneGraph Forum Forum Index OpenSceneGraph Forum
Official forum which mirrors the existent OSG mailing lists. Messages posted here are forwarded to the mailing list and vice versa.
 
   FAQFAQ    SearchSearch    MemberlistMemberlist    RulesRules    UsergroupsUsergroups    RegisterRegister 
 Mail2Forum SettingsMail2Forum Settings  ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
   AlbumAlbum  OpenSceneGraph IRC ChatOpenSceneGraph IRC Chat   SmartFeedSmartFeed 

how to set width and Stipple of a osgText::BoundingBox?


 
Post new topic   Reply to topic    OpenSceneGraph Forum Forum Index -> General
View previous topic :: View next topic  
Author Message
lq37
User


Joined: 04 Oct 2009
Posts: 97

PostPosted: Tue Oct 27, 2015 4:21 pm    Post subject:
how to set width and Stipple of a osgText::BoundingBox?
Reply with quote

Hi,

I want to modify text.cpp so can set osgText::BoundingBox's width and line Stipple.

Here is how osg draw BOUNDINGBOX in text.cpp:

if (_drawMode & BOUNDINGBOX)
{

if (_textBB.valid())
{
state.applyTextureMode(0,GL_TEXTURE_2D,osg::StateAttribute::OFF);

const osg::Matrix& matrix = _autoTransformCache[contextID]._matrix;

osg::Vec3 c00(osg::Vec3(_textBB.xMin(),_textBB.yMin(),_textBB.zMin())*matrix);
osg::Vec3 c10(osg::Vec3(_textBB.xMax(),_textBB.yMin(),_textBB.zMin())*matrix);
osg::Vec3 c11(osg::Vec3(_textBB.xMax(),_textBB.yMax(),_textBB.zMin())*matrix);
osg::Vec3 c01(osg::Vec3(_textBB.xMin(),_textBB.yMax(),_textBB.zMin())*matrix);


gl.Color4f(colorMultiplier.r()*_textBBColor.r(),colorMultiplier.g()*_textBBColor.g(),colorMultiplier.b()*_textBBColor.b(),colorMultiplier.a()*_textBBColor.a());
gl.Begin(GL_LINE_LOOP);
gl.Vertex3fv(c00.ptr());
gl.Vertex3fv(c10.ptr());
gl.Vertex3fv(c11.ptr());
gl.Vertex3fv(c01.ptr());
gl.End();
}
}

I have added this two line before gl.Begin(GL_LINE_LOOP):

glLineWidth (2.0);
glLineStipple (1, 0x0F0F);

It seems not work,need help!

Thank you!

Cheers,
Lv
Back to top
View user's profile Send private message
robertosfield
OSG Project Lead


Joined: 18 Mar 2009
Posts: 12264

PostPosted: Tue Oct 27, 2015 4:27 pm    Post subject:
how to set width and Stipple of a osgText::BoundingBox?
Reply with quote

Hi Lv,


I haven't tried modifying the drawing style of bounding box of an osgText::Text before, but it should be possible by decorating the Text subgraph with an osg::StateSet with the osg::LineStipple and osg::LineWidth StateAttributes attached to the StateSet to control the stipple and line width respectively. 

The only restriction on doing this with osgText::Text will be that osgText manages the StateSet of the Text object automatically, to enable the correct texture to be assigned and to be shared between Text elements.  This means your own osg::StateSet should be assigned to an Node that decorates the Text object rather that the Text itself.


Robert.


On 27 October 2015 at 16:22, Lv Qing < (
Only registered users can see emails on this board!
Get registred or enter the forums!
)> wrote:
Quote:
Hi,

I want to modify text.cpp so can set osgText::BoundingBox's width and line Stipple.

Here is how osg draw BOUNDINGBOX in text.cpp:

 if (_drawMode & BOUNDINGBOX)
    {

        if (_textBB.valid())
        {
            state.applyTextureMode(0,GL_TEXTURE_2D,osg::StateAttribute::OFF);

            const osg::Matrix& matrix = _autoTransformCache[contextID]._matrix;

            osg::Vec3 c00(osg::Vec3(_textBB.xMin(),_textBB.yMin(),_textBB.zMin())*matrix);
            osg::Vec3 c10(osg::Vec3(_textBB.xMax(),_textBB.yMin(),_textBB.zMin())*matrix);
            osg::Vec3 c11(osg::Vec3(_textBB.xMax(),_textBB.yMax(),_textBB.zMin())*matrix);
            osg::Vec3 c01(osg::Vec3(_textBB.xMin(),_textBB.yMax(),_textBB.zMin())*matrix);


            gl.Color4f(colorMultiplier.r()*_textBBColor.r(),colorMultiplier.g()*_textBBColor.g(),colorMultiplier.b()*_textBBColor.b(),colorMultiplier.a()*_textBBColor.a());
            gl.Begin(GL_LINE_LOOP);
                gl.Vertex3fv(c00.ptr());
                gl.Vertex3fv(c10.ptr());
                gl.Vertex3fv(c11.ptr());
                gl.Vertex3fv(c01.ptr());
            gl.End();
        }
    }

I have added this two line before gl.Begin(GL_LINE_LOOP):

glLineWidth (2.0);
glLineStipple (1, 0x0F0F);

It seems not work,need help!

Thank you!

Cheers,
Lv

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=65460#65460





_______________________________________________
osg-users mailing list
(
Only registered users can see emails on this board!
Get registred or enter the forums!
)
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


------------------
Post generated by Mail2Forum
Back to top
View user's profile Send private message
lq37
User


Joined: 04 Oct 2009
Posts: 97

PostPosted: Tue Oct 27, 2015 4:48 pm    Post subject:
Reply with quote

Thx!Robert!

The situation is,we have modified the text.cpp to create some other styles rather than boundingbox.

Like a BoundingLine,one end to one of the corner of a BoundingBox,the other end linked to a osg::Node.

So if a text have a BoundingLine and a BoundingBox,I just want draw the BoundingBox as normal,but draw the BoundingLine with LineStipple .So I think one osg::StateSet may not solve this problem.

I am not quiet familiar with the openGL programming since I use osg at first.I search the web found people use this code to set
Linewidth and Stipple

glLineWidth (2.0);
glLineStipple (1, 0x0F0F);

And I look into text.cpp,found lots of code like use openGL directly,such as :

//glClear(GL_STENCIL_BUFFER_BIT);

// enable stencil buffer
glEnable(GL_STENCIL_TEST);

// write a one to the stencil buffer everywhere we are about to draw
glStencilFunc(GL_ALWAYS, 1, 1);

// write only to the stencil buffer if we pass the depth test
glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE);

// Disable writing to the color buffer so we only write to the stencil
// buffer and the depth buffer
glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);

// make sure the depth buffer is enabled
// glEnable(GL_DEPTH_TEST);
// glDepthMask(GL_TRUE);
// glDepthFunc(GL_LESS);

// Arrrgh! Why does the code only seem to work correctly if I call this?
glDepthMask(GL_FALSE);



So I think use the openGL code to draw different style may be the qucik way.




...

Thank you!

Cheers,
Lv
Back to top
View user's profile Send private message
robertosfield
OSG Project Lead


Joined: 18 Mar 2009
Posts: 12264

PostPosted: Tue Oct 27, 2015 5:19 pm    Post subject:
how to set width and Stipple of a osgText::BoundingBox?
Reply with quote

Hi Lv,


osgText::Text implementation is very pretty old now, with a design driven by the needs of very old hardware.  If I were to rewrite osgText I would not implement it the has been.  I would not recommend adding OpenGL coding into osgText::Text as this breaks OSG's ability to do lazy state updating.


Robert.


On 27 October 2015 at 16:48, Lv Qing < (
Only registered users can see emails on this board!
Get registred or enter the forums!
)> wrote:
Quote:
Thx!Robert!

    The situation is,we  have modified the text.cpp to create some other styles rather than boundingbox.

    Like a BoundingLine,one end to one of the corner of a BoundingBox,the other end linked to a osg::Node.

   So if a text have a BoundingLine and a BoundingBox,I just want draw the BoundingBox as normal,but draw the BoundingLine with LineStipple .So I think one osg::StateSet may not solve this problem.

  I am not quiet  familiar with the openGL programming since I use osg at first.I search the web found people use this code to set
Linewidth and Stipple

glLineWidth (2.0);
glLineStipple (1, 0x0F0F);

And I look into text.cpp,found lots of code like use openGL directly,such as :

 //glClear(GL_STENCIL_BUFFER_BIT);

 // enable stencil buffer
    glEnable(GL_STENCIL_TEST);

    // write a one to the stencil buffer everywhere we are about to draw
    glStencilFunc(GL_ALWAYS, 1, 1);

    // write only to the stencil buffer if we pass the depth test
    glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE);

    // Disable writing to the color buffer so we only write to the stencil
    // buffer and the depth buffer
    glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);

    // make sure the depth buffer is enabled
//    glEnable(GL_DEPTH_TEST);
//    glDepthMask(GL_TRUE);
//    glDepthFunc(GL_LESS);

    // Arrrgh! Why does the code only seem to work correctly if I call this?
    glDepthMask(GL_FALSE);



 So I think use the openGL code to draw different style may be the qucik way.




...

Thank you!

Cheers,
Lv

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=65462#65462





_______________________________________________
osg-users mailing list
(
Only registered users can see emails on this board!
Get registred or enter the forums!
)
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org




------------------
Post generated by Mail2Forum
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    OpenSceneGraph Forum Forum Index -> General All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum

Similar Topics
Topic Author Forum Replies Posted
No new posts Colored Bounding Box over osgText::Text dhhabyc General 1 Fri Apr 05, 2019 12:43 pm View latest post
No new posts osgText::Text dissapears when reparen... dhhabyc General 0 Wed Mar 27, 2019 1:48 pm View latest post
No new posts osgText crash with multiple Viewers ravidavi General 3 Tue Dec 18, 2018 8:50 am View latest post
No new posts osgText 3.6.3 crash Trajce Nikolov NICK General 2 Wed Sep 12, 2018 12:25 pm View latest post
No new posts osgText: two thread-safety issues gwaldron General 1 Tue Jul 31, 2018 2:54 pm View latest post


Board Security Anti Bot Question MOD - phpBB MOD against Spam Bots
Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP