[osg-users] openGL error 'stack overflow' at after RenderBin::draw(..)

58 views
Skip to first unread message

Nebi Sarikaya

unread,
Dec 23, 2018, 5:44:41 PM12/23/18
to osg-...@lists.openscenegraph.org
Hi,

I am trying to draw lines on the screen. And I am trying to use pure openGL to draw lines.The lines can be drawn on the screen. But I get openGL error 'stack overflow' at after RenderBin::draw(..) message. My code is below:


Code:

void draw::drawImplementation(osg::RenderInfo& renderInfo) const
{



Viewport* viewPort = renderInfo.getCurrentCamera()->getViewport();

double width = viewPort->width();
double height = viewPort->height();

double orgX = width / 2;
double orgY = height / 2;

osg::Quat matrix = renderInfo.getCurrentCamera()->getViewMatrix().getRotate();

glEnable(GL_LINE_SMOOTH);
glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
glOrtho(0.0, width, 0.0, height, -1, 1);

glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();

glTranslated(orgX, orgY, 0);
glRotated(rotate, 0, 0, 1);
glTranslated(-orgX, -orgY, 0);


glLineWidth(2.0f);
glColor4d(0, 255, 0, 255);
glBegin(GL_LINES);
if (orgY < height && orgY > 0) {
glVertex2d(orgX + 25, orgY);
glVertex2d(orgX + 260, orgY);
glVertex2d(orgX - 25, orgY);
glVertex2d(orgX - 260, orgY);
}

glEnd();

glLineWidth(5.0f);
glColor4d(0, 0, 0, 255);
glBegin(GL_LINES);
if (orgY < height && orgY > 0) {
glVertex2d(orgX + 23, orgY);
glVertex2d(orgX + 262, orgY);
glVertex2d(orgX - 23, orgY);
glVertex2d(orgX - 262, orgY);
}
glEnd();


glLineWidth(2.0f);
glColor4d(0, 255, 0, 255);
glBegin(GL_LINES);

int yLoc = orgY + 250;
for (int i = 0; i < 17; i++) {
if (yLoc < height && yLoc > 0) {
glVertex2d(orgX + 25, yLoc);
glVertex2d(orgX + 165, yLoc);
glVertex2d(orgX - 25, yLoc);
glVertex2d(orgX - 165, yLoc);

glVertex2d(orgX - 165, yLoc);
glVertex2d(orgX - 165, yLoc - 20);
glVertex2d(orgX + 165, yLoc);
glVertex2d(orgX + 165, yLoc - 20);

}
yLoc = yLoc + 250;
}

glEnd();

glLineWidth(5.0f);
glColor4d(0, 0, 0, 255);
glBegin(GL_LINES);

yLoc = (int)orgY + 250;
for (int i = 0; i < 17; i++) {
if (yLoc < height && yLoc > 0) {
glVertex2d(orgX + 23, yLoc);
glVertex2d(orgX + 165, yLoc);
glVertex2d(orgX - 23, yLoc);
glVertex2d(orgX - 165, yLoc);

glVertex2d(orgX - 165, yLoc);
glVertex2d(orgX - 165, yLoc - 22);
glVertex2d(orgX + 165, yLoc);
glVertex2d(orgX + 165, yLoc - 22);

}

yLoc = yLoc + 250;
}
glEnd();


}




Thank you!

Cheers,
Nebi[/code]

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





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

Chris Hanson

unread,
Dec 24, 2018, 6:53:16 AM12/24/18
to OpenSceneGraph Users
You are doing two PushMatrix operations per draw call, but you never PopMatrix, so the OpenGL matrix stack gets more and more full and eventually overflows.

At this point, functionally, you can either add two PopMatrix calls somewhere at the end of the draw function, or if you don't need the matrix stack (your current code isn't using the data you pushed, so it won't change functionality) just remove the two pushmatrix calls.
--
Chris 'Xenon' Hanson, omo sanza lettere. Xe...@AlphaPixel.com http://www.alphapixel.com/
Training • Consulting • Contracting
3D • Scene Graphs (Open Scene Graph/OSG) • OpenGL 2 • OpenGL 3 • OpenGL 4 • GLSL • OpenGL ES 1 • OpenGL ES 2 • OpenCL
Legal/IP • Forensics • Imaging  UAVs • GIS • GPS • osgEarth • Terrain • Telemetry • Cryptography • LIDAR • Embedded • Mobile • iPhone/iPad/iOS • Android
@alphapixel facebook.com/alphapixel (775) 623-PIXL [7495]

Nebi Sarikaya

unread,
Dec 24, 2018, 9:49:17 AM12/24/18
to osg-...@lists.openscenegraph.org
Chris,

Thank you for your interest and answer. I need glPushMatrix and glPopMatrix since as you may see on the screenshot some of the drawings are static on the other hand positions of some of the drawings dinamically change.

Know I need to put text inside the boxes and next to the pitch lines. I know that osg::Text can work for me for the static ones. Bu what souls I do for the dynamic ones? Is there any way to rotate osg::Text just like we rotate in openGL. What I mean is, I need to rotate text just beside the pitch lines and aligned next to them. These texts will show the pitch degrees.

Thank you!

Cheers,
Nebi

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

Nebi Sarikaya

unread,
Dec 30, 2018, 3:49:18 AM12/30/18
to osg-...@lists.openscenegraph.org
At last I managed to do somethings using osgText::Text, but I had to create a new class called "TextMod" means modified text derived from osgText::Text class, and I created a function setting offset to TextMod class. By setting different offset values to each text I could set all the positions of the texts at the center origin point. So when I rotate the pitch ladders all text labels rotate aligned with the pitch ladders.

Actually I did a similar HUD using NASA World Wind Java. There is a TextRenderer class in WWJ API and by that way a text can be rendered on GLCanvas. So when the matrix is rotated all drawings and texts rotates. That was actually more easy to implement.

If anyone knows an easier way please let me know.

Thank you!

Cheers,
Nebi

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



Untitled.jpg

Chris Hanson

unread,
Dec 30, 2018, 9:30:32 AM12/30/18
to OpenSceneGraph Users
I'm not totally clear on how you're doing things, but I think it's probably more cumbersome than it should be.

I usually put all of the text and HUD elements into a group and position them relative to the group and then rotate and shift that group. All the sub-children will rotate properly.

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

Nebi Sarikaya

unread,
Jan 7, 2019, 2:40:08 AM1/7/19
to osg-...@lists.openscenegraph.org
Hi Chris;

Can you be more specific on "I usually put all of the text and HUD elements into a group and position them relative to the group and then rotate and shift that group. All the sub-children will rotate properly. " ?

Thank you!

Cheers,
Nebi

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

Chris Hanson

unread,
Jan 7, 2019, 5:20:25 AM1/7/19
to OpenSceneGraph Users
Well, it's hard to say because I don't really know how you are doing it now, but it seems to me like you're spending a lot of effort rotating and positioning each text element individually. Normally, I don't go through that process.

Normally, I make a hierarchy of a few groups, each with various children individually positioned. Then, I can adjust the overall position and rotation of the whole set by applying position and rotation transforms to the Group node, not to each text or other sub-element.

From your description (maybe I misinterpreted what you were saying) it didn't sound like you were doing it this way, and I worried that you were making unnecessary work for yourself as a result.


Nebi Sarikaya

unread,
Feb 19, 2022, 10:03:33 PM2/19/22
to OpenSceneGraph Users
Hello,

This may be an old subject, but how do you rotate all osg::Text's as a group in 2D space?

Thanks

Trajce Nikolov NICK

unread,
Feb 20, 2022, 1:11:07 AM2/20/22
to osg-...@googlegroups.com
Hi Nebi,

You can put osg::MatrixTransform on top of the group and setMatrix(myRotateMatrix). And you construct myRotateMatrix with Quaternion, something like this:

osg::Quat q;
q.makeRotate(osg::Vec3(0,1,0),osg::Vec3(0,angle,0));

osg::Matrix myRotateMatrix;
myRotateMatrix = osg::Matrix::rotate(q);

osgh::ref_ptr<osg;;MatrixTransform> mxt = new osg::MatrixTransform;
mxt.setMatrix(myRotateMatrix);

mxt->addChild(myTextGroup);

Something like this

--
You received this message because you are subscribed to the Google Groups "OpenSceneGraph Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to osg-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/osg-users/fa4f53fd-c5cc-4e3e-bf9a-a27a3eb766ban%40googlegroups.com.


--
trajce nikolov nick

Nebi Sarikaya

unread,
Feb 20, 2022, 1:31:40 PM2/20/22
to OpenSceneGraph Users
Hello Nick,

First of all, thank you for your answer. Actually, I tried all of the methods you indicated. My may problem here is I think to place the Group Node on the 2D space. Think of the HUD example of OSG. There are lines of osg::Text's there. And they are positioned on the 2D Ortho projection Matrix. But I think since I can not place the root node (group node) of osg::Texts on 2D ortho projection matrix (renderInfo.getCurrentCamera()->setProjectionMatrix(osg::Matrix::ortho2D(0, width, 0, height));) This does not work. You may see that on the picture below, The texts does not rotate based on the center. If I solve this problem, I will be very relieved. Here is my Drawable implemetation:

osg::ref_ptr<osg::MatrixTransform> transform = new osg::MatrixTransform;


HUDDrawable::HUDDrawable(osg::ref_ptr<osg::Group> geode) : _geode(geode) {
        timesFont = "fonts/arial.ttf";
         addTexts ();
        transform->addChild(_geode); // OSG::TEXTs ARE ADDED AS SHILD TO _geode Group in a function.
}

void HUDDrawable::setRotate(float& rotate) {
        _rotate = rotate;
        osg::Quat q;
        q.makeRotate(osg::Vec3(0, 1, 0), osg::Vec3(0, _rotate, 0)); // THESE INSTRUCTION DOES NOT WORK....


        osg::Matrix myRotateMatrix;
        myRotateMatrix = osg::Matrix::rotate(q);

       
        transform->setMatrix(myRotateMatrix);
}

void HUDDrawable::drawImplementation(osg::RenderInfo& renderInfo) const


{

        Viewport* viewPort = renderInfo.getCurrentCamera()->getViewport();

        double width = viewPort->width();
        double height = viewPort->height();

        double orgX = width / 2;
        double orgY = height / 2;

        osg::Vec3 position(orgX, orgY, 0.0); // CENTER OF THE HUD

        for (short int i = 0; i < 34; i++) { // HERE I POSITION THE OSG::TEXTs ON THE HUD BEASED ON THE CENTER OF THE 2D SPACE AND OFFSET THAT SET IN THE BELOW FUNCTION.
               
                pozitivePitchLadderLabelsArray[i]->setPosition(position); // IN THIS ARRAY EACH ELEMENT IS AN OSG::TEXT
                negativePitchLadderLabelsArray[i]->setPosition(position);
        }

        renderInfo.getCurrentCamera()->setProjectionMatrix(osg::Matrix::ortho2D(0, width, 0, height));
       
        glPushMatrix();


        glEnable(GL_LINE_SMOOTH);
        glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);
        glEnable(GL_BLEND);
        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

        glTranslated(orgX, orgY, 0);
        glRotated(_rotate, 0, 0, 1);
        glTranslated(-orgX, -orgY, 0);

//// DRAW PITCH LADDDERSAND OTHER STUFF HERE  WITH OPENGL COMMANDS  ///

        glPopMatrix(); //FINISH DRAWING
}

void HUDDrawable::addTexts() {
    for (short int i = 0; i < 34; i++) {
             osg::Text* text= new   osg::Text;
             text->setOffser(offset); // I APPLY AN OFFSET TO TEXT SO TEXT IS NOT PLACED ON THE CENTER OF THE HUD
               _geode->addChild text); // HERE OSG::TEXTs ADDED AS CHILD TO osg::Group, BUT osg::Group DOWS NOT HAVE POSITION ON 2D SPACE, HOW I AM GOING TO DO THAT???
               pozitivePitchLadderLabelsArray[i] =  text ;
    }

    for (short int i = 0; i < 34; i++) {
             osg::Text* text= new  osg::Text;
             text->setOffser(offset); // I APPLY AN OFFSET TO TEXT SO TEXT IS NOT PLACED ON THE CENTER OF THE HUD
            _geode->addChild(text );
              negativePitchLadderLabelsArray[i] =  text ;
    }
}

Thanks
1.png

Nebi Sarikaya

unread,
Feb 20, 2022, 1:37:19 PM2/20/22
to OpenSceneGraph Users
Another question is, How can I apply glscissors or similar kind of clipping functionality to osg::Text? I want to limit the space the HUD is drawn and I want to clip the 2D Space. How can I do that and I apply it it osg::Text?

Thanks

Trajce Nikolov NICK

unread,
Feb 20, 2022, 2:02:52 PM2/20/22
to osg-...@googlegroups.com
Hi Nebi,

Can you come up with a compilable sample (not only snippets) so I can check it here? I believe it is the setup of the quaternion. Just send me a file with all of it, like main.cpp. I did this before including the scissors so relax I will help you ;-) 



--
trajce nikolov nick
Reply all
Reply to author
Forward
0 new messages