[require] GLSL >= 1.10 [vertex shader] uniform int index; varying vec4 m[2]; varying vec4 pos; void main() { gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex; m[0].xy = vec2(1.0, 1.1); m[1].xy = vec2(2.0, 2.1); m[0].zw = vec2(5.0, 5.1); m[1].zw = vec2(6.0, 6.1); if (index >= 2) m[index-2].zw = vec2(0.0, 0.1); else m[index].xy = vec2(0.0, 0.1); pos = gl_Position; } [fragment shader] uniform int index; varying vec4 m[2]; varying vec4 pos; void main() { /* Correct the fragment coordinate to window size. */ vec2 p_gl = gl_FragCoord.xy / 125.0 - 1.0; vec2 err = abs(p_gl - pos.xy); bool pass = (length(err) < 0.001); if (!pass) { normalize(err); } else { err = vec2(1.0, 0.0); } for (int i = 0; i < 2; i++) pass = pass && m[i].xy == (index == i ? vec2(0.0, 0.1) : vec2(1.0, 1.1) + vec2(i)); for (int i = 0; i < 2; i++) pass = pass && m[i].zw == (index == 2+i ? vec2(0.0, 0.1) : vec2(5.0, 5.1) + vec2(i)); gl_FragColor = pass ? vec4(0.0, 1.0, 0.0, 1.0) : vec4(err.x, 0.0, err.y, 1.0); } [test] clear color 0.5 0.5 0.5 0.5 clear ortho uniform int index 0 draw rect 5 5 10 10 probe rgb 10 25 0.0 1.0 0.0 uniform int index 1 draw rect 185 5 10 10 probe rgb 190 10 0.0 1.0 0.0 uniform int index 2 draw rect 5 185 10 10 probe rgb 10 190 0.0 1.0 0.0 uniform int index 3 draw rect 185 185 10 10 probe rgb 190 190 0.0 1.0 0.0 uniform int index 1 draw rect 5 20 10 10 probe rgb 10 25 0.0 1.0 0.0