This project implements an off-screen image rendering pipeline using OpenGL and EGL, optimized for running on GPU hardware. The core functionality revolves around rendering triangles and applying color gradients using vertex and fragment shaders. The result is an image that is generated entirely using the graphics card, providing fast and efficient rendering for large datasets or complex visualizations.
The rendering process begins with setting up an EGL context and creating an off-screen surface. The project uses the following steps to render images:
-
Vertex Setup:
- Vertices are defined with 3D positions (x, y, z) and color attributes (r, g, b, a).
-
Shader Compilation:
- The project uses vertex and fragment shaders to process the vertices and colors, applying transformations and interpolating the colors across the surface of the triangles.
-
Off-Screen Context Creation:
- EGL is used to create a rendering context without a display, enabling GPU-based off-screen rendering.
-
Rendering:
- The image is rendered using OpenGL commands, where the triangles are rasterized, and the final image is stored in memory.
-
Image Generation:
- The rendered image is copied from the GPU's memory to CPU memory and saved as a file (e.g., PNG format) for further use.
- C++ Compiler: Any modern C++ compiler (e.g., GCC, Clang).
- OpenGL: A library for rendering 2D and 3D vector graphics.
- EGL: A native platform interface to create rendering contexts for OpenGL.
- GLM: OpenGL Mathematics library for handling transformations.
- Qt: for handling colors and images
- CMake (optional): If you want to build the project using a CMake build system.
-
Install the required libraries: OpenGL, EGL, GLM, and Qt.
sudo apt-get install libegl1-mesa-dev libgl1-mesa-dev qtbase5-dev libglm-dev
-
Navigate to the project directory.
cd image_renderer -
Compile the project using g++:
g++ -std=c++17 -o image_renderer main.cpp trianglerenderer.cpp renderegl.cpp renderegl2.cpp RenderOffScreen.cpp -lEGL -lGL -lQt5Widgets
Compile using CMake:
mkdir build
cd build
cmake ..
makeOnce compiled, you can run the project as follows:
./image_rendererBy default, the program will generate an image based on the predefined vertex and color data. The image will be saved in the same directory as the executable.
As an example of this GPU-based renderer, a Bathymetric Image was generated from real-world depth data.
