diff options
author | Rhys Weatherley <rhys.weatherley@nokia.com> | 2009-09-15 06:28:19 (GMT) |
---|---|---|
committer | Rhys Weatherley <rhys.weatherley@nokia.com> | 2009-09-15 06:28:19 (GMT) |
commit | afd7ba59f1fd9f14c4b7cd85aba764ef6066d64e (patch) | |
tree | 98e1c1a91bb61f4e9ef441c87536812f186f02a1 /doc/src/snippets | |
parent | d94f6a35202d2d62671072b4ba78e75b07d630bd (diff) | |
download | Qt-afd7ba59f1fd9f14c4b7cd85aba764ef6066d64e.zip Qt-afd7ba59f1fd9f14c4b7cd85aba764ef6066d64e.tar.gz Qt-afd7ba59f1fd9f14c4b7cd85aba764ef6066d64e.tar.bz2 |
qdoc: Shift snippets in QGLShaderProgram out into doc/src/snippets
Diffstat (limited to 'doc/src/snippets')
-rw-r--r-- | doc/src/snippets/code/src_opengl_qglshaderprogram.cpp | 92 |
1 files changed, 92 insertions, 0 deletions
diff --git a/doc/src/snippets/code/src_opengl_qglshaderprogram.cpp b/doc/src/snippets/code/src_opengl_qglshaderprogram.cpp new file mode 100644 index 0000000..2997297 --- /dev/null +++ b/doc/src/snippets/code/src_opengl_qglshaderprogram.cpp @@ -0,0 +1,92 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +QGLShader shader(QGLShader::VertexShader); +shader.compile(code); + +QGLShaderProgram program(context); +program.addShader(shader); +program.link(); + +program.enable(); +//! [0] + +//! [1] +program.addShader(QGLShader::VertexShader, + "attribute highp vec4 vertex;\n" + "attribute mediump mat4 matrix;\n" + "void main(void)\n" + "{\n" + " gl_Position = matrix * vertex;\n" + "}"); +program.addShader(QGLShader::FragmentShader, + "uniform mediump vec4 color;\n" + "void main(void)\n" + "{\n" + " gl_FragColor = color;\n" + "}"); +program.link(); +program.enable(); + +int vertexLocation = program.attributeLocation("vertex"); +int matrixLocation = program.attributeLocation("matrix"); +int colorLocation = program.uniformLocation("color"); +//! [1] + +//! [2] +static GLfloat const triangleVertices[] = { + 60.0f, 10.0f, 0.0f, + 110.0f, 110.0f, 0.0f, + 10.0f, 110.0f, 0.0f +}; + +QColor color(0, 255, 0, 255); + +QMatrix4x4 pmvMatrix; +pmvMatrix.ortho(rect()); + +program.setAttributeArray(vertexLocation, triangleVertices, 3); +program.setUniformValue(matrixLocation, pmvMatrix); +program.setUniformValue(colorLocation, color); + +glDrawArrays(GL_TRIANGLES, 0, 3); +//! [2] |