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. How to: Smooth rendering mainloop ?!? [solved]
QtWS25 Last Chance

How to: Smooth rendering mainloop ?!? [solved]

Scheduled Pinned Locked Moved Game Development
10 Posts 4 Posters 3.9k 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.
  • T Offline
    T Offline
    the_scrabi
    wrote on last edited by
    #1

    How is it possible to crate a main loop for a game that renders smoothly, and doesn't create an overheat? In Glut i'd use glutIdleFunc() but what to do in Qt?

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      What version of Qt are you using ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • T Offline
        T Offline
        the_scrabi
        wrote on last edited by
        #3

        qt5.1

        1 Reply Last reply
        0
        • M Offline
          M Offline
          matti-
          wrote on last edited by
          #4

          Something wrong with QTimer?

          Author of <a href="http://mmark.777-team.org/">MMark13</a>

          1 Reply Last reply
          0
          • T Offline
            T Offline
            the_scrabi
            wrote on last edited by
            #5

            This example here witch i run on X11/Linux tends to create tiny framebloopers. Could it be that Qpainter is creating that bloopers?
            @
            Test::Test()
            :QWidget()
            ,timer(new QTimer())
            {
            connect(timer, SIGNAL(timeout()),
            this, SLOT(mainLoop()));
            resize(600, 600);
            timer->start(1000/60);
            }

            void Test::mainLoop()
            {
            repaint();
            }

            void Test::paintEvent(QPaintEvent *e)
            {
            static int x = 0;
            static int y = 0;
            QPainter painter(this);
            painter.setViewport(0, 0, width(), height());
            painter.setWindow(0, 0, width(), height());

                painter.setPen(QPen(Qt::black)); 
                painter.drawRect(++x, ++y, 50, 50); 
            

            }
            @

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              There's something strange here, you were talking about OpenGL and now you're using the QPainter api. So what do you want to achieve ?

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0
              • JKSHJ Offline
                JKSHJ Offline
                JKSH
                Moderators
                wrote on last edited by
                #7

                [quote author="SGaist" date="1380570030"]There's something strange here, you were talking about OpenGL and now you're using the QPainter api. So what do you want to achieve ?[/quote]I think the_scrabi said "If I were to use the OpenGL Utility Toolkit, I'd use glutIdleFunc(). How do I accomplish the same effect in Qt (not GLUT)?"

                [quote author="the_scrabi" date="1380559312"]
                timer->start(1000/60);
                [/quote]QTimer::start() takes an integer so 1000/60 == 17 (not 16.66667). Your repaints will be slower than your screen refresh rate.

                I don't do graphics programming so I don't know the best solution to your problem, but have you looked at Qt's OpenGL functions? See the "QOpenGL*" classes in http://qt-project.org/doc/qt-5.1/qtgui/qtgui-module.html This example might also be useful: http://qt-project.org/doc/qt-5.1/qtgui/openglwindow.html

                Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

                1 Reply Last reply
                0
                • SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  [quote author="JKSH" date="1380588497"][quote author="SGaist" date="1380570030"]There's something strange here, you were talking about OpenGL and now you're using the QPainter api. So what do you want to achieve ?[/quote]I think the_scrabi said "If I were to use the OpenGL Utility Toolkit, I'd use glutIdleFunc(). How do I accomplish the same effect in Qt (not GLUT)?"[/quote]
                  Indeed that's what I understood, so I thought that he wanted to know what could replace glutIdleFunc when using OpenGL with Qt

                  Interested in AI ? www.idiap.ch
                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                  1 Reply Last reply
                  0
                  • T Offline
                    T Offline
                    the_scrabi
                    wrote on last edited by
                    #9

                    I need to apologize. I'm learning OpenGL at the moment, so I didn't use it in my Code above. I thought Qpainter would do it … it didn't, hence i rewrote everything using OpenGL and Qtimer and yes there are no framebloopers anymore. But that kind of confuses me... isn't Qpainter based on OpenGL in Qt5 ?!?

                    Here is the code: http://pastebin.com/AYQ3GkEV

                    Also this example here (http://qt-project.org/doc/qt-5.1/qtgui/openglwindow.html) confused me a bit. It doesn't use Qtimer to generate an animation.

                    1 Reply Last reply
                    0
                    • SGaistS Offline
                      SGaistS Offline
                      SGaist
                      Lifetime Qt Champion
                      wrote on last edited by
                      #10

                      QPainter can make use of OpenGL but not necessarily, and you can also use OpenGL code directly (it all depend on what you want to do)

                      Anyway, the example shows another way to trigger the update of the window using QEvent::UpdateRequest. Event which will be handled in the event() function. Following the code path, the event handling will do a call to renderNow(), and at the end of it, renderLater() is called, which will queue a new UpdateRequest and all starts again

                      Interested in AI ? www.idiap.ch
                      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                      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