Skip to content

build-cpp/glfw_template

Repository files navigation

glfw_template

Simple template to get started with OpenGL using GLFW and GLEW.

This template uses cmkr together with vcpkg for frictionless cross platform dependency management with CMake.

Building (IDE)

Clone this repository and open it in your favorite IDE with CMake support (Visual Studio, CLion, Qt Creator). Everything should work out of the box.

Building (command line)

cmake -B build
cmake --build build

Note: On Ubuntu you need to run sudo apt-get install libgl-dev libxinerama-dev libxcursor-dev xorg-dev libglu1-mesa-dev to use this template.

cmake.toml

Under the hood cmkr generates the CMakeLists.txt required to build this project from the cmake.toml file:

[cmake]
version = "3.15"
cmkr-include = "cmake/cmkr.cmake"

[project]
name = "glfw_template"
include-after = [
    "cmake/generate_shaders.cmake"
]

# See https://vcpkg.io/en/packages.html for available packages
# Chose a version from https://github.com/microsoft/vcpkg/releases
[vcpkg]
version = "2021.05.12"
packages = ["glfw3", "glew"]

# vcpkg will download the packages, but you still need to find them to use them
[find-package]
glfw3 = {}
GLEW = {}

[target.example]
type = "executable"
sources = [
    "src/example.cpp",
    "shaders/FragmentShader.glsl",
    "shaders/VertexShader.glsl",
]
link-libraries = ["glfw", "GLEW::GLEW"]
compile-features = ["cxx_std_11"]
cmake-after = """
generate_shaders(${CMKR_TARGET})
"""