Skip to content
varomixPublic

About

Moss Graphics Framework

Resources

Stars

1 star

Watchers

0 watching

Forks

Latest commit

 

History

4 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Moss Framework

A lightweight, modern 2D/3D game framework built on SDL3 and Metal (macOS/iOS) or Vulkan/Direct3D (cross-platform via SDL3 GPU backend).

Features

  • 2D Rendering: High-performance batch-based 2D renderer with:

    • Texture rendering with rotation, scaling, and tinting
    • Custom fragment shader support per-draw-call
    • Shape drawing (rectangles, circles, lines, triangles)
    • Text rendering with built-in font
    • Automatic batching for optimal performance
  • 3D Rendering: Basic 3D capabilities including:

    • Mesh loading and rendering
    • Instanced rendering support
    • Perspective camera
  • Asset Management:

    • Texture loading (PNG, JPG via stb_image)
    • Procedural texture generation (checkerboard, gradients, solid colors)
    • Shader loading (SPIR-V, MSL)
    • Audio loading and playback
  • Physics: Box2D integration for 2D physics simulation

  • Scene Management: Scene switching and lifecycle management (create, update, render, destroy)

  • Additional Systems:

    • Tweening/animation system
    • Tilemap loading and rendering (WIP)
    • LDTK level editor integration (WIP)
    • Input handling (keyboard, mouse, gamepad)
    • Camera systems (2D and 3D)

Building

Requirements

  • CMake 3.20+
  • C compiler (Clang, GCC, or MSVC)
  • SDL3 (automatically fetched by CMake)
  • Box2D (automatically fetched by CMake)

macOS/Linux

mkdir build && cd build
cmake ..
make -j$(nproc)

Windows (Visual Studio)

mkdir build && cd build
cmake .. -G "Visual Studio 17 2022"
cmake --build . --config Release

Quick Start

Basic Window

#include <moss/moss.h>

void render(MossApp *app) {
    begin_2d(app, NULL);
    draw_rect(app, RECT(100, 100, 200, 150), RED);
    end_2d(app);
}

int main() {
    MossApp *app = create_app(&(MossConfig){
        .title = "My Game",
        .width = 800,
        .height = 600,
        .target_fps = 60,
    });
    
    run(app, &(Scene){ .on_render = render });
    destroy_app(app);
    return 0;
}

Loading and Drawing Textures

TextureHandle player;

void create(MossApp *app) {
    player = load_texture(app, "assets/player.png");
}

void render(MossApp *app) {
    begin_2d(app, NULL);
    draw_texture(app, player, VEC2(100, 100), WHITE);
    end_2d(app);
}

Custom Shaders

// Load shaders
ShaderHandle wave = load_shader(app, "shaders/wave.metal");

// Draw with custom shader using draw_texture_opts
draw_texture_opts(app, &(DrawTextureOptions){
    .texture = texture,
    .position = VEC2(100, 100),
    .tint = WHITE,
    .shader = wave
});

Examples

The examples/ directory contains 16 progressive examples:

  1. 01_hello_window - Basic window creation
  2. 02_input_scene - Input handling and scene switching
  3. 03_shapes - Drawing shapes
  4. 04_sprites - Textures and procedural generation
  5. 05_objects - Object/component system
  6. 06_collision - Basic collision detection
  7. 07_tweens - Animation tweening
  8. 08_text - Text rendering
  9. 09_tilemap - Tilemap loading and rendering
  10. 10_3d_cube - Basic 3D rendering
  11. 11_mixed_2d_3d - Combining 2D and 3D
  12. 12_arrows_game - Simple game example
  13. 13_physics - Box2D physics
  14. 14_ldtk - LDTK level loading
  15. 15_scenes - Scene management
  16. 16_shaders - Custom fragment shaders

Run an example:

./bin/04_sprites

Project Structure

├── include/moss/     # Public API headers
├── src/              # Framework implementation
├── examples/         # Example programs
├── deps/             # Third-party code (stb_image, cJSON)
├── docs/             # Documentation
└── build/            # Build artifacts (generated)

API Overview

Core

  • create_app() / destroy_app() - Application lifecycle
  • run() - Main loop with scene
  • get_dt() - Delta time
  • get_time() - Application time

2D Drawing

  • begin_2d() / end_2d() - 2D render pass
  • draw_texture() / draw_texture_ex() / draw_texture_opts() - Texture drawing
  • draw_rect() / draw_circle() / draw_line() - Shape drawing
  • draw_text() - Text rendering

Assets

  • load_texture() / unload_texture()
  • load_shader() / unload_shader()
  • make_checkerboard() / make_gradient() / make_graphic() - Procedural textures

Input

  • is_key_down() / is_key_pressed()
  • mouse_position() / is_mouse_button_down()

Math

  • VEC2(), VEC3(), RECT(), COLOR() - Constructor macros
  • Vector operations: vec2_add(), vec2_sub(), vec2_length(), etc.
  • Matrix operations: mat4_identity(), mat4_multiply(), mat4_ortho(), etc.

Shader Development

Shaders are written in GLSL 450 and compiled to SPIR-V and MSL:

cd examples/16_shaders
./build_shaders.sh

The framework supports custom fragment shaders for 2D texture effects. See examples/16_shaders/shaders/ for examples.

Dependencies

License

[Not sure yet - probably MIT]

About

Moss Graphics Framework

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages