summaryrefslogtreecommitdiffhomepage
path: root/main/main.cpp
blob: a5acb0caaf4f5bf50b6b1ce41d09caaf1da86663 (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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#include "app.hpp"
#include "tile-defs.hpp"
#include <Magnum/Math/Vector3.h>
#include <Magnum/GL/DefaultFramebuffer.h>
#include <Magnum/GL/Renderer.h>
#include <Magnum/Trade/AbstractImporter.h>

namespace floormat {

chunk app::make_test_chunk()
{
    constexpr auto N = TILE_MAX_DIM;
    chunk c;
    for (auto [x, k, pt] : c) {
        const auto& atlas = pt.x > N/2 && pt.y >= N/2 ? floor2 : floor1;
        x.ground_image = { atlas, (std::uint8_t)(k % atlas->num_tiles().product()) };
    }
    constexpr auto K = N/2;
    c[{K,   K  }].wall_north = { wall1, 0 };
    c[{K,   K  }].wall_west  = { wall2, 0 };
    c[{K,   K+1}].wall_north = { wall1, 0 };
    c[{K+1, K  }].wall_west  = { wall2, 0 };
    return c;
}

void app::drawEvent() {
#if 0
    GL::defaultFramebuffer.clear(GL::FramebufferClear::Color | GL::FramebufferClear::Depth);
    GL::Renderer::setDepthMask(true);
    GL::Renderer::setDepthFunction(GL::Renderer::DepthFunction::LessOrEqual);
    GL::Renderer::enable(GL::Renderer::Feature::DepthTest);
#else
    GL::defaultFramebuffer.clear(GL::FramebufferClear::Color);
    GL::Renderer::setDepthFunction(GL::Renderer::DepthFunction::Never);
#endif

    //update_window_scale(windowSize());
    {
        float dt = std::min(1.f/20, timeline.previousFrameDuration());
        update(dt);
    }

    draw_chunk(_chunk);
    draw_wireframe_quad();
    draw_wireframe_box();
    draw_menu();
    display_menu();

    swapBuffers();
    redraw();
    timeline.nextFrame();
}

void app::draw_chunk(chunk& c)
{
    _shader.set_tint({1, 1, 1, 1});
    _floor_mesh.draw(_shader, c);
    _wall_mesh.draw(_shader, c);
}

void app::draw_wireframe_quad()
{
    constexpr float LINE_WIDTH = 1;

    constexpr auto X = TILE_SIZE[0], Y = TILE_SIZE[1];
    constexpr float N = TILE_MAX_DIM/2.f;
    const Vector3 center {X*N, Y*N, 0};
    _shader.set_tint({1, 0, 0, 1});
    _wireframe_quad.draw(_shader, {center, {TILE_SIZE[0], TILE_SIZE[1]}, LINE_WIDTH});
    _shader.set_tint({1, 1, 1, 1});
}

void app::draw_wireframe_box()
{
    constexpr float LINE_WIDTH = 1.5;

    constexpr auto X = TILE_SIZE[0], Y = TILE_SIZE[1];
    constexpr float N = TILE_MAX_DIM/2.f;
    constexpr Vector3 size{TILE_SIZE[0], TILE_SIZE[1], TILE_SIZE[2]*1.5f};
    const Vector3 center1{X*(N+3), Y*(N+2), 0},
                  center2{X*(N-2), Y*(N-4), 0};
    _shader.set_tint({0, 1, 0, 1});
    _wireframe_box.draw(_shader, {center1, size, LINE_WIDTH});
    _wireframe_box.draw(_shader, {center2, size, LINE_WIDTH});
}

} // namespace floormat

MAGNUM_APPLICATION_MAIN(floormat::app)

#ifdef _MSC_VER
#include <cstdlib> // for __arg{c,v}
#ifdef __clang__
#    pragma clang diagnostic push
#    pragma clang diagnostic ignored "-Wmain"
#endif
extern "C" int __stdcall WinMain(void*, void*, void*, int);

extern "C" int __stdcall WinMain(void*, void*, void*, int)
{
    return main(__argc, __argv);
}
#ifdef __clang__
#    pragma clang diagnostic pop
#endif
#endif