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.
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();
}
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...Hi Robert !
I just want to bump this to tell the issue have been resolved. On the last code snippet i posted you can see i create a new camera, set the graphics context and set the viewers camera to this one. This was what caused the issue and when i instead extracted the associated camera directly from the viewer and set the graphics context it solved the issue. I'm not exactly sure why this is happening, maybe you understand that better then me :) But its definitely the reason causing the bug