14 QOpenGLFunctions *f = QOpenGLContext::currentContext()->functions();
15 f->glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
22 m_projection.setToIdentity();
23 m_projection.perspective(45.0f, w /
float(h), 0.01f, 100.0f);
30 QOpenGLFunctions *f = QOpenGLContext::currentContext()->functions();
31 f->glClear(GL_COLOR_BUFFER_BIT);
39class MyGLWidget :
public QOpenGLWidget,
protected QOpenGLFunctions
42 void initializeGL() override
44 initializeOpenGLFunctions();
55format.setDepthBufferSize(24);
56format.setStencilBufferSize(8);
57format.setVersion(3, 2);
58format.setProfile(QSurfaceFormat::CoreProfile);
59widget->setFormat(format);
64 void paintGL() override
66 QOpenGLFunctions_3_2_Core *f = QOpenGLContext::currentContext()->versionFunctions<QOpenGLFunctions_3_2_Core>();
68 f->glDrawArraysInstanced(...);
75class MyGLWidget :
public QOpenGLWidget
80 QOpenGLVertexArrayObject m_vao;
82 QOpenGLShaderProgram *m_program;
83 QOpenGLShader *m_shader;
84 QOpenGLTexture *m_texture;
88 : m_program(0), m_shader(0), m_texture(0)
112 if (m_vao.isCreated())
119 m_texture =
new QOpenGLTexture(QImage(...));
121 m_shader =
new QOpenGLShader(...);
122 m_program =
new QOpenGLShaderProgram(...);
137 connect(context(), &QOpenGLContext::aboutToBeDestroyed,
this, &MyGLWidget::cleanup);
147 disconnect(context(), &QOpenGLContext::aboutToBeDestroyed,
this, &MyGLWidget::cleanup);
154 QApplication app(argc, argv);
156 QSurfaceFormat format;
157 format.setDepthBufferSize(24);
158 format.setStencilBufferSize(8);
159 format.setVersion(3, 2);
160 format.setProfile(QSurfaceFormat::CoreProfile);
161 QSurfaceFormat::setDefaultFormat(format);
int main(int argc, char *argv[])
[ctor_close]