[osg-users] osgQt aspect ratio issue when inside QMainWindow
OpenSceneGraph Users
osg-users at lists.openscenegraph.org
Tue Feb 25 05:32:00 PST 2020
Hi Mohamed,
thank you for your reply. Actually, the methods initializeGL, resizeGL
and paintGL are not virtual and are already implemented inside the
osgQOpenGLWidget class.
Probably there's some function inside these methods that is called only
once, probably at window initialization, or that is effective only the at
the first time.
I am currently reading the code but I am not an expert on OpenSceneGraph
and I can't figure out what's missing (i.e. why window resize causes just
an image stretch).
Il giorno lunedì 24 febbraio 2020 14:14:53 UTC+1, mohamed selim ha scritto:
>
> 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+unsubscribe at googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/osg-users/3dddce23-89d9-4b0f-b8c7-bd9e429ef36e%40googlegroups.com.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openscenegraph.org/pipermail/osg-users-openscenegraph.org/attachments/20200225/03944926/attachment.html>
More information about the osg-users
mailing list