diff options
| author | Charles <sircharlesaze@gmail.com> | 2020-05-10 12:13:55 +0200 |
|---|---|---|
| committer | Charles <sircharlesaze@gmail.com> | 2020-05-10 12:13:55 +0200 |
| commit | aea23b389a5eba09b3865209a08843e66481dd54 (patch) | |
| tree | 4840787b9cdebaa998808ef1399a4bf4c76a75a3 | |
| download | cardioid-aea23b389a5eba09b3865209a08843e66481dd54.tar.gz cardioid-aea23b389a5eba09b3865209a08843e66481dd54.tar.bz2 cardioid-aea23b389a5eba09b3865209a08843e66481dd54.zip | |
Initial commit, SDL boilerplate
| -rw-r--r-- | .gitignore | 4 | ||||
| -rw-r--r-- | Makefile | 35 | ||||
| -rw-r--r-- | READMD.md | 3 | ||||
| -rw-r--r-- | inc/graphics.h | 18 | ||||
| -rw-r--r-- | src/grahpics.c | 71 | ||||
| -rw-r--r-- | src/main.c | 12 |
6 files changed, 143 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..6b92c48 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +*.o +a.out +cardioid +*.exe diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..f3fa3dd --- /dev/null +++ b/Makefile @@ -0,0 +1,35 @@ +RM = rm -f +MKDIR = mkdir -p + +NAME = cardioid + +SRCDIR = src +INCDIR = inc +OBJDIR = obj + +CC = gcc +CCFLAGS = -Wall -Wextra -I$(INCDIR) $(shell sdl2-config --cflags) +LDFLAGS = $(shell sdl2-config --libs) + +SRC = $(shell find $(SRCDIR) -type f -name "*.c") +INC = $(shell find $(INCDIR) -type f -name "*.h") +OBJ = $(SRC:$(SRCDIR)/%.c=$(OBJDIR)/%.o) + +all: prebuild $(NAME) + +prebuild: + $(MKDIR) $(OBJDIR) + +$(NAME): $(OBJ) + $(CC) -o $@ $^ $(LDFLAGS) + +$(OBJDIR)/%.o: $(SRCDIR)/%.c $(INC) + $(CC) $(CCFLAGS) -c -o $@ $< + +clean: + $(RM) $(OBJ) + +fclean: clean + $(RM) $(NAME) + +re: fclean all diff --git a/READMD.md b/READMD.md new file mode 100644 index 0000000..ecd3b66 --- /dev/null +++ b/READMD.md @@ -0,0 +1,3 @@ +# Cardioid + +Cardoid visualizer diff --git a/inc/graphics.h b/inc/graphics.h new file mode 100644 index 0000000..efe7dcd --- /dev/null +++ b/inc/graphics.h @@ -0,0 +1,18 @@ +#ifndef GRAPHICS_H +# define GRAPHICS_H + +# include <stdbool.h> +# include <SDL2/SDL.h> + +typedef struct +{ + SDL_Window *window; + SDL_Renderer *renderer; + bool running; +} t_state; + +void graphics_init(t_state *state, int width, int height); +void graphics_quit(t_state *state); +void graphics_run(t_state *state); + +#endif 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; +} |
