A C++ OpenGL demo project showcasing modern graphics programming using popular libraries like GLFW, GLAD, and GLM.
This project serves as a foundation for OpenGL development in C++. It's currently a minimal setup that includes all the necessary dependencies and build configuration to start developing OpenGL applications.
- GLFW - Cross-platform library for creating windows, contexts, and handling input
- GLAD - OpenGL Function Loader for loading OpenGL functions
- GLM - OpenGL Mathematics library for graphics math operations
Before building this project, ensure you have the following installed:
- CMake (version 3.6 or higher)
- C++ Compiler with C++11 support:
- GCC 4.8+ (Linux)
- Clang 3.3+ (macOS/Linux)
- Visual Studio 2013+ (Windows)
- OpenGL drivers (usually comes with graphics drivers)
On Ubuntu/Debian systems, install the required packages:
sudo apt update
sudo apt install build-essential cmake libgl1-mesa-dev libglu1-mesa-devOn Fedora/CentOS/RHEL systems:
sudo dnf install gcc-c++ cmake mesa-libGL-devel mesa-libGLU-devel# Ubuntu/Debian
sudo apt install libxrandr-dev libxinerama-dev libxcursor-dev libxi-dev
# Fedora/CentOS/RHEL
sudo dnf install libXrandr-devel libXinerama-devel libXcursor-devel libXi-develwebclub-demo/
├── CMakeLists.txt # Main CMake configuration
├── README.md # This file
├── src/ # Source code directory
│ └── main.cpp # Main application entry point
├── vendors/ # Third-party libraries
│ ├── glad/ # OpenGL function loader
│ ├── glfw/ # Window management library
│ └── glm/ # Mathematics library
└── build/ # Build output directory (generated)
This project uses CMake as the build system. Follow these steps to build the project:
git clone --recursive <repository-url>
cd webclub-demomkdir build
cd buildcmake -S . -B buildcmake --build build./build/Application- Place
.cppand.cfiles in thesrc/directory - Place
.hand.hppfiles in thesrc/directory - CMake will automatically detect and include them in the build
The project is configured to:
- Use C++11 standard
- Build GLFW as a static library
- Disable GLFW examples, tests, and documentation
- Include all necessary headers and link required libraries
This project is structured to easily accommodate additional third-party libraries. Here are common approaches:
For libraries with CMake support:
-
Add as Git Submodule
git submodule add https://github.com/vendor/library.git vendors/library git submodule update --init --recursive
-
Update CMakeLists.txt
# Add to your CMakeLists.txt after existing add_subdirectory calls add_subdirectory(vendors/library) # Add include directories target_include_directories(Application PRIVATE vendors/library/include) # Link the library target_link_libraries(Application library_name)
For header-only libraries (like most of GLM):
-
Download and Extract
cd vendors/ wget https://github.com/vendor/library/archive/main.zip unzip main.zip mv library-main library -
Add Include Directory
target_include_directories(Application PRIVATE vendors/library/include)
For modern CMake (3.11+):
include(FetchContent)
FetchContent_Declare(
library_name
GIT_REPOSITORY https://github.com/vendor/library.git
GIT_TAG main # or specific version tag
)
FetchContent_MakeAvailable(library_name)
target_link_libraries(Application library_name)-
CMake not found: Install CMake from cmake.org or using your package manager
-
OpenGL headers not found: Install development packages for OpenGL
# Ubuntu/Debian sudo apt install mesa-common-dev -
GLFW dependencies missing: Install X11 development libraries
# Ubuntu/Debian sudo apt install libx11-dev libxrandr-dev libxinerama-dev libxcursor-dev libxi-dev -
Build fails on older systems: Ensure your compiler supports C++11
To perform a clean build:
rm -rf build/
mkdir build
cd build
cmake ..
cmake --build .This project currently contains a minimal main.cpp file. To start developing:
- Add OpenGL context creation code
- Implement basic rendering pipeline
- Add shaders and geometry
- Implement user input handling
This project is licensed under the MIT License - see the LICENSE file for details.