A real-time 2D Black Hole & Orbital Mechanics Simulation built using Modern C++20 and OpenGL.
The original recording can be viewed here:
๐น Watch Full Demo
This project is a real-time physics simulation of a black hole interacting with surrounding celestial bodies through Newtonian gravity.
The simulation demonstrates stable orbital mechanics, gravitational attraction, and fixed timestep physics while rendering everything using Modern OpenGL and GLSL shaders.
The project was built primarily as a graphics programming and physics-engine learning project while also serving as the foundation for a lightweight rendering framework (SOGL).
- ๐ Newtonian Gravity Simulation
- โซ Massive Black Hole Object
- ๐ช Stable Planetary Orbits
- ๐ Fixed Timestep Physics
- ๐ฏ Euler Integration
- ๐ Modern OpenGL Rendering
- ๐จ GLSL Shader Pipeline
- ๐งฉ Modular Engine Architecture
- ๐ฆ Custom SOGL Rendering Framework
- โก Real-time Simulation
- ๐ต Procedurally Generated Circle Meshes
- ๐ฅ Cross-platform build using CMake
The simulation uses Newton's Universal Law of Gravitation.
[ F = G\frac{m_1m_2}{r^2} ]
[ a = \frac{F}{m} ]
[ v = v + a\Delta t ]
[ x = x + v\Delta t ]
The physics engine runs using a fixed timestep to ensure deterministic and stable orbital motion independent of rendering frame rate.
BlackHoleSimulation
โ
โโโ assets/
โ โโโ models/
โ โโโ shaders/
โ โโโ textures/
โ
โโโ docs/
โ โโโ demo.gif
โ โโโ demo.mp4
โ
โโโ libs/
โ โโโ glad/
โ โโโ glfw/
โ โโโ glm/
โ
โโโ SOGL/
โ โโโ graphic/
โ โโโ shaders/
โ โโโ window/
โ
โโโ src/
โ โโโ core/
โ โโโ rendering/
โ โโโ simulation/
โ โโโ main.cpp
โ
โโโ CMakeLists.txt
โโโ README.md
| Technology | Purpose |
|---|---|
| C++20 | Programming Language |
| OpenGL 4.6 | Graphics API |
| GLFW | Window & Input |
| GLAD | OpenGL Loader |
| GLM | Mathematics |
| GLSL | Shader Programming |
| CMake | Build System |
- C++20 compatible compiler
- CMake 3.20+
- OpenGL 4.6 capable GPU
- Git
- MinGW-w64 or
- Visual Studio 2022
git clone https://github.com/KrishMaheshwariDev/Black-Hole-Simulation
cd Black-Hole-Simulationcmake -B buildcmake --build build./build/BlackHoleSim.exeor
cd build
BlackHoleSim.exe| Key | Action |
|---|---|
| ESC | Exit Simulation |
| NumPad - | Zoom out |
| NumPad + | Zoom in |
This project also includes SOGL, a lightweight OpenGL rendering framework created during development.
It provides abstractions over:
- Window Creation
- Vertex Arrays
- Vertex Buffers
- Mesh Rendering
- Shader Management
- Renderer Utilities
SOGL is intentionally lightweight and educational, designed for graphics experiments rather than production use.
This project provided hands-on experience with:
- Modern OpenGL
- Graphics Pipeline
- GLSL Programming
- Mesh Generation
- Orbital Mechanics
- Newtonian Gravity
- Numerical Integration
- Fixed Timestep Game Loops
- CMake Project Organization
- Engine Architecture
- Multiple Black Holes
- N-Body Simulation
- Camera Controls
- Zoom & Pan
- ImGui Controls
- Collision Detection
- Accretion Disk
- Particle Effects
- Relativistic Physics
- Barnes-Hut Optimization
- Save / Load Simulation
Contributions, suggestions, and bug reports are welcome.
If you'd like to improve the project:
- Fork the repository.
- Create a new branch.
- Commit your changes.
- Open a Pull Request.
This project is licensed under the MIT License.
Feel free to use the code for learning, experimentation, or personal projects.
B.Tech Computer Science (Data Science)
GitHub:
https://github.com/KrishMaheshwariDev
LinkedIn:
https://www.linkedin.com/in/krish-maheshwari
It helps others discover the project and motivates future development.
