From b701dde3dbed54adb2ed7be465f91f890085161d Mon Sep 17 00:00:00 2001 From: Jacob Signorovitch Date: Tue, 17 Dec 2024 11:56:18 -0500 Subject: [PATCH] Initial commit. --- .clang-format | 12 ++++++++ .gitignore | 2 ++ Makefile | 64 +++++++++++++++++++++++++++++++++++++++++++ res/shaders/test.frag | 10 +++++++ res/shaders/test.vert | 21 ++++++++++++++ src/include/main.hpp | 0 src/main.cpp | 7 +++++ 7 files changed, 116 insertions(+) create mode 100644 .clang-format create mode 100644 .gitignore create mode 100644 Makefile create mode 100644 res/shaders/test.frag create mode 100644 res/shaders/test.vert create mode 100644 src/include/main.hpp create mode 100644 src/main.cpp diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..fbd9e79 --- /dev/null +++ b/.clang-format @@ -0,0 +1,12 @@ +--- +BasedOnStyle: LLVM +AlignConsecutiveShortCaseStatements: + Enabled: true + AcrossEmptyLines: true + AcrossComments: true +AllowShortBlocksOnASingleLine: Always +AllowShortCaseLabelsOnASingleLine: true +AllowShortIfStatementsOnASingleLine: AllIfsAndElse +AllowShortLoopsOnASingleLine: true +IndentWidth: 4 +PointerAlignment: Left diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d7323bc --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +build +*.out diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..33dec5c --- /dev/null +++ b/Makefile @@ -0,0 +1,64 @@ +NAME = ln-frag + +TARGET = $(NAME).out + +SRC_DIR = src +INC_DIR = $(SRC_DIR)/include +SHADER_DIR = res/shaders +BUILD_DIR = build +OBJ_DIR = $(BUILD_DIR)/obj +SPV_DIR = $(BUILD_DIR)/spv + +CXX = clang++ +LINK = clang +GLSLC = glslc +CFLAGS = -Wall -DDBG -ggdb +LDFLAGS = + +SRC_FILES = $(wildcard $(SRC_DIR)/*.cpp) +OBJ_FILES = $(patsubst $(SRC_DIR)/%.cpp, $(OBJ_DIR)/%.o, $(SRC_FILES)) +OBJ_FILES_NOMAIN = $(filter-out $(OBJ_DIR)/main.o, $(OBJ_FILES)) # Object files without main.c. +SHADER_FILES = $(wildcard $(SHADER_DIR)/*) + +RESETCOLOR = \033[0m +WHITE = $(RESETCOLOR)\033[37m +WHITE_BOLD = $(RESETCOLOR)\033[37;1m + +all: $(TARGET) + +release: clean +release: CFLAGS = -Wall -O2 +release: $(TARGET) + +run: $(TARGET) + @ echo -e "$(WHITE_BOLD)Running... $(RESETCOLOR)./$(TARGET)" + @ ./$(TARGET) + +# Compile project sources. +$(OBJ_DIR)/%.o: $(SRC_DIR)/%.cpp $(INC_DIR)/%.hpp + @ mkdir -p $(OBJ_DIR) + @ echo -e "$(WHITE_BOLD)Compiling $(WHITE)$<$(WHITE_BOLD)... $(RESETCOLOR)$(CXX) $(CFLAGS) -c $< -o $@" + @ $(CXX) $(CFLAGS) -c $< -o $@ + +# Compile vertex shaders. +$(SPV_DIR)/%-vert.spv: $(SHADER_DIR)/%.vert + @ mkdir -p $(SPV_DIR) + @ echo -e "$(WHITE_BOLD)Compiling vertex shader $(WHITE)$<$(WHITE_BOLD)... $(RESETCOLOR)$(GLSLC) $< -o $@" + @ $(GLSLC) $< -o $@ + +# Compile fragment shaders. +$(SPV_DIR)/%-frag.spv: $(SHADER_DIR)/%.frag + @ mkdir -p $(SPV_DIR) + @ echo -e "$(WHITE_BOLD)Compiling fragment shader $(WHITE)$<$(WHITE_BOLD)... $(RESETCOLOR)$(GLSLC) $< -o $@" + @ $(GLSLC) $< -o $@ + +# Link to final binary. +$(TARGET): $(OBJ_FILES) + @ echo -e "$(WHITE_BOLD)Linking $(WHITE)$(TARGET)$(WHITE_BOLD)...$(RESETCOLOR) $(LINK) -o $(TARGET) $(OBJ_FILES) $(LDFLAGS)" + @ $(LINK) -o $(TARGET) $(OBJ_FILES) $(LDFLAGS) + +clean: + @ echo -e "$(WHITE_BOLD)Cleaning up...$(WHITE) $(OBJ_DIR)/*.o $(TARGET) $(SPV_DIR)/*.spv $(RESETCOLOR)" + @ rm -rf $(OBJ_DIR)/*.o $(TARGET) $(SPV_DIR)/*.spv + +.PHONY: all clean nocolor release run diff --git a/res/shaders/test.frag b/res/shaders/test.frag new file mode 100644 index 0000000..a31ca5f --- /dev/null +++ b/res/shaders/test.frag @@ -0,0 +1,10 @@ +// Simple triangle fragment shader. +#version 450 + +layout(location = 0) in vec3 fragColor; + +layout(location = 0) out vec4 outColor; + +void main() { + outColor = vec4(fragColor, 1.0); +} diff --git a/res/shaders/test.vert b/res/shaders/test.vert new file mode 100644 index 0000000..7a1fadd --- /dev/null +++ b/res/shaders/test.vert @@ -0,0 +1,21 @@ +// Simple triangle vertex shader. +#version 450 + +layout(location = 0) out vec3 fragColor; + +vec2 positions[3] = vec2[]( + vec2(0.0, -0.5), + vec2(0.5, 0.5), + vec2(-0.5, 0.5) + ); + +vec3 colors[3] = vec3[]( + vec3(1.0, 0.0, 0.0), + vec3(0.0, 1.0, 0.0), + vec3(0.0, 0.0, 1.0) + ); + +void main() { + gl_Position = vec4(positions[gl_VertexIndex], 0.0, 1.0); + fragColor = colors[gl_VertexIndex]; +} diff --git a/src/include/main.hpp b/src/include/main.hpp new file mode 100644 index 0000000..e69de29 diff --git a/src/main.cpp b/src/main.cpp new file mode 100644 index 0000000..014ccd2 --- /dev/null +++ b/src/main.cpp @@ -0,0 +1,7 @@ +#include + +int main(int argc, char** argv) { + printf("Hello, world!\n"); + + return 0; +}