1

I used to cap the render framerate in GLFW using the function.

glfwSwapInterval(1);

Now i am building a Opengl project in QT using the Qt opengl features.

in the main function i set the global value.

QGLFormat  format;
    format.setDepthBufferSize(24);
    format.setStencilBufferSize(8);
    format.setSampleBuffers(true);
    format.setSamples(4);
    format.setSwapInterval(1);
    QGLFormat::setDefaultFormat(format);

This is how the Qt opengl class header looks like.

   class GLWidget : public  QGLWidget
{
    Q_OBJECT;
public:
    explicit GLWidget(QWidget *parent = 0);
    void initializeGL() override;
    void paintGL() override;
    void resizeGL(int w, int h) override;
    QTimer timer;

};

In the constructor for the class

 GLWidget::GLWidget(QWidget *parent) :QGLWidget(parent)
{
    connect(&timer, &QTimer::timeout, this, [&]() {  
        QElapsedTimer elapsedtimer;
        elapsedtimer.start();
        updateGL();
        qDebug() << elapsedtimer.elapsed();
    });
    timer.setInterval(0);
    timer.start();
}

But still the render loop is not synced the Qdebug values keeps varying from 8 to 16.

Summit
  • 2,112
  • 2
  • 12
  • 36
  • 3
    See [`QGLFormat::setSwapInterval`](https://doc.qt.io/qt-5/qglformat.html#setSwapInterval). Note, however, that [`QGLWidget` is obsolete](https://doc.qt.io/qt-5/qglwidget.html). Assuming you're using Qt5 you should consider using [`QOpenGLWidget`](https://doc.qt.io/qt-5/qopenglwidget.html) instead. – G.M. Sep 03 '20 at 07:28
  • @G.M thanks for your reply , i have updated the question based on your input but still the render loop is not synced. – Summit Sep 03 '20 at 11:11
  • 1
    The code shown works for me -- `paintGL` is invoked at a rate of 60Hz. Are you sure you're not confusing the rate rate at which `updateGL` is called rather than `paintGL`? They're not the same thing. – G.M. Sep 03 '20 at 12:33
  • @G.M The debug output varies from " qDebug() << elapsedtimer.elapsed();" 9 to 16 does not stay at constant rate. – Summit Sep 04 '20 at 02:37
  • @G.M i might be confusing the difference between updateGL and paintGL , how can i calculate the frame rate of paintGL ? – Summit Sep 04 '20 at 02:47
  • 1
    As a starting point, put a `qDebug` statement in your `paintGL` implementation that outputs the current frame number and timestamp. – G.M. Sep 04 '20 at 07:36

0 Answers0