aboutsummaryrefslogtreecommitdiffstats
path: root/examples/simplegame/main.cpp
blob: 062006612e333f8426a11ceee97f77ec6f2888fa (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
66
67
/** ---------------------------------------------------------------------------
 * @file: simplegame.cpp
 *
 * Copyright (c) 2017 Yann Herklotz Grave <ymherklotz@gmail.com>
 * MIT License, see LICENSE file for more details.
 * ----------------------------------------------------------------------------
 */

#include <yage.cpp>

#include <iostream>

using std::cout;

using namespace yage;

int main()
{
    Window window;
    GlslProgram textureProgram;

    window.create("Simple Game", 800, 640);
    SpriteBatch sp;

    textureProgram.compileShadersFromFile("examples/resources/textureshader.vert",
                                   "examples/resources/textureshader.frag");
    textureProgram.linkShaders();

    Texture fountain = ResourceManager::getTexture(
        "examples/resources/dngn_blood_fountain.png");
    Texture breast_plate =
        ResourceManager::getTexture("examples/resources/breast_black.png");

    cout << "texture: " << fountain.width << ", " << fountain.height << '\n';

    Camera camera(800, 640);

    while (!window.shouldClose()) {
        window.clearBuffer();
        Texture texture = fountain;

        window.pollEvents();
        if (window.keyPressed(yage::key::SPACE)) {
            cout << "Pressed A" << '\n';
        }
        if (window.keyPressed(yage::key::E)) {
            texture = breast_plate;
        }

        textureProgram.use();
        camera.update(textureProgram);

        glActiveTexture(GL_TEXTURE0);

        GLint texture_location = textureProgram.getUniformLocation("texture_sampler");
        glUniform1i(texture_location, 0);

        sp.draw({0.f, 0.f, 64.f, 64.f}, {0, 0, 1, 1}, texture.id,
                Colour(255, 0, 255, 255), 0);
        sp.render();

        glBindTexture(GL_TEXTURE_2D, 0);
        textureProgram.unuse();

        window.swapBuffer();
    }
}