用于渲染彩色矩形的着色器
OpenGL 意义上的着色器程序包含许多不同的着色器。任何着色器程序必须至少有一个顶点着色器,用于计算屏幕上各点的位置,以及一个片段着色器,用于计算每个像素的颜色。 (实际上故事更长,更复杂,但无论如何……)
以下着色器适用于 #version 110
,但应说明以下几点:
顶点着色器:
#version 110
// x and y coordinates of one of the corners
attribute vec2 input_Position;
// rgba colour of the corner. If all corners are blue,
// the rectangle is blue. If not, the colours are
// interpolated (combined) towards the center of the rectangle
attribute vec4 input_Colour;
// The vertex shader gets the colour, and passes it forward
// towards the fragment shader which is responsible with colours
// Must match corresponding declaration in the fragment shader.
varying vec4 Colour;
void main()
{
// Set the final position of the corner
gl_Position = vec4(input_Position, 0.0f, 1.0f);
// Pass the colour to the fragment shader
UV = input_UV;
}
片段着色器:
#version 110
// Must match declaration in the vertex shader.
varying vec4 Colour;
void main()
{
// Set the fragment colour
gl_FragColor = vec4(Colour);
}