Browse Source

Lesson 3.1

Godzil 3 years ago
parent
commit
de06abaa60
1 changed files with 42 additions and 2 deletions
  1. 42 2
      source/main.c

+ 42 - 2
source/main.c

@@ -8,16 +8,56 @@
  */
 
 #include <stdio.h>
-#include <log.h>
+#include <stdint.h>
+#include <stdbool.h>
 
 #include <SDL.h>
 
+#include <log.h>
+
+SDL_Window *window = NULL;
+SDL_Renderer *renderer = NULL;
+bool isRunning = false;
+
+
+bool initialiseWindow()
+{
+    bool ret = false;
+
+    if (SDL_Init(SDL_INIT_EVERYTHING))
+    {
+        log(TLOG_PANIC, NULL, "SDL Initialisation error!! error: %s", SDL_GetError());
+        goto exit;
+    }
+
+    window = SDL_CreateWindow(NULL,
+                              SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
+                              800, 600,
+                              SDL_WINDOW_BORDERLESS);
+    if (window == NULL)
+    {
+        log(TLOG_PANIC, NULL, "SDL Window creation error: %s", SDL_GetError());
+        goto exit;
+    }
+
+    renderer = SDL_CreateRenderer(window, -1, 0);
+    if (renderer == NULL)
+    {
+        log(TLOG_PANIC, NULL, "SDL Renderer creation error: %s", SDL_GetError());
+        goto exit;
+    }
+
+    ret = true;
+exit:
+    return ret;
+}
+
 int main(int argc, char *argv[])
 {
     MAX_DEBUG_LEVEL = TLOG_DEBUG;
 
     log(TLOG_ALWAYS, NULL, "Booting 3D Engine (version %s)!", VERSION);
-
+    isRunning = initialiseWindow();
 
     return 0;
 }