diff --git a/Makefile b/Makefile index d8b7811..ff3b050 100644 --- a/Makefile +++ b/Makefile @@ -4,19 +4,17 @@ all: windows run # Function that expands to all files recursively rwildcard=$(wildcard $1$2) $(foreach d,$(wildcard $1*),$(call rwildcard,$d/,$2)) -# All `.cpp` files in `src` directory +# Directory where all source files are stored SRC_DIR := src -SRC_FILES := $(call rwildcard,$(SRC_DIR)/,*.cpp) +# All source files stored in $SRC_DIR +SRC_FILES := $(shell find $(SRC_DIR) -name '*.cpp') # Directory to store `.o` files OBJ_DIR := obj -# These two lines compile all object files from updated `.cpp` files, I do not understand this -OBJ_FILES := $(patsubst $(SRC_DIR)/%.cpp,$(OBJ_DIR)/%.o,$(filter $(SRC_DIR)/%.cpp,$(SRC_FILES))) \ - $(patsubst %.cpp,$(OBJ_DIR)/%.o,$(filter-out $(SRC_DIR)/%.cpp,$(SRC_FILES))) -INCLUDE_DIR := include -HEADER_FILES := $(call rwildcard,$(INCLUDE_DIR)/,*.hpp) - -# Rule for compiling source files -$(OBJ_DIR)/%.o: $(SRC_DIR)/%.cpp $(HEADER_FILES) + +# Create string repr of object files from source files +OBJ_FILES := $(patsubst $(SRC_DIR)/%.cpp,$(OBJ_DIR)/%.o,$(SRC_FILES)) +# Rule for compiling object files based on changes in the source files +$(OBJ_DIR)/%.o: $(SRC_DIR)/%.cpp @echo -n "$@ " @mkdir -p $(@D) @$(CXX) -c $< -o $@ $(CXXFLAGS) @@ -24,18 +22,17 @@ $(OBJ_DIR)/%.o: $(SRC_DIR)/%.cpp $(HEADER_FILES) SHADER_DIR := shaders SHADER_OUT_DIR := obj -SHADER_VERT_FILES := $(call rwildcard,$(SHADER_DIR)/,*.vert) -SHADER_FRAG_FILES := $(call rwildcard,$(SHADER_DIR)/,*.frag) +SHADER_VERT_FILES := $(shell find $(SHADER_DIR) -name '*.vert') +SHADER_FRAG_FILES := $(shell find $(SHADER_DIR) -name '*.frag') + -SHADER_VERT_SPIRV_FILES := $(patsubst $(SHADER_DIR)/%.vert,$(SHADER_OUT_DIR)/%.vert.spv,$(filter $(SHADER_DIR)/%.vert,$(SHADER_VERT_FILES))) \ - $(patsubst %.vert,$(SHADER_OUT_DIR)/%.vert.spv,$(filter-out $(SHADER_DIR)/%.vert,$(SHADER_VERT_FILES))) +SHADER_VERT_SPIRV_FILES := $(patsubst $(SHADER_DIR)/%.vert,$(SHADER_OUT_DIR)/%.vert.spv,$(SHADER_VERT_FILES)) $(SHADER_OUT_DIR)/%.vert.spv: $(SHADER_DIR)/%.vert @echo "Compiling Vertex Shaders" @mkdir -p $(@D) @$(GLSLC) -c $< -o $@ -SHADER_FRAG_SPIRV_FILES := $(patsubst $(SHADER_DIR)/%.frag,$(SHADER_OUT_DIR)/%.frag.spv,$(filter $(SHADER_DIR)/%.frag,$(SHADER_FRAG_FILES))) \ - $(patsubst %.frag,$(SHADER_OUT_DIR)/%.frag.spv,$(filter-out $(SHADER_DIR)/%.frag,$(SHADER_FRAG_FILES))) +SHADER_FRAG_SPIRV_FILES := $(patsubst $(SHADER_DIR)/%.frag,$(SHADER_OUT_DIR)/%.frag.spv,$(SHADER_FRAG_FILES)) $(SHADER_OUT_DIR)/%.frag.spv: $(SHADER_DIR)/%.frag @echo "Compiling Fragment Shaders" @mkdir -p $(@D) @@ -50,6 +47,7 @@ PROGRAM := main program: $(OBJ_FILES) @echo "" @echo "Object Files Compiled!" + @echo "" @echo "Compiling Executable..." $(CXX) $^ -o $(PROGRAM) $(CXXFLAGS) @@ -59,45 +57,43 @@ windows: @$(MAKE) shaders \ GLSLC="./bin/glslc.exe" \ --no-print-directory - @echo "Shaders Compiled!" @echo -n "Compiling Object Files: " @$(MAKE) program \ CXX="x86_64-w64-mingw32-g++" \ CXXFLAGS="-I include -L lib/x86_64-w64-mingw32 -lopengl32 -lglfw3dll -lvulkan -std=c++20" \ --no-print-directory + @echo "" linux: @echo "Making game for Linux" @$(MAKE) shaders \ GLSLC="./bin/glslc" \ --no-print-directory - @echo "Shaders Compiled!" @echo -n "Compiling Object Files: " @$(MAKE) program \ CXX="g++" \ CXXFLAGS="-I include -L lib/x86_64-linux-gnu -lglfw3 -lvulkan -lGL -std=c++20" \ --no-print-directory - + @echo "" shaders: $(SHADER_VERT_SPIRV_FILES) $(SHADER_FRAG_SPIRV_FILES) - @echo "Compiling Shaders: GLSLC = $(GLSLC)" - -# shaders-linux: + @echo "Shaders Compiled!" test: - @echo $(SRC_FILES) - @echo $(OBJ_FILES) - @echo $(SHADER_VERT_FILES) - @echo $(SHADER_FRAG_FILES) - @echo $(SHADER_VERT_SPIRV_FILES) - @echo $(SHADER_FRAG_SPIRV_FILES) + @echo " SRC_FILES: $(SRC_FILES)" + @echo " OBJ_FILES: $(OBJ_FILES)" + @echo " SHADER_VERT_FILES: $(SHADER_VERT_FILES)" + @echo " SHADER_FRAG_FILES: $(SHADER_FRAG_FILES)" + @echo "SHADER_VERT_SPIRV_FILES: $(SHADER_VERT_SPIRV_FILES)" + @echo "SHADER_FRAG_SPIRV_FILES: $(SHADER_FRAG_SPIRV_FILES)" run: @# Uses wildcard to be platform independant -- might cause unintended behavior - ./$(PROGRAM)* + @echo ">>> Starting Program" + @./$(PROGRAM)* clean: @rm -rf $(PROGRAM) $(PROGRAM).exe $(OBJ_DIR) diff --git a/README.md b/README.md index 3653a89..2683ce1 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,20 @@ # Vulkan-Engine-cpp -This is a game engine prototype I'm creating by following [this tutorial](https://www.youtube.com/playlist?list=PL8327DO66nu9qYVKLDmdLW_84-yE4auCR) +This program uses Vulkan to render inside of a GLFW window and requires your computer to be compatible with Vulkan. \ +This is a game engine prototype I'm creating by following [this tutorial](https://www.youtube.com/playlist?list=PL8327DO66nu9qYVKLDmdLW_84-yE4auCR). \ +All libraries and headers are included so it should be as plug and play as possible. Makefile can cross-compile to a Windows executable using MinGW. \ +Uses C++20 by default. +## Download/Execution +Just pull, `cd` into the repo, and call `make`. Default directive is to build for Windows, run `make linux` to build +for linux. + +## Dependencies +Everything needed is included. Your computer must support the Vulkan API. \ +To compile for Windows, as stated above, a MinGW compiler is required. *The included GLFW library is built for MinGW not MSVC*. \ +The MinGW compiler that I'm using is from the Ubuntu 22.04 package manager (jammy) on WSL. +If you're using Msys2 or w64devkit you will probably need to modify the make file directly to change which binary is being executed. + +### Showcase: +[](images/demo.png) diff --git a/images/demo.png b/images/demo.png new file mode 100644 index 0000000..54bbb49 Binary files /dev/null and b/images/demo.png differ