<div dir="ltr">Hi,<div>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).</div><div>Can you help me, please? I have been struggling with this few lines of code for 5 days now.</div><div><br></div><div>I can provide source code as follows...</div><div><br></div><div>Thank you so much</div><div><br></div><div><pre style="background-color:#2b2b2b;color:#a9b7c6;font-family:'DejaVu Sans Mono';font-size:9.0pt;"><span style="color:#bbb529;">#include </span><span style="color:#6a8759;">"mainwindow.h"<br></span><span style="color:#6a8759;"><br></span><span style="color:#b5b6e3;">MainWindow</span>::<span style="color:#ffc66d;">MainWindow</span>(<span style="color:#b5b6e3;">QWidget </span>*parent)<br>        : <span style="color:#b5b6e3;">QMainWindow</span>(parent)<br>{<br>    <span style="color:#b5b6e3;">QSurfaceFormat </span>format = <span style="color:#b5b6e3;">QSurfaceFormat</span>::defaultFormat()<span style="color:#cc7832;">;<br></span><span style="color:#cc7832;">    </span>format.setVersion(<span style="color:#6897bb;">2</span><span style="color:#cc7832;">, </span><span style="color:#6897bb;">0</span>)<span style="color:#cc7832;">;<br></span><span style="color:#cc7832;">    </span>format.setProfile(<span style="color:#b5b6e3;">QSurfaceFormat</span>::<span style="color:#9876aa;font-style:italic;">CompatibilityProfile</span>)<span style="color:#cc7832;">;<br></span><span style="color:#cc7832;">    </span>format.setRenderableType(<span style="color:#b5b6e3;">QSurfaceFormat</span>::<span style="color:#9876aa;font-style:italic;">OpenGL</span>)<span style="color:#cc7832;">;<br></span><span style="color:#cc7832;">    </span>format.setOption(<span style="color:#b5b6e3;">QSurfaceFormat</span>::<span style="color:#9876aa;font-style:italic;">DebugContext</span>)<span style="color:#cc7832;">;<br></span><span style="color:#cc7832;">    </span>format.setDepthBufferSize(<span style="color:#6897bb;">24</span>)<span style="color:#cc7832;">;<br></span><span style="color:#cc7832;">    </span>format.setSamples(<span style="color:#6897bb;">8</span>)<span style="color:#cc7832;">;<br></span><span style="color:#cc7832;">    </span>format.setStencilBufferSize(<span style="color:#6897bb;">8</span>)<span style="color:#cc7832;">;<br></span><span style="color:#cc7832;">    </span>format.setSwapBehavior(<span style="color:#b5b6e3;">QSurfaceFormat</span>::<span style="color:#9876aa;font-style:italic;">DoubleBuffer</span>)<span style="color:#cc7832;">;<br></span><span style="color:#cc7832;">    </span><span style="color:#b5b6e3;">QSurfaceFormat</span>::setDefaultFormat(format)<span style="color:#cc7832;">;<br></span><span style="color:#cc7832;"><br></span><span style="color:#cc7832;">    </span><span style="color:#9373a5;">osgWidget </span>= <span style="color:#cc7832;">new </span><span style="color:#b5b6e3;">osgQOpenGLWidget</span>(<span style="color:#cc7832;">this</span>)<span style="color:#cc7832;">;<br></span><span style="color:#cc7832;">    </span><span style="color:#b5b6e3;">QObject</span>::connect(<span style="color:#9373a5;">osgWidget</span><span style="color:#cc7832;">, </span>&<span style="color:#b5b6e3;">osgQOpenGLWidget</span>::initialized<span style="color:#cc7832;">, this, </span>&<span style="color:#b5b6e3;">MainWindow</span>::setupOsgView)<span style="color:#cc7832;">;<br></span><span style="color:#cc7832;"><br></span><span style="color:#808080;">    </span>setCentralWidget(<span style="color:#9373a5;">osgWidget</span>)<span style="color:#cc7832;">;<br></span><span style="color:#cc7832;">    </span><span style="color:#9373a5;">osgWidget</span>->show()<span style="color:#cc7832;">;<br></span>}<br><br><span style="color:#cc7832;">void </span><span style="color:#b5b6e3;">MainWindow</span>::<span style="color:#ffc66d;">setupOsgView</span>() {<br><br>    <span style="color:#9373a5;">osgWidget</span>->getOsgViewer()->setCameraManipulator(<span style="color:#cc7832;">new </span><span style="color:#b5b6e3;">osgGA</span>::<span style="color:#b5b6e3;">TerrainManipulator</span>())<span style="color:#cc7832;">;<br></span><span style="color:#cc7832;">    </span><span style="color:#9373a5;">osgWidget</span>->getOsgViewer()->addEventHandler(<span style="color:#cc7832;">new </span><span style="color:#b5b6e3;">osgGA</span>::<span style="color:#b5b6e3;">StateSetManipulator</span>(<span style="color:#9373a5;">osgWidget</span>->getOsgViewer()->getCamera()->getOrCreateStateSet()))<span style="color:#cc7832;">;<br></span><span style="color:#cc7832;">    </span><span style="color:#9373a5;">osgWidget</span>->getOsgViewer()->addEventHandler(<span style="color:#cc7832;">new </span><span style="color:#b5b6e3;">osgViewer</span>::<span style="color:#b5b6e3;">ThreadingHandler</span>)<span style="color:#cc7832;">;<br></span><span style="color:#cc7832;">    </span><span style="color:#9373a5;">osgWidget</span>->getOsgViewer()->addEventHandler(<span style="color:#cc7832;">new </span><span style="color:#b5b6e3;">osgViewer</span>::<span style="color:#b5b6e3;">WindowSizeHandler</span>)<span style="color:#cc7832;">;<br></span><span style="color:#cc7832;">    </span><span style="color:#9373a5;">osgWidget</span>->getOsgViewer()->addEventHandler(<span style="color:#cc7832;">new </span><span style="color:#b5b6e3;">osgViewer</span>::<span style="color:#b5b6e3;">StatsHandler</span>)<span style="color:#cc7832;">;<br></span><span style="color:#cc7832;">    </span><span style="color:#9373a5;">osgWidget</span>->getOsgViewer()->addEventHandler(<span style="color:#cc7832;">new </span><span style="color:#b5b6e3;">osgViewer</span>::<span style="color:#b5b6e3;">RecordCameraPathHandler</span>)<span style="color:#cc7832;">;<br></span><span style="color:#cc7832;">    </span><span style="color:#9373a5;">osgWidget</span>->getOsgViewer()->addEventHandler(<span style="color:#cc7832;">new </span><span style="color:#b5b6e3;">osgViewer</span>::<span style="color:#b5b6e3;">LODScaleHandler</span>)<span style="color:#cc7832;">;<br></span><span style="color:#cc7832;">    </span><span style="color:#9373a5;">osgWidget</span>->getOsgViewer()->addEventHandler(<span style="color:#cc7832;">new </span><span style="color:#b5b6e3;">osgViewer</span>::<span style="color:#b5b6e3;">ScreenCaptureHandler</span>)<span style="color:#cc7832;">;<br></span><span style="color:#cc7832;"><br></span><span style="color:#cc7832;">    </span><span style="color:#b5b6e3;">osg</span>::<span style="color:#b5b6e3;">ref_ptr</span><<span style="color:#b5b6e3;">osg</span>::<span style="color:#b5b6e3;">Node</span>> loadedModel = <span style="color:#b5b6e3;">osgDB</span>::readRefNodeFile(<span style="color:#6a8759;">"cow.osg"</span>)<span style="color:#cc7832;">;<br></span><span style="color:#cc7832;">    if</span>(<span style="color:#5f8c8a;">!</span>loadedModel) {<br>        <span style="color:#b5b6e3;">std</span>::cout <span style="color:#5f8c8a;"><< </span><span style="color:#6a8759;">"No data loaded" </span><span style="color:#5f8c8a;"><< </span><span style="color:#b5b6e3;">std</span>::endl<span style="color:#cc7832;">;<br></span><span style="color:#cc7832;">    </span>}<br><br>    <span style="color:#b5b6e3;">osgUtil</span>::<span style="color:#b5b6e3;">Optimizer </span>optimizer<span style="color:#cc7832;">;<br></span><span style="color:#cc7832;">    </span>optimizer.optimize(loadedModel)<span style="color:#cc7832;">;<br></span><span style="color:#cc7832;"><br></span><span style="color:#cc7832;">    </span><span style="color:#9373a5;">osgWidget</span>->getOsgViewer()->setSceneData(loadedModel)<span style="color:#cc7832;">;<br></span>}<br><br><span style="color:#b5b6e3;">MainWindow</span>::<span style="color:#ffc66d;">~MainWindow</span>()<br>{<br><br>}</pre></div></div>

<p></p>

-- <br />
You received this message because you are subscribed to the Google Groups "OpenSceneGraph Users" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an email to <a href="mailto:osg-users+unsubscribe@googlegroups.com">osg-users+unsubscribe@googlegroups.com</a>.<br />
To view this discussion on the web visit <a href="https://groups.google.com/d/msgid/osg-users/af2c229c-e76e-4b27-9a22-06d3ecd5935a%40googlegroups.com?utm_medium=email&utm_source=footer">https://groups.google.com/d/msgid/osg-users/af2c229c-e76e-4b27-9a22-06d3ecd5935a%40googlegroups.com</a>.<br />