Skip to content

Commit 843a050

Browse files
committed
Refactoring for MinGW64
1 parent b1edd3c commit 843a050

28 files changed

Lines changed: 355 additions & 611 deletions

.github/workflows/linux.yml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: linux-build
2+
3+
on:
4+
push:
5+
pull_request:
6+
7+
jobs:
8+
build:
9+
runs-on: ubuntu-latest
10+
11+
steps:
12+
- name: Checkout
13+
uses: actions/checkout@v4
14+
15+
- name: Install dependencies
16+
run: |
17+
sudo apt-get update
18+
sudo apt-get install -y \
19+
build-essential \
20+
cmake \
21+
libglew-dev \
22+
libglfw3-dev \
23+
libglm-dev \
24+
libgl1-mesa-dev \
25+
libx11-dev \
26+
libxi-dev \
27+
libxrandr-dev \
28+
libxxf86vm-dev \
29+
libxcursor-dev
30+
31+
- name: Configure and build lessons
32+
run: |
33+
set -euo pipefail
34+
cmake -S . -B build
35+
cmake --build build -j$(nproc)

.github/workflows/windows.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: windows-build
2+
3+
on:
4+
push:
5+
pull_request:
6+
7+
jobs:
8+
build:
9+
runs-on: windows-latest
10+
defaults:
11+
run:
12+
shell: msys2 {0}
13+
steps:
14+
- name: Checkout
15+
uses: actions/checkout@v4
16+
17+
- name: Set up MSYS2 (MinGW-w64)
18+
uses: msys2/setup-msys2@v2
19+
with:
20+
msystem: MINGW64
21+
update: true
22+
install: >-
23+
mingw-w64-x86_64-toolchain
24+
mingw-w64-x86_64-cmake
25+
mingw-w64-x86_64-glew
26+
mingw-w64-x86_64-glfw
27+
mingw-w64-x86_64-glm
28+
29+
- name: Configure and build lessons
30+
run: |
31+
set -euo pipefail
32+
cmake -S . -B build -G "MinGW Makefiles"
33+
cmake --build build

CMakeLists.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
cmake_minimum_required(VERSION 3.21)
2+
3+
project(opengl-cpp-course LANGUAGES CXX)
4+
5+
add_subdirectory(lesson01)
6+
add_subdirectory(lesson02)
7+
add_subdirectory(lesson03)
8+
add_subdirectory(lesson04)
9+
add_subdirectory(lesson05)
10+
add_subdirectory(lesson06)
11+
add_subdirectory(lesson07)

README.md

Lines changed: 43 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,33 @@
11
# OpenGL C++ Course
22

33
**Update**
4-
I made some changes to the code by which everything should now work for MSVC 2019 using Boost 1.74.0.
4+
The build instructions below now target MinGW-w64 (via MSYS2) instead of MSVC.
55

66
## Purpose and expectations
7-
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.
8-
9-
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.
10-
11-
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.
12-
13-
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.
7+
This repository contains the source code for the OpenGL C++ course. The course
8+
teaches students how to effectively use C++ in conjunction with OpenGL to build
9+
graphical programs. The course is made in a concise manner and I refer often to
10+
external resources which I expect the student to read (or at least glance
11+
through). The learning strategy employed here is "Learning by example" and
12+
"Learning by doing". This means that example code is provided and the student is
13+
given the opportunity to practice with the material in the form of exercises.
14+
15+
We assume that the student is relatively comfortable reading C++ code and has
16+
some previous experience with it. The exercises are constructed in such a way
17+
that the student only has to change a few lines of code. Furthermore, we expect
18+
that the student is familiar with matrix-vector multiplication and has some
19+
understanding of matrix mathematics. Finally, we expect that the student is a
20+
bit familiar using the command line.
21+
22+
This course focuses on running OpenGL in a Windows environment using MinGW-w64,
23+
although it should also run under Linux (I have tested it for Linux Ubuntu). If
24+
you want to compile the programs on Linux, please read
25+
[below](#compilation-instructions-for-linux) as the instructions for CMake
26+
differ slightly. OpenGL and the libraries we are using are cross-platform and
27+
thus work on Windows, Mac as well as Linux.
28+
29+
Feedback on this course is always much appreciated if provided in a constructive
30+
manner. Feel free to use the Issues system on Github for this purpose.
1431

1532
## Lesson overview
1633
1. [Compiling and running an OpenGL program](lesson01/README.md)
@@ -21,42 +38,39 @@ Feedback on this course is always much appreciated if provided in a constructive
2138
6. [Textures](lesson06/README.md)
2239
7. [Anaglyph](lesson07/README.md)
2340

24-
## Prerequisite software
25-
In order to compile the software, you need to download and install the following packages.
41+
## Preparation of compilation environment
2642

27-
* [CMake](https://cmake.org/download/) - During the installation, you need to select **Add CMAKE to the system PATH for all users**.
28-
* [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++'
29-
* [Git](https://git-scm.com/download/win) - You can use the default settings during the installation procedure.
30-
* [Python](https://www.python.org/downloads/) - Use the latest Python 3 version!
43+
In order to compile the software under Windows, install the the MinGW-w64
44+
toolchain via [MSYS2](https://www.msys2.org/). Next, open **MSYS2 MinGW 64-bit**
45+
and install using `pacman` the dependencies using the following instruction
3146

32-
## Dependencies
33-
* GLFW
34-
* Boost
35-
* Glew
36-
* GLM
37-
38-
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).
47+
```bash
48+
pacman -S --needed \
49+
mingw-w64-x86_64-toolchain \
50+
mingw-w64-x86_64-cmake \
51+
mingw-w64-x86_64-glew \
52+
mingw-w64-x86_64-glfw \
53+
mingw-w64-x86_64-glm
54+
```
3955

40-
## Compilation instructions for Windows
41-
Open the `Native x64 Native Tools Command Prompt` and go to the repository root folder.
56+
## Compilation instructions for Windows (MinGW-w64)
57+
Open the **MSYS2 MinGW 64-bit** shell and go to the repository root folder.
4258

4359
Create a build directory and execute CMake; note that you need to change `XX` to the lesson of interest.
4460

4561
```
4662
mkdir build
47-
cd build
48-
cmake ..\lessonXX -G "NMake Makefiles"
49-
nmake
63+
cmake -S lessonXX -B build/lessonXX -G "MinGW Makefiles"
64+
cmake --build build/lessonXX
5065
```
5166

5267
## Compilation instructions for Linux
5368
Open a terminal, go to the root folder of the repository and use the following commands.
5469

5570
```
5671
mkdir build
57-
cd build
58-
cmake ..\lessonXX
59-
make -j5
72+
cmake -S lessonXX -B build/lessonXX
73+
cmake --build build/lessonXX -j5
6074
```
6175

6276
## Troubleshooting

lesson01/CMakeLists.txt

Lines changed: 16 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,76 +1,27 @@
1-
# set minimum cmake requirements
2-
cmake_minimum_required(VERSION 3.5)
3-
project (occ-lesson01)
1+
cmake_minimum_required(VERSION 3.21)
42

5-
# add custom directory to look for .cmake files
6-
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_SOURCE_DIR}/cmake/modules )
3+
project (occ-lesson01 LANGUAGES CXX)
74

8-
# Enable release build
9-
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
10-
message(STATUS "Setting build type to 'Release' as none was specified.")
11-
set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build." FORCE)
12-
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "MinSizeRel" "RelWithDebInfo")
13-
endif()
5+
set(CMAKE_CXX_STANDARD 17)
6+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
7+
set(CMAKE_CXX_EXTENSIONS OFF)
148

15-
# set directory to boost
16-
if(WIN32)
17-
SET(BOOST_ROOT "../vendor/boost-1.74.0-win-x64")
18-
else()
19-
add_definitions(-DEIGEN_NO_DEBUG -Wno-literal-suffix)
20-
SET(BOOST_INCLUDEDIR "/usr/include")
21-
SET(BOOST_LIBRARYDIR "/usr/lib/x86_64-linux-gnu")
22-
endif()
23-
24-
# set Boost
25-
set (Boost_NO_SYSTEM_PATHS ON)
26-
set (Boost_USE_MULTITHREADED ON)
27-
set (Boost_USE_STATIC_LIBS ON)
28-
set (Boost_USE_STATIC_RUNTIME OFF)
29-
set (BOOST_ALL_DYN_LINK OFF)
30-
set (Boost_NO_BOOST_CMAKE ON)
31-
32-
# Include libraries
339
find_package(OpenGL REQUIRED)
34-
find_package(Boost COMPONENTS chrono regex system serialization filesystem log thread REQUIRED)
35-
find_package(GLFW3 REQUIRED)
36-
if(WIN32)
10+
find_package(glfw3 CONFIG REQUIRED)
3711
find_package(GLEW REQUIRED)
38-
find_package(GLM REQUIRED)
39-
else()
40-
find_package(PkgConfig REQUIRED)
41-
pkg_check_modules(GLEW REQUIRED glew)
42-
pkg_check_modules(GLFW3 REQUIRED glfw3)
43-
endif()
44-
12+
find_package(glm CONFIG REQUIRED)
4513

46-
# Set include folders
47-
include_directories(${CMAKE_CURRENT_SOURCE_DIR}
48-
${CMAKE_BINARY_DIR}
49-
${Boost_INCLUDE_DIRS}
50-
${GLEW_INCLUDE_DIRS}
51-
${GLUT_INCLUDE_DIRS}
52-
${GLM_INCLUDE_DIRS}
53-
${GLFW3_INCLUDE_DIRS})
54-
55-
# Add sources
56-
file(GLOB_RECURSE SOURCES "*.cpp")
14+
file(GLOB SOURCES "*.cpp")
5715
add_executable(occ-lesson01 ${SOURCES})
5816

59-
# Link libraries
6017
target_link_libraries(occ-lesson01
61-
${GLFW3_LIBRARIES}
62-
${OPENGL_glu_LIBRARY}
63-
${OPENGL_gl_LIBRARY}
64-
${Boost_LIBRARIES}
65-
${GLEW_LIBRARIES})
66-
67-
# add Boost definition
68-
add_definitions(-DBOOST_LOG_DYN_LINK)
18+
PRIVATE
19+
glfw
20+
OpenGL::GL
21+
GLEW::GLEW
22+
glm::glm
23+
)
6924

70-
# add Wno-literal-suffix to suppress warning messages
71-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
25+
target_compile_definitions(occ-lesson01 PRIVATE GLM_ENABLE_EXPERIMENTAL)
7226

73-
###
74-
# Installing
75-
##
76-
install (TARGETS occ-lesson01 DESTINATION bin)
27+
install(TARGETS occ-lesson01 DESTINATION bin)

lesson01/README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,12 @@
99
* Conceptually understanding attributes and uniforms
1010

1111
## Compilation instructions
12+
Build from the repository root in a MinGW-w64 shell.
13+
1214
```
1315
mkdir build
14-
cd build
15-
cmake ..\lesson01 -G "NMake Makefiles"
16-
nmake
16+
cmake -S lesson01 -B build/lesson01 -G "MinGW Makefiles"
17+
cmake --build build/lesson01
1718
```
1819

1920
If the compilation is not working or if the program shows weird behavior, please check the [troubleshooting section](../README.md#troubleshooting).

lesson02/CMakeLists.txt

Lines changed: 16 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,76 +1,27 @@
1-
# set minimum cmake requirements
2-
cmake_minimum_required(VERSION 3.5)
3-
project (occ-lesson02)
1+
cmake_minimum_required(VERSION 3.21)
42

5-
# add custom directory to look for .cmake files
6-
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_SOURCE_DIR}/cmake/modules )
3+
project (occ-lesson02 LANGUAGES CXX)
74

8-
# Enable release build
9-
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
10-
message(STATUS "Setting build type to 'Release' as none was specified.")
11-
set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build." FORCE)
12-
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "MinSizeRel" "RelWithDebInfo")
13-
endif()
5+
set(CMAKE_CXX_STANDARD 17)
6+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
7+
set(CMAKE_CXX_EXTENSIONS OFF)
148

15-
# set directory to boost
16-
if(WIN32)
17-
SET(BOOST_ROOT "../vendor/boost-1.74.0-win-x64")
18-
else()
19-
add_definitions(-DEIGEN_NO_DEBUG -Wno-literal-suffix)
20-
SET(BOOST_INCLUDEDIR "/usr/include")
21-
SET(BOOST_LIBRARYDIR "/usr/lib/x86_64-linux-gnu")
22-
endif()
23-
24-
# set Boost
25-
set (Boost_NO_SYSTEM_PATHS ON)
26-
set (Boost_USE_MULTITHREADED ON)
27-
set (Boost_USE_STATIC_LIBS ON)
28-
set (Boost_USE_STATIC_RUNTIME OFF)
29-
set (BOOST_ALL_DYN_LINK OFF)
30-
set (Boost_NO_BOOST_CMAKE ON)
31-
32-
# Include libraries
339
find_package(OpenGL REQUIRED)
34-
find_package(Boost COMPONENTS chrono regex system serialization filesystem log thread REQUIRED)
35-
find_package(GLFW3 REQUIRED)
36-
if(WIN32)
10+
find_package(glfw3 CONFIG REQUIRED)
3711
find_package(GLEW REQUIRED)
38-
find_package(GLM REQUIRED)
39-
else()
40-
find_package(PkgConfig REQUIRED)
41-
pkg_check_modules(GLEW REQUIRED glew)
42-
pkg_check_modules(GLFW3 REQUIRED glfw3)
43-
endif()
44-
12+
find_package(glm CONFIG REQUIRED)
4513

46-
# Set include folders
47-
include_directories(${CMAKE_CURRENT_SOURCE_DIR}
48-
${CMAKE_BINARY_DIR}
49-
${Boost_INCLUDE_DIRS}
50-
${GLEW_INCLUDE_DIRS}
51-
${GLUT_INCLUDE_DIRS}
52-
${GLM_INCLUDE_DIRS}
53-
${GLFW3_INCLUDE_DIRS})
54-
55-
# Add sources
56-
file(GLOB_RECURSE SOURCES "*.cpp")
14+
file(GLOB SOURCES "*.cpp")
5715
add_executable(occ-lesson02 ${SOURCES})
5816

59-
# Link libraries
6017
target_link_libraries(occ-lesson02
61-
${GLFW3_LIBRARIES}
62-
${OPENGL_glu_LIBRARY}
63-
${OPENGL_gl_LIBRARY}
64-
${Boost_LIBRARIES}
65-
${GLEW_LIBRARIES})
66-
67-
# add Boost definition
68-
add_definitions(-DBOOST_LOG_DYN_LINK)
18+
PRIVATE
19+
glfw
20+
OpenGL::GL
21+
GLEW::GLEW
22+
glm::glm
23+
)
6924

70-
# add Wno-literal-suffix to suppress warning messages
71-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
25+
target_compile_definitions(occ-lesson02 PRIVATE GLM_ENABLE_EXPERIMENTAL)
7226

73-
###
74-
# Installing
75-
##
76-
install (TARGETS occ-lesson02 DESTINATION bin)
27+
install(TARGETS occ-lesson02 DESTINATION bin)

0 commit comments

Comments
 (0)