summaryrefslogtreecommitdiff
path: root/initialize.c
diff options
context:
space:
mode:
Diffstat (limited to 'initialize.c')
-rw-r--r--initialize.c40
1 files changed, 40 insertions, 0 deletions
diff --git a/initialize.c b/initialize.c
new file mode 100644
index 0000000..75d9e2d
--- /dev/null
+++ b/initialize.c
@@ -0,0 +1,40 @@
+#include<stdio.h>
+#include <SDL2/SDL.h>
+#include <SDL2/SDL_mixer.h>
+#include <SDL2/SDL_image.h>
+#include "./constants.h"
+#include "./structs.h"
+
+int initialize_window(App* app) {
+ if(SDL_Init(SDL_INIT_EVERYTHING) != 0) {
+ fprintf(stderr, "Error initializing SDL.\n");
+ return FALSE;
+ }
+ app->window = SDL_CreateWindow(
+ GAME_TITLE,
+ SDL_WINDOWPOS_CENTERED,
+ SDL_WINDOWPOS_CENTERED,
+ WINDOW_WIDTH,
+ WINDOW_HEIGHT,
+ SDL_WINDOW_BORDERLESS
+ );
+ if(!app->window) {
+ fprintf(stderr, "Error creating SDL_Window.\n");
+ return FALSE;
+ }
+ app->renderer = SDL_CreateRenderer(app->window, -1, 0);
+ if(!app->renderer) {
+ fprintf(stderr, "Error creating SDL_Renderer");
+ return FALSE;
+ }
+ IMG_Init(IMG_INIT_PNG);
+ Mix_OpenAudio(44100, MIX_DEFAULT_FORMAT, 2, 1024);
+ Mix_AllocateChannels(MAX_SND_CHANNELS);
+ return TRUE;
+}
+
+void destroy_window(App *app) {
+ SDL_DestroyRenderer(app->renderer);
+ SDL_DestroyWindow(app->window);
+ SDL_Quit();
+}