Results 1 to 3 of 3

Thread: Render OpenGL graphics in a child window

  1. #1
    Join Date
    Apr 2024
    Posts
    2
    Qt products
    Qt5
    Platforms
    Windows

    Unhappy Render OpenGL graphics in a child window

    Hi there,

    I followed an online guide and can render OpenGL image in a QML QQuickItem now.

    As shown in the picture:
    qml_picture01.jpg

    The black wireframe in left is defined as QQuickItem area (OpenGL rendering area, 800 * 600 px), but we can see, the rendered OpenGL result shows in the whole background.

    In my software, I'll have a few components shown on the screen. OpenGL render area should be in one of the components. Say, stay in right-lower corner of the screen.

    Can I render OpenGL in a child window? And can I place the child window in the place I want?

    Any suggestions for me?
    And have I made it clear for you?

    I tried to create a new QQuickWindow. But it shows as a stand alone window not as a child window or a part of the background.

    Thank you.

  2. #2
    Join Date
    Jul 2008
    Location
    Germany
    Posts
    507
    Thanks
    11
    Thanked 76 Times in 74 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Render OpenGL graphics in a child window

    Hi, can you show us your code?

    Ginsengelf

  3. #3
    Join Date
    Apr 2024
    Posts
    2
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Render OpenGL graphics in a child window

    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:

    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
    }
    }
    This is a piece of "main.cpp":


    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:


    void OGLRender:aint()
    {
    m_window->beginExternalCommands();
    render();
    m_window->endExternalCommands();
    }
    I wrote the code referencing this tutorial:
    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.

Similar Threads

  1. Render child widget relative to paint event rectangles
    By jmalicke in forum Qt Programming
    Replies: 3
    Last Post: 8th March 2016, 22:20
  2. Do offscreen render(openGL) with Qt5
    By stereoMatching in forum Qt Programming
    Replies: 4
    Last Post: 26th June 2013, 11:34
  3. Render image on QLabel using openGl
    By vinodpaul in forum Newbie
    Replies: 2
    Last Post: 14th August 2012, 17:57
  4. OpenGL render to texture
    By Nicuvëo in forum Qt Programming
    Replies: 2
    Last Post: 26th March 2011, 12:07
  5. Add OpenGl window to the grid layout of the child qwidget.
    By pastispast in forum Qt Programming
    Replies: 1
    Last Post: 26th November 2010, 21:09

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.