Hi Angelo,

I believe you should handle from the osgQOpenGLWidget virtual methods, 
which should be something like virtual void resizeGL( int width, int height ); 

As it's expected it should be called whenever there's a change in the 
widget size. From there you would be able to call 
osgViewer::GraphicsWindowEmbedded 
resized method as 
well as camera's necessary adjustment for the new size and most important 
the aspect ration for this new size.


On Thursday, February 20, 2020 at 3:12:43 PM UTC+1, Angelo Emanuele 
Fiorilla wrote:
>
> 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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/osg-users/dcfa7c78-c750-428c-ae4a-8db831fed0a2%40googlegroups.com.
_______________________________________________
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to