[osg-users] osgQt aspect ratio issue when inside QMainWindow
OpenSceneGraph Users
osg-users at lists.openscenegraph.org
Thu Feb 20 02:50:45 PST 2020
Hi,
I am trying to put an osgQOpenGLWidget inside a QMainWindow. I managed to
made it quite easily but the resulting image is stretched and I cannot
change its aspect ratio to made it right (the cow.osg is really stretched).
Can you help me, please? I have been struggling with this few lines of code
for 5 days now.
I can provide source code as follows...
Thank you so much
#include "mainwindow.h"
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
{
QSurfaceFormat format = QSurfaceFormat::defaultFormat();
format.setVersion(2, 0);
format.setProfile(QSurfaceFormat::CompatibilityProfile);
format.setRenderableType(QSurfaceFormat::OpenGL);
format.setOption(QSurfaceFormat::DebugContext);
format.setDepthBufferSize(24);
format.setSamples(8);
format.setStencilBufferSize(8);
format.setSwapBehavior(QSurfaceFormat::DoubleBuffer);
QSurfaceFormat::setDefaultFormat(format);
osgWidget = new osgQOpenGLWidget(this);
QObject::connect(osgWidget, &osgQOpenGLWidget::initialized, this, &MainWindow::setupOsgView);
setCentralWidget(osgWidget);
osgWidget->show();
}
void MainWindow::setupOsgView() {
osgWidget->getOsgViewer()->setCameraManipulator(new osgGA::TerrainManipulator());
osgWidget->getOsgViewer()->addEventHandler(new osgGA::StateSetManipulator(osgWidget->getOsgViewer()->getCamera()->getOrCreateStateSet()));
osgWidget->getOsgViewer()->addEventHandler(new osgViewer::ThreadingHandler);
osgWidget->getOsgViewer()->addEventHandler(new osgViewer::WindowSizeHandler);
osgWidget->getOsgViewer()->addEventHandler(new osgViewer::StatsHandler);
osgWidget->getOsgViewer()->addEventHandler(new osgViewer::RecordCameraPathHandler);
osgWidget->getOsgViewer()->addEventHandler(new osgViewer::LODScaleHandler);
osgWidget->getOsgViewer()->addEventHandler(new osgViewer::ScreenCaptureHandler);
osg::ref_ptr<osg::Node> loadedModel = osgDB::readRefNodeFile("cow.osg");
if(!loadedModel) {
std::cout << "No data loaded" << std::endl;
}
osgUtil::Optimizer optimizer;
optimizer.optimize(loadedModel);
osgWidget->getOsgViewer()->setSceneData(loadedModel);
}
MainWindow::~MainWindow()
{
}
--
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/af2c229c-e76e-4b27-9a22-06d3ecd5935a%40googlegroups.com.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openscenegraph.org/pipermail/osg-users-openscenegraph.org/attachments/20200220/322b9153/attachment.html>
More information about the osg-users
mailing list