Compare commits

..

6 Commits

Author SHA1 Message Date
8f21c8d141 feat: windows build instructions 2025-10-01 09:13:02 +02:00
9b18f8a902 feat: cmake config (windows) 2025-10-01 09:12:57 +02:00
9dbd600c57 feat: avoid use of glew_static (windows) 2025-10-01 09:12:33 +02:00
618bfceddb feat: explicit conversion to string 2025-10-01 09:12:23 +02:00
624186e4fb feat: use math defines (windows) 2025-10-01 09:12:13 +02:00
91c0e7b2a6 feat: avoid use of glew_static 2025-10-01 09:12:04 +02:00
6 changed files with 75 additions and 22 deletions

View File

@ -1,29 +1,55 @@
cmake_minimum_required(VERSION 3.11) cmake_minimum_required(VERSION 3.16)
project(CodingGame LANGUAGES C CXX) project(CodingGame LANGUAGES C CXX)
include(FetchContent) # --- deps via vcpkg ---
# (vcpkg installs decide static vs shared; no "SDL3-shared" component needed)
find_package(SDL3 CONFIG REQUIRED)
find_package(OpenGL REQUIRED)
find_package(GLEW CONFIG REQUIRED)
find_package(glm CONFIG REQUIRED)
FetchContent_Declare( # --- exe ---
glm add_executable(CodingGame
GIT_REPOSITORY https://github.com/g-truc/glm.git src/prelude.cpp
GIT_TAG bf71a834948186f4097caa076cd2663c69a10e1e #refs/tags/1.0.1 src/file_manager.cpp
src/shader.cpp
src/block.cpp
src/vertex.cpp
src/texture.cpp
src/model.cpp
src/main.cpp
) )
FetchContent_MakeAvailable(glm) set_property(TARGET CodingGame PROPERTY CXX_STANDARD 17)
set_property(TARGET CodingGame PROPERTY CXX_STANDARD_REQUIRED ON)
find_package(SDL3 REQUIRED CONFIG REQUIRED COMPONENTS SDL3-shared) file(COPY ${CMAKE_SOURCE_DIR}/src/shaders DESTINATION ${CMAKE_BINARY_DIR}/)
find_package(OpenGL REQUIRED)
find_package(GLEW REQUIRED)
# Add -ggdb to debug builds target_include_directories(CodingGame PRIVATE
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -ggdb") ${CMAKE_SOURCE_DIR}/include
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -ggdb") ${CMAKE_SOURCE_DIR}/contrib
)
add_executable(CodingGame src/prelude.cpp src/file_manager.cpp src/shader.cpp src/block.cpp src/vertex.cpp src/texture.cpp src/model.cpp src/main.cpp) target_link_libraries(CodingGame PRIVATE
glm::glm
OpenGL::GL
SDL3::SDL3 # vcpkgs SDL3 target
GLEW::GLEW
)
set_property(TARGET CodingGame PROPERTY CXX_STANDARD_REQUIRED 17) # Debug flags per toolchain
if (MSVC)
target_compile_options(CodingGame PRIVATE $<$<CONFIG:Debug>:/Zi>)
target_link_options(CodingGame PRIVATE $<$<CONFIG:Debug>:/DEBUG:FULL>)
else()
target_compile_options(CodingGame PRIVATE $<$<CONFIG:Debug>:-ggdb>)
endif()
file(COPY src/shaders DESTINATION ${CMAKE_BINARY_DIR}/) # --- copy runtime DLLs next to the exe on Windows ---
# (CMake 3.21+)
target_include_directories(CodingGame PRIVATE ${CMAKE_SOURCE_DIR}/include ${CMAKE_SOURCE_DIR}/contrib) if (WIN32)
target_link_libraries(CodingGame PRIVATE SDL3::SDL3 OpenGL::GL GLEW::GLEW glm::glm) add_custom_command(TARGET CodingGame POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
$<TARGET_RUNTIME_DLLS:CodingGame> $<TARGET_FILE_DIR:CodingGame>
COMMAND_EXPAND_LISTS)
endif()

25
WINDOWS.md Normal file
View File

@ -0,0 +1,25 @@
# Setup VCPKG
```console
git clone https://github.com/microsoft/vcpkg C:\vcpkg
C:\vcpkg\bootstrap-vcpkg.bat
# install deps for 64-bit Windows
C:\vcpkg\vcpkg install sdl3 glew glm --triplet x64-windows
```
# Configure
```console
cmake -S . -B build `
-G "Visual Studio 17 2022" -A x64 `
-DCMAKE_TOOLCHAIN_FILE=C:/vcpkg/scripts/buildsystems/vcpkg.cmake `
-DVCPKG_TARGET_TRIPLET=x64-windows `
-DCMAKE_BUILD_TYPE=Debug
```
# Build
```console
cmake --build build --config Debug
```

View File

@ -1,6 +1,6 @@
#ifndef PRELUDE_H_ #ifndef PRELUDE_H_
#define PRELUDE_H_ #define PRELUDE_H_
#define GLEW_STATIC // #define GLEW_STATIC
#include <GL/glew.h> #include <GL/glew.h>
#include "SDL3/SDL.h" #include "SDL3/SDL.h"

View File

@ -1,4 +1,6 @@
#include <iostream> #include <iostream>
#define _USE_MATH_DEFINES
#include <cmath>
#include <vector> #include <vector>
#include <glm/glm.hpp> #include <glm/glm.hpp>
#include <glm/ext/quaternion_geometric.hpp> #include <glm/ext/quaternion_geometric.hpp>

View File

@ -215,7 +215,7 @@ Object Object::LoadFile(const std::string& filename) {
iss >> mtlFile; iss >> mtlFile;
std::filesystem::path fullPath = filename; std::filesystem::path fullPath = filename;
std::filesystem::path mtlPath = fullPath.replace_filename(mtlFile); std::filesystem::path mtlPath = fullPath.replace_filename(mtlFile);
obj.LoadMaterials(mtlPath); obj.LoadMaterials(mtlPath.u8string());
std::cout << "loaded mtl at '" << mtlPath << "' with " std::cout << "loaded mtl at '" << mtlPath << "' with "
<< obj.m_materials.size() << " materials" << std::endl; << obj.m_materials.size() << " materials" << std::endl;
break; break;

View File

@ -6,7 +6,7 @@
#include <errno.h> #include <errno.h>
#include "prelude.h" #include "prelude.h"
#define GLEW_STATIC // #define GLEW_STATIC
#include <GL/glew.h> #include <GL/glew.h>
#define SCREEN_WIDTH 1024 #define SCREEN_WIDTH 1024