A real-time visualization application that uses OpenCL for parallel computing and OpenGL for rendering. The project generates and animates points in a parametric pattern using GPU compute shaders.
This project demonstrates the integration between OpenCL (for parallel computing) and OpenGL (for graphics rendering) to create real-time mathematical visualizations. The system calculates point positions using parametric formulas on the GPU via OpenCL and renders them using OpenGL.
flowchart LR
A["๐ main.cpp<br/>Entry Point"] --> B["๐ฎ Application<br/>Main Controller"]
B --> C["๐ช Window<br/>GLFW + OpenGL"]
B --> D["โก OpenCLCompute<br/>GPU Computing"]
B --> E["๐จ Renderer<br/>OpenGL Graphics"]
classDef entry fill:#e3f2fd,stroke:#1976d2,stroke-width:2px,color:#000
classDef app fill:#f3e5f5,stroke:#7b1fa2,stroke-width:2px,color:#000
classDef window fill:#e8f5e8,stroke:#388e3c,stroke-width:2px,color:#000
classDef compute fill:#fff3e0,stroke:#f57c00,stroke-width:2px,color:#000
classDef render fill:#fce4ec,stroke:#c2185b,stroke-width:2px,color:#000
class A entry
class B app
class C window
class D compute
class E render
flowchart TD
A["๐ Start Main Loop"] --> B["๐ก Poll Window Events"]
B --> C["โฑ๏ธ Update Timing<br/>(deltaTime, elapsedTime)"]
C --> D["โก Execute OpenCL Kernel<br/>(Calculate Point Positions)"]
D --> E["๐ค Transfer Data<br/>(OpenCL โ OpenGL Buffer)"]
E --> F["๐จ Render Points<br/>(OpenGL Pipeline)"]
F --> G["๐ Swap Buffers<br/>(Display Frame)"]
G --> H["๐ Print Performance Stats<br/>(FPS, Frame Time)"]
H --> I{"๐ช Should Close?"}
I -->|No| B
I -->|Yes| J["๐ Exit"]
classDef loop fill:#e8f5e8,stroke:#388e3c,stroke-width:2px,color:#000
classDef process fill:#fff3e0,stroke:#f57c00,stroke-width:2px,color:#000
classDef render fill:#fce4ec,stroke:#c2185b,stroke-width:2px,color:#000
classDef decision fill:#e3f2fd,stroke:#1976d2,stroke-width:2px,color:#000
class A,B,G,H loop
class C,D,E process
class F render
class I,J decision
- Manages application lifecycle
- Coordinates Window, OpenCLCompute and Renderer
- Controls timing and performance statistics
- Executes the main rendering loop
- GLFW wrapper
- Window creation and management
- OpenGL context
- Event handling
- OpenCL platform initialization
- Kernel compilation and execution
- OpenCL buffer management
- Parallel point position calculation
- OpenGL buffer management (VBO/VAO)
- Shader compilation
- Rendering pipeline
- GPU data updates
-
Initialization:
- Application setup via
Application::Config - GLFW window creation
- OpenCL context initialization
- OpenGL buffers and shaders setup
- Application setup via
-
Main Loop:
- Events: Process window events
- Timing: Update delta and elapsed time
- Compute: Execute OpenCL kernel to calculate new positions
- Transfer: Copy data from OpenCL to OpenGL
- Render: Render points on screen
- Display: Swap buffers and show frame
- Stats: Print performance statistics
-
OpenCL Kernel (
fill_points.cl):// Animated parametric formula x = 0.8 * cos(4ฯ * (a*u + 0.1*t)) y = 0.8 * sin(2ฯ * (b*u + 0.2*t))
- OpenCL: For parallel computing
- OpenGL: For rendering
- GLFW: For window creation
- GLEW: For OpenGL extensions
- CMake: For build system
# Build the project
./build.sh
# Run
./run.sh
# or
./build/visProjectMain settings are in main.cpp:
Application::Config config;
config.windowWidth = 1366;
config.windowHeight = 768;
config.pointCount = 1200000; // Number of points
config.vsync = false;
config.kernelPath = "../kernels/fill_points.cl";
config.vertexPath = "../shaders/vertex_1.glsl";
config.fragmentPath = "../shaders/fragment_1.glsl";The system monitors and displays in real-time:
- FPS: Frames per second
- Frame Time: Time per frame in milliseconds
- Elapsed Time: Total elapsed time
- Patterns: Modify
fill_points.clfor different parametric equations - Shaders: Customize
vertex_1.glslandfragment_1.glslfor different visual effects - Points: Adjust
pointCountfor more/less density - Animation: Modify time parameters in the kernel
โโโ src/
โ โโโ main.cpp # Entry point
โ โโโ application.cpp # Main controller
โ โโโ window.cpp # GLFW management
โ โโโ compute.cpp # OpenCL compute
โ โโโ renderer.cpp # OpenGL rendering
โ โโโ common.cpp # Utilities
โโโ include/ # Headers
โโโ shaders/ # GLSL shaders
โโโ kernels/ # OpenCL kernels
โโโ build/ # Compiled files
- Parallel Computing: Up to 1.2M gravitational interactions calculated simultaneously per second on GPU (using current kernel with direct sumation)
- Efficient Rendering: Direct use of OpenGL vertex buffers
- Synchronization: Optimized transfer between OpenCL and OpenGL
-
Real-time: 60+ FPS with smooth visualization using
$10^5$ points with medium grade GPUs