This repository is a template OpenGL project configured using CMake. It supports cross-platform builds, and provides a good starting point to begin OpenGL development.
The intended usage for this repository is to be a template for future Github repositories. See this guide for more information.
To configure and build the project, do the following from the root directory of the repository:
mkdir build
cd build
cmake ..
This will configure the CMake and will generate platform-specific build files. To build, execute the following from within the build directory:
cmake --build .
Or build using whatever generated build system CMake produced.
By default, the CMake project will automatically link with GLAD, GLFW, and OpenGL. There is optional built-in support for a few other ubiquitous libraries. Create an issue to request default support for additional libraries, or make a pull request with your addition.
GLAD loader files will be generated based on the CMake cache variables set in CMakeLists.txt. Setting these variables allows one to specify the parameters for the loader similar to what the corresponding webservice allows you to do.
GLFW is linked automatically against the main project. This works without requiring any additional dependencies to be installed on Windows, but Linux may require some additional steps depending on your environment:
-
Make sure you have a working compiler (GCC / CLANG) and build system, and that they're accessible to CMake. Stable versions of GCC (note: this project supports C++17 by default) and Make can be pulled down through:
sudo apt-get install build-essential
-
X11 may need to be installed for OpenGL window creation:
sudo apt-get install libx11-dev
-
RandR headers (dependency of X11) may need to be installed as well:
sudo apt-get install xorg-dev libglu1-mesa-dev
There is built-in support for linking with a few other libraries that are well-known in the OpenGL community. These libraries are supported through the LinkXXXX.cmake
scripts found in the cmake
directory.
Some of these are configured to be optionally added as sub-projects, such as ASSIMP:
set(ENABLE_ASSIMP OFF CACHE BOOL "Add Open Asset Import Library (assimp) to the project" FORCE)
Setting these flags to ON
will add them to the project and will link them with the main executable. Depending on how you extend the project structure after the template is used, you may have to manually link with these libraries again with your sub-projects.
This can be accomplished by adding the following lines:
include(${CMAKE_DIR}/<Linking Script>.cmake)
<Linking Script>(<Target> <Access>)
Where <Linking Script>
is the name of the CMake script and linking macro, <Target>
is the build target to link against, and <Access>
is the access specifier for the linkage / header inclusion.