Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
src_gui_qopenglshaderprogram.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
3#include <QColor>
4#include <QString>
5#include <QtOpenGL/QOpenGLShader>
6
9QObject *context = nullptr;
10QRectF rect() { return QRectF(); }
11
12void wrapper() {
15shader.compileSourceCode(code);
16
18program.addShader(&shader);
19program.link();
20
21program.bind();
23
25program.addShaderFromSourceCode(QOpenGLShader::Vertex,
26 "attribute highp vec4 vertex;\n"
27 "uniform highp mat4 matrix;\n"
28 "void main(void)\n"
29 "{\n"
30 " gl_Position = matrix * vertex;\n"
31 "}");
32program.addShaderFromSourceCode(QOpenGLShader::Fragment,
33 "uniform mediump vec4 color;\n"
34 "void main(void)\n"
35 "{\n"
36 " gl_FragColor = color;\n"
37 "}");
38program.link();
39program.bind();
40
41int vertexLocation = program.attributeLocation("vertex");
42int matrixLocation = program.uniformLocation("matrix");
43int colorLocation = program.uniformLocation("color");
45
47static GLfloat const triangleVertices[] = {
48 60.0f, 10.0f, 0.0f,
49 110.0f, 110.0f, 0.0f,
50 10.0f, 110.0f, 0.0f
51};
52
53QColor color(0, 255, 0, 255);
54
55QMatrix4x4 pmvMatrix;
56pmvMatrix.ortho(rect());
57
58program.enableAttributeArray(vertexLocation);
59program.setAttributeArray(vertexLocation, triangleVertices, 3);
60program.setUniformValue(matrixLocation, pmvMatrix);
61program.setUniformValue(colorLocation, color);
62
63glDrawArrays(GL_TRIANGLES, 0, 3);
64
65program.disableAttributeArray(vertexLocation);
67
68} // wrapper
69} // src_gui_qopenglshaderprogram
The QColor class provides colors based on RGB, HSV or CMYK values.
Definition qcolor.h:31
The QMatrix4x4 class represents a 4x4 transformation matrix in 3D space.
Definition qmatrix4x4.h:25
void ortho(const QRect &rect)
This is an overloaded member function, provided for convenience. It differs from the above function o...
\inmodule QtCore
Definition qobject.h:103
The QOpenGLShaderProgram class allows OpenGL shader programs to be linked and used.
The QOpenGLShader class allows OpenGL shaders to be compiled.
\inmodule QtCore\reentrant
Definition qrect.h:484
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
typedef GLfloat(GL_APIENTRYP PFNGLGETPATHLENGTHNVPROC)(GLuint path
GLuint color
[2]
GLuint program
GLuint shader
Definition qopenglext.h:665