Initial commit
This commit is contained in:
@@ -0,0 +1,3 @@
|
|||||||
|
.vscode/
|
||||||
|
bin/
|
||||||
|
obj/
|
||||||
@@ -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
|
||||||
+95
@@ -0,0 +1,95 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include <SDL2/SDL.h>
|
||||||
|
#include <SDL2/SDL_mouse.h>
|
||||||
|
#include <SDL2/SDL_ttf.h>
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user