sdl and opengl contexts

This commit is contained in:
2025-11-23 10:10:57 +00:00
parent bed8e5e363
commit d5ac791a1a
6 changed files with 218 additions and 12 deletions

View File

@@ -3,26 +3,32 @@ INCLUDE_DIR = inc
SRC_DIR = src
BUILD_DIR = build
# imgui bs
# imgui
IMGUI_DIR = lib/imgui
INCLUDE_DIR += $(IMGUI_DIR) $(IMGUI_DIR)/backends
# Compiler, flags and libraries
CXX = g++
CXX = g++
CXXFLAGS = -std=c++17
LIBS = -lGL -lglm `pkg-config --libs sdl3 sdl3-image`
# =============================== Don't touch below pwease :3 ===============================
# Compiler and linker settings
# Include dirs in compiler flags
CXXFLAGS += $(addprefix -I, $(INCLUDE_DIR))
# Source files
SRC = $(wildcard $(SRC_DIR)/*.cpp)
# Source files (app + subdirs)
SRC := $(wildcard $(SRC_DIR)/*.cpp) $(wildcard $(SRC_DIR)/*/*.cpp)
# Imgui specific stuff
SRC += $(IMGUI_DIR)/imgui.cpp $(IMGUI_DIR)/imgui_demo.cpp $(IMGUI_DIR)/imgui_draw.cpp $(IMGUI_DIR)/imgui_tables.cpp $(IMGUI_DIR)/imgui_widgets.cpp
SRC += $(IMGUI_DIR)/backends/imgui_impl_sdl3.cpp $(IMGUI_DIR)/backends/imgui_impl_opengl3.cpp
# ImGui specific sources (explicit list)
IMGUI_SRC := \
$(IMGUI_DIR)/imgui.cpp \
$(IMGUI_DIR)/imgui_demo.cpp \
$(IMGUI_DIR)/imgui_draw.cpp \
$(IMGUI_DIR)/imgui_tables.cpp \
$(IMGUI_DIR)/imgui_widgets.cpp \
$(IMGUI_DIR)/backends/imgui_impl_sdl3.cpp \
$(IMGUI_DIR)/backends/imgui_impl_opengl3.cpp
SRC += $(IMGUI_SRC)
# Target executable
UNAME := $(shell uname -s)
@@ -30,8 +36,13 @@ BUILD_DIR := $(BUILD_DIR)/$(UNAME)
OBJ_DIR := $(BUILD_DIR)/objs
BIN = $(BUILD_DIR)/main
# Note: I have no clue how this works, copilot made it for me cus my usual makefile didn't like the directory structure :P
# Object files corresponding to the source files
OBJS = $(addprefix $(OBJ_DIR)/, $(addsuffix .o, $(basename $(notdir $(SRC)))))
# Map source paths to object paths so subdirectories are preserved.
# - Files under `$(SRC_DIR)` become `$(OBJ_DIR)/<subdirs>/name.o`
# - ImGui files (in `$(IMGUI_DIR)` and its `backends`) become `$(OBJ_DIR)/name.o`
OBJS := $(foreach f,$(SRC),$(if $(filter $(SRC_DIR)/%,$(f)),$(patsubst $(SRC_DIR)/%.cpp,$(OBJ_DIR)/%.o,$(f)),$(if $(filter $(IMGUI_DIR)/backends/%,$(f)),$(patsubst $(IMGUI_DIR)/backends/%.cpp,$(OBJ_DIR)/%.o,$(f)),$(patsubst $(IMGUI_DIR)/%.cpp,$(OBJ_DIR)/%.o,$(f)))) )
# black magic wizardry below this line (pwease don't touch i beg you)
dev: CXXFLAGS += -g -Wall -Wformat
@@ -43,6 +54,8 @@ release: all
dirs:
@mkdir -p $(BUILD_DIR)
@mkdir -p $(OBJ_DIR)
# create any required subdirectories for object files
@mkdir -p $(sort $(dir $(OBJS)))
# Even more imgui specific stuff >:(
$(OBJ_DIR)/%.o: $(IMGUI_DIR)/%.cpp
@@ -58,7 +71,9 @@ all: dirs $(BIN)
@echo Build complete
$(BIN): $(OBJS)
$(CXX) -o $@ $^ $(CXXFLAGS) $(LIBS)
$(CXX) $(CXXFLAGS) -o $@ $^ $(LIBS)
.PHONY: all dev release clean dirs
clean:
rm -rf $(BUILD_DIR)