aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/grahpics.c71
-rw-r--r--src/main.c12
2 files changed, 83 insertions, 0 deletions
diff --git a/src/grahpics.c b/src/grahpics.c
new file mode 100644
index 0000000..ae9409d
--- /dev/null
+++ b/src/grahpics.c
@@ -0,0 +1,71 @@
+#include "graphics.h"
+
+#define WINDOW_TITLE "Title"
+
+static const char *g_sdl_error_str;
+
+#define SDL_CALL(x) \
+ SDL_ClearError(); \
+ x; \
+ g_sdl_error_str = SDL_GetError(); \
+ if (*g_sdl_error_str != '\0') { \
+ SDL_Log("ERROR SDL: %s", g_sdl_error_str); \
+ exit(EXIT_FAILURE); \
+ }
+
+
+static void update(t_state *state);
+static void event_handler(t_state *state);
+
+void graphics_init(t_state *state, int width, int height)
+{
+ SDL_CALL(SDL_Init(SDL_INIT_VIDEO));
+ SDL_CALL(state->window = SDL_CreateWindow(
+ WINDOW_TITLE,
+ SDL_WINDOWPOS_UNDEFINED,
+ SDL_WINDOWPOS_UNDEFINED,
+ width,
+ height,
+ 0
+ ));
+ SDL_CALL(state->renderer = SDL_CreateRenderer(state->window, -1, 0));
+ state->running = true;
+}
+
+void graphics_quit(t_state *state)
+{
+ SDL_DestroyRenderer(state->renderer);
+ SDL_DestroyWindow(state->window);
+ SDL_Quit();
+}
+
+void graphics_run(t_state *state)
+{
+ while (state->running)
+ {
+ event_handler(state);
+ update(state);
+ SDL_Delay(3);
+ }
+}
+
+static
+void update(t_state *state)
+{
+ // do stuff
+}
+
+static
+void event_handler(t_state *state)
+{
+ SDL_Event e;
+ while (SDL_PollEvent(&e))
+ {
+ switch (e.type)
+ {
+ case SDL_QUIT:
+ state->running = false;
+ break;
+ }
+ }
+}
diff --git a/src/main.c b/src/main.c
new file mode 100644
index 0000000..91c8dde
--- /dev/null
+++ b/src/main.c
@@ -0,0 +1,12 @@
+#include "graphics.h"
+
+int main()
+{
+ t_state state;
+
+ graphics_init(&state, 640, 480);
+ graphics_run(&state);
+ graphics_quit(&state);
+
+ return 0;
+}