The storage qualifiers in
and out
actually have a purpose that contains and supersedes that of varying
and attribute
. They define what variables are respectively inputs and outputs for the shader. See the GLSL 4.2 reference card page 7:
in
: linkage into shader from previous stage
out
: linkage out of a shader to next stage
attribute
: same as in
for vertex shader
varying
: same as out
for vertex shader, same as in
for fragment shader (Note: these are erroneously flipped around in the above-mentioned reference card.)
With the side note that the latter two are sort of deprecated: they are not present in the 4.2 core profile, only in the compatibility profile.
What exactly do they do?
As for usage, take the vertex shader from An intro to modern OpenGL. Chapter 2.2: Shaders:
#version 110
attribute vec2 position;
varying vec2 texcoord;
void main()
{
gl_Position = vec4(position, 0.0, 1.0);
texcoord = position * vec2(0.5) + vec2(0.5);
}
It should be rewritten in 4.2 core as:
#version 420
in vec2 position;
out vec2 texcoord;
void main()
{
gl_Position = vec4(position, 0.0, 1.0);
texcoord = position * vec2(0.5) + vec2(0.5);
}
Unhelpful Tutorials
I'm guessing the main reason you find "outdated" tutorial code is that not everyone has access to GLSL 3.3+ compatible hardware. Regardless, for a good and more up to date tutorial I'll gladly point you in the direction of Nicol Bolas' Learning Modern 3D Graphics Programming.