From f42740d8ccedecd44ce7b1ecafe534ed40c46f4d Mon Sep 17 00:00:00 2001 From: Warwick Date: Mon, 14 Feb 2022 15:58:25 +0000 Subject: [PATCH] Allow the game to be run from any directory --- .gitignore | 24 +++++++++++------------- src/helpers/RootDir.h | 2 -- src/helpers/RootDir.h.in | 2 +- src/main.cpp | 10 ++++------ 4 files changed, 16 insertions(+), 22 deletions(-) delete mode 100644 src/helpers/RootDir.h diff --git a/.gitignore b/.gitignore index 9dd73a4..40c7f50 100644 --- a/.gitignore +++ b/.gitignore @@ -1,14 +1,12 @@ -# Ignore Builds -build/ +# Ignore Cmake build files +.cache/ +.cmake/ +CMakeCache.txt +CMakeFiles/ +Game +Makefile +cmake_install.cmake +compile_commands.json -# Ignore autoconf cruft for now -Makefile.in -aclocal.m4 -autom4te.cache/ -autoscan.log -compile -config.h.in -configure -depcomp -install-sh -missing +# Ignore Cmake'd files +src/helpers/RootDir.h diff --git a/src/helpers/RootDir.h b/src/helpers/RootDir.h deleted file mode 100644 index 415955a..0000000 --- a/src/helpers/RootDir.h +++ /dev/null @@ -1,2 +0,0 @@ -#pragma once -#define ROOT_DIR "/" diff --git a/src/helpers/RootDir.h.in b/src/helpers/RootDir.h.in index 0f6c92c..684b24e 100644 --- a/src/helpers/RootDir.h.in +++ b/src/helpers/RootDir.h.in @@ -1,2 +1,2 @@ #pragma once -#define ROOT_DIR "@SMAKE_SOURCE_DIR@/" +#define ROOT_DIR "@CMAKE_SOURCE_DIR@/" diff --git a/src/main.cpp b/src/main.cpp index 4ac0e53..7974c19 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -16,6 +16,7 @@ #include "ShaderLoader.h" // Camera #include "PlayerCamera.h" +#include "helpers/RootDir.h" // Include error class #include "Error.h" @@ -68,10 +69,8 @@ int main(int argc, char **argv) { // Create event handling struct SDL_Event input; - ShaderLoader shader("./data/shaders" - "/vertex.glsl", - "./data/shaders" - "/fragment.glsl"); + ShaderLoader shader(ROOT_DIR "data/shaders/vertex.glsl", + ROOT_DIR "data/shaders/fragment.glsl"); float vertices[] = { // positions // texture Co-ords @@ -126,8 +125,7 @@ int main(int argc, char **argv) { glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); // Load texture image - SDL_Surface *image = IMG_Load("./data" - "/container.jpg"); + SDL_Surface *image = IMG_Load(ROOT_DIR "data/container.jpg"); if (image == nullptr) { error.crash("SDL2_image was unable to load a texture", IMG_GetError()); }