Initial window setup

This commit is contained in:
Nathan Chapman 2025-07-20 20:08:40 -06:00
commit b37a540bc7
12 changed files with 25734 additions and 0 deletions

27
.editorconfig Normal file
View File

@ -0,0 +1,27 @@
# See http://editorconfig.org to read about the EditorConfig format.
# - In theory automatically supported by VS2017+ and most common IDE or text editors.
# - In practice VS2019-VS2022 stills don't trim trailing whitespaces correctly :(
# - Suggest installing this to trim whitespaces:
# GitHub https://github.com/madskristensen/TrailingWhitespace
# VS2019 https://marketplace.visualstudio.com/items?itemName=MadsKristensen.TrailingWhitespaceVisualizer
# VS2022 https://marketplace.visualstudio.com/items?itemName=MadsKristensen.TrailingWhitespace64
# (in spite of its name doesn't only visualize but also trims)
# - Alternative for older VS2010 to VS2015: https://marketplace.visualstudio.com/items?itemName=EditorConfigTeam.EditorConfig
# top-most EditorConfig file
root = true
# Default settings:
[*]
indent_style = space
indent_size = 2
insert_final_newline = true
trim_trailing_whitespace = true
[imstb_*]
indent_size = 3
trim_trailing_whitespace = false
[Makefile]
indent_style = tab
indent_size = 4

30
.gitattributes vendored Normal file
View File

@ -0,0 +1,30 @@
* text=auto
*.c text
*.cpp text
*.h text
*.m text
*.mm text
*.md text
*.txt text
*.html text
*.bat text
*.frag text
*.vert text
*.mkb text
*.icf text
*.sln text eol=crlf
*.vcxproj text eol=crlf
*.vcxproj.filters text eol=crlf
*.natvis text eol=crlf
Makefile text eol=lf
*.sh text eol=lf
*.pbxproj text eol=lf
*.storyboard text eol=lf
*.plist text eol=lf
*.png binary
*.ttf binary
*.lib binary

23
.gitignore vendored Normal file
View File

@ -0,0 +1,23 @@
# CMake build directories
build/
cmake-build-*/
out/
.cache/
# CMake generated files
CMakeFiles/
CMakeCache.txt
cmake_install.cmake
Makefile
*.vcxproj*
*.sln
# IDE specific files
.idea/
.vscode/
*.user
# Other temporary files
*.log
*.tmp
*.swp

63
CMakeLists.txt Normal file
View File

@ -0,0 +1,63 @@
cmake_minimum_required(VERSION 3.19)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
project(Main)
file(GLOB SOURCES src/*.h src/*.cpp src/*.c)
add_executable(Main ${SOURCES})
target_include_directories(Main PUBLIC include src)
# # Add ImGui sources
# file(GLOB IMGUI_SOURCES
# ${CMAKE_CURRENT_LIST_DIR}/include/imgui/*.cpp
# )
# file(GLOB TINY_GLTF_SOURCES ${CMAKE_CURRENT_LIST_DIR}/include/tiny_gltf/*.cc)
# target_sources(Main PRIVATE ${IMGUI_SOURCES})
# target_sources(Main PRIVATE ${TINY_GLTF_SOURCES})
find_package(glfw3 3.4 REQUIRED)
set(OpenGL_GL_PREFERENCE GLVND)
find_package(OpenGL REQUIRED)
find_package(glm REQUIRED)
# # copy shader files
# file(GLOB GLSL_SOURCE_FILES
# shaders/*.frag
# shaders/*.vert
# )
# add_custom_target(Shaders DEPENDS ${GLSL_SOURCE_FILES})
# add_dependencies(Main Shaders)
# add_custom_command(TARGET Shaders POST_BUILD
# COMMAND ${CMAKE_COMMAND} -E copy_directory
# "$<TARGET_PROPERTY:Main,SOURCE_DIR>/shaders"
# "$<TARGET_PROPERTY:Main,BINARY_DIR>/$<CONFIGURATION>/shaders"
# )
# # copy assets
# file(GLOB ASSET_FILES assets/*)
# add_custom_target(
# Assets
# DEPENDS ${ASSET_FILES}
# )
# add_dependencies(Main Assets)
# add_custom_command(TARGET Assets POST_BUILD
# COMMAND ${CMAKE_COMMAND} -E copy_directory
# "$<TARGET_PROPERTY:Main,SOURCE_DIR>/assets"
# "$<TARGET_PROPERTY:Main,BINARY_DIR>/$<CONFIGURATION>/assets"
# )
if(UNIX)
set(GLFW3_LIBRARY glfw)
endif()
include_directories(${GLFW3_INCLUDE_DIR} ${GLM_INCLUDE_DIR})
target_link_libraries(Main ${GLFW3_LIBRARY} OpenGL::GL)

43
compile Executable file
View File

@ -0,0 +1,43 @@
#!/bin/sh
RUN_AFTER_BUILD=0
CMAKE_ARGS=""
BINARY_NAME="Main"
BUILD_DIR="build"
for arg in "$@"; do
case "$arg" in
--clean)
echo "Cleaning build directory..."
rm -rf build/*
;;
--debug)
echo "Enabling debug build..."
CMAKE_ARGS="-DCMAKE_BUILD_TYPE=Debug"
;;
--run)
RUN_AFTER_BUILD=1
;;
*)
echo "Unknown argument: $arg"
echo "Usage: $0 [--clean] [--debug] [--run]"
exit 1
;;
esac
done
mkdir -p "$BUILD_DIR"
cmake -B "$BUILD_DIR" -S . -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ $CMAKE_ARGS
cmake --build "$BUILD_DIR" -- -j"$(nproc)"
if [ "$RUN_AFTER_BUILD" -eq 1 ]; then
if [ -x "build/$BINARY_NAME" ]; then
echo "Running ./$BINARY_NAME..."
"./build/$BINARY_NAME"
else
echo "Error: Binary 'build/$BINARY_NAME' not found or not executable."
exit 1
fi
fi

80
compile_commands.json Normal file
View File

@ -0,0 +1,80 @@
[
{
"directory": "/home/nathan/dev/cpp/game_animation_programming/build",
"command": "/usr/bin/c++ -I/home/nathan/dev/cpp/game_animation_programming/include -I/home/nathan/dev/cpp/game_animation_programming/src -std=gnu++17 -o CMakeFiles/Main.dir/src/file.cpp.o -c /home/nathan/dev/cpp/game_animation_programming/src/file.cpp",
"file": "/home/nathan/dev/cpp/game_animation_programming/src/file.cpp",
"output": "CMakeFiles/Main.dir/src/file.cpp.o"
},
{
"directory": "/home/nathan/dev/cpp/game_animation_programming/build",
"command": "/usr/bin/cc -I/home/nathan/dev/cpp/game_animation_programming/include -I/home/nathan/dev/cpp/game_animation_programming/src -o CMakeFiles/Main.dir/src/glad.c.o -c /home/nathan/dev/cpp/game_animation_programming/src/glad.c",
"file": "/home/nathan/dev/cpp/game_animation_programming/src/glad.c",
"output": "CMakeFiles/Main.dir/src/glad.c.o"
},
{
"directory": "/home/nathan/dev/cpp/game_animation_programming/build",
"command": "/usr/bin/c++ -I/home/nathan/dev/cpp/game_animation_programming/include -I/home/nathan/dev/cpp/game_animation_programming/src -std=gnu++17 -o CMakeFiles/Main.dir/src/main.cpp.o -c /home/nathan/dev/cpp/game_animation_programming/src/main.cpp",
"file": "/home/nathan/dev/cpp/game_animation_programming/src/main.cpp",
"output": "CMakeFiles/Main.dir/src/main.cpp.o"
},
{
"directory": "/home/nathan/dev/cpp/game_animation_programming/build",
"command": "/usr/bin/c++ -I/home/nathan/dev/cpp/game_animation_programming/include -I/home/nathan/dev/cpp/game_animation_programming/src -std=gnu++17 -o CMakeFiles/Main.dir/src/model.cpp.o -c /home/nathan/dev/cpp/game_animation_programming/src/model.cpp",
"file": "/home/nathan/dev/cpp/game_animation_programming/src/model.cpp",
"output": "CMakeFiles/Main.dir/src/model.cpp.o"
},
{
"directory": "/home/nathan/dev/cpp/game_animation_programming/build",
"command": "/usr/bin/c++ -I/home/nathan/dev/cpp/game_animation_programming/include -I/home/nathan/dev/cpp/game_animation_programming/src -std=gnu++17 -o CMakeFiles/Main.dir/src/renderer.cpp.o -c /home/nathan/dev/cpp/game_animation_programming/src/renderer.cpp",
"file": "/home/nathan/dev/cpp/game_animation_programming/src/renderer.cpp",
"output": "CMakeFiles/Main.dir/src/renderer.cpp.o"
},
{
"directory": "/home/nathan/dev/cpp/game_animation_programming/build",
"command": "/usr/bin/c++ -I/home/nathan/dev/cpp/game_animation_programming/include -I/home/nathan/dev/cpp/game_animation_programming/src -std=gnu++17 -o CMakeFiles/Main.dir/src/user_interface.cpp.o -c /home/nathan/dev/cpp/game_animation_programming/src/user_interface.cpp",
"file": "/home/nathan/dev/cpp/game_animation_programming/src/user_interface.cpp",
"output": "CMakeFiles/Main.dir/src/user_interface.cpp.o"
},
{
"directory": "/home/nathan/dev/cpp/game_animation_programming/build",
"command": "/usr/bin/c++ -I/home/nathan/dev/cpp/game_animation_programming/include -I/home/nathan/dev/cpp/game_animation_programming/src -std=gnu++17 -o CMakeFiles/Main.dir/src/window.cpp.o -c /home/nathan/dev/cpp/game_animation_programming/src/window.cpp",
"file": "/home/nathan/dev/cpp/game_animation_programming/src/window.cpp",
"output": "CMakeFiles/Main.dir/src/window.cpp.o"
},
{
"directory": "/home/nathan/dev/cpp/game_animation_programming/build",
"command": "/usr/bin/c++ -I/home/nathan/dev/cpp/game_animation_programming/include -I/home/nathan/dev/cpp/game_animation_programming/src -std=gnu++17 -o CMakeFiles/Main.dir/include/imgui/imgui.cpp.o -c /home/nathan/dev/cpp/game_animation_programming/include/imgui/imgui.cpp",
"file": "/home/nathan/dev/cpp/game_animation_programming/include/imgui/imgui.cpp",
"output": "CMakeFiles/Main.dir/include/imgui/imgui.cpp.o"
},
{
"directory": "/home/nathan/dev/cpp/game_animation_programming/build",
"command": "/usr/bin/c++ -I/home/nathan/dev/cpp/game_animation_programming/include -I/home/nathan/dev/cpp/game_animation_programming/src -std=gnu++17 -o CMakeFiles/Main.dir/include/imgui/imgui_draw.cpp.o -c /home/nathan/dev/cpp/game_animation_programming/include/imgui/imgui_draw.cpp",
"file": "/home/nathan/dev/cpp/game_animation_programming/include/imgui/imgui_draw.cpp",
"output": "CMakeFiles/Main.dir/include/imgui/imgui_draw.cpp.o"
},
{
"directory": "/home/nathan/dev/cpp/game_animation_programming/build",
"command": "/usr/bin/c++ -I/home/nathan/dev/cpp/game_animation_programming/include -I/home/nathan/dev/cpp/game_animation_programming/src -std=gnu++17 -o CMakeFiles/Main.dir/include/imgui/imgui_impl_glfw.cpp.o -c /home/nathan/dev/cpp/game_animation_programming/include/imgui/imgui_impl_glfw.cpp",
"file": "/home/nathan/dev/cpp/game_animation_programming/include/imgui/imgui_impl_glfw.cpp",
"output": "CMakeFiles/Main.dir/include/imgui/imgui_impl_glfw.cpp.o"
},
{
"directory": "/home/nathan/dev/cpp/game_animation_programming/build",
"command": "/usr/bin/c++ -I/home/nathan/dev/cpp/game_animation_programming/include -I/home/nathan/dev/cpp/game_animation_programming/src -std=gnu++17 -o CMakeFiles/Main.dir/include/imgui/imgui_impl_opengl3.cpp.o -c /home/nathan/dev/cpp/game_animation_programming/include/imgui/imgui_impl_opengl3.cpp",
"file": "/home/nathan/dev/cpp/game_animation_programming/include/imgui/imgui_impl_opengl3.cpp",
"output": "CMakeFiles/Main.dir/include/imgui/imgui_impl_opengl3.cpp.o"
},
{
"directory": "/home/nathan/dev/cpp/game_animation_programming/build",
"command": "/usr/bin/c++ -I/home/nathan/dev/cpp/game_animation_programming/include -I/home/nathan/dev/cpp/game_animation_programming/src -std=gnu++17 -o CMakeFiles/Main.dir/include/imgui/imgui_tables.cpp.o -c /home/nathan/dev/cpp/game_animation_programming/include/imgui/imgui_tables.cpp",
"file": "/home/nathan/dev/cpp/game_animation_programming/include/imgui/imgui_tables.cpp",
"output": "CMakeFiles/Main.dir/include/imgui/imgui_tables.cpp.o"
},
{
"directory": "/home/nathan/dev/cpp/game_animation_programming/build",
"command": "/usr/bin/c++ -I/home/nathan/dev/cpp/game_animation_programming/include -I/home/nathan/dev/cpp/game_animation_programming/src -std=gnu++17 -o CMakeFiles/Main.dir/include/imgui/imgui_widgets.cpp.o -c /home/nathan/dev/cpp/game_animation_programming/include/imgui/imgui_widgets.cpp",
"file": "/home/nathan/dev/cpp/game_animation_programming/include/imgui/imgui_widgets.cpp",
"output": "CMakeFiles/Main.dir/include/imgui/imgui_widgets.cpp.o"
}
]

15914
include/glad/glad.h Normal file

File diff suppressed because one or more lines are too long

32
src/basic.h Normal file
View File

@ -0,0 +1,32 @@
#pragma once
#define GLM_ENABLE_EXPERIMENTAL
#include <string>
#include <glm/glm.hpp>
#include <glm/gtx/quaternion.hpp>
typedef unsigned char u8;
typedef unsigned short u16;
typedef unsigned int u32;
typedef unsigned long long u64;
typedef char s8;
typedef short s16;
typedef int s32;
typedef long long s64;
typedef s32 b32;
typedef float f32;
typedef double f64;
typedef std::string string;
#define array_count(array) (sizeof(array) / sizeof((array)[0]))
using Vector2 = glm::vec2;
using Vector3 = glm::vec3;
using Matrix4 = glm::mat4;
using Quaternion = glm::quat;

9436
src/glad.c Normal file

File diff suppressed because one or more lines are too long

17
src/main.cpp Normal file
View File

@ -0,0 +1,17 @@
#include <cstdio>
#include "renderer.h"
Renderer renderer;
int main () {
init_renderer(&renderer);
while (!glfwWindowShouldClose(renderer.window)) {
update_renderer(&renderer);
}
cleanup_renderer(&renderer);
return 0;
}

55
src/renderer.cpp Normal file
View File

@ -0,0 +1,55 @@
#include "renderer.h"
bool init_renderer(Renderer* renderer) {
// Creating the window and setting it as the current context
glfwInit();
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 6);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
renderer->window = glfwCreateWindow(renderer->window_width, renderer->window_height, "Terrain Rendering", nullptr, nullptr);
if (renderer->window == nullptr) {
printf("Failed to create GLFW window\n");
glfwTerminate();
return false;
}
glfwMakeContextCurrent(renderer->window);
// Initializing GLAD
if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress)) {
printf("Failed to initialize GLAD\n");
return false;
}
glViewport(0, 0, renderer->window_width, renderer->window_height);
glfwSetFramebufferSizeCallback(renderer->window, framebuffer_size_callback);
return true;
}
void cleanup_renderer(Renderer* renderer) {
glfwTerminate();
}
void update_renderer(Renderer* renderer) {
// Process input
if (glfwGetKey(renderer->window, GLFW_KEY_ESCAPE == GLFW_PRESS)) {
glfwSetWindowShouldClose(renderer->window, true);
}
// Draw calls
glClearColor(0.2f, 0.3f, 0.3f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);
// Swap and poll events
glfwSwapBuffers(renderer->window);
glfwPollEvents();
}
void framebuffer_size_callback(GLFWwindow* window, s32 width, s32 height) {
glViewport(0, 0, width, height);
}

14
src/renderer.h Normal file
View File

@ -0,0 +1,14 @@
#include "basic.h"
#include <glad/glad.h>
#include <GLFW/glfw3.h>
struct Renderer {
GLFWwindow* window = nullptr;
u32 window_width = 800;
u32 window_height = 600;
};
bool init_renderer(Renderer* renderer);
void cleanup_renderer(Renderer* renderer);
void update_renderer(Renderer* renderer);
void framebuffer_size_callback(GLFWwindow* window, s32 width, s32 height);