aboutsummaryrefslogtreecommitdiff
path: root/tests/main.cpp
blob: 35957172fbee3a5f5d00390f86156a1117380e03 (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
#include <stdio.h>
#include <mglpp/mglpp.hpp>
#include <mglpp/window/Window.hpp>
#include <mglpp/graphics/Texture.hpp>
#include <mglpp/graphics/Sprite.hpp>
#include <mglpp/graphics/Font.hpp>
#include <mglpp/graphics/Text.hpp>
#include <mglpp/graphics/Rectangle.hpp>

struct Delegate : public mgl::Window::Delegate {
    Delegate() {}

    void draw() override {
        mgl::Rectangle rect(window->get_cursor_position().to_vec2f(), { 100.0f, 500.0f });
        rect.set_color({255, 0, 0, 255});
        window->draw(rect);

        mgl::Sprite sprite(*texture, { 100.0f - 10.0f, 0.0f });
        sprite.set_color({255, 255, 255, 128});
        window->draw(sprite);

        mgl::Text text("hello world!\nGood bye world!", { 0.0f, 0.0f }, *font);
        window->draw(text);
    }

    mgl::Window *window;
    mgl::Texture *texture;
    mgl::Font *font;
};

int main(int argc, char **argv) {
    mgl::Init init;

    Delegate delegate;
    mgl::Window window(&delegate);
    if(!window.create("mglpp", 1920, 1080))
        return 1;

    mgl::Texture texture;
    if(!texture.load_from_file("depends/mgl/tests/X11.png"))
        return 1;

    mgl::Font font;
    if(!font.load_from_file("/usr/share/fonts/noto/NotoSans-Regular.ttf", 32))
        return 1;

    delegate.window = &window;
    delegate.texture = &texture;
    delegate.font = &font;

    while(true) {
        window.poll_events();
        window.draw();
    }

    return 0;
}