Thank you, Ginsengelf.
The code is quite scattered, I'll try to Jigsaw it out.
OpenGLItem in the "Main.qml" piece is the QQuickItem to render OpenGL scene:
This is a piece of "main.cpp":
OpenGLItem {
id: openGLItem
visible: true
anchors.top: tab1.bottom
width: 800
height: 600
Rectangle {
anchors.fill: parent
color: "transparent"
border.color: "black"
border.width: 1
}
}
int main(int argc, char *argv[])
{
// QCoreApplication::setAttribute(Qt::AA_EnableHighDp iScaling);
QGuiApplication app(argc, argv);
// For OpenGL rendering
QQuickWindow::setGraphicsApi(QSGRendererInterface: :OpenGL);
// Register OpenGL rendering QQuickItem
qmlRegisterType<OpenGLItem>("com.OpenGLItem", 1, 0, "OpenGLItem");
// Register Object receiving function calls from QML to C++
qmlRegisterType<Tab1Panel>("com.tab1panel", 1, 0, "Tab1Panel");
QQmlApplicationEngine engine;
const QUrl url(u"qrc:/Slicer3D/Main.qml"_qs);
QObject::connect(
&engine,
&QQmlApplicationEngine:bjectCreationFailed,
&app,
[]() { QCoreApplication::exit(-1); },
Qt::QueuedConnection);
engine.load(url);
Here "render()" is to render OpenGL scene, "m_window" is from "window()" method call of "OpenGLItem", the QQuickItem:
I wrote the code referencing this tutorial:
void OGLRender:aint()
{
m_window->beginExternalCommands();
render();
m_window->endExternalCommands();
}
https://doc.qt.io/qt-6/qtquick-scene...l-example.html
As we can see, in the code, we don't have a chance to assign any window handle to OpenGL.
I think OpenGL just is rendered on the whole background of application window.
My current solution is to render OpenGL scene to an offscreen framebuffer,
And draw the rendered buffer with 2 triangles on to part of the application window background.
Say, We set top-left vertex as -1.0, 1.0,
bottom-right vertex as 0.0, 0.0,
The OpenGL scene would be rendered in top-left quarter of the screen.
But resizing the window makes the OpenGL scene showing deformed.
My solution is to fix the application window as maximized size.
That's my current solution, not easy and not quite good, I have to say.
Bookmarks