Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions .github/workflows/linux.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
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 \
libpng-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)
34 changes: 34 additions & 0 deletions .github/workflows/windows.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
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-libpng
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
11 changes: 11 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
76 changes: 46 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,35 @@
# 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.
[![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)

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

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.
## 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 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)
Expand All @@ -21,42 +40,39 @@ 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.

* [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!
## Preparation of compilation environment

## Dependencies
* GLFW
* Boost
* Glew
* GLM
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

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
Open a terminal, go to the root folder of the repository and use the following commands.

```
mkdir build
cd build
cmake ..\lessonXX
make -j5
cmake -S lessonXX -B build/lessonXX
cmake --build build/lessonXX -j5
```

## Troubleshooting
Expand Down
81 changes: 16 additions & 65 deletions lesson01/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
7 changes: 4 additions & 3 deletions lesson01/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
81 changes: 16 additions & 65 deletions lesson02/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
Loading