https://github.com/d3m1d0s/opengltemplate
Modern C++20 OpenGL starter template with CMake, GLFW, and GLAD
https://github.com/d3m1d0s/opengltemplate
cmake cmakelists cpp cpp20 cross-platform glad glfw graphics opengl template
Last synced: 27 days ago
JSON representation
Modern C++20 OpenGL starter template with CMake, GLFW, and GLAD
- Host: GitHub
- URL: https://github.com/d3m1d0s/opengltemplate
- Owner: d3m1d0s
- License: mit
- Created: 2025-08-19T14:21:15.000Z (10 months ago)
- Default Branch: main
- Last Pushed: 2025-09-17T22:06:44.000Z (9 months ago)
- Last Synced: 2025-11-05T02:17:20.549Z (7 months ago)
- Topics: cmake, cmakelists, cpp, cpp20, cross-platform, glad, glfw, graphics, opengl, template
- Language: CMake
- Homepage:
- Size: 80.1 KB
- Stars: 1
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# OpenGLTemplate
[](https://github.com/d3m1d0s/OpenGLTemplate/actions/workflows/cmake-multi-platform.yml)


A modern **C++20 OpenGL starter template** with [GLFW](https://www.glfw.org/) and [GLAD](https://glad.dav1d.de/).
Works **out-of-the-box**: uses preinstalled packages (vcpkg/Conan/system) or auto-fetches sources via CMake.
---
## π Table of Contents
- [β‘ Quick Start](#-quick-start)
- [π» Recommended IDE: CLion](#-recommended-ide-clion)
- [β¨ Features](#-features)
- [π¦ Dependencies](#-dependencies)
- [πΌοΈ Example Output](#-example-output)
- [π Project Structure](#-project-structure)
- [π Troubleshooting](#-troubleshooting)
- [π License](#-license)
- [π Attribution](#-attribution)
---
## β‘ Quick Start
Tip: Itβs recommended to preinstall [Dependencies](#-dependencies).
If something goes wrong - check [Troubleshooting](#-troubleshooting).
```bash
git clone https://github.com//.git
cd OpenGLTemplate
cmake -B build -S .
cmake --build build
./build/OpenGLTemplate # Windows: .\build\OpenGLTemplate.exe
```
---
## π» Recommended IDE: CLion
[JetBrains CLion](https://www.jetbrains.com/clion/) is a great choice for CMake/C++ projects.
Just open this folder in CLion and it will automatically detect the `CMakeLists.txt` and configure everything.
Tip: if you use **vcpkg** with CLion, set a toolchain file in
`Settings β Build, Execution, Deployment β CMake β CMake options` and pick a proper triplet (e.g. `x64-windows-static`):
```bash
-DCMAKE_TOOLCHAIN_FILE=C://scripts/buildsystems/vcpkg.cmake
-DVCPKG_TARGET_TRIPLET=x64-windows-static
```
---
## β¨ Features
* βοΈ Minimal CMake (>= 3.20), C++20.
* π Cross-platform: Windows, Linux, macOS.
* π Dual dependency strategy:
* Uses `find_package` if `glfw3` / `glad` are installed.
* Otherwise `FetchContent` pulls GLFW 3.4 & GLAD 0.1.36.
* π Clean linking: `OpenGL::GL`, `glfw`, `glad`.
---
## π¦ Dependencies
### πͺ Windows (via vcpkg)
```powershell
vcpkg install glfw3 glad
cmake -B build -S . -DCMAKE_TOOLCHAIN_FILE=C:/vcpkg/scripts/buildsystems/vcpkg.cmake -DVCPKG_TARGET_TRIPLET=x64-windows-static
```
> Static triplets easiest (no DLLs). Dynamic require shipping `glfw3.dll`.
### π§ Linux (system packages)
```bash
sudo apt install cmake g++ pkg-config libglfw3-dev libgl1-mesa-dev
sudo apt install libglad-dev # If glad is not available via your package manager, no worries - this template will fetch it automatically.
cmake -B build -S .
cmake --build build
```
### π macOS (Homebrew)
```bash
brew install cmake glfw
brew install glad # If glad is not available via your package manager, no worries - this template will fetch it automatically.
cmake -B build -S .
cmake --build build
```
> macOS OpenGL is capped at **4.1**.
### π¦ Self-contained (no pkg manager)
Do nothing - CMake auto-fetches **GLFW 3.4** and **GLAD 0.1.36**.
---
## πΌοΈ Example Output
Opens a **800Γ600 window**, clears to white, prints OpenGL version, e.g.:
```
OpenGL: 3.3.0 - Build 31.0.101.2135
```
---
## π Project Structure
```
OpenGLTemplate/
ββ src/ # C++ sources (main.cpp included)
ββ include/ # Headers
ββ shaders/ # GLSL files
ββ assets/ # Textures, models
ββ CMakeLists.txt
ββ README.md
```
> To bump OpenGL version, edit in CMake:
> `set(GLAD_API "gl=4.6")`.
## π Troubleshooting
- **Windows: mixing toolchains/triplets**
Errors like `__security_cookie`, `sscanf_s`, or `fprintf` usually mean youβre compiling with **MinGW** but linked **MSVC** vcpkg triplets (or vice versa).
Align them:
- MSVC β `x64-windows` / `x64-windows-static`
- MinGW-w64 β `x64-mingw-dynamic` / `x64-mingw-static`
- **CMake canβt find `glfw3Config.cmake`**
If using vcpkg, make sure you pass the toolchain file and a triplet:
```bash
-DCMAKE_TOOLCHAIN_FILE=/scripts/buildsystems/vcpkg.cmake
-DVCPKG_TARGET_TRIPLET=x64-windows-static # or your platform
- **DLLs missing on Windows (dynamic triplets)**
Copy runtime DLLs (e.g., `glfw3.dll`) next to your executable or use a static triplet.
- **Linux: missing dev packages**
Some distros donβt ship certain OpenGL helpers (e.g., `libglad-dev`).
On Ubuntu/Debian, enable `universe` or just skip it β this template will **auto-fetch GLAD** via `FetchContent`.
---
## π License
This project is licensed under the [MIT License](LICENSE).
---
## π Attribution
This project was originally generated from [d3m1d0s/OpenGLTemplate](https://github.com/d3m1d0s/OpenGLTemplate) - MIT.
If you use this as a template, please keep this line or move it to your `NOTICE` file.