~jb55/polyadvent

ref: 5d1a173bea9026bf34c8e135d3fe68d122710aa7 polyadvent/main.c -rw-r--r-- 2.7 KiB
5d1a173bWilliam Casarin no debug 1 year, 8 months ago
                                                                                
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
107
108
109
110
111
112
113
#include "animation.h"
#include "event.h"
#include "fbo.h"
#include "file.h"
#include "game.h"
#include "debug.h"
#include "geometry.h"
#include "gl.h"
#include "hires.h"
#include "ply.h"
#include "poisson.h"
#include "quickhull.h"
#include "render.h"
#include "scene.h"
#include "slab_geom.h"
#include "slab.h"
#include "terrain.h"
#include "uniform.h"
#include "update.h"
#include "util.h"
#include "window.h"



#include <assert.h>
#include <time.h>

int main(void)
{
    int nsamples;

    int seed = time(NULL);
    /* int seed = 42; */
    debug("seed %d\n", seed);
    srand(seed);

    struct game game;
    game.seed = seed;

    /* SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES); */
    int width = 640;
    int height = 480;
    game_init(&game, width, height);
    /* reset_scene(&game); */
    entity_test_scene(&game);

    check_gl();
    double last = hires_time_in_seconds();
    static float depth_vp[MAT4_ELEMS];
    mat4_id(depth_vp);

    struct render_config fbo_render_config = {
      .draw_ui = 1,
      .is_depth_pass = 1,
      .camera = game.test_resources.sun_camera_id,
      .projection = game.test_resources.proj_ortho,
      .depth_vp = depth_vp
    };

    struct render_config default_config = {
      .draw_ui = 1,
      .is_depth_pass = 0,
      .camera = game.test_resources.camera_node_id,
      .projection = game.test_resources.proj_persp,
      .depth_vp = depth_vp
    };


    while (!game.quit) {
        game.frame++;
        process_events(&game.input, game.frame);
        if (game.input.resized_height) {
            /* printf("handling resize %d %d\n", game.input.resized_width, */
            /*        game.input.resized_height); */
            handle_resize(&game, game.input.resized_width, game.input.resized_height);
        }
        //default_config.camera = game.test_resources.camera_node->mat;
        double new_time = hires_time_in_seconds();
        double frame_time = new_time - last;
        game.dt = frame_time;

        update(&game);

        /* while (accumulator >= dt) { */
        /*     t += dt; */
        /*     accumulator -= dt; */
        /* } */

        default_config.camera = game.test_resources.camera_node_id;

        last = new_time;

        struct fbo *fbo = &game.test_resources.shadow_buffer;
        check_fbo(fbo);
        bind_fbo(fbo);
        /* glDrawBuffer(GL_NONE); */

        render(&game, &fbo_render_config);
        unbind_fbo(&game.test_resources.shadow_buffer);
        render(&game, &default_config);

        /* Swap front and back buffers */
        SDL_GL_SwapWindow(game.window);
    }

    /* free(slab_buffer); */
    /* free_slab_geom(&geom, NULL) */

    //SDL_GL_DeleteContext(gl);
    //return 0;
}