polyadvent

A game engine from scratch in C
git clone git://jb55.com/polyadvent
Log | Files | Refs | README

main.c (2748B)


      1 
      2 #include "animation.h"
      3 #include "event.h"
      4 #include "fbo.h"
      5 #include "file.h"
      6 #include "game.h"
      7 #include "debug.h"
      8 #include "geometry.h"
      9 #include "gl.h"
     10 #include "hires.h"
     11 #include "ply.h"
     12 #include "poisson.h"
     13 #include "quickhull.h"
     14 #include "render.h"
     15 #include "scene.h"
     16 #include "slab_geom.h"
     17 #include "slab.h"
     18 #include "terrain.h"
     19 #include "uniform.h"
     20 #include "update.h"
     21 #include "util.h"
     22 #include "window.h"
     23 
     24 
     25 
     26 #include <assert.h>
     27 #include <time.h>
     28 
     29 int main(void)
     30 {
     31     int nsamples;
     32 
     33     int seed = time(NULL);
     34     /* int seed = 42; */
     35     debug("seed %d\n", seed);
     36     srand(seed);
     37 
     38     struct game game;
     39     game.seed = seed;
     40 
     41     /* SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES); */
     42     int width = 640;
     43     int height = 480;
     44     game_init(&game, width, height);
     45     /* reset_scene(&game); */
     46     entity_test_scene(&game);
     47 
     48     check_gl();
     49     double last = hires_time_in_seconds();
     50     static float depth_vp[MAT4_ELEMS];
     51     mat4_id(depth_vp);
     52 
     53     struct render_config fbo_render_config = {
     54       .draw_ui = 1,
     55       .is_depth_pass = 1,
     56       .camera = game.test_resources.sun_camera_id,
     57       .projection = game.test_resources.proj_ortho,
     58       .depth_vp = depth_vp
     59     };
     60 
     61     struct render_config default_config = {
     62       .draw_ui = 1,
     63       .is_depth_pass = 0,
     64       .camera = game.test_resources.camera_node_id,
     65       .projection = game.test_resources.proj_persp,
     66       .depth_vp = depth_vp
     67     };
     68 
     69 
     70     while (!game.quit) {
     71         game.frame++;
     72         process_events(&game.input, game.frame);
     73         if (game.input.resized_height) {
     74             /* printf("handling resize %d %d\n", game.input.resized_width, */
     75             /*        game.input.resized_height); */
     76             handle_resize(&game, game.input.resized_width, game.input.resized_height);
     77         }
     78         //default_config.camera = game.test_resources.camera_node->mat;
     79         double new_time = hires_time_in_seconds();
     80         double frame_time = new_time - last;
     81         game.dt = frame_time;
     82 
     83         update(&game);
     84 
     85         /* while (accumulator >= dt) { */
     86         /*     t += dt; */
     87         /*     accumulator -= dt; */
     88         /* } */
     89 
     90         default_config.camera = game.test_resources.camera_node_id;
     91 
     92         last = new_time;
     93 
     94         struct fbo *fbo = &game.test_resources.shadow_buffer;
     95         check_fbo(fbo);
     96         bind_fbo(fbo);
     97         /* glDrawBuffer(GL_NONE); */
     98 
     99         render(&game, &fbo_render_config);
    100         unbind_fbo(&game.test_resources.shadow_buffer);
    101         render(&game, &default_config);
    102 
    103         /* Swap front and back buffers */
    104         SDL_GL_SwapWindow(game.window);
    105     }
    106 
    107     /* free(slab_buffer); */
    108     /* free_slab_geom(&geom, NULL) */
    109 
    110     //SDL_GL_DeleteContext(gl);
    111     //return 0;
    112 }
    113