# evan-ciao/garden-opengl architecture

> Architecture diagram of the GitHub repository evan-ciao/garden-opengl, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-08-21). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/evan-ciao/garden-opengl
- Repository: https://github.com/evan-ciao/garden-opengl

## Overview

##### Project type and overall purpose
- This is a small, learning-oriented 3D graphics/demo application written in C++ using OpenGL 1.3.
- It uses SDL for windowing and input, SOIL for texture loading, and some Irrlicht headers for math utilities.
- Core functionality: initialize graphics context, load models/textures, enter game loop, process input & physics (sphere collisions), then render the scene.

##### File structure to extract major components
- Root headers (playerEntity.hpp, gameObject.hpp, mesh.hpp, rigidbody.hpp, world.hpp, camera.hpp, renderer.hpp, collider.hpp) define the in-engine components.
- main.cpp – the entry point, sets up SDL/OpenGL, drives the game loop.
- data/ and models/ folders – store raw assets (bitmaps, .obj meshes, model-specific headers and Python scripts).
- /SDL, include/SOIL, include/irrlicht – third-party libraries compiled into lib/libSDL*.a and lib/libSOIL.a.
- Makefile.win – build script (Windows), .gitignore – ignores build artifacts.

##### Extract architectural insights from the README
- “playerEntity” handles input callbacks, updates camera and position.
- “world” manages all game objects, performs collision checks every frame.
- Physics is limited to a sphere-vs-mesh “Collide and Slide” algorithm in world.hpp and collider.hpp.

a. Application Launcher (main.cpp)
b. Window & Context (SDL → OpenGL)
c. Input Subsystem (SDL event loop → playerEntity)
d. Game World
- Entity Manager (world.hpp)
- GameObject (gameObject.hpp) + Components
– Transform
– Mesh Component (mesh.hpp)
– Rigidbody Component (rigidbody.hpp)
– Collider (collider.hpp)
e. Physics & Collision
- Collision Handler (world + collider)
f. Camera (camera.hpp)
g. Rendering Pipeline (renderer.hpp)
- Shader-less fixed-function OpenGL 1.3
- Asset Loader (SOIL for textures, custom .obj loader in mesh)
h. Data Storage (models/, data/)
i. External Libraries (SDL, SOIL, Irrlicht math)
j. GPU / Display

##### Relationships & data flow
- main.cpp initializes SDL & OpenGL → loads assets via mesh/renderer.
- enters Game Loop:
1) Poll SDL events → dispatch to playerEntity (input subsystem).
2) playerEntity updates Camera and player’s GameObject transform.
3) world.update():
- For each GameObject with Rigidbody & Collider, test sphere-mesh collisions.
- Resolve positions.
4) renderer.render():
- For each GameObject with Mesh, submit vertex data + texture to OpenGL.
- Asset Loader reads from disk (models/, data/) once at startup.
- External libs provide windowing, input, image loading, math support.

##### Architectural patterns & design principles
- Component-based entity system (GameObject + pluggable components).
- Single main loop orchestrating subsystems (input → physics → render).
- Separation of concerns: input logic in playerEntity, collision in world/collider, rendering in renderer.
- Header-only style (to avoid linking hassles), minimal dependencies.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Application Launcher
    main["Application Launcher\n(main.cpp)"]:::core
    click main "https://github.com/evan-ciao/garden-opengl/blob/main/main.cpp"

    %% Infrastructure
    subgraph "Infrastructure (Window & Context)" 
        SDLHeaders["SDL Headers"]:::infra
        click SDLHeaders "https://github.com/evan-ciao/garden-opengl/tree/main/include/SDL"
        SDLLibMain["libSDLmain.a"]:::infra
        click SDLLibMain "https://github.com/evan-ciao/garden-opengl/blob/main/lib/libSDLmain.a"
        SDLLibLA["libSDL.la"]:::infra
        click SDLLibLA "https://github.com/evan-ciao/garden-opengl/blob/main/lib/libSDL.la"
        OpenGL["OpenGL Context"]:::infra
    end

    %% Subsystems
    subgraph "Subsystems"
        Input["Input Subsystem\n(SDL event loop)"]:::subsystem
        PlayerEntity["PlayerEntity\n(playerEntity.hpp)"]:::core
        click PlayerEntity "https://github.com/evan-ciao/garden-opengl/blob/main/playerEntity.hpp"
        Physics["Physics & Collision"]:::subsystem
        Renderer["Rendering Pipeline"]:::subsystem
        CameraNode["Camera\n(camera.hpp)"]:::core
        click CameraNode "https://github.com/evan-ciao/garden-opengl/blob/main/camera.hpp"
    end

    %% Engine Core
    subgraph "Engine Core"
        World["World (Entity Manager)\n(world.hpp)"]:::core
        click World "https://github.com/evan-ciao/garden-opengl/blob/main/world.hpp"
        GameObject["GameObject\n(gameObject.hpp)"]:::core
        click GameObject "https://github.com/evan-ciao/garden-opengl/blob/main/gameObject.hpp"
        subgraph Components
            MeshComp["Mesh Component\n(mesh.hpp)"]:::core
            click MeshComp "https://github.com/evan-ciao/garden-opengl/blob/main/mesh.hpp"
            Rigidbody["Rigidbody Component\n(rigidbody.hpp)"]:::core
            click Rigidbody "https://github.com/evan-ciao/garden-opengl/blob/main/rigidbody.hpp"
            Collider["Collider Component\n(collider.hpp)"]:::core
            click Collider "https://github.com/evan-ciao/garden-opengl/blob/main/collider.hpp"
        end
    end

    %% Rendering Pipeline Details
    subgraph "Rendering Details"
        RendererModule["Renderer Module\n(renderer.hpp)"]:::subsystem
        click RendererModule "https://github.com/evan-ciao/garden-opengl/blob/main/renderer.hpp"
        AssetLoader["Asset Loader\n(SOIL)"]:::subsystem
        click AssetLoader "https://github.com/evan-ciao/garden-opengl/blob/main/include/SOIL/SOIL.h"
        click AssetLoader "https://github.com/evan-ciao/garden-opengl/blob/main/lib/libSOIL.a"
    end

    %% Data Storage
    subgraph "Data Storage"
        Textures["Texture Assets\ndata/man.bmp"]:::data
        click Textures "https://github.com/evan-ciao/garden-opengl/blob/main/data/man.bmp"
        MeshAssets["Mesh Assets\nmodels/*.obj\nmodels/*.hpp"]:::data
    end

    %% External Libraries
    subgraph "External Libraries"
        SDLExt["SDL"]:::external
        click SDLExt "https://github.com/evan-ciao/garden-opengl/tree/main/include/SDL/*"
        SOILExt["SOIL"]:::external
        click SOILExt "https://github.com/evan-ciao/garden-opengl/tree/main/include/SOIL/*"
        Irrlicht["Irrlicht Math"]:::external
        click Irrlicht "https://github.com/evan-ciao/garden-opengl/tree/main/include/irrlicht/*"
    end

    %% GPU/Display
    GPU["GPU / Display"]:::gpu

    %% Connections
    main -->|initializes| SDLHeaders
    SDLHeaders -->|creates| OpenGL
    main -->|calls| Input
    Input -->|dispatches events| PlayerEntity
    PlayerEntity -->|updates transform| GameObject
    PlayerEntity -->|updates camera| CameraNode
    main -->|loads assets| MeshComp
    MeshComp -->|loads textures| AssetLoader
    AssetLoader -->|reads data| Textures
    MeshComp -->|reads mesh| MeshAssets

    main -->|starts loop| World
    World -->|contains| GameObject
    GameObject -->|has| MeshComp
    GameObject -->|has| Rigidbody
    GameObject -->|has| Collider

    World -->|performs collisions| Physics
    Physics -->|uses| Collider
    Physics -->|uses| MeshComp

    World -->|submits| Renderer
    Renderer -->|invokes| RendererModule
    RendererModule -->|issues draw calls| OpenGL
    RendererModule -->|binds textures| AssetLoader
    RendererModule -->|binds camera| CameraNode

    OpenGL -->|renders to| GPU

    %% Build Scripts & Metadata
    subgraph "Build & Metadata"
        MakeWin["Makefile.win"]:::infra
        GitIgnore[".gitignore"]:::infra
        Readme["README.md"]:::infra
    end
    main -->|build info| MakeWin
    main -->|versioning| GitIgnore
    main -->|documentation| Readme

    %% Styles
    classDef core fill:#DFF2BF,stroke:#4F8A10,color:#4F8A10;
    classDef subsystem fill:#BDE5F8,stroke:#00529B,color:#00529B;
    classDef infra fill:#E6E6FA,stroke:#9370DB,color:#9370DB;
    classDef data fill:#FFF2CC,stroke:#9F6000,color:#9F6000;
    classDef external fill:#F8E0E6,stroke:#D32F2F,color:#D32F2F;
    classDef gpu fill:#F0F8FF,stroke:#4682B4,color:#4682B4;
```
