From 843a05020627b0512969f7bc76a8e2c4bfdeb45b Mon Sep 17 00:00:00 2001 From: ifilot Date: Fri, 6 Feb 2026 18:30:10 +0100 Subject: [PATCH 1/4] Refactoring for MinGW64 --- .github/workflows/linux.yml | 35 +++++++++++++ .github/workflows/windows.yml | 33 +++++++++++++ CMakeLists.txt | 11 +++++ README.md | 72 ++++++++++++++++----------- lesson01/CMakeLists.txt | 81 ++++++------------------------ lesson01/README.md | 7 +-- lesson02/CMakeLists.txt | 81 ++++++------------------------ lesson02/README.md | 7 +-- lesson03/CMakeLists.txt | 80 ++++++------------------------ lesson03/README.md | 7 +-- lesson04/CMakeLists.txt | 81 ++++++------------------------ lesson04/README.md | 7 +-- lesson04/model.cpp | 38 +++++++------- lesson04/model.h | 5 +- lesson05/CMakeLists.txt | 81 ++++++------------------------ lesson05/README.md | 7 +-- lesson05/model.cpp | 38 +++++++------- lesson05/model.h | 5 +- lesson06/CMakeLists.txt | 93 ++++++++--------------------------- lesson06/README.md | 7 +-- lesson06/model.cpp | 52 ++++++++++---------- lesson06/model.h | 5 +- lesson06/pngfuncs.cpp | 1 + lesson06/pngfuncs.h | 1 + lesson07/CMakeLists.txt | 81 ++++++------------------------ lesson07/README.md | 7 +-- lesson07/model.cpp | 38 +++++++------- lesson07/model.h | 5 +- 28 files changed, 355 insertions(+), 611 deletions(-) create mode 100644 .github/workflows/linux.yml create mode 100644 .github/workflows/windows.yml create mode 100644 CMakeLists.txt diff --git a/.github/workflows/linux.yml b/.github/workflows/linux.yml new file mode 100644 index 0000000..7036d91 --- /dev/null +++ b/.github/workflows/linux.yml @@ -0,0 +1,35 @@ +name: linux-build + +on: + push: + pull_request: + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Install dependencies + run: | + sudo apt-get update + sudo apt-get install -y \ + build-essential \ + cmake \ + libglew-dev \ + libglfw3-dev \ + libglm-dev \ + libgl1-mesa-dev \ + libx11-dev \ + libxi-dev \ + libxrandr-dev \ + libxxf86vm-dev \ + libxcursor-dev + + - name: Configure and build lessons + run: | + set -euo pipefail + cmake -S . -B build + cmake --build build -j$(nproc) diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml new file mode 100644 index 0000000..55854f8 --- /dev/null +++ b/.github/workflows/windows.yml @@ -0,0 +1,33 @@ +name: windows-build + +on: + push: + pull_request: + +jobs: + build: + runs-on: windows-latest + defaults: + run: + shell: msys2 {0} + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Set up MSYS2 (MinGW-w64) + uses: msys2/setup-msys2@v2 + with: + msystem: MINGW64 + update: true + install: >- + mingw-w64-x86_64-toolchain + mingw-w64-x86_64-cmake + mingw-w64-x86_64-glew + mingw-w64-x86_64-glfw + mingw-w64-x86_64-glm + + - name: Configure and build lessons + run: | + set -euo pipefail + cmake -S . -B build -G "MinGW Makefiles" + cmake --build build diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..6564986 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,11 @@ +cmake_minimum_required(VERSION 3.21) + +project(opengl-cpp-course LANGUAGES CXX) + +add_subdirectory(lesson01) +add_subdirectory(lesson02) +add_subdirectory(lesson03) +add_subdirectory(lesson04) +add_subdirectory(lesson05) +add_subdirectory(lesson06) +add_subdirectory(lesson07) diff --git a/README.md b/README.md index 98dc52a..b1eb9ed 100644 --- a/README.md +++ b/README.md @@ -1,16 +1,33 @@ # OpenGL C++ Course **Update** -I made some changes to the code by which everything should now work for MSVC 2019 using Boost 1.74.0. +The build instructions below now target MinGW-w64 (via MSYS2) instead of MSVC. ## Purpose and expectations -This repository contains the source code for the OpenGL C++ course. The course teaches students how to effectively use C++ in conjunction with OpenGL to build graphical programs. The course is made in a concise manner and we refer often to external resources which we expect the student to read (or at least glance through). The learning strategy employed here is "Learning by example" and "Learning by doing". This means that example code is provided and the student is given the opportunity to practice with the material in the form of exercises. - -We assume that the student is relatively comfortable reading C++ code and has some previous experience with it. The exercises are constructed in such a way that the student only has to change a few lines of code. Furthermore, we expect that the reader is familiar with matrix-vector multiplication and has some understanding of mathematics. Finally, we expect that the user is a bit familiar using the Windows command prompt. - -This course focuses on running OpenGL in a Windows environment, although it should also run under Linux (we have tested it for Linux Debian). If you want to compile the programs on Linux, please read [below](#compilation-instructions-for-linux) as the instructions for CMake differ slightly. OpenGL and the libraries we are using are cross-platform and thus work on Windows, Mac OS X as well as Linux. - -Feedback on this course is always much appreciated if provided in a constructive manner. Feel free to use the Issues system on Github for this purpose. +This repository contains the source code for the OpenGL C++ course. The course +teaches students how to effectively use C++ in conjunction with OpenGL to build +graphical programs. The course is made in a concise manner and I refer often to +external resources which I expect the student to read (or at least glance +through). The learning strategy employed here is "Learning by example" and +"Learning by doing". This means that example code is provided and the student is +given the opportunity to practice with the material in the form of exercises. + +We assume that the student is relatively comfortable reading C++ code and has +some previous experience with it. The exercises are constructed in such a way +that the student only has to change a few lines of code. Furthermore, we expect +that the student is familiar with matrix-vector multiplication and has some +understanding of matrix mathematics. Finally, we expect that the student is a +bit familiar using the command line. + +This course focuses on running OpenGL in a Windows environment using MinGW-w64, +although it should also run under Linux (I have tested it for Linux Ubuntu). If +you want to compile the programs on Linux, please read +[below](#compilation-instructions-for-linux) as the instructions for CMake +differ slightly. OpenGL and the libraries we are using are cross-platform and +thus work on Windows, Mac as well as Linux. + +Feedback on this course is always much appreciated if provided in a constructive +manner. Feel free to use the Issues system on Github for this purpose. ## Lesson overview 1. [Compiling and running an OpenGL program](lesson01/README.md) @@ -21,32 +38,30 @@ Feedback on this course is always much appreciated if provided in a constructive 6. [Textures](lesson06/README.md) 7. [Anaglyph](lesson07/README.md) -## Prerequisite software -In order to compile the software, you need to download and install the following packages. +## Preparation of compilation environment -* [CMake](https://cmake.org/download/) - During the installation, you need to select **Add CMAKE to the system PATH for all users**. -* [Microsoft Visual Studio Community Edition](https://visualstudio.microsoft.com/downloads/) - Use the 2019 version. Under 'Workloads', you only need to select 'Desktop Development with C++' -* [Git](https://git-scm.com/download/win) - You can use the default settings during the installation procedure. -* [Python](https://www.python.org/downloads/) - Use the latest Python 3 version! +In order to compile the software under Windows, install the the MinGW-w64 +toolchain via [MSYS2](https://www.msys2.org/). Next, open **MSYS2 MinGW 64-bit** +and install using `pacman` the dependencies using the following instruction -## Dependencies -* GLFW -* Boost -* Glew -* GLM - -You can easily download these dependencies by double-clicking on `download_dep.py` in the `vendor` folder. This might take a while though! Especially the compiled Boost libraries are relatively big (~300MB). +```bash +pacman -S --needed \ + mingw-w64-x86_64-toolchain \ + mingw-w64-x86_64-cmake \ + mingw-w64-x86_64-glew \ + mingw-w64-x86_64-glfw \ + mingw-w64-x86_64-glm +``` -## Compilation instructions for Windows -Open the `Native x64 Native Tools Command Prompt` and go to the repository root folder. +## Compilation instructions for Windows (MinGW-w64) +Open the **MSYS2 MinGW 64-bit** shell and go to the repository root folder. Create a build directory and execute CMake; note that you need to change `XX` to the lesson of interest. ``` mkdir build -cd build -cmake ..\lessonXX -G "NMake Makefiles" -nmake +cmake -S lessonXX -B build/lessonXX -G "MinGW Makefiles" +cmake --build build/lessonXX ``` ## Compilation instructions for Linux @@ -54,9 +69,8 @@ Open a terminal, go to the root folder of the repository and use the following c ``` mkdir build -cd build -cmake ..\lessonXX -make -j5 +cmake -S lessonXX -B build/lessonXX +cmake --build build/lessonXX -j5 ``` ## Troubleshooting diff --git a/lesson01/CMakeLists.txt b/lesson01/CMakeLists.txt index 091c4db..d374e02 100644 --- a/lesson01/CMakeLists.txt +++ b/lesson01/CMakeLists.txt @@ -1,76 +1,27 @@ -# set minimum cmake requirements -cmake_minimum_required(VERSION 3.5) -project (occ-lesson01) +cmake_minimum_required(VERSION 3.21) -# add custom directory to look for .cmake files -set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_SOURCE_DIR}/cmake/modules ) +project (occ-lesson01 LANGUAGES CXX) -# Enable release build -if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) - message(STATUS "Setting build type to 'Release' as none was specified.") - set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build." FORCE) - set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "MinSizeRel" "RelWithDebInfo") -endif() +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD_REQUIRED ON) +set(CMAKE_CXX_EXTENSIONS OFF) -# set directory to boost -if(WIN32) -SET(BOOST_ROOT "../vendor/boost-1.74.0-win-x64") -else() -add_definitions(-DEIGEN_NO_DEBUG -Wno-literal-suffix) -SET(BOOST_INCLUDEDIR "/usr/include") -SET(BOOST_LIBRARYDIR "/usr/lib/x86_64-linux-gnu") -endif() - -# set Boost -set (Boost_NO_SYSTEM_PATHS ON) -set (Boost_USE_MULTITHREADED ON) -set (Boost_USE_STATIC_LIBS ON) -set (Boost_USE_STATIC_RUNTIME OFF) -set (BOOST_ALL_DYN_LINK OFF) -set (Boost_NO_BOOST_CMAKE ON) - -# Include libraries find_package(OpenGL REQUIRED) -find_package(Boost COMPONENTS chrono regex system serialization filesystem log thread REQUIRED) -find_package(GLFW3 REQUIRED) -if(WIN32) +find_package(glfw3 CONFIG REQUIRED) find_package(GLEW REQUIRED) -find_package(GLM REQUIRED) -else() -find_package(PkgConfig REQUIRED) -pkg_check_modules(GLEW REQUIRED glew) -pkg_check_modules(GLFW3 REQUIRED glfw3) -endif() - +find_package(glm CONFIG REQUIRED) -# Set include folders -include_directories(${CMAKE_CURRENT_SOURCE_DIR} - ${CMAKE_BINARY_DIR} - ${Boost_INCLUDE_DIRS} - ${GLEW_INCLUDE_DIRS} - ${GLUT_INCLUDE_DIRS} - ${GLM_INCLUDE_DIRS} - ${GLFW3_INCLUDE_DIRS}) - -# Add sources -file(GLOB_RECURSE SOURCES "*.cpp") +file(GLOB SOURCES "*.cpp") add_executable(occ-lesson01 ${SOURCES}) -# Link libraries target_link_libraries(occ-lesson01 - ${GLFW3_LIBRARIES} - ${OPENGL_glu_LIBRARY} - ${OPENGL_gl_LIBRARY} - ${Boost_LIBRARIES} - ${GLEW_LIBRARIES}) - -# add Boost definition -add_definitions(-DBOOST_LOG_DYN_LINK) + PRIVATE + glfw + OpenGL::GL + GLEW::GLEW + glm::glm +) -# add Wno-literal-suffix to suppress warning messages -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") +target_compile_definitions(occ-lesson01 PRIVATE GLM_ENABLE_EXPERIMENTAL) -### -# Installing -## -install (TARGETS occ-lesson01 DESTINATION bin) +install(TARGETS occ-lesson01 DESTINATION bin) diff --git a/lesson01/README.md b/lesson01/README.md index f18df73..31a35a9 100644 --- a/lesson01/README.md +++ b/lesson01/README.md @@ -9,11 +9,12 @@ * Conceptually understanding attributes and uniforms ## Compilation instructions +Build from the repository root in a MinGW-w64 shell. + ``` mkdir build -cd build -cmake ..\lesson01 -G "NMake Makefiles" -nmake +cmake -S lesson01 -B build/lesson01 -G "MinGW Makefiles" +cmake --build build/lesson01 ``` If the compilation is not working or if the program shows weird behavior, please check the [troubleshooting section](../README.md#troubleshooting). diff --git a/lesson02/CMakeLists.txt b/lesson02/CMakeLists.txt index 17f4b8b..2aa49f5 100644 --- a/lesson02/CMakeLists.txt +++ b/lesson02/CMakeLists.txt @@ -1,76 +1,27 @@ -# set minimum cmake requirements -cmake_minimum_required(VERSION 3.5) -project (occ-lesson02) +cmake_minimum_required(VERSION 3.21) -# add custom directory to look for .cmake files -set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_SOURCE_DIR}/cmake/modules ) +project (occ-lesson02 LANGUAGES CXX) -# Enable release build -if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) - message(STATUS "Setting build type to 'Release' as none was specified.") - set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build." FORCE) - set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "MinSizeRel" "RelWithDebInfo") -endif() +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD_REQUIRED ON) +set(CMAKE_CXX_EXTENSIONS OFF) -# set directory to boost -if(WIN32) -SET(BOOST_ROOT "../vendor/boost-1.74.0-win-x64") -else() -add_definitions(-DEIGEN_NO_DEBUG -Wno-literal-suffix) -SET(BOOST_INCLUDEDIR "/usr/include") -SET(BOOST_LIBRARYDIR "/usr/lib/x86_64-linux-gnu") -endif() - -# set Boost -set (Boost_NO_SYSTEM_PATHS ON) -set (Boost_USE_MULTITHREADED ON) -set (Boost_USE_STATIC_LIBS ON) -set (Boost_USE_STATIC_RUNTIME OFF) -set (BOOST_ALL_DYN_LINK OFF) -set (Boost_NO_BOOST_CMAKE ON) - -# Include libraries find_package(OpenGL REQUIRED) -find_package(Boost COMPONENTS chrono regex system serialization filesystem log thread REQUIRED) -find_package(GLFW3 REQUIRED) -if(WIN32) +find_package(glfw3 CONFIG REQUIRED) find_package(GLEW REQUIRED) -find_package(GLM REQUIRED) -else() -find_package(PkgConfig REQUIRED) -pkg_check_modules(GLEW REQUIRED glew) -pkg_check_modules(GLFW3 REQUIRED glfw3) -endif() - +find_package(glm CONFIG REQUIRED) -# Set include folders -include_directories(${CMAKE_CURRENT_SOURCE_DIR} - ${CMAKE_BINARY_DIR} - ${Boost_INCLUDE_DIRS} - ${GLEW_INCLUDE_DIRS} - ${GLUT_INCLUDE_DIRS} - ${GLM_INCLUDE_DIRS} - ${GLFW3_INCLUDE_DIRS}) - -# Add sources -file(GLOB_RECURSE SOURCES "*.cpp") +file(GLOB SOURCES "*.cpp") add_executable(occ-lesson02 ${SOURCES}) -# Link libraries target_link_libraries(occ-lesson02 - ${GLFW3_LIBRARIES} - ${OPENGL_glu_LIBRARY} - ${OPENGL_gl_LIBRARY} - ${Boost_LIBRARIES} - ${GLEW_LIBRARIES}) - -# add Boost definition -add_definitions(-DBOOST_LOG_DYN_LINK) + PRIVATE + glfw + OpenGL::GL + GLEW::GLEW + glm::glm +) -# add Wno-literal-suffix to suppress warning messages -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") +target_compile_definitions(occ-lesson02 PRIVATE GLM_ENABLE_EXPERIMENTAL) -### -# Installing -## -install (TARGETS occ-lesson02 DESTINATION bin) +install(TARGETS occ-lesson02 DESTINATION bin) diff --git a/lesson02/README.md b/lesson02/README.md index be0b716..18c002b 100644 --- a/lesson02/README.md +++ b/lesson02/README.md @@ -6,11 +6,12 @@ * Understand the different projection and how to build these ## Compilation instructions +Build from the repository root in a MinGW-w64 shell. + ``` mkdir build -cd build -cmake ..\lesson02 -G "NMake Makefiles" -nmake +cmake -S lesson02 -B build/lesson02 -G "MinGW Makefiles" +cmake --build build/lesson02 ``` ## Running the program diff --git a/lesson03/CMakeLists.txt b/lesson03/CMakeLists.txt index 4df0397..ef85ff9 100644 --- a/lesson03/CMakeLists.txt +++ b/lesson03/CMakeLists.txt @@ -1,75 +1,27 @@ -# set minimum cmake requirements -cmake_minimum_required(VERSION 3.5) -project (occ-lesson03) +cmake_minimum_required(VERSION 3.21) -# add custom directory to look for .cmake files -set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_SOURCE_DIR}/cmake/modules ) +project (occ-lesson03 LANGUAGES CXX) -# Enable release build -if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) - message(STATUS "Setting build type to 'Release' as none was specified.") - set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build." FORCE) - set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "MinSizeRel" "RelWithDebInfo") -endif() +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD_REQUIRED ON) +set(CMAKE_CXX_EXTENSIONS OFF) -# set directory to boost -if(WIN32) -SET(BOOST_ROOT "../vendor/boost-1.74.0-win-x64") -else() -add_definitions(-DEIGEN_NO_DEBUG -Wno-literal-suffix) -SET(BOOST_INCLUDEDIR "/usr/include") -SET(BOOST_LIBRARYDIR "/usr/lib/x86_64-linux-gnu") -endif() -# set Boost -set (Boost_NO_SYSTEM_PATHS ON) -set (Boost_USE_MULTITHREADED ON) -set (Boost_USE_STATIC_LIBS ON) -set (Boost_USE_STATIC_RUNTIME OFF) -set (BOOST_ALL_DYN_LINK OFF) -set (Boost_NO_BOOST_CMAKE ON) - -# Include libraries find_package(OpenGL REQUIRED) -find_package(Boost COMPONENTS chrono regex system serialization filesystem log thread REQUIRED) -find_package(GLFW3 REQUIRED) -if(WIN32) +find_package(glfw3 CONFIG REQUIRED) find_package(GLEW REQUIRED) -find_package(GLM REQUIRED) -else() -find_package(PkgConfig REQUIRED) -pkg_check_modules(GLEW REQUIRED glew) -pkg_check_modules(GLFW3 REQUIRED glfw3) -endif() - +find_package(glm CONFIG REQUIRED) -# Set include folders -include_directories(${CMAKE_CURRENT_SOURCE_DIR} - ${CMAKE_BINARY_DIR} - ${Boost_INCLUDE_DIRS} - ${GLEW_INCLUDE_DIRS} - ${GLUT_INCLUDE_DIRS} - ${GLM_INCLUDE_DIRS} - ${GLFW3_INCLUDE_DIRS}) - -# Add sources -file(GLOB_RECURSE SOURCES "*.cpp") +file(GLOB SOURCES "*.cpp") add_executable(occ-lesson03 ${SOURCES}) -# Link libraries target_link_libraries(occ-lesson03 - ${GLFW3_LIBRARIES} - ${OPENGL_glu_LIBRARY} - ${OPENGL_gl_LIBRARY} - ${Boost_LIBRARIES} - ${GLEW_LIBRARIES}) - -# add Boost definition -add_definitions(-DBOOST_LOG_DYN_LINK) + PRIVATE + glfw + OpenGL::GL + GLEW::GLEW + glm::glm +) -# add Wno-literal-suffix to suppress warning messages -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") +target_compile_definitions(occ-lesson03 PRIVATE GLM_ENABLE_EXPERIMENTAL) -### -# Installing -## -install (TARGETS occ-lesson03 DESTINATION bin) +install(TARGETS occ-lesson03 DESTINATION bin) diff --git a/lesson03/README.md b/lesson03/README.md index 96d9aad..5ff1569 100644 --- a/lesson03/README.md +++ b/lesson03/README.md @@ -5,11 +5,12 @@ * Understand how Shader programs work and how to edit them ## Compilation instructions +Build from the repository root in a MinGW-w64 shell. + ``` mkdir build -cd build -cmake ..\lesson03 -G "NMake Makefiles" -nmake +cmake -S lesson03 -B build/lesson03 -G "MinGW Makefiles" +cmake --build build/lesson03 ``` ## Running the program diff --git a/lesson04/CMakeLists.txt b/lesson04/CMakeLists.txt index 63350c2..fcd79d5 100644 --- a/lesson04/CMakeLists.txt +++ b/lesson04/CMakeLists.txt @@ -1,76 +1,27 @@ -# set minimum cmake requirements -cmake_minimum_required(VERSION 3.5) -project (occ-lesson04) +cmake_minimum_required(VERSION 3.21) -# add custom directory to look for .cmake files -set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_SOURCE_DIR}/cmake/modules ) +project (occ-lesson04 LANGUAGES CXX) -# Enable release build -if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) - message(STATUS "Setting build type to 'Release' as none was specified.") - set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build." FORCE) - set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "MinSizeRel" "RelWithDebInfo") -endif() +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD_REQUIRED ON) +set(CMAKE_CXX_EXTENSIONS OFF) -# set directory to boost -if(WIN32) -SET(BOOST_ROOT "../vendor/boost-1.74.0-win-x64") -else() -add_definitions(-DEIGEN_NO_DEBUG -Wno-literal-suffix) -SET(BOOST_INCLUDEDIR "/usr/include") -SET(BOOST_LIBRARYDIR "/usr/lib/x86_64-linux-gnu") -endif() - -# set Boost -set (Boost_NO_SYSTEM_PATHS ON) -set (Boost_USE_MULTITHREADED ON) -set (Boost_USE_STATIC_LIBS ON) -set (Boost_USE_STATIC_RUNTIME OFF) -set (BOOST_ALL_DYN_LINK OFF) -set (Boost_NO_BOOST_CMAKE ON) - -# Include libraries find_package(OpenGL REQUIRED) -find_package(Boost COMPONENTS chrono regex system serialization filesystem log thread REQUIRED) -find_package(GLFW3 REQUIRED) -if(WIN32) +find_package(glfw3 CONFIG REQUIRED) find_package(GLEW REQUIRED) -find_package(GLM REQUIRED) -else() -find_package(PkgConfig REQUIRED) -pkg_check_modules(GLEW REQUIRED glew) -pkg_check_modules(GLFW3 REQUIRED glfw3) -endif() - +find_package(glm CONFIG REQUIRED) -# Set include folders -include_directories(${CMAKE_CURRENT_SOURCE_DIR} - ${CMAKE_BINARY_DIR} - ${Boost_INCLUDE_DIRS} - ${GLEW_INCLUDE_DIRS} - ${GLUT_INCLUDE_DIRS} - ${GLM_INCLUDE_DIRS} - ${GLFW3_INCLUDE_DIRS}) - -# Add sources -file(GLOB_RECURSE SOURCES "*.cpp") +file(GLOB SOURCES "*.cpp") add_executable(occ-lesson04 ${SOURCES}) -# Link libraries target_link_libraries(occ-lesson04 - ${GLFW3_LIBRARIES} - ${OPENGL_glu_LIBRARY} - ${OPENGL_gl_LIBRARY} - ${Boost_LIBRARIES} - ${GLEW_LIBRARIES}) - -# add Boost definition -add_definitions(-DBOOST_LOG_DYN_LINK) + PRIVATE + glfw + OpenGL::GL + GLEW::GLEW + glm::glm +) -# add Wno-literal-suffix to suppress warning messages -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") +target_compile_definitions(occ-lesson04 PRIVATE GLM_ENABLE_EXPERIMENTAL) -### -# Installing -## -install (TARGETS occ-lesson04 DESTINATION bin) +install(TARGETS occ-lesson04 DESTINATION bin) diff --git a/lesson04/README.md b/lesson04/README.md index 4df5570..08a3935 100644 --- a/lesson04/README.md +++ b/lesson04/README.md @@ -5,11 +5,12 @@ * Understand vertex normals ## Compilation instructions +Build from the repository root in a MinGW-w64 shell. + ``` mkdir build -cd build -cmake ..\lesson04 -G "NMake Makefiles" -nmake +cmake -S lesson04 -B build/lesson04 -G "MinGW Makefiles" +cmake --build build/lesson04 ``` ## Explanation diff --git a/lesson04/model.cpp b/lesson04/model.cpp index 4a560e6..7eda0c8 100644 --- a/lesson04/model.cpp +++ b/lesson04/model.cpp @@ -53,9 +53,9 @@ void Model::load_data(const std::string& path) { if(file.is_open()) { // set regex patterns - static const boost::regex v_line("v\\s+([0-9.-]+)\\s+([0-9.-]+)\\s+([0-9.-]+).*"); - static const boost::regex vn_line("vn\\s+([0-9.-]+)\\s+([0-9.-]+)\\s+([0-9.-]+).*"); - static const boost::regex f_line("f\\s+([0-9]+)\\/\\/([0-9]+)\\s+([0-9]+)\\/\\/([0-9]+)\\s+([0-9]+)\\/\\/([0-9]+).*"); + static const std::regex v_line("v\\s+([0-9.-]+)\\s+([0-9.-]+)\\s+([0-9.-]+).*"); + static const std::regex vn_line("vn\\s+([0-9.-]+)\\s+([0-9.-]+)\\s+([0-9.-]+).*"); + static const std::regex f_line("f\\s+([0-9]+)\\/\\/([0-9]+)\\s+([0-9]+)\\/\\/([0-9]+)\\s+([0-9]+)\\/\\/([0-9]+).*"); // construct holders std::vector _positions; @@ -72,30 +72,30 @@ void Model::load_data(const std::string& path) { // start reading while(std::getline(file, line)) { - boost::smatch what1; + std::smatch what1; - if (boost::regex_match(line, what1, v_line)) { - glm::vec3 pos(boost::lexical_cast(what1[1]), - boost::lexical_cast(what1[2]), - boost::lexical_cast(what1[3])); + if (std::regex_match(line, what1, v_line)) { + glm::vec3 pos(std::stof(what1[1]), + std::stof(what1[2]), + std::stof(what1[3])); _positions.push_back(pos); } - if (boost::regex_match(line, what1, vn_line)) { - glm::vec3 normal(boost::lexical_cast(what1[1]), - boost::lexical_cast(what1[2]), - boost::lexical_cast(what1[3])); + if (std::regex_match(line, what1, vn_line)) { + glm::vec3 normal(std::stof(what1[1]), + std::stof(what1[2]), + std::stof(what1[3])); _normals.push_back(normal); } - if (boost::regex_match(line, what1, f_line)) { - position_indices.push_back(boost::lexical_cast(what1[1]) - 1); - position_indices.push_back(boost::lexical_cast(what1[3]) - 1); - position_indices.push_back(boost::lexical_cast(what1[5]) - 1); + if (std::regex_match(line, what1, f_line)) { + position_indices.push_back(static_cast(std::stoul(what1[1])) - 1); + position_indices.push_back(static_cast(std::stoul(what1[3])) - 1); + position_indices.push_back(static_cast(std::stoul(what1[5])) - 1); - normal_indices.push_back(boost::lexical_cast(what1[2]) - 1); - normal_indices.push_back(boost::lexical_cast(what1[4]) - 1); - normal_indices.push_back(boost::lexical_cast(what1[6]) - 1); + normal_indices.push_back(static_cast(std::stoul(what1[2])) - 1); + normal_indices.push_back(static_cast(std::stoul(what1[4])) - 1); + normal_indices.push_back(static_cast(std::stoul(what1[6])) - 1); } } diff --git a/lesson04/model.h b/lesson04/model.h index 5c870c3..2c8733b 100644 --- a/lesson04/model.h +++ b/lesson04/model.h @@ -21,10 +21,7 @@ #define GLEW_STATIC #endif #include -#include -#include -#include -#include +#include #include #include diff --git a/lesson05/CMakeLists.txt b/lesson05/CMakeLists.txt index 79eb7d3..bf94a44 100644 --- a/lesson05/CMakeLists.txt +++ b/lesson05/CMakeLists.txt @@ -1,76 +1,27 @@ -# set minimum cmake requirements -cmake_minimum_required(VERSION 3.5) -project (occ-lesson05) +cmake_minimum_required(VERSION 3.21) -# add custom directory to look for .cmake files -set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_SOURCE_DIR}/cmake/modules ) +project (occ-lesson05 LANGUAGES CXX) -# Enable release build -if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) - message(STATUS "Setting build type to 'Release' as none was specified.") - set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build." FORCE) - set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "MinSizeRel" "RelWithDebInfo") -endif() +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD_REQUIRED ON) +set(CMAKE_CXX_EXTENSIONS OFF) -# set directory to boost -if(WIN32) -SET(BOOST_ROOT "../vendor/boost-1.74.0-win-x64") -else() -add_definitions(-DEIGEN_NO_DEBUG -Wno-literal-suffix) -SET(BOOST_INCLUDEDIR "/usr/include") -SET(BOOST_LIBRARYDIR "/usr/lib/x86_64-linux-gnu") -endif() - -# set Boost -set (Boost_NO_SYSTEM_PATHS ON) -set (Boost_USE_MULTITHREADED ON) -set (Boost_USE_STATIC_LIBS ON) -set (Boost_USE_STATIC_RUNTIME OFF) -set (BOOST_ALL_DYN_LINK OFF) -set (Boost_NO_BOOST_CMAKE ON) - -# Include libraries find_package(OpenGL REQUIRED) -find_package(Boost COMPONENTS chrono regex system serialization filesystem log thread REQUIRED) -find_package(GLFW3 REQUIRED) -if(WIN32) +find_package(glfw3 CONFIG REQUIRED) find_package(GLEW REQUIRED) -find_package(GLM REQUIRED) -else() -find_package(PkgConfig REQUIRED) -pkg_check_modules(GLEW REQUIRED glew) -pkg_check_modules(GLFW3 REQUIRED glfw3) -endif() - +find_package(glm CONFIG REQUIRED) -# Set include folders -include_directories(${CMAKE_CURRENT_SOURCE_DIR} - ${CMAKE_BINARY_DIR} - ${Boost_INCLUDE_DIRS} - ${GLEW_INCLUDE_DIRS} - ${GLUT_INCLUDE_DIRS} - ${GLM_INCLUDE_DIRS} - ${GLFW3_INCLUDE_DIRS}) - -# Add sources -file(GLOB_RECURSE SOURCES "*.cpp") +file(GLOB SOURCES "*.cpp") add_executable(occ-lesson05 ${SOURCES}) -# Link libraries target_link_libraries(occ-lesson05 - ${GLFW3_LIBRARIES} - ${OPENGL_glu_LIBRARY} - ${OPENGL_gl_LIBRARY} - ${Boost_LIBRARIES} - ${GLEW_LIBRARIES}) - -# add Boost definition -add_definitions(-DBOOST_LOG_DYN_LINK) + PRIVATE + glfw + OpenGL::GL + GLEW::GLEW + glm::glm +) -# add Wno-literal-suffix to suppress warning messages -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") +target_compile_definitions(occ-lesson05 PRIVATE GLM_ENABLE_EXPERIMENTAL) -### -# Installing -## -install (TARGETS occ-lesson05 DESTINATION bin) +install(TARGETS occ-lesson05 DESTINATION bin) diff --git a/lesson05/README.md b/lesson05/README.md index 87886c0..af92645 100644 --- a/lesson05/README.md +++ b/lesson05/README.md @@ -5,11 +5,12 @@ * Using Phong Shader ## Compilation instructions +Build from the repository root in a MinGW-w64 shell. + ``` mkdir build -cd build -cmake ..\lesson05 -G "NMake Makefiles" -nmake +cmake -S lesson05 -B build/lesson05 -G "MinGW Makefiles" +cmake --build build/lesson05 ``` ## Running the program diff --git a/lesson05/model.cpp b/lesson05/model.cpp index 4a560e6..7eda0c8 100644 --- a/lesson05/model.cpp +++ b/lesson05/model.cpp @@ -53,9 +53,9 @@ void Model::load_data(const std::string& path) { if(file.is_open()) { // set regex patterns - static const boost::regex v_line("v\\s+([0-9.-]+)\\s+([0-9.-]+)\\s+([0-9.-]+).*"); - static const boost::regex vn_line("vn\\s+([0-9.-]+)\\s+([0-9.-]+)\\s+([0-9.-]+).*"); - static const boost::regex f_line("f\\s+([0-9]+)\\/\\/([0-9]+)\\s+([0-9]+)\\/\\/([0-9]+)\\s+([0-9]+)\\/\\/([0-9]+).*"); + static const std::regex v_line("v\\s+([0-9.-]+)\\s+([0-9.-]+)\\s+([0-9.-]+).*"); + static const std::regex vn_line("vn\\s+([0-9.-]+)\\s+([0-9.-]+)\\s+([0-9.-]+).*"); + static const std::regex f_line("f\\s+([0-9]+)\\/\\/([0-9]+)\\s+([0-9]+)\\/\\/([0-9]+)\\s+([0-9]+)\\/\\/([0-9]+).*"); // construct holders std::vector _positions; @@ -72,30 +72,30 @@ void Model::load_data(const std::string& path) { // start reading while(std::getline(file, line)) { - boost::smatch what1; + std::smatch what1; - if (boost::regex_match(line, what1, v_line)) { - glm::vec3 pos(boost::lexical_cast(what1[1]), - boost::lexical_cast(what1[2]), - boost::lexical_cast(what1[3])); + if (std::regex_match(line, what1, v_line)) { + glm::vec3 pos(std::stof(what1[1]), + std::stof(what1[2]), + std::stof(what1[3])); _positions.push_back(pos); } - if (boost::regex_match(line, what1, vn_line)) { - glm::vec3 normal(boost::lexical_cast(what1[1]), - boost::lexical_cast(what1[2]), - boost::lexical_cast(what1[3])); + if (std::regex_match(line, what1, vn_line)) { + glm::vec3 normal(std::stof(what1[1]), + std::stof(what1[2]), + std::stof(what1[3])); _normals.push_back(normal); } - if (boost::regex_match(line, what1, f_line)) { - position_indices.push_back(boost::lexical_cast(what1[1]) - 1); - position_indices.push_back(boost::lexical_cast(what1[3]) - 1); - position_indices.push_back(boost::lexical_cast(what1[5]) - 1); + if (std::regex_match(line, what1, f_line)) { + position_indices.push_back(static_cast(std::stoul(what1[1])) - 1); + position_indices.push_back(static_cast(std::stoul(what1[3])) - 1); + position_indices.push_back(static_cast(std::stoul(what1[5])) - 1); - normal_indices.push_back(boost::lexical_cast(what1[2]) - 1); - normal_indices.push_back(boost::lexical_cast(what1[4]) - 1); - normal_indices.push_back(boost::lexical_cast(what1[6]) - 1); + normal_indices.push_back(static_cast(std::stoul(what1[2])) - 1); + normal_indices.push_back(static_cast(std::stoul(what1[4])) - 1); + normal_indices.push_back(static_cast(std::stoul(what1[6])) - 1); } } diff --git a/lesson05/model.h b/lesson05/model.h index 5c870c3..2c8733b 100644 --- a/lesson05/model.h +++ b/lesson05/model.h @@ -21,10 +21,7 @@ #define GLEW_STATIC #endif #include -#include -#include -#include -#include +#include #include #include diff --git a/lesson06/CMakeLists.txt b/lesson06/CMakeLists.txt index 3b6b85f..07375f8 100644 --- a/lesson06/CMakeLists.txt +++ b/lesson06/CMakeLists.txt @@ -1,84 +1,31 @@ -# set minimum cmake requirements -cmake_minimum_required(VERSION 3.5) -project (occ-lesson06) +cmake_minimum_required(VERSION 3.21) -# add custom directory to look for .cmake files -set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_SOURCE_DIR}/cmake/modules ) +project (occ-lesson06 LANGUAGES CXX) -# Enable release build -if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) - message(STATUS "Setting build type to 'Release' as none was specified.") - set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build." FORCE) - set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "MinSizeRel" "RelWithDebInfo") -endif() +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD_REQUIRED ON) +set(CMAKE_CXX_EXTENSIONS OFF) -# set directory to boost -if(WIN32) -SET(BOOST_ROOT "../vendor/boost-1.74.0-win-x64") -else() -add_definitions(-DEIGEN_NO_DEBUG -Wno-literal-suffix) -SET(BOOST_INCLUDEDIR "/usr/include") -SET(BOOST_LIBRARYDIR "/usr/lib/x86_64-linux-gnu") -endif() - -# set Boost -set (Boost_NO_SYSTEM_PATHS ON) -set (Boost_USE_MULTITHREADED ON) -set (Boost_USE_STATIC_LIBS ON) -set (Boost_USE_STATIC_RUNTIME OFF) -set (BOOST_ALL_DYN_LINK OFF) -set (Boost_NO_BOOST_CMAKE ON) - -# Include libraries find_package(OpenGL REQUIRED) -find_package(Boost COMPONENTS chrono regex system serialization filesystem log thread REQUIRED) -find_package(GLFW3 REQUIRED) -if(WIN32) +find_package(glfw3 CONFIG REQUIRED) find_package(GLEW REQUIRED) -find_package(GLM REQUIRED) +find_package(glm CONFIG REQUIRED) find_package(PNG REQUIRED) find_package(ZLIB REQUIRED) -else() -find_package(PkgConfig REQUIRED) -pkg_check_modules(GLEW REQUIRED glew) -pkg_check_modules(GLFW3 REQUIRED glfw3) -pkg_check_modules(PNG REQUIRED libpng) -endif() - -message(STATUS "Boost include dirs: ${Boost_INCLUDE_DIRS}") - -# Set include folders -include_directories(${CMAKE_CURRENT_SOURCE_DIR} - ${CMAKE_BINARY_DIR} - ${Boost_INCLUDE_DIRS} - ${GLEW_INCLUDE_DIRS} - ${GLUT_INCLUDE_DIRS} - ${GLM_INCLUDE_DIRS} - ${GLFW3_INCLUDE_DIRS} - ${PNG_INCLUDE_DIRS} - ${ZLIB_INCLUDE_DIRS}) -# Add sources -file(GLOB_RECURSE SOURCES "*.cpp") +file(GLOB SOURCES "*.cpp") add_executable(occ-lesson06 ${SOURCES}) -# Link libraries target_link_libraries(occ-lesson06 - ${GLFW3_LIBRARIES} - ${OPENGL_glu_LIBRARY} - ${OPENGL_gl_LIBRARY} - ${Boost_LIBRARIES} - ${GLEW_LIBRARIES} - ${PNG_LIBRARIES} - ${ZLIB_LIBRARIES}) - -# add Boost definition -add_definitions(-DBOOST_LOG_DYN_LINK) - -# add Wno-literal-suffix to suppress warning messages -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") - -### -# Installing -## -install (TARGETS occ-lesson06 DESTINATION bin) + PRIVATE + glfw + OpenGL::GL + GLEW::GLEW + glm::glm + PNG::PNG + ZLIB::ZLIB +) + +target_compile_definitions(occ-lesson06 PRIVATE GLM_ENABLE_EXPERIMENTAL) + +install(TARGETS occ-lesson06 DESTINATION bin) diff --git a/lesson06/README.md b/lesson06/README.md index 55ff86c..b93965d 100644 --- a/lesson06/README.md +++ b/lesson06/README.md @@ -3,11 +3,12 @@ ## Learning goals ## Compilation instructions +Build from the repository root in a MinGW-w64 shell. + ``` mkdir build -cd build -cmake ..\lesson06 -G "NMake Makefiles" -nmake +cmake -S lesson06 -B build/lesson06 -G "MinGW Makefiles" +cmake --build build/lesson06 ``` ## Running the program diff --git a/lesson06/model.cpp b/lesson06/model.cpp index 818b43e..f990868 100644 --- a/lesson06/model.cpp +++ b/lesson06/model.cpp @@ -53,10 +53,10 @@ void Model::load_data(const std::string& path) { if(file.is_open()) { // set regex patterns - static const boost::regex v_line("v\\s+([0-9.-]+)\\s+([0-9.-]+)\\s+([0-9.-]+).*"); - static const boost::regex vn_line("vn\\s+([0-9.-]+)\\s+([0-9.-]+)\\s+([0-9.-]+).*"); - static const boost::regex vt_line("vt\\s+([0-9.-]+)\\s+([0-9.-]+).*"); - static const boost::regex f_line("f\\s+([0-9]+)\\/([0-9]+)\\/([0-9]+)\\s+([0-9]+)\\/([0-9]+)\\/([0-9]+)\\s+([0-9]+)\\/([0-9]+)\\/([0-9]+).*"); + static const std::regex v_line("v\\s+([0-9.-]+)\\s+([0-9.-]+)\\s+([0-9.-]+).*"); + static const std::regex vn_line("vn\\s+([0-9.-]+)\\s+([0-9.-]+)\\s+([0-9.-]+).*"); + static const std::regex vt_line("vt\\s+([0-9.-]+)\\s+([0-9.-]+).*"); + static const std::regex f_line("f\\s+([0-9]+)\\/([0-9]+)\\/([0-9]+)\\s+([0-9]+)\\/([0-9]+)\\/([0-9]+)\\s+([0-9]+)\\/([0-9]+)\\/([0-9]+).*"); // construct holders std::vector _positions; @@ -75,40 +75,40 @@ void Model::load_data(const std::string& path) { // start reading while(std::getline(file, line)) { - boost::smatch what1; + std::smatch what1; - if (boost::regex_match(line, what1, v_line)) { - glm::vec3 pos(boost::lexical_cast(what1[1]), - boost::lexical_cast(what1[2]), - boost::lexical_cast(what1[3])); + if (std::regex_match(line, what1, v_line)) { + glm::vec3 pos(std::stof(what1[1]), + std::stof(what1[2]), + std::stof(what1[3])); _positions.push_back(pos); } - if (boost::regex_match(line, what1, vn_line)) { - glm::vec3 normal(boost::lexical_cast(what1[1]), - boost::lexical_cast(what1[2]), - boost::lexical_cast(what1[3])); + if (std::regex_match(line, what1, vn_line)) { + glm::vec3 normal(std::stof(what1[1]), + std::stof(what1[2]), + std::stof(what1[3])); _normals.push_back(normal); } - if (boost::regex_match(line, what1, vt_line)) { - glm::vec2 uv(boost::lexical_cast(what1[1]), - boost::lexical_cast(what1[2])); + if (std::regex_match(line, what1, vt_line)) { + glm::vec2 uv(std::stof(what1[1]), + std::stof(what1[2])); _uvs.push_back(uv); } - if (boost::regex_match(line, what1, f_line)) { - position_indices.push_back(boost::lexical_cast(what1[1]) - 1); - position_indices.push_back(boost::lexical_cast(what1[4]) - 1); - position_indices.push_back(boost::lexical_cast(what1[7]) - 1); + if (std::regex_match(line, what1, f_line)) { + position_indices.push_back(static_cast(std::stoul(what1[1])) - 1); + position_indices.push_back(static_cast(std::stoul(what1[4])) - 1); + position_indices.push_back(static_cast(std::stoul(what1[7])) - 1); - uv_indices.push_back(boost::lexical_cast(what1[2]) - 1); - uv_indices.push_back(boost::lexical_cast(what1[5]) - 1); - uv_indices.push_back(boost::lexical_cast(what1[8]) - 1); + uv_indices.push_back(static_cast(std::stoul(what1[2])) - 1); + uv_indices.push_back(static_cast(std::stoul(what1[5])) - 1); + uv_indices.push_back(static_cast(std::stoul(what1[8])) - 1); - normal_indices.push_back(boost::lexical_cast(what1[3]) - 1); - normal_indices.push_back(boost::lexical_cast(what1[6]) - 1); - normal_indices.push_back(boost::lexical_cast(what1[9]) - 1); + normal_indices.push_back(static_cast(std::stoul(what1[3])) - 1); + normal_indices.push_back(static_cast(std::stoul(what1[6])) - 1); + normal_indices.push_back(static_cast(std::stoul(what1[9])) - 1); } } diff --git a/lesson06/model.h b/lesson06/model.h index 82dd9cd..497cdfe 100644 --- a/lesson06/model.h +++ b/lesson06/model.h @@ -21,10 +21,7 @@ #define GLEW_STATIC #endif #include -#include -#include -#include -#include +#include #include #include diff --git a/lesson06/pngfuncs.cpp b/lesson06/pngfuncs.cpp index 33ec6be..0e90a2b 100644 --- a/lesson06/pngfuncs.cpp +++ b/lesson06/pngfuncs.cpp @@ -10,6 +10,7 @@ **************************************************************************/ #include "pngfuncs.h" +#include void PNG::write_image_buffer_to_png(const std::string& filename, const std::vector& buffer, unsigned int width, unsigned int height, unsigned int col) { png_structp png_ptr; diff --git a/lesson06/pngfuncs.h b/lesson06/pngfuncs.h index 8f6938a..6dc06dd 100644 --- a/lesson06/pngfuncs.h +++ b/lesson06/pngfuncs.h @@ -16,6 +16,7 @@ #include #include #include +#include namespace PNG { diff --git a/lesson07/CMakeLists.txt b/lesson07/CMakeLists.txt index 512ba62..278d1cf 100644 --- a/lesson07/CMakeLists.txt +++ b/lesson07/CMakeLists.txt @@ -1,76 +1,27 @@ -# set minimum cmake requirements -cmake_minimum_required(VERSION 3.5) -project (occ-lesson07) +cmake_minimum_required(VERSION 3.21) -# add custom directory to look for .cmake files -set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_SOURCE_DIR}/cmake/modules ) +project (occ-lesson07 LANGUAGES CXX) -# Enable release build -if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) - message(STATUS "Setting build type to 'Release' as none was specified.") - set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build." FORCE) - set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "MinSizeRel" "RelWithDebInfo") -endif() +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD_REQUIRED ON) +set(CMAKE_CXX_EXTENSIONS OFF) -# set directory to boost -if(WIN32) -SET(BOOST_ROOT "../vendor/boost-1.74.0-win-x64") -else() -add_definitions(-DEIGEN_NO_DEBUG -Wno-literal-suffix) -SET(BOOST_INCLUDEDIR "/usr/include") -SET(BOOST_LIBRARYDIR "/usr/lib/x86_64-linux-gnu") -endif() - -# set Boost -set (Boost_NO_SYSTEM_PATHS ON) -set (Boost_USE_MULTITHREADED ON) -set (Boost_USE_STATIC_LIBS ON) -set (Boost_USE_STATIC_RUNTIME OFF) -set (BOOST_ALL_DYN_LINK OFF) -set (Boost_NO_BOOST_CMAKE ON) - -# Include libraries find_package(OpenGL REQUIRED) -find_package(Boost COMPONENTS chrono regex system serialization filesystem log thread REQUIRED) -find_package(GLFW3 REQUIRED) -if(WIN32) +find_package(glfw3 CONFIG REQUIRED) find_package(GLEW REQUIRED) -find_package(GLM REQUIRED) -else() -find_package(PkgConfig REQUIRED) -pkg_check_modules(GLEW REQUIRED glew) -pkg_check_modules(GLFW3 REQUIRED glfw3) -endif() - +find_package(glm CONFIG REQUIRED) -# Set include folders -include_directories(${CMAKE_CURRENT_SOURCE_DIR} - ${CMAKE_BINARY_DIR} - ${Boost_INCLUDE_DIRS} - ${GLEW_INCLUDE_DIRS} - ${GLUT_INCLUDE_DIRS} - ${GLM_INCLUDE_DIRS} - ${GLFW3_INCLUDE_DIRS}) - -# Add sources -file(GLOB_RECURSE SOURCES "*.cpp") +file(GLOB SOURCES "*.cpp") add_executable(occ-lesson07 ${SOURCES}) -# Link libraries target_link_libraries(occ-lesson07 - ${GLFW3_LIBRARIES} - ${OPENGL_glu_LIBRARY} - ${OPENGL_gl_LIBRARY} - ${Boost_LIBRARIES} - ${GLEW_LIBRARIES}) - -# add Boost definition -add_definitions(-DBOOST_LOG_DYN_LINK) + PRIVATE + glfw + OpenGL::GL + GLEW::GLEW + glm::glm +) -# add Wno-literal-suffix to suppress warning messages -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") +target_compile_definitions(occ-lesson07 PRIVATE GLM_ENABLE_EXPERIMENTAL) -### -# Installing -## -install (TARGETS occ-lesson07 DESTINATION bin) +install(TARGETS occ-lesson07 DESTINATION bin) diff --git a/lesson07/README.md b/lesson07/README.md index 35ddf78..0a68bf3 100644 --- a/lesson07/README.md +++ b/lesson07/README.md @@ -4,11 +4,12 @@ * Understand how anaglyph stereographic rendering works ## Compilation instructions +Build from the repository root in a MinGW-w64 shell. + ``` mkdir build -cd build -cmake ..\lesson07 -G "NMake Makefiles" -nmake +cmake -S lesson07 -B build/lesson07 -G "MinGW Makefiles" +cmake --build build/lesson07 ``` ## Running the program diff --git a/lesson07/model.cpp b/lesson07/model.cpp index 4a560e6..7eda0c8 100644 --- a/lesson07/model.cpp +++ b/lesson07/model.cpp @@ -53,9 +53,9 @@ void Model::load_data(const std::string& path) { if(file.is_open()) { // set regex patterns - static const boost::regex v_line("v\\s+([0-9.-]+)\\s+([0-9.-]+)\\s+([0-9.-]+).*"); - static const boost::regex vn_line("vn\\s+([0-9.-]+)\\s+([0-9.-]+)\\s+([0-9.-]+).*"); - static const boost::regex f_line("f\\s+([0-9]+)\\/\\/([0-9]+)\\s+([0-9]+)\\/\\/([0-9]+)\\s+([0-9]+)\\/\\/([0-9]+).*"); + static const std::regex v_line("v\\s+([0-9.-]+)\\s+([0-9.-]+)\\s+([0-9.-]+).*"); + static const std::regex vn_line("vn\\s+([0-9.-]+)\\s+([0-9.-]+)\\s+([0-9.-]+).*"); + static const std::regex f_line("f\\s+([0-9]+)\\/\\/([0-9]+)\\s+([0-9]+)\\/\\/([0-9]+)\\s+([0-9]+)\\/\\/([0-9]+).*"); // construct holders std::vector _positions; @@ -72,30 +72,30 @@ void Model::load_data(const std::string& path) { // start reading while(std::getline(file, line)) { - boost::smatch what1; + std::smatch what1; - if (boost::regex_match(line, what1, v_line)) { - glm::vec3 pos(boost::lexical_cast(what1[1]), - boost::lexical_cast(what1[2]), - boost::lexical_cast(what1[3])); + if (std::regex_match(line, what1, v_line)) { + glm::vec3 pos(std::stof(what1[1]), + std::stof(what1[2]), + std::stof(what1[3])); _positions.push_back(pos); } - if (boost::regex_match(line, what1, vn_line)) { - glm::vec3 normal(boost::lexical_cast(what1[1]), - boost::lexical_cast(what1[2]), - boost::lexical_cast(what1[3])); + if (std::regex_match(line, what1, vn_line)) { + glm::vec3 normal(std::stof(what1[1]), + std::stof(what1[2]), + std::stof(what1[3])); _normals.push_back(normal); } - if (boost::regex_match(line, what1, f_line)) { - position_indices.push_back(boost::lexical_cast(what1[1]) - 1); - position_indices.push_back(boost::lexical_cast(what1[3]) - 1); - position_indices.push_back(boost::lexical_cast(what1[5]) - 1); + if (std::regex_match(line, what1, f_line)) { + position_indices.push_back(static_cast(std::stoul(what1[1])) - 1); + position_indices.push_back(static_cast(std::stoul(what1[3])) - 1); + position_indices.push_back(static_cast(std::stoul(what1[5])) - 1); - normal_indices.push_back(boost::lexical_cast(what1[2]) - 1); - normal_indices.push_back(boost::lexical_cast(what1[4]) - 1); - normal_indices.push_back(boost::lexical_cast(what1[6]) - 1); + normal_indices.push_back(static_cast(std::stoul(what1[2])) - 1); + normal_indices.push_back(static_cast(std::stoul(what1[4])) - 1); + normal_indices.push_back(static_cast(std::stoul(what1[6])) - 1); } } diff --git a/lesson07/model.h b/lesson07/model.h index 5c870c3..2c8733b 100644 --- a/lesson07/model.h +++ b/lesson07/model.h @@ -21,10 +21,7 @@ #define GLEW_STATIC #endif #include -#include -#include -#include -#include +#include #include #include From 6f860b33843e537f0141c6db83ec5392242c396c Mon Sep 17 00:00:00 2001 From: ifilot Date: Fri, 6 Feb 2026 18:36:26 +0100 Subject: [PATCH 2/4] PNG library --- .github/workflows/linux.yml | 1 + .github/workflows/windows.yml | 1 + 2 files changed, 2 insertions(+) diff --git a/.github/workflows/linux.yml b/.github/workflows/linux.yml index 7036d91..141a3bf 100644 --- a/.github/workflows/linux.yml +++ b/.github/workflows/linux.yml @@ -22,6 +22,7 @@ jobs: libglfw3-dev \ libglm-dev \ libgl1-mesa-dev \ + libpng-dev \ libx11-dev \ libxi-dev \ libxrandr-dev \ diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml index 55854f8..244b9bb 100644 --- a/.github/workflows/windows.yml +++ b/.github/workflows/windows.yml @@ -23,6 +23,7 @@ jobs: mingw-w64-x86_64-toolchain mingw-w64-x86_64-cmake mingw-w64-x86_64-glew + mingw-w64-x86_64-libpng mingw-w64-x86_64-glfw mingw-w64-x86_64-glm From f3bd074cb8b02a2d01b6689df85c0262ee52ed03 Mon Sep 17 00:00:00 2001 From: ifilot Date: Fri, 6 Feb 2026 18:39:38 +0100 Subject: [PATCH 3/4] Adding badges --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index b1eb9ed..46953a0 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,8 @@ # OpenGL C++ Course +[![windows-build](https://github.com/ifilot/opengl-cpp-course/actions/workflows/windows.yml/badge.svg)](https://github.com/ifilot/opengl-cpp-course/actions/workflows/windows.yml) +[![linux-build](https://github.com/ifilot/opengl-cpp-course/actions/workflows/linux.yml/badge.svg)](https://github.com/ifilot/opengl-cpp-course/actions/workflows/linux.yml) + **Update** The build instructions below now target MinGW-w64 (via MSYS2) instead of MSVC. From b089d91f89de50ce1add329e4b2e681dfef088fd Mon Sep 17 00:00:00 2001 From: ifilot Date: Fri, 6 Feb 2026 18:41:30 +0100 Subject: [PATCH 4/4] Adding image to README.md --- README.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/README.md b/README.md index 46953a0..ad0d539 100644 --- a/README.md +++ b/README.md @@ -3,8 +3,7 @@ [![windows-build](https://github.com/ifilot/opengl-cpp-course/actions/workflows/windows.yml/badge.svg)](https://github.com/ifilot/opengl-cpp-course/actions/workflows/windows.yml) [![linux-build](https://github.com/ifilot/opengl-cpp-course/actions/workflows/linux.yml/badge.svg)](https://github.com/ifilot/opengl-cpp-course/actions/workflows/linux.yml) -**Update** -The build instructions below now target MinGW-w64 (via MSYS2) instead of MSVC. +![Screenshot of rotating cube](lesson02/images/rotating_cube.jpg) ## Purpose and expectations This repository contains the source code for the OpenGL C++ course. The course