aboutsummaryrefslogtreecommitdiff
path: root/tests/main.c
blob: 478e432220595ed28314a6ed79abcda868da9158 (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
#include <stdio.h>
#include <mgl/mgl.h>
#include <mgl/window.h>
#include <mgl/graphics/texture.h>
#include <mgl/graphics/rectangle.h>
#include <mgl/graphics/sprite.h>

typedef struct {
    mgl_texture *texture;
} Userdata;

static void draw(mgl_window *window, void *userdata) {
    mgl_context *context = mgl_get_context();
    Userdata *u = userdata;

    mgl_rectangle rect = {
        .color = { 1.0f, 0.0f, 0.0f, 1.0f },
        .position = { window->cursor_position.x, window->cursor_position.y },
        .size = { 100.0f, 500.0f }
    };
    mgl_rectangle_draw(context, &rect);

    mgl_sprite sprite;
    mgl_sprite_init(&sprite, u->texture, 100.0f - 10.0f, 0.0f);
    mgl_sprite_set_color(&sprite, 1.0f, 1.0f, 1.0f, 0.5f);
    mgl_sprite_draw(context, &sprite);
}

int main(int argc, char **argv) {
    if(mgl_init() != 0)
        return 1;

    mgl_texture texture;

    Userdata userdata;
    userdata.texture = &texture;

    mgl_window_callback window_callback;
    window_callback.userdata = &userdata;
    window_callback.draw = draw;

    mgl_window window;
    if(mgl_window_create(&window, "mgl", 1280, 720, &window_callback) != 0)
        return 1;

    if(mgl_texture_load_from_file(&texture, "X11.png", NULL) != 0)
        return 1;

    for(;;) {
        mgl_window_events_poll(&window);
        mgl_window_draw(&window);
    }

    mgl_texture_unload(&texture);
    mgl_window_deinit(&window);
    mgl_deinit();
    return 0;
}