#include <QtCore/QElapsedTimer>
#include <QtGui/QOpenGLFunctions>
#include <QtGui/QSurfaceFormat>
#include <QtOpenGL/QOpenGLWindow>
#include <QtWidgets/QApplication>
class OpenGLWindow : public QOpenGLWindow, private QOpenGLFunctions
{
public:
OpenGLWindow()
{
setTitle("OpenGL ES 2.0, Qt6, C++");
resize(380, 380);
QSurfaceFormat surfaceFormat;
surfaceFormat.setSwapInterval(1);
connect(this, SIGNAL(frameSwapped()), this, SLOT(update()));
setFormat(surfaceFormat);
}
private:
void initializeGL() override
{
initializeOpenGLFunctions();
glClearColor(0.2f, 0.2f, 0.2f, 1.f);
m_elapsedTimer.start();
}
void resizeGL(int w, int h) override
{
glViewport(0, 0, w, h);
}
void paintGL() override
{
float dt = m_elapsedTimer.elapsed() / 1000.f;
m_elapsedTimer.restart();
qDebug() << dt;
glClear(GL_COLOR_BUFFER_BIT);
}
private:
QElapsedTimer m_elapsedTimer;
};
int main(int argc, char *argv[])
{
QApplication::setAttribute(Qt
::ApplicationAttribute::AA_UseDesktopOpenGL);
OpenGLWindow w;
w.show();
return app.exec();
}
#include <QtCore/QElapsedTimer>
#include <QtGui/QOpenGLFunctions>
#include <QtGui/QSurfaceFormat>
#include <QtOpenGL/QOpenGLWindow>
#include <QtWidgets/QApplication>
class OpenGLWindow : public QOpenGLWindow, private QOpenGLFunctions
{
public:
OpenGLWindow()
{
setTitle("OpenGL ES 2.0, Qt6, C++");
resize(380, 380);
QSurfaceFormat surfaceFormat;
surfaceFormat.setSwapInterval(1);
connect(this, SIGNAL(frameSwapped()), this, SLOT(update()));
setFormat(surfaceFormat);
}
private:
void initializeGL() override
{
initializeOpenGLFunctions();
glClearColor(0.2f, 0.2f, 0.2f, 1.f);
m_elapsedTimer.start();
}
void resizeGL(int w, int h) override
{
glViewport(0, 0, w, h);
}
void paintGL() override
{
float dt = m_elapsedTimer.elapsed() / 1000.f;
m_elapsedTimer.restart();
qDebug() << dt;
glClear(GL_COLOR_BUFFER_BIT);
}
private:
QElapsedTimer m_elapsedTimer;
};
int main(int argc, char *argv[])
{
QApplication::setAttribute(Qt::ApplicationAttribute::AA_UseDesktopOpenGL);
QApplication app(argc, argv);
OpenGLWindow w;
w.show();
return app.exec();
}
To copy to clipboard, switch view to plain text mode
Bookmarks