14QOpenGLShader shader(QOpenGLShader::Vertex);
15shader.compileSourceCode(code);
17QOpenGLShaderProgram program(
context);
18program.addShader(&shader);
25program.addShaderFromSourceCode(QOpenGLShader::Vertex,
26 "attribute highp vec4 vertex;\n"
27 "uniform highp mat4 matrix;\n"
30 " gl_Position = matrix * vertex;\n"
32program.addShaderFromSourceCode(QOpenGLShader::Fragment,
33 "uniform mediump vec4 color;\n"
36 " gl_FragColor = color;\n"
41int vertexLocation = program.attributeLocation(
"vertex");
42int matrixLocation = program.uniformLocation(
"matrix");
43int colorLocation = program.uniformLocation(
"color");
47static GLfloat
const triangleVertices[] = {
53QColor color(0, 255, 0, 255);
56pmvMatrix.ortho(rect());
58program.enableAttributeArray(vertexLocation);
59program.setAttributeArray(vertexLocation, triangleVertices, 3);
60program.setUniformValue(matrixLocation, pmvMatrix);
61program.setUniformValue(colorLocation, color);
63glDrawArrays(GL_TRIANGLES, 0, 3);
65program.disableAttributeArray(vertexLocation);