Skip to content

Commit 9beb77b

Browse files
authored
Release v1.0.0 (#2)
* Refactoring for MinGW64 * PNG library * Adding badges * Adding image to README.md
1 parent b1edd3c commit 9beb77b

28 files changed

Lines changed: 360 additions & 612 deletions

.github/workflows/linux.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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+
libpng-dev \
26+
libx11-dev \
27+
libxi-dev \
28+
libxrandr-dev \
29+
libxxf86vm-dev \
30+
libxcursor-dev
31+
32+
- name: Configure and build lessons
33+
run: |
34+
set -euo pipefail
35+
cmake -S . -B build
36+
cmake --build build -j$(nproc)

.github/workflows/windows.yml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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-libpng
27+
mingw-w64-x86_64-glfw
28+
mingw-w64-x86_64-glm
29+
30+
- name: Configure and build lessons
31+
run: |
32+
set -euo pipefail
33+
cmake -S . -B build -G "MinGW Makefiles"
34+
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: 46 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,35 @@
11
# OpenGL C++ Course
22

3-
**Update**
4-
I made some changes to the code by which everything should now work for MSVC 2019 using Boost 1.74.0.
3+
[![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)
4+
[![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)
55

6-
## 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.
6+
![Screenshot of rotating cube](lesson02/images/rotating_cube.jpg)
127

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

1534
## Lesson overview
1635
1. [Compiling and running an OpenGL program](lesson01/README.md)
@@ -21,42 +40,39 @@ Feedback on this course is always much appreciated if provided in a constructive
2140
6. [Textures](lesson06/README.md)
2241
7. [Anaglyph](lesson07/README.md)
2342

24-
## Prerequisite software
25-
In order to compile the software, you need to download and install the following packages.
26-
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+
## Preparation of compilation environment
3144

32-
## Dependencies
33-
* GLFW
34-
* Boost
35-
* Glew
36-
* GLM
45+
In order to compile the software under Windows, install the the MinGW-w64
46+
toolchain via [MSYS2](https://www.msys2.org/). Next, open **MSYS2 MinGW 64-bit**
47+
and install using `pacman` the dependencies using the following instruction
3748

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).
49+
```bash
50+
pacman -S --needed \
51+
mingw-w64-x86_64-toolchain \
52+
mingw-w64-x86_64-cmake \
53+
mingw-w64-x86_64-glew \
54+
mingw-w64-x86_64-glfw \
55+
mingw-w64-x86_64-glm
56+
```
3957

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

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

4563
```
4664
mkdir build
47-
cd build
48-
cmake ..\lessonXX -G "NMake Makefiles"
49-
nmake
65+
cmake -S lessonXX -B build/lessonXX -G "MinGW Makefiles"
66+
cmake --build build/lessonXX
5067
```
5168

5269
## Compilation instructions for Linux
5370
Open a terminal, go to the root folder of the repository and use the following commands.
5471

5572
```
5673
mkdir build
57-
cd build
58-
cmake ..\lessonXX
59-
make -j5
74+
cmake -S lessonXX -B build/lessonXX
75+
cmake --build build/lessonXX -j5
6076
```
6177

6278
## 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)