Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. OpenGL based QQuickItem can't rendering with other QML elements at the same time

OpenGL based QQuickItem can't rendering with other QML elements at the same time

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
1 Posts 1 Posters 278 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • 0 Offline
    0 Offline
    0x5FB5
    wrote on last edited by
    #1

    I'm new in Qt/OpenGL stuff and I've created an OpenGL based QQuickItem class that should render 3D.
    If I use it without any QML elements in scene it works, but when I set together something like Rectangle, I only can see black rectangle instead of 3D render. What's wrong?
    1255a310-d6ce-49ce-ae59-5b83f93ed076-image.png
    ec07645d-915d-4db5-8c98-39bae1f994ea-image.png

    For example, this is how render works:

    GLWindow::GLWindow(QQuickItem *parent) : QQuickItem(parent)
    {
        setFlag(QQuickItem::ItemHasContents, true);
    
        frameTimer = new QTimer(this);
    
        connect(this, &GLWindow::windowChanged, this, &GLWindow::handleWindowChanged);
        connect(frameTimer, &QTimer::timeout, this, &GLWindow::updateScene);
    
        frameTimer->start(FRAMERATE_MS);
    }
    
    void GLWindow::updateScene()
    {
        if (window())
            window()->update();
    }
    
    void GLWindow::render()
    {
        initializeOpenGLFunctions();
    
        glClearColor(0.f, 0.f, 0.f, 1.f);
    
        QPoint cursorPos = QCursor::pos();
    
        // VIEWPORT
        qreal ratio = window()->devicePixelRatio();
    
        GLint x = static_cast<GLint>(ratio * parentItem()->x());
        GLint y = static_cast<GLint>(ratio * parentItem()->y());
        GLsizei w = static_cast<GLsizei>(ratio * parentItem()->width());
        GLsizei h = static_cast<GLsizei>(ratio * parentItem()->height());
    
        glViewport(x, y, w, h);
    
        glEnable(GL_DEPTH_TEST);
        glEnable(GL_SCISSOR_TEST);
    
        glScissor(x, y, w, h);
    
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    
        glDisable(GL_SCISSOR_TEST);
        glDisable(GL_DEPTH_TEST);
    
       // Rendering stuff...
    }
    
    void GLWindow::handleWindowChanged(QQuickWindow *win)
    {
        if (win) {
            connect(win, &QQuickWindow::afterRendering, this, &GLWindow::render, Qt::DirectConnection);
            win->setClearBeforeRendering(true);
        }
    }
    
    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved