summaryrefslogtreecommitdiff
path: root/data/shaders/sprite-vertex.glsl
blob: d6efd3fd7713102986c2374a081c1688793a313a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#version 120

uniform mat4 projection;
uniform vec2 position;
uniform vec2 anchor;
uniform vec2 scale;
uniform float rotation;

void main(void) {
    mat4 rotationMatrix = mat4(cos(rotation), -sin(rotation), 0.0, 0.0,
                               sin(rotation), cos(rotation),  0.0, 0.0,
                               0.0,           0.0,            1.0, 0.0,
                               0.0,           0.0,            0.0, 1.0);
    mat4 translationMatrix = mat4(1.0, 0.0, 0.0, position.x - anchor.x,
                                  0.0, 1.0, 0.0, position.y - anchor.y,
                                  0.0, 0.0, 1.0, 0.0,
                                  0.0, 0.0, 0.0, 1.0);
    mat4 scaleMatrix = mat4(scale.x, 0.0,     0.0, 0.0,
                            0.0,     scale.y, 0.0, 0.0,
                            0.0,     0.0,     1.0, 0.0,
                            0.0,     0.0,     0.0, 1.0);

    gl_Position = projection * (gl_Vertex * scaleMatrix *
                                rotationMatrix * translationMatrix);
    gl_TexCoord[0] = gl_MultiTexCoord0;
}