OpenGL Tutorial Release 1.0 by Digia, Qt Learning
-
The "OpenGL Tutorial":http://qt-project.org/wiki/Developer-Guides (dated February 28, 2013) provided is a excellent introduction to OpenGL using the Qt framework. However, the document has some inconsistencies regarding the shaders. I can't find any other ways of giving feedback other than posting here:
Edit:
The document does not state what version of Qt it is based on, but I am using Qt 5.0.1. This of course implies the use of OpenGL ES, and I would assume that a tutorial published on February 28th 2013 was using Qt 5.0.1. The source code examples referred to in the documents have however problems compiling in Qt 5.0.1 due to the shaders.Section 3.1, page 20: paragraph states: ".., the vertex variable needs to be declared as an attribute vec4." But in the following source code it is declared as: in vec4 vertex;, and this do not compile (QOpenGLShaderProgram). It should be attribute vec4 vertex;
Same section and page: paragraph states: "The main() function the sets the built in hl_FragColor output variable...". First, it is gl_FragColor. Secondly, the following source code is given in the document:
@uniform vec4 color;
out vec4 fragColor;
void main(void)
{
fragColor = color;
}@This results in a compiling error when calling QOpenGLShaderProgram.addShaderFromSourceCode(QOpenGLShader::Fragment,....
It should be:
@uniform mediump vec4 color;
void main(void)
{
gl_FragColor = color;
}@As the document is self is pointing out, functions in GLSL need to specify in/out, but this do not apply for the main-function.
The same errors occur in the shaders given in section 3.3 page 27, section 3.4 page 30 and section 3.5 pages 34-35.Luckily, I saw it right away, but as an introduction tutorial it should be corrected.
-
A lot of your comments and issues in that document come from the differences between desktop OpenGL and OpenGL ES 2, e.g. "attribute vec4 vertex" vs. "in vec4 vertex". Also it doesn't even have to be a vec4 of course :)
Qt5 is perfectly capable of using desktop OpenGL, it's just tat the pre-compiled packages on Windows are built against ES 2. Qt 5.0.2 should address this or you can build your own Qt.
There are other differences based upon OpenGL versions too. For example, gl_FragColor is not defined in later versions of OpenGL/GLSL and you can declare your own output variable to be called whatever you like.