[osg-users] Osg Text issues

OpenSceneGraph Users osg-users at lists.openscenegraph.org
Mon Jan 27 07:56:55 PST 2020


Hello, sorry for a late reply. I have digged further into this problem and 
figured out the source of the issue. I am using 3.6.4. release which was 
the latest at the time. The problem comes when launching OpenSceneGraph 
through a QOpenGlWIdget, i have used a simple example from 
https://vicrucann.github.io/tutorials/qt-osg-navigation/ , i will paste my 
code below so it is easier to follow(although most is copy pasted)


QtOSGWidget(QWidget* parent = 0)


      : QOpenGLWidget(parent)


        , _mGraphicsWindow(new osgViewer::GraphicsWindowEmbedded( this->x(), this->y(),


                                                                  this->width(), this->height() ) )


        , _mViewer(new osgViewer::Viewer)


      // take care of HDPI screen, e.g. Retina display on Mac


      , m_scale(QApplication::desktop()->devicePixelRatio())


      {


        _mGraphicsWindow->init();




        osg::Group* root = new osg::Group;




        osg::StateSet* rootStateSet = root->getOrCreateStateSet();


        rootStateSet->setMode( GL_DEPTH_TEST, osg::StateAttribute::ON );




        osgText::Text* text = new osgText::Text();


        text->setText("ABRAKADABRA");


        text->setCharacterSize(14);


        text->setCharacterSizeMode(osgText::Text::CharacterSizeMode::SCREEN_COORDS);


        text->setAutoRotateToScreen(true);


        text->setColor(osg::Vec4(0,0,0,1));




        osg::Geode* drawableText = new osg::Geode;


        drawableText->addDrawable(text);


        root->addChild(drawableText);




        osg::Camera* camera = new osg::Camera;


        camera->setViewport( 0, 0, this->width(), this->height() );


        camera->setClearColor( osg::Vec4( 0.9f, 0.9f, 1.f, 1.f ) );


        float aspectRatio = static_cast<float>( this->width()) / static_cast<float>( this->height() );


        camera->setProjectionMatrixAsPerspective( 30.f, aspectRatio, 1.f, 1000.f );


        camera->setGraphicsContext( _mGraphicsWindow );




        _mViewer->setCamera(camera);


        _mViewer->setSceneData(root);


        osgGA::TrackballManipulator* manipulator = new osgGA::TrackballManipulator;


        manipulator->setAllowThrow( false );


        this->setMouseTracking(true);


        _mViewer->setCameraManipulator(manipulator);


        _mViewer->setThreadingModel(osgViewer::Viewer::SingleThreaded);


        _mViewer->realize();


        




      }


 virtual void paintGL() {


    _mViewer->frame();


  }


int main(int argc, char** argv)


{


    QSurfaceFormat glFormat;


    glFormat.setVersion(3, 3);


    glFormat.setProfile(QSurfaceFormat::CoreProfile);


    glFormat.setSamples(4); //anti aliasing


    QSurfaceFormat::setDefaultFormat(glFormat);




    QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);




    QApplication qapp(argc, argv);


    QMainWindow window;


    QtOSGWidget* widget = new QtOSGWidget(&window);




    window.setCentralWidget(widget);


    window.show();




    return qapp.exec();


}


When running directly through OpenSceneGraph i get the result i want, i 
post the code for clarity


    QSurfaceFormat glFormat;


    glFormat.setVersion(3, 3);


    glFormat.setProfile(QSurfaceFormat::CoreProfile);


    glFormat.setSamples(4); //anti aliasing


    QSurfaceFormat::setDefaultFormat(glFormat);




    QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);




    osg::Group* root = new osg::Group;


    osgViewer::Viewer viewer;




    osg::Camera* camera = new osg::Camera;


    camera->setReferenceFrame(osg::Transform::ABSOLUTE_RF);


    camera->setProjectionMatrixAsOrtho2D(0,1280,0,1024);


    camera->setViewMatrix(osg::Matrix::identity());




    camera->getOrCreateStateSet()->setMode(GL_LIGHTING,osg::StateAttribute::OFF);


    camera->setClearColor(osg::Vec4(1.0,1.0,1.0,1.0));


    camera->setClearMask(


    GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT|GL_STENCIL_BUFFER_BIT


    );




    camera->setCullingMode(osg::CullStack::SMALL_FEATURE_CULLING);


    camera->addChild(root);


    osgText::Text* text = new osgText::Text();


    text->setText("ABRAKADABRA");


    text->setCharacterSize(14);


    text->setCharacterSizeMode(osgText::Text::CharacterSizeMode::SCREEN_COORDS);


    text->setAutoRotateToScreen(true);


    text->setColor(osg::Vec4(0, 0, 0, 1));


    text->setPosition(osg::Vec3(500,500,0));



    osg::Geode* drawableText = new osg::Geode;


    drawableText->addDrawable(text);


    root->addChild(drawableText);


    viewer.setThreadingModel(osgViewer::Viewer::SingleThreaded);


    viewer.setSceneData(camera);


    viewer.realize();


    return viewer.run();

Ange koden här...

The result can be compared in this image https://imgur.com/a/S7IsZs5. Now i 
have tried to fiddle with millions of parameters but i cannot understand 
how to solve this behaviour. Does anybody have an idea what causes it and 
how to prevent it?

I am relying on integration with Qt in my application so it is a necessity 
that it works together.
Thanks 

//Regards Dan

Den onsdag 20 november 2019 kl. 16:08:46 UTC+1 skrev Robert Osfield:
>
> Hi Dan,
>
> On Wed, 20 Nov 2019 at 14:54, Dan johansson <johans... at hotmail.com 
> <javascript:>> wrote:
>
>> I understand its difficult to help with such little information, 
>> unfortunately that is all there is so i cannot provide more code regarding 
>> this specific case. The osgtext example looks splendid, i copied and 
>> replaced my code with an example there and it now looks much cleaner. I'm 
>> still clueless as to what caused the issue. I can add i have built OSG with 
>> core profile and disabled the shader pipeline, but i am still wondering 
>> what actual renders the text as i haven't added a shader program to it in 
>> the way i would with a geode/geometry structure.
>>
>
> Are you using OSG from github master or the stable 3.6.x or other 
> release?  If you are using master I'd recommend using the latest 3.6.4 
> release as it doesn't include the experimental shader pipeline work.
>
> From 3.6.x onwards osgText provides it's own shaders so you don't need to 
> provide them yourself.  I can't provide any guesses as to what is wrong 
> with your original code, the best thing I can do is to recommend comparing 
> the example code to your own to see what differences there are.
>
> Cheers,
> Robert.
>

-- 
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+unsubscribe at googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/osg-users/5369a0aa-c85c-4db5-8692-1c5ff356bc07%40googlegroups.com.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openscenegraph.org/pipermail/osg-users-openscenegraph.org/attachments/20200127/e2fc66ab/attachment-0001.html>


More information about the osg-users mailing list