From ad5062ffe53aef8e1782e97bff7ad2d400df4773 Mon Sep 17 00:00:00 2001 From: Garritt McCune Date: Tue, 26 Sep 2023 18:55:02 -0500 Subject: [PATCH] Initial commit --- .gitignore | 3 ++ Makefile | 38 ++++++++++++++++++++++ src/main.c | 95 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 136 insertions(+) create mode 100644 .gitignore create mode 100644 Makefile create mode 100644 src/main.c diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b0d5277 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +.vscode/ +bin/ +obj/ diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..930342a --- /dev/null +++ b/Makefile @@ -0,0 +1,38 @@ +CC = gcc +CFLAGS=-g -Wall -DDEBUG -Wpedantic -Wextra -Wunused-result -std=c99 -pedantic-errors -lSDL2 -lSDL2_ttf +SRCDIR=src +OBJDIR=obj +SRCS=$(wildcard $(SRCDIR)/*.c) + +# Substitute all .c with .o from SRCS +OBJS=$(patsubst $(SRCDIR)/%.c, $(OBJDIR)/%.o, $(SRCS)) +BINDIR=bin +BIN=$(BINDIR)/game + +all: $(BIN) +release: CFLAGS=-Wall -Wpedantic -O2 -lSDL2 -lSDL2_ttf +release: clean +release: $(BIN) + +$(BIN): $(OBJS) $(BINDIR) + $(CC) $(CFLAGS) $(OBJS) -o $@ + +$(OBJDIR)/%.o: $(SRCDIR)/%.c $(OBJDIR) + $(CC) $(CFLAGS) -c $< -o $@ + +$(BINDIR): + mkdir $@ + +$(OBJDIR): + mkdir $@ + +.PHONY: clean +.PHONY: test +.PHONY: disass + +clean: + rm -rf $(BINDIR)/* $(OBJDIR)/* +test: + $(BIN) +disass: + objdump -S --disassemble $(OBJDIR)/$(FILE).o > $(OBJDIR)/$(FILE).s \ No newline at end of file diff --git a/src/main.c b/src/main.c new file mode 100644 index 0000000..00fb375 --- /dev/null +++ b/src/main.c @@ -0,0 +1,95 @@ +#include +#include +#include +#include + +int Exit = 0; +int XRel = 0, YRel = 0; +int XOrg = 0, YOrg = 0; + +typedef struct { + SDL_Window *window; + SDL_Renderer *renderer; + unsigned short DefaultFontSize; +} Client; + +Client app; +const int SCREEN_WIDTH = 1280; +const int SCREEN_HEIGHT = 720; + +void HandleInput(void); +void Cleanup(void); + +int main(int argc, char** argv){ + memset(&app, 0, sizeof(app)); + + atexit(Cleanup); + + app.window = SDL_CreateWindow("SDL Tutorial", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN); + + if (app.window == NULL) { + printf("Window creation failed: %s\n", SDL_GetError()); + return -1; + } + + SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "linear"); + + app.renderer = SDL_CreateRenderer(app.window, -1, SDL_RENDERER_ACCELERATED); + + if (app.renderer == NULL) { + printf("Renderer failed: %s\n", SDL_GetError()); + return -1; + } + + while(!Exit) { + SDL_Delay(16); + + HandleInput(); + + SDL_SetRenderDrawColor(app.renderer, 0, 0, 255, 0); + + SDL_RenderClear(app.renderer); + + SDL_RenderPresent(app.renderer); + } +} + +void Cleanup(void) { + SDL_DestroyWindow(app.window); + SDL_DestroyRenderer(app.renderer); + TTF_Quit(); + SDL_Quit(); +} + +void HandleInput(void) { + SDL_Event event; + while(SDL_PollEvent(&event)) { + switch (event.type) { + case SDL_QUIT: + Exit = 1; + break; + // case SDL_MOUSEBUTTONDOWN: + // if (event.button.button == SDL_BUTTON_RIGHT) Exit = 1; + // MouseDown = 1; + // break; + // case SDL_MOUSEBUTTONUP: + // MouseDown = 0; + // break; + // case SDL_MOUSEMOTION: + // //if (MainMenu->HitCheck(event.motion.x, event.motion.y, &MainMenu->Area)) { + // if (MouseDown){ + // XRel += event.motion.xrel; + // YRel += event.motion.yrel; + // } + // break; + // case SDL_MOUSEWHEEL: + // if (event.wheel.y > 0 && ZoomLevel < 2) ZoomLevel += .05; + // else if (event.wheel.y < 0 && ZoomLevel > 0.25) ZoomLevel -= .05; + // break; + case SDL_TEXTINPUT: + case SDL_KEYDOWN: + default: + break; + } + } +} \ No newline at end of file