Asia/Kolkata
ProjectsMay 29, 2025

Building Shaders in C++

Building Shaders in C++

GPU Shaders Demo

A demonstration project for learning and experimenting with GPU shaders using OpenGL. This project provides simple examples to understand how to implement and use shaders in graphics programming.

Overview

This project showcases various shader implementations using OpenGL, GLEW, and GLFW. Each example demonstrates different aspects of shader programming, starting with basic concepts like rendering a simple triangle.

Prerequisites

To build and run this project, you'll need:
  • C++17 compatible compiler
  • CMake (minimum 3.10)
  • OpenGL (3.3+)
  • GLEW (OpenGL Extension Wrangler Library)
  • GLFW3 (Graphics Library Framework)

Installing dependencies

Ubuntu/Debian:

macOS:

Windows:

It's recommended to use vcpkg or similar package managers:

Building the Project

  1. Clone the repository:
  1. Create and navigate to build directory:
  1. Generate build files with CMake:
  1. Build the project:

Running Examples

The project includes several examples, each demonstrating different shader techniques:

Triangle Example

A simple example showing a colored triangle rendered with basic vertex and fragment shaders. To run this example: This example demonstrates:
  • Setting up an OpenGL context with GLFW
  • Compiling and linking vertex and fragment shaders
  • Creating and using vertex buffer objects (VBO) and vertex array objects (VAO)
  • Drawing a basic shape with a solid color

Project Structure

gpu-shaders-demo/
├── CMakeLists.txt       # Project configuration and build settings
├── examples/            # Contains individual example programs
│   └── triangle.cpp     # Basic triangle rendering example
├── shaders/             # GLSL shader files (copied to build directory at compile time)
└── src/                 # Main source code
    └── main.cpp         # Simple menu program listing available examples

Controls

  • Press ESC to close any example window
  • Window can be resized, and the viewport will adjust accordingly

Adding New Examples

To add a new example:
  1. Create a new .cpp file in the examples/ directory
  2. Add the example to CMakeLists.txt using the add_example() function
  3. If needed, add any shader files to the shaders/ directory

Recent projects

HomeLab Controller

HomeLab Controller

gnome
Desktop
C
Avatar
Sep 2026 · 1 min read
A Controller software for my homelab written for Gnome based desktop environments.
The Eden Project
Avatar
Nov 2025 · 4 min read
What if music wasn't so inaccessible..
Run over a Deer
Avatar
Nov 2025 · 1 min read
A Silly little game based on the hit movie Over The Hedge