Important: Please read the Qt Code of Conduct -

OpenGL glBegin(GL_TRIANGLES) work only first time

  • Hi all,
    first of all I'm completely new in OpenGL and Initiate in Qt )
    I try relate Qml and OpenGL, so I take example openglunderqml
    as in example I create own class
    @class QProject1Main : public QQuickItem

    void QProject1Main::handleWindowChanged(QQuickWindow *win) {
    if (win) {
    connect(win, SIGNAL(beforeRendering()), this, SLOT(paint()), Qt::DirectConnection);

    void QProject1Main::paint() {
    qDebug() << "QProject1Main::paint()";
    qreal ratio = window()->devicePixelRatio();
    int w = int(ratio * window()->width());
    int h = int(ratio * window()->height());
    glViewport(0, 0, w, h);

    // each iteration bg color change from green to read
    glClearColor(((float)++idx)/100, 0.3, 0.3, 1);


    // triangle pain only at first iteration
    glColor3f(0.5f, 0.5f, 0.5f);
    glVertex3f( 0.1f, 0.8f, 0.1f);
    glVertex3f(-0.8f,-0.8f, 0.1f);
    glVertex3f( 0.8f,-0.8f, 0.1f);

    I'm resize window to call paint method and see that background color changed but triangle paint only first time (

  • I'm add timer to my QML but receive same problem triangle visible only first time

    Window {
    id: wndMain
    visible: true
    width: 360
    height: 360

    QProject1Main {
        id: core
        anchors.fill: parent
    Text {
        text: qsTr("Black rectangle - it's OpenGL baby ;)")
        anchors.centerIn: parent
        color: "red"
    Timer {
            id: tGameTimer
            interval: 29
            running: true
            repeat: true
            onTriggered: {
                console.log("timer paint call")


  • in article class SquircleRenderer exists but in examples it's not esists

  • hey all
    any body know how to call SwapBuffers?

  • I've had the same problem. After the first frame, everything I draw is condensed to the lower left corner of the window. I've not come to a definite answer, but my guess here is that QtQuick doesn't cooperate well with the obsolete fixed function pipeline of OpenGL. It seems to tamper with some state variables.

    Try using custom shaders.

  • Try using custom shaders.
    are you mean create something like Geometry Shaders and move triangle with sync as in example?
    I'll try, thank you

  • The geometry shader is optional, you'll probably only need vertex and pixel shader.

    Although there are other ways, the "OpenGL under QML" example is probably a good place to start from:

  • yes, I take code from this example, thank you

Log in to reply