Skip to content

Zig library for windowing, handle input and rendering

License

Notifications You must be signed in to change notification settings

diogok/make-it-render

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

121 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Make it render

A Zig library for cross-platform window handling and CPU-based rendering, without any dependencies.

It is an experimental project with constant changes.

What this is

  • Abstraction between X11, Windows and macOS (soon?)
  • Window management, keyboard and mouse input events
  • Text rendering with Unicode support (embedded Terminus and Unifont fonts)
  • Image loading (PBM format) and scaling
  • A Canvas to put pixels on
  • Pure Zig — only uses C when linking to Win32 required libraries
  • Produces small and performant statically-linked binaries
  • No dependencies, all in one

What this is not

  • It is not a GUI library or game engine
  • It does not use GPU (no OpenGL nor Vulkan)
  • It does not support mobile (no Android nor iOS)

Structure

Each module is independent and usable by itself. The glue module ties them together.

  • anywindow — Window handling abstraction
    • x11: native X11 protocol implementation (no Xlib)
    • windows: Win32 API
    • macos: (planned)
  • text — Font loading, glyph rendering, Unicode support
    • fonts: embedded Unifont and Terminus (multiple sizes)
    • bdf: BDF font format parser (with gzip support)
  • image — Image loading
    • pbm: PBM format (P1 ASCII and P4 binary)
  • glue.zig — Joins everything
    • canvas: infinite drawing canvas with z-order
    • image: nearest-neighbor scaling

Work in progress

Notably missing:

  • Wayland support
  • macOS support

Usage

Building

zig build        # build the library and demo
zig build run    # run the demo
zig build test   # run tests
zig build docs   # generate documentation

As a dependency

zig fetch --save git+https://github.com/diogok/make-it-render

Then in your build.zig, import the module:

const make_it_render = b.dependency("make_it_render", .{ .target = target, .optimize = optimize });
exe_mod.addImport("make_it_render", make_it_render.module("make_it_render"));

Example

const std = @import("std");
const make_it_render = @import("make_it_render");

pub fn main() !void {
    var gpa = std.heap.GeneralPurposeAllocator(.{}){};
    defer std.debug.assert(gpa.deinit() != .leak);
    const allocator = gpa.allocator();

    var wm = try make_it_render.anywindow.WindowManager.init(allocator);
    defer wm.deinit();

    var window = try wm.createWindow(.{ .title = "hello, world." });
    defer window.deinit();

    var canvas = make_it_render.glue.Canvas.init(allocator, &window);
    defer canvas.deinit();

    try window.show();

    while (window.status == .open) {
        const event = try wm.receive();
        switch (event) {
            .close => window.close(),
            .draw => try canvas.draw(),
            else => {},
        }
    }
}

See src/demo.zig for a more complete example with text rendering, image loading, mouse tracking, and fullscreen toggle.

License

MIT

About

Zig library for windowing, handle input and rendering

Topics

Resources

License

Stars

Watchers

Forks

Languages