aboutsummaryrefslogtreecommitdiffstats
path: root/src/render.cpp
blob: 908b6200b332e9761ef874005e2f8d339637db0b (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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include <render.hpp>

static Shader *currentShader = nullptr;

namespace Render {

Shader worldShader;
Shader textShader;

void initShaders(void)
{
    // create the world shader
    worldShader.create("shaders/world.vert", "shaders/world.frag");
    worldShader.addUniform("texture");
    worldShader.addUniform("ortho");
    worldShader.addUniform("tex_color");
    worldShader.addUniform("transform");
    worldShader.addUniform("ambientLight");
    worldShader.addUniform("lightImpact");
    worldShader.addUniform("light");
    worldShader.addUniform("lightColor");
    worldShader.addUniform("lightSize");

    // create the text shader
    textShader.create("shaders/new.vert", "shaders/new.frag");
    textShader.addUniform("sampler");
    textShader.addUniform("ortho"); // actually not used, ortho in new.vert is mislabeled (actually transform)
    textShader.addUniform("tex_color");
    textShader.addUniform("ortho"); // this is transform
}

void useShader(Shader *s)
{
    currentShader = s;
}

void drawRect(vec2 ll, vec2 ur, float z)
{
    GLfloat verts[] = {ll.x, ll.y, z,
                       ur.x, ll.y, z,
                       ur.x, ur.y, z,

                       ur.x, ur.y, z,
                       ll.x, ur.y, z,
                       ll.x, ll.y, z};

    GLfloat tex[] = {0.0, 1.0,
                     1.0, 1.0,
                     1.0, 0.0,

                     1.0, 0.0,
                     0.0, 0.0,
                     0.0, 1.0};

    glUniform1i(currentShader->uniform[WU_texture], 0);
    currentShader->enable();

    glVertexAttribPointer(currentShader->coord, 3, GL_FLOAT, GL_FALSE, 0, verts);
    glVertexAttribPointer(currentShader->tex, 2, GL_FLOAT, GL_FALSE, 0, tex);
    glDrawArrays(GL_TRIANGLES, 0, 6);

    currentShader->disable();
}

}