Thanks to visit codestin.com
Credit goes to github.com

Skip to content

elvismello/visualizations_cpp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

33 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

OpenCL Visualization Project

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.

๐ŸŽฏ Overview

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.

๐Ÿ—๏ธ System Architecture

High-Level Overview

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
Loading

Application Main Loop

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
Loading

๐Ÿ”ง Main Components

1. Application (Main Controller)

  • Manages application lifecycle
  • Coordinates Window, OpenCLCompute and Renderer
  • Controls timing and performance statistics
  • Executes the main rendering loop

2. Window (Window Management)

  • GLFW wrapper
  • Window creation and management
  • OpenGL context
  • Event handling

3. OpenCLCompute (Parallel Computing)

  • OpenCL platform initialization
  • Kernel compilation and execution
  • OpenCL buffer management
  • Parallel point position calculation

4. Renderer (OpenGL Rendering)

  • OpenGL buffer management (VBO/VAO)
  • Shader compilation
  • Rendering pipeline
  • GPU data updates

๐Ÿš€ Execution Flow

  1. Initialization:

    • Application setup via Application::Config
    • GLFW window creation
    • OpenCL context initialization
    • OpenGL buffers and shaders setup
  2. 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
  3. 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))

๐Ÿ“‹ Requirements

  • OpenCL: For parallel computing
  • OpenGL: For rendering
  • GLFW: For window creation
  • GLEW: For OpenGL extensions
  • CMake: For build system

๐Ÿƒโ€โ™‚๏ธ How to Run

# Build the project
./build.sh

# Run
./run.sh
# or
./build/visProject

โš™๏ธ Configuration

Main 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";

๐Ÿ“Š Performance

The system monitors and displays in real-time:

  • FPS: Frames per second
  • Frame Time: Time per frame in milliseconds
  • Elapsed Time: Total elapsed time

๐ŸŽจ Customization

  • Patterns: Modify fill_points.cl for different parametric equations
  • Shaders: Customize vertex_1.glsl and fragment_1.glsl for different visual effects
  • Points: Adjust pointCount for more/less density
  • Animation: Modify time parameters in the kernel

๐Ÿ—๏ธ File Structure

โ”œโ”€โ”€ 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

๐ŸŽฏ Technical Features

  • 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

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors