Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Game Development
  4. OpenGL glBegin(GL_TRIANGLES) work only first time
Forum Updated to NodeBB v4.3 + New Features

OpenGL glBegin(GL_TRIANGLES) work only first time

Scheduled Pinned Locked Moved Game Development
8 Posts 2 Posters 4.1k Views 1 Watching
  • 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.
  • G Offline
    G Offline
    Galbarad
    wrote on last edited by
    #1

    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);
    win->setClearBeforeRendering(false);
    }
    }

    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);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    glLoadIdentity();
    

    // triangle pain only at first iteration
    glColor3f(0.5f, 0.5f, 0.5f);
    glBegin(GL_TRIANGLES);
    glVertex3f( 0.1f, 0.8f, 0.1f);
    glVertex3f(-0.8f,-0.8f, 0.1f);
    glVertex3f( 0.8f,-0.8f, 0.1f);
    glEnd();
    }
    @

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

    1 Reply Last reply
    0
    • G Offline
      G Offline
      Galbarad
      wrote on last edited by
      #2

      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")
                  wndMain.update()
              }
      }
      

      }
      @

      1 Reply Last reply
      0
      • G Offline
        G Offline
        Galbarad
        wrote on last edited by
        #3

        in article http://qt-project.org/doc/qt-5/qtquick-scenegraph-openglunderqml-example.html class SquircleRenderer exists but in examples openglunderqml.pro it's not esists

        1 Reply Last reply
        0
        • G Offline
          G Offline
          Galbarad
          wrote on last edited by
          #4

          hey all
          any body know how to call SwapBuffers?

          1 Reply Last reply
          0
          • C Offline
            C Offline
            Cmdr
            wrote on last edited by
            #5

            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.

            1 Reply Last reply
            0
            • G Offline
              G Offline
              Galbarad
              wrote on last edited by
              #6

              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

              1 Reply Last reply
              0
              • C Offline
                C Offline
                Cmdr
                wrote on last edited by
                #7

                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:

                http://qt-project.org/doc/qt-5/qtquick-scenegraph-openglunderqml-example.html

                1 Reply Last reply
                0
                • G Offline
                  G Offline
                  Galbarad
                  wrote on last edited by
                  #8

                  yes, I take code from this example, thank you

                  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