# gue-ni/opengl_flightsim architecture

> Architecture diagram of the GitHub repository gue-ni/opengl_flightsim, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-12). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/gue-ni/opengl_flightsim
- Repository: https://github.com/gue-ni/opengl_flightsim

## Overview

##### Main Components
- Application Core – This includes the main entry point (main.cpp) and overall application loop that ties together simulation updates, input processing, and rendering.
- Rendering Engine – Implemented through gfx.cpp/gfx.h and the associated OpenGL shader programs (the shaders directory). This component manages the graphics pipeline including shader management, drawing calls, and integration with SDL and GLEW.
- Flight Model & Physics – Files like flightmodel.h, ai.h, and pid.h indicate that there is a simulation subsystem handling physics, control logic, and possibly AI for simulation behavior.
- Asset Management – The assets directory (with subdirectories for models, data, and textures) clearly shows that this component is responsible for loading and managing 3D models, textures, and other external resources needed for rendering.
- UI/Debug Tools – The included ImGui library within the lib directory (lib/imgui) suggests that a user interface or debug overlays are available for the simulator.
- Terrain and Map Tools – The tools/terrain folder and its scripts (e.g., create_map.sh, decode_heightmap.py) point to a separate subsystem for generating or processing terrain data, which is then used by the simulation.

##### Relationships and Interactions
- The Application Core takes user input (via keyboard or joystick) and passes commands to the Flight Model component to update aircraft physics and state.
- The Rendering Engine communicates with OpenGL through GLEW and utilizes shader programs (from the shaders folder) to render models, terrains, and environmental effects (e.g., skybox, billboarding).
- The Asset Management system loads models, textures, and CSV data files (such as airfoil data in the assets/data folder) which are then used by both the Simulation Core and Rendering Engine.
- External tools for terrain generation might output data that is consumed by the simulator’s terrain module.

##### Architectural Patterns
- Modular Architecture: Code is organized into modules for core functionality (simulation loop, flight model), rendering, asset management, and tools for data preparation.
- Data Flow and Separation of Concerns: There is a clear separation between simulation (physics and state updates), graphical rendering (visual output and shader management), and asset/resource management.
- Integration of Third-Party Libraries: SDL2 handles window creation and input, GLEW manages OpenGL extensions, and glm provides math support, all of which are central to the overall design of the system.

a. Clear labels for each component:
- Core simulation modules (e.g., main loop, flight model).
- Graphics/Rendering modules (shader management, OpenGL calls).
- External resource components (assets, third-party libraries).
- Build/Configuration Tools: mention of CMake (and Visual Studio project files shown in the file tree) to underline how everything is integrated.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Simulation Core
    subgraph "Simulation Core"
        AC("Application Core/Main Loop"):::core
        IH("Input Handling"):::core
        FM("Flight Model/Physics"):::core
    end

    %% Graphics and Rendering
    subgraph "Graphics/Rendering"
        RE("Rendering Engine<br>OpenGL+SDL2+GLEW"):::rendering
        SP("Shader Programs"):::rendering
        UI("User Interface (ImGui)"):::rendering
    end

    %% Asset Management
    subgraph "Asset Management"
        AM("Asset Management"):::assets
    end

    %% Terrain Tools
    subgraph "Terrain Tools"
        TP("Terrain Processing Tools"):::tools
    end

    %% External Dependencies and Build Tools
    ED("External Dependencies<br>SDL2, GLEW, OpenGL, glm"):::external
    BT("Build/Configuration Tools<br>CMake, VS Projects"):::tools

    %% Connections within Simulation Core
    AC --> IH
    IH --> FM

    %% Simulation to Rendering Flow
    FM --> RE

    %% Asset Management feeds both Simulation and Rendering
    AM --> FM
    AM --> RE

    %% Terrain Tools provide input to Asset Management
    TP --> AM

    %% UI feeds back into the Application Core
    UI --> AC

    %% External Dependencies link to Rendering components
    ED --> RE
    ED --> UI

    %% Build tools connect to the Application Core
    BT --> AC

    %% Rendering Engine uses Shader Programs
    RE --> SP

    %% Styles
    classDef core fill:#f9d5bb,stroke:#d35400,stroke-width:2px;
    classDef rendering fill:#d5f5e3,stroke:#27ae60,stroke-width:2px;
    classDef assets fill:#d6eaf8,stroke:#2e86c1,stroke-width:2px;
    classDef tools fill:#f9e79f,stroke:#f1c40f,stroke-width:2px;
    classDef external fill:#fadbd8,stroke:#e74c3c,stroke-width:2px;

    class AC,IH,FM core;
    class RE,UI,SP rendering;
    class AM assets;
    class TP,BT tools;
    class ED external;

    %% Click Events
    click AC "https://github.com/gue-ni/opengl_flightsim/blob/master/OpenGL_Flightsim/src/main.cpp"
    click RE "https://github.com/gue-ni/opengl_flightsim/blob/master/OpenGL_Flightsim/src/gfx.cpp"
    click RE "https://github.com/gue-ni/opengl_flightsim/blob/master/OpenGL_Flightsim/src/gfx.h"
    click SP "https://github.com/gue-ni/opengl_flightsim/tree/master/OpenGL_Flightsim/shaders"
    click FM "https://github.com/gue-ni/opengl_flightsim/blob/master/OpenGL_Flightsim/src/flightmodel.h"
    click FM "https://github.com/gue-ni/opengl_flightsim/blob/master/OpenGL_Flightsim/src/pid.h"
    click FM "https://github.com/gue-ni/opengl_flightsim/blob/master/OpenGL_Flightsim/src/ai.h"
    click AM "https://github.com/gue-ni/opengl_flightsim/tree/master/OpenGL_Flightsim/assets"
    click UI "https://github.com/gue-ni/opengl_flightsim/tree/master/OpenGL_Flightsim/lib/imgui"
    click TP "https://github.com/gue-ni/opengl_flightsim/tree/master/tools/terrain"
```
