使用QT写一段OpenGL的调用代码
时间: 2023-04-04 21:05:11 浏览: 130
基于QT的OpenGL实例源码
我可以回答这个问题。以下是使用QT写一段OpenGL的调用代码的示例:
#include <QOpenGLWidget>
#include <QOpenGLFunctions>
class MyOpenGLWidget : public QOpenGLWidget, protected QOpenGLFunctions
{
public:
MyOpenGLWidget(QWidget *parent = nullptr) : QOpenGLWidget(parent) {}
protected:
void initializeGL() override
{
initializeOpenGLFunctions();
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
}
void paintGL() override
{
glClear(GL_COLOR_BUFFER_BIT);
glBegin(GL_TRIANGLES);
glColor3f(1.0f, 0.0f, 0.0f);
glVertex3f(-0.5f, -0.5f, 0.0f);
glColor3f(0.0f, 1.0f, 0.0f);
glVertex3f(0.5f, -0.5f, 0.0f);
glColor3f(0.0f, 0.0f, 1.0f);
glVertex3f(0.0f, 0.5f, 0.0f);
glEnd();
}
void resizeGL(int w, int h) override
{
glViewport(0, 0, w, h);
}
};
阅读全文