From 6a80b1b70ec069b051c0e31aafac6eb596e20261 Mon Sep 17 00:00:00 2001 From: Charles Date: Tue, 19 May 2020 13:22:59 +0200 Subject: Back to basic SDL application boilerplate --- src/state.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 src/state.c (limited to 'src/state.c') diff --git a/src/state.c b/src/state.c new file mode 100644 index 0000000..ee68b77 --- /dev/null +++ b/src/state.c @@ -0,0 +1,34 @@ +#include "config.h" +#include "mandel.h" + +bool state_init(State *state) +{ + SDL_CALL(SDL_Init(SDL_INIT_VIDEO)); + SDL_CALL(state->window = SDL_CreateWindow( + MANDEL_WINDOW_TITLE, + SDL_WINDOWPOS_UNDEFINED, + SDL_WINDOWPOS_UNDEFINED, + MANDEL_WINDOW_WIDTH, + MANDEL_WINDOW_HEIGHT, + 0)); + SDL_CALL(state->renderer = SDL_CreateRenderer(state->window, -1, 0)); + state->running = true; + return state; +} + +void state_run(State *state) +{ + while (state->running) + { + event_handle(state); + } +} + +void state_quit(State *state) +{ + /* free(state->palette); */ + /* SDL_FreeSurface(state->surface); */ + SDL_DestroyRenderer(state->renderer); + SDL_DestroyWindow(state->window); + SDL_Quit(); +} -- cgit