diff options
author | David Phillips <dbphillipsnz@gmail.com> | 2016-01-12 20:41:56 +1300 |
---|---|---|
committer | David Phillips <dbphillipsnz@gmail.com> | 2016-01-12 20:41:56 +1300 |
commit | 58bef85206c7cce153400e51b247e2476e9e65a4 (patch) | |
tree | 9e9856c8c554545c44834c89fe0086f9a36abf22 /window.c | |
download | tetris-58bef85206c7cce153400e51b247e2476e9e65a4.tar.xz |
Initial commit of rough-arse Tetris
Diffstat (limited to 'window.c')
-rw-r--r-- | window.c | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/window.c b/window.c new file mode 100644 index 0000000..2128f1c --- /dev/null +++ b/window.c @@ -0,0 +1,44 @@ +#include "window.h" + +#include <SDL.h> + +int display_init(struct window *wobj) +{ + if (SDL_Init(SDL_INIT_VIDEO|SDL_INIT_TIMER) < 0) + { + fprintf(stderr,"Couldn't init SDL: %s\n", SDL_GetError()); + return EXIT_FAILURE; + } + + /* Create run-of-the-mill window at specified size */ + wobj->window = SDL_CreateWindow( + wobj->title, + SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, + wobj->width, wobj->height, + SDL_WINDOW_SHOWN + ); + if (wobj->window == NULL) + { + fprintf(stderr, "Couldn't create window: %s\n", SDL_GetError()); + return EXIT_FAILURE; + } + + /* Grab window surface */ + wobj->surface = SDL_GetWindowSurface(wobj->window); + if (wobj->surface == NULL) + { + fprintf(stderr, "Couldn't grab window surface: %s\n", SDL_GetError()); + return EXIT_FAILURE; + } + + /* Clear/blank surface with grey, and update it */ + SDL_FillRect(wobj->surface, NULL, SDL_MapRGB(wobj->surface->format, 0x33, 0x33, 0x33)); + SDL_UpdateWindowSurface(wobj->window); + return EXIT_SUCCESS; +} + +void display_stop(struct window *wobj) +{ + SDL_DestroyWindow(wobj->window); + SDL_Quit(); +} |