summaryrefslogtreecommitdiffstats
path: root/examples/opengl/hellowindow
diff options
context:
space:
mode:
authorSamuel Rødal <samuel.rodal@nokia.com>2011-08-22 10:49:28 +0200
committerSamuel Rødal <samuel.rodal@nokia.com>2011-08-29 10:25:24 +0200
commit6e28e8441b698c3397c2c78125c877f2e9867cb1 (patch)
tree1e3ad0e43cb775854835817cd04bdc8b5e047e15 /examples/opengl/hellowindow
parentaaa4a26f82f99fa8724841eba91bad029306e0ce (diff)
Copy core GL functionality to QtGui with QGL -> QOpenGL naming.
Change-Id: Ibc989afa4a30dd184d41d1a1cd89f97196e48855 Reviewed-on: http://codereview.qt.nokia.com/3710 Reviewed-by: Gunnar Sletta <gunnar.sletta@nokia.com>
Diffstat (limited to 'examples/opengl/hellowindow')
-rw-r--r--examples/opengl/hellowindow/hellowindow.cpp43
-rw-r--r--examples/opengl/hellowindow/hellowindow.h12
-rw-r--r--examples/opengl/hellowindow/hellowindow.pro2
3 files changed, 28 insertions, 29 deletions
diff --git a/examples/opengl/hellowindow/hellowindow.cpp b/examples/opengl/hellowindow/hellowindow.cpp
index 3c4f88bdfe..cc1f52a92c 100644
--- a/examples/opengl/hellowindow/hellowindow.cpp
+++ b/examples/opengl/hellowindow/hellowindow.cpp
@@ -1,6 +1,6 @@
#include "hellowindow.h"
-#include <QGuiGLContext>
+#include <QOpenGLContext>
#include <QTimer>
@@ -10,7 +10,7 @@ Renderer::Renderer(const QSurfaceFormat &format, Renderer *share)
: m_initialized(false)
, m_format(format)
{
- m_context = new QGuiGLContext;
+ m_context = new QOpenGLContext;
m_context->setFormat(format);
if (share)
m_context->setShareContext(share->m_context);
@@ -91,11 +91,11 @@ void Renderer::render(QSurface *surface, const QColor &color, const QSize &viewS
modelview.rotate(m_fAngle, 0.0f, 0.0f, 1.0f);
modelview.translate(0.0f, -0.2f, 0.0f);
- program.bind();
- program.setUniformValue(matrixUniform, modelview);
- program.setUniformValue(colorUniform, color);
+ m_program->bind();
+ m_program->setUniformValue(matrixUniform, modelview);
+ m_program->setUniformValue(colorUniform, color);
paintQtLogo();
- program.release();
+ m_program->release();
glDisable(GL_DEPTH_TEST);
glDisable(GL_CULL_FACE);
@@ -107,20 +107,20 @@ void Renderer::render(QSurface *surface, const QColor &color, const QSize &viewS
void Renderer::paintQtLogo()
{
- program.enableAttributeArray(normalAttr);
- program.enableAttributeArray(vertexAttr);
- program.setAttributeArray(vertexAttr, vertices.constData());
- program.setAttributeArray(normalAttr, normals.constData());
+ m_program->enableAttributeArray(normalAttr);
+ m_program->enableAttributeArray(vertexAttr);
+ m_program->setAttributeArray(vertexAttr, vertices.constData());
+ m_program->setAttributeArray(normalAttr, normals.constData());
glDrawArrays(GL_TRIANGLES, 0, vertices.size());
- program.disableAttributeArray(normalAttr);
- program.disableAttributeArray(vertexAttr);
+ m_program->disableAttributeArray(normalAttr);
+ m_program->disableAttributeArray(vertexAttr);
}
void Renderer::initialize()
{
glClearColor(0.1f, 0.1f, 0.2f, 1.0f);
- QGLShader *vshader = new QGLShader(QGLShader::Vertex, this);
+ QOpenGLShader *vshader = new QOpenGLShader(QOpenGLShader::Vertex, this);
const char *vsrc =
"attribute highp vec4 vertex;\n"
"attribute mediump vec3 normal;\n"
@@ -138,7 +138,7 @@ void Renderer::initialize()
"}\n";
vshader->compileSourceCode(vsrc);
- QGLShader *fshader = new QGLShader(QGLShader::Fragment, this);
+ QOpenGLShader *fshader = new QOpenGLShader(QOpenGLShader::Fragment, this);
const char *fsrc =
"varying mediump vec4 color;\n"
"void main(void)\n"
@@ -147,14 +147,15 @@ void Renderer::initialize()
"}\n";
fshader->compileSourceCode(fsrc);
- program.addShader(vshader);
- program.addShader(fshader);
- program.link();
+ m_program = new QOpenGLShaderProgram;
+ m_program->addShader(vshader);
+ m_program->addShader(fshader);
+ m_program->link();
- vertexAttr = program.attributeLocation("vertex");
- normalAttr = program.attributeLocation("normal");
- matrixUniform = program.uniformLocation("matrix");
- colorUniform = program.uniformLocation("sourceColor");
+ vertexAttr = m_program->attributeLocation("vertex");
+ normalAttr = m_program->attributeLocation("normal");
+ matrixUniform = m_program->uniformLocation("matrix");
+ colorUniform = m_program->uniformLocation("sourceColor");
m_fAngle = 0;
createGeometry();
diff --git a/examples/opengl/hellowindow/hellowindow.h b/examples/opengl/hellowindow/hellowindow.h
index c114b09a24..6ff7411251 100644
--- a/examples/opengl/hellowindow/hellowindow.h
+++ b/examples/opengl/hellowindow/hellowindow.h
@@ -1,12 +1,12 @@
#include <QWindow>
-#include <QtOpenGL/qgl.h>
-#include <QtOpenGL/qglshaderprogram.h>
-#include <QtOpenGL/qglframebufferobject.h>
+#include <QtGui/qopengl.h>
+#include <QtGui/qopenglshaderprogram.h>
+#include <QColor>
#include <QTime>
-class QGuiGLContext;
+class QOpenGLContext;
class Renderer : public QObject
{
@@ -31,7 +31,6 @@ private:
void extrude(qreal x1, qreal y1, qreal x2, qreal y2);
QVector<QVector3D> vertices;
QVector<QVector3D> normals;
- QGLShaderProgram program;
int vertexAttr;
int normalAttr;
int matrixUniform;
@@ -39,7 +38,8 @@ private:
bool m_initialized;
QSurfaceFormat m_format;
- QGuiGLContext *m_context;
+ QOpenGLContext *m_context;
+ QOpenGLShaderProgram *m_program;
};
class HelloWindow : public QWindow
diff --git a/examples/opengl/hellowindow/hellowindow.pro b/examples/opengl/hellowindow/hellowindow.pro
index 44003d8863..555dc83574 100644
--- a/examples/opengl/hellowindow/hellowindow.pro
+++ b/examples/opengl/hellowindow/hellowindow.pro
@@ -6,8 +6,6 @@ TEMPLATE = app
DEPENDPATH += .
INCLUDEPATH += .
-QT += opengl widgets
-
# Input
HEADERS += hellowindow.h
SOURCES += hellowindow.cpp main.cpp