Skip to content

Commit

Permalink
Added showcase to README. Updated Makefile
Browse files Browse the repository at this point in the history
  • Loading branch information
Sargates committed Mar 2, 2024
1 parent 72c5cd9 commit 032226b
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 30 deletions.
54 changes: 25 additions & 29 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,38 +4,35 @@ 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)


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)
Expand All @@ -50,6 +47,7 @@ PROGRAM := main
program: $(OBJ_FILES)
@echo ""
@echo "Object Files Compiled!"
@echo ""
@echo "Compiling Executable..."
$(CXX) $^ -o $(PROGRAM) $(CXXFLAGS)

Expand All @@ -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)
Expand Down
17 changes: 16 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -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:
[<img src="images/demo.png" width="720"/>](images/demo.png)
Binary file added images/demo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 032226b

Please sign in to comment.