diff options
Diffstat (limited to 'examples')
-rw-r--r-- | examples/opengl/contextinfo/renderwindow.cpp | 12 | ||||
-rw-r--r-- | examples/opengl/contextinfo/widget.cpp | 9 | ||||
-rw-r--r-- | examples/opengl/hellowindow/hellowindow.cpp | 22 | ||||
-rw-r--r-- | examples/opengl/textures/glwidget.cpp | 2 | ||||
-rw-r--r-- | examples/opengl/textures/glwidget.h | 3 |
5 files changed, 27 insertions, 21 deletions
diff --git a/examples/opengl/contextinfo/renderwindow.cpp b/examples/opengl/contextinfo/renderwindow.cpp index ab8e89fab8..85fb19bd1a 100644 --- a/examples/opengl/contextinfo/renderwindow.cpp +++ b/examples/opengl/contextinfo/renderwindow.cpp @@ -43,6 +43,7 @@ #include <QMatrix4x4> #include <QOpenGLContext> #include <QOpenGLShaderProgram> +#include <QOpenGLFunctions> RenderWindow::RenderWindow(const QSurfaceFormat &format) : m_context(0), @@ -177,10 +178,11 @@ void RenderWindow::render() return; } + QOpenGLFunctions *f = m_context->functions(); if (!m_initialized) { m_initialized = true; - glEnable(GL_DEPTH_TEST); - glClearColor(0, 0, 0, 1); + f->glEnable(GL_DEPTH_TEST); + f->glClearColor(0, 0, 0, 1); init(); emit ready(); } @@ -189,8 +191,8 @@ void RenderWindow::render() return; const qreal retinaScale = devicePixelRatio(); - glViewport(0, 0, width() * retinaScale, height() * retinaScale); - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + f->glViewport(0, 0, width() * retinaScale, height() * retinaScale); + f->glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); m_program->bind(); QMatrix4x4 matrix; @@ -204,7 +206,7 @@ void RenderWindow::render() else // no VAO support, set the vertex attribute arrays now setupVertexAttribs(); - glDrawArrays(GL_TRIANGLES, 0, 3); + f->glDrawArrays(GL_TRIANGLES, 0, 3); m_vao.release(); m_program->release(); diff --git a/examples/opengl/contextinfo/widget.cpp b/examples/opengl/contextinfo/widget.cpp index 6d4b97ca8f..ff78639e24 100644 --- a/examples/opengl/contextinfo/widget.cpp +++ b/examples/opengl/contextinfo/widget.cpp @@ -312,13 +312,14 @@ void Widget::renderWindowReady() QString vendor, renderer, version, glslVersion; const GLubyte *p; - if ((p = glGetString(GL_VENDOR))) + QOpenGLFunctions *f = context->functions(); + if ((p = f->glGetString(GL_VENDOR))) vendor = QString::fromLatin1(reinterpret_cast<const char *>(p)); - if ((p = glGetString(GL_RENDERER))) + if ((p = f->glGetString(GL_RENDERER))) renderer = QString::fromLatin1(reinterpret_cast<const char *>(p)); - if ((p = glGetString(GL_VERSION))) + if ((p = f->glGetString(GL_VERSION))) version = QString::fromLatin1(reinterpret_cast<const char *>(p)); - if ((p = glGetString(GL_SHADING_LANGUAGE_VERSION))) + if ((p = f->glGetString(GL_SHADING_LANGUAGE_VERSION))) glslVersion = QString::fromLatin1(reinterpret_cast<const char *>(p)); m_output->append(tr("\nVendor: %1").arg(vendor)); diff --git a/examples/opengl/hellowindow/hellowindow.cpp b/examples/opengl/hellowindow/hellowindow.cpp index 2864883f5e..3b5971c0d3 100644 --- a/examples/opengl/hellowindow/hellowindow.cpp +++ b/examples/opengl/hellowindow/hellowindow.cpp @@ -41,6 +41,7 @@ #include "hellowindow.h" #include <QOpenGLContext> +#include <QOpenGLFunctions> #include <qmath.h> Renderer::Renderer(const QSurfaceFormat &format, Renderer *share, QScreen *screen) @@ -142,15 +143,16 @@ void Renderer::render() m_initialized = true; } - glViewport(0, 0, viewSize.width() * surface->devicePixelRatio(), viewSize.height() * surface->devicePixelRatio()); + QOpenGLFunctions *f = m_context->functions(); + f->glViewport(0, 0, viewSize.width() * surface->devicePixelRatio(), viewSize.height() * surface->devicePixelRatio()); - glClearColor(0.1f, 0.1f, 0.2f, 1.0f); - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + f->glClearColor(0.1f, 0.1f, 0.2f, 1.0f); + f->glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - glFrontFace(GL_CW); - glCullFace(GL_FRONT); - glEnable(GL_CULL_FACE); - glEnable(GL_DEPTH_TEST); + f->glFrontFace(GL_CW); + f->glCullFace(GL_FRONT); + f->glEnable(GL_CULL_FACE); + f->glEnable(GL_DEPTH_TEST); QMatrix4x4 modelview; modelview.rotate(m_fAngle, 0.0f, 1.0f, 0.0f); @@ -164,8 +166,8 @@ void Renderer::render() paintQtLogo(); m_program->release(); - glDisable(GL_DEPTH_TEST); - glDisable(GL_CULL_FACE); + f->glDisable(GL_DEPTH_TEST); + f->glDisable(GL_CULL_FACE); m_context->swapBuffers(surface); @@ -187,8 +189,6 @@ void Renderer::paintQtLogo() void Renderer::initialize() { - glClearColor(0.1f, 0.1f, 0.2f, 1.0f); - QOpenGLShader *vshader = new QOpenGLShader(QOpenGLShader::Vertex, this); vshader->compileSourceCode( "attribute highp vec4 vertex;" diff --git a/examples/opengl/textures/glwidget.cpp b/examples/opengl/textures/glwidget.cpp index ac1e7965af..305ca1aa4c 100644 --- a/examples/opengl/textures/glwidget.cpp +++ b/examples/opengl/textures/glwidget.cpp @@ -83,6 +83,8 @@ void GLWidget::setClearColor(const QColor &color) void GLWidget::initializeGL() { + initializeOpenGLFunctions(); + makeObject(); glEnable(GL_DEPTH_TEST); diff --git a/examples/opengl/textures/glwidget.h b/examples/opengl/textures/glwidget.h index fee47b9b48..b210b0fd8f 100644 --- a/examples/opengl/textures/glwidget.h +++ b/examples/opengl/textures/glwidget.h @@ -43,10 +43,11 @@ #include <QtWidgets> #include <QGLWidget> +#include <QOpenGLFunctions> QT_FORWARD_DECLARE_CLASS(QGLShaderProgram); -class GLWidget : public QGLWidget +class GLWidget : public QGLWidget, protected QOpenGLFunctions { Q_OBJECT |