Qt QOpenGLWidget updateGL: Scheduling Repaints and Updating OpenGL Rendering
The 'updateGL()' function in the 'QOpenGLWidget' class is used to schedule a repaint of the widget. This function is typically called when you want to update the OpenGL rendering of the widget.
When 'updateGL()' is called, it will cause the 'paintGL()' function to be called on the next event loop iteration. Inside the 'paintGL()' function, you can perform any OpenGL rendering operations necessary to update the widget's visual appearance.
Here's an example of how to use 'updateGL()':
// MyOpenGLWidget.h
#include <QOpenGLWidget>
class MyOpenGLWidget : public QOpenGLWidget
{
public:
MyOpenGLWidget(QWidget *parent = nullptr);
protected:
void initializeGL() override;
void paintGL() override;
private:
// OpenGL state and data
};
// MyOpenGLWidget.cpp
MyOpenGLWidget::MyOpenGLWidget(QWidget *parent)
: QOpenGLWidget(parent)
{
}
void MyOpenGLWidget::initializeGL()
{
// Initialize OpenGL state and data
}
void MyOpenGLWidget::paintGL()
{
// Perform OpenGL rendering operations
}
void someFunction()
{
MyOpenGLWidget *widget = new MyOpenGLWidget();
widget->updateGL(); // Schedule a repaint
}
In this example, 'updateGL()' is called to schedule a repaint of the 'MyOpenGLWidget' instance. This will eventually trigger a call to the 'paintGL()' function, where you can perform the necessary OpenGL rendering operations to update the widget's visual appearance.
原文地址: https://www.cveoy.top/t/topic/pi6e 著作权归作者所有。请勿转载和采集!