• Stars
    star
    124
  • Rank 286,386 (Top 6 %)
  • Language
    Zig
  • License
    MIT License
  • Created over 3 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Application framework based on OpenGL ES 2.0. Runs on desktop machines, Android phones and the web

Zero Graphics

A very minimal OpenGL ES 2.0 library for Zig. Opens you a window and let's you draw things. Comes with a pixel-perfect 2D renderer and maybe some day even with a bit of a 3D api.

Logo

Features

  • Multi-platform support
    • Desktop (Linux, MacOS, Windows, ...)
    • WebAssembly
    • Android
  • Pixel perfect 2D rendering
    • Primitives (line, rectangle, triangle, ...)
    • Text / TTF fonts
    • Textures
  • Basic 3D rendering
    • Multi-mesh models with flat textures
  • Zig-style immediate-mode user interface
  • Proper DPI scaling support in renderer

Project status

CI

The CI coverage currently looks like this:

Β· Windows macOS Linux
Desktop βœ… βœ… βœ…
WebAssembly βœ… βœ… βœ…
Android βœ… βœ… βœ…
zero-init βœ… βœ… βœ…
zero-convert βœ… βœ… βœ…

Status: Nightly Build

Previews

Work-in-progress, but works quite well already. There is one big project depending on it and is used as a real-world application driver behind Zero Graphics.

Preview screenshot for SDL2

Preview screenshot in FireFox

Project Goals

Basic Framework

  • Support the following platforms
    • Wasm
      • Create OpenGL ES 2.0 context
      • Input Mouse
      • Input Keyboard
    • Linux Desktop
      • Create OpenGL ES 2.0 context
      • Input Mouse
      • Input Keyboard
    • Windows Desktop (not tested, but should work via SDL2)
    • Android
      • Create OpenGL ES 2.0 context
      • Input Mouse
      • Input Keyboard
  • Create an OpenGL ES 2.0 context
  • Provide input events
    • Single pointer motion (finger or mouse)
    • Single click event (finger, mouse)
    • Text input for keyboard (utf-8 encoded)
  • Provide window events
    • Resize
    • Close
  • Provide access to the underlying backend
  • Allow creation of single-file applications
    • Single executable for easy distribution
    • Embedded resources

2D Rendering library

  • Pixel perfect drawing of
    • Lines
    • Rectangles
    • Images
      • Basic "copy full texture to rectangle"
      • Copy portion of texture ("atlas rendering")
  • TTF font rendering via stb_ttf
  • Image loading via zigimg
  • Stack based/nested scissoring

3D Rendering library

  • Tool based on Assimp to convert models into loadable format
    • static geometry
    • dynamic/animated geometry
  • Blender export script
  • Draw static geometry
  • Draw animated geometry
    • Skinning based on skeletons
  • Axis- and camera aligned billboards
  • Basic particles
  • Tiny built-in pipeline with
    • shadow mapping
    • planar reflections
    • water reflections

Dependencies

Desktop

Web

Android

  • Android SDK
  • Android NDK
  • Android Build Tools
  • OpenJDK
  • some other tools

Building / Running

This project uses submodules, so to get started, clone the repo with submodules recursively:

[user@computer work]$ git clone https://github.com/MasterQ32/zero-graphics --recurse-submodules

or, if you already cloned the repository:

[user@computer work]$ git clone https://github.com/MasterQ32/zero-graphics
[user@computer work]$ cd zero-graphics/
[user@computer zero-graphics]$ git submodule update --init --recursive

Desktop PC

Requires SDL2 to be installed.

[user@computer zero-graphics]$ zig build run

A window should open with the application in fullscreen.

The following environment variables can control how zero-graphics behaves:

  • ZEROG_FULLSCREEN is y for forced fullscreen or n for forced window mode.
  • ZEROG_RESIZEABLE is y for forced resizable window.
  • ZEROG_DPI is a number specifying the pixel density.

Web/Wasm version

Includes a teeny tiny web server for debugging.

[user@computer zero-graphics]$ zig build install run-wasm

Now visit http://127.0.0.1:8000/demo_application.htm to see the demo.

Android

Connect your phone first and install both a JDK as well as the Android SDK with NDK included. The ZeroGraphics build system will tell you if it couldn't auto-detect the SDK paths.

[user@computer zero-graphics]$ zig build -Denable-android run-app

The app should now be installed and started on your phone.

Documentation

Getting started

To create a new project, build this repository with zig build first. Then use the tool zero-init from zig-out/bin to initialize a new project:

[felix@denkplatte-v2 ~]$ mkdir game
[felix@denkplatte-v2 ~]$ cd game
[felix@denkplatte-v2 game]$ /path/to/zero-graphics/zig-out/bin/zero-init symlink # initialize via symlink, quickest option. use zero-init -h to see all options
[felix@denkplatte-v2 game]$ ls
src  vendor  build.zig
[felix@denkplatte-v2 game]$ zig build
[felix@denkplatte-v2 game]$ zig build run
info(sdl): SDL Video Driver:     x11
info(sdl): Render resolution:  1280Γ—720
info(sdl): Virtual resolution: 1280Γ—720
info(demo): OpenGL Version:       OpenGL ES 3.2 Mesa 21.2.3
info(demo): OpenGL Vendor:        AMD
info(demo): OpenGL Renderer:      AMD Radeon(TM) Vega 10 Graphics (RAVEN, DRM 3.41.0, 5.13.19_1, LLVM 12.0.1)
info(demo): OpenGL GLSL:          OpenGL ES GLSL ES 3.20
info(zero_graphics): [shader compiler] [other] Shader Stats: SGPRS: 16 VGPRS: 8 Code Size: 212 LDS: 0 Scratch: 0 Max Waves: 10 Spilled SGPRs: 0 Spilled VGPRs: 0 PrivMem VGPRs: 0
info(zero_graphics): [shader compiler] [other] Shader Stats: SGPRS: 16 VGPRS: 8 Code Size: 40 LDS: 0 Scratch: 0 Max Waves: 10 Spilled SGPRs: 0 Spilled VGPRs: 0 PrivMem VGPRs: 0
info(zero_graphics): [shader compiler] [other] Shader Stats: SGPRS: 8 VGPRS: 24 Code Size: 52 LDS: 0 Scratch: 0 Max Waves: 10 Spilled SGPRs: 0 Spilled VGPRs: 0 PrivMem VGPRs: 0
info(zero_graphics): [shader compiler] [other] Shader Stats: SGPRS: 8 VGPRS: 24 Code Size: 24 LDS: 0 Scratch: 0 Max Waves: 10 Spilled SGPRs: 0 Spilled VGPRs: 0 PrivMem VGPRs: 0
info(zero_graphics): [shader compiler] [other] Shader Stats: SGPRS: 8 VGPRS: 8 Code Size: 60 LDS: 0 Scratch: 0 Max Waves: 10 Spilled SGPRs: 0 Spilled VGPRs: 0 PrivMem VGPRs: 0
info(zero_graphics): [shader compiler] [other] Shader Stats: SGPRS: 16 VGPRS: 20 Code Size: 392 LDS: 0 Scratch: 0 Max Waves: 10 Spilled SGPRs: 0 Spilled VGPRs: 0 PrivMem VGPRs: 0

Check out the file src/main.zig to see your app skeleton. You can also adjust the build.zig to set your project name.

The functions are roughly called in this order:

Application workflow

The separation between application init and graphics init is relevant for Android apps which will destroy their window when you send it into the background and will recreate it when it is selected again. This means that all GPU content will be lost then and must be restored.

Your application state will not be destroyed, so the rendering can render the same data as before.

Architecture

zero-graphics follows a somewhat unusual architecture for Zig applications. Your applications is a package that will be consumed by a zero-graphics host. This host is implementing the "main loop" and will invoke both update and render periodically. It will also initialize and open the window and pump events.

This design allows zero-graphics to run on several different platforms, including most desktop PCs, Android and even web browsers via WebAssembly.

You can check out the Sdk.zig file to find out how a application is built.

More Repositories

1

kristall

Graphical small-internet client for windows, linux, MacOS X and BSDs. Supports gemini, http, https, gopher, finger.
C++
653
star
2

zig-network

A smallest-common-subset of socket functions for crossplatform networking, TCP & UDP
Zig
271
star
3

ZigAndroidTemplate

This repository contains a example on how to create a minimal Android app in Zig.
Zig
202
star
4

SDL.zig

A shallow wrapper around SDL that provides object API and error handling
C
188
star
5

VersaTile

A simple 3D model editor based on simple quads and a sprite set.
C
160
star
6

LoLa

LoLa is a small programming language meant to be embedded into games.
Zig
150
star
7

zig-args

Simple-to-use argument parser with struct-based config
Zig
119
star
8

zig-qoi

Quite OK Image format encoder/decoder written in Zig
Zig
109
star
9

zig-opengl

OpenGL binding generator based on the opengl registry
C#
62
star
10

Ziguana-Game-System

A retro-style gaming console running on bare x86 metal written in Zig
Zig
47
star
11

parser-toolkit

A toolkit that makes it easier to write recursive-descent parsers in Zig.
Zig
45
star
12

TinyVG

A new format for vector graphics: Tiny vector graphics
Zig
36
star
13

TextEditor

A backbone for text editors. No rendering, no input, but everything else.
Zig
32
star
14

zig-serve

Server implementations for several protocols in Zig. Includes http(s), gemini and gopher
Zig
30
star
15

zig-bearssl

A BearSSL binding for Zig
Zig
27
star
16

livedecode

A super hacky tool to decode unknown binary formats
Zig
26
star
17

any-pointer

A type erasure library for Zig that is meant to be eventually upstreamed to std
Zig
25
star
18

ZTT

Precompiled Zig text template engine
Zig
20
star
19

spu-mark-ii

CPU and home computer project
VHDL
17
star
20

zig-gamedev-lib

xq's Zig Game Development Library
Zig
16
star
21

SoftRenderLib

A collection of software rendering routines
Zig
16
star
22

BrokenRemote

A remote debugging tool for The Binding of Isaac: Afterbirth+
C++
14
star
23

zig-mqtt

A build package for mqtt-c.
Zig
14
star
24

gurl

A curl-like cli application to interact with Gemini sites.
Zig
14
star
25

ftz

A simple cross-platform file transfer utility
Zig
14
star
26

zig-uri

A small URI parser that parses URIs after RFC3986
Zig
12
star
27

makeshift

A dead-simple programming language
Zig
11
star
28

zig-gemtext

A zig library to manipulate gemini text files
Zig
10
star
29

SDL.zig-Example

A small usage example on how to build and use SDL.zig
Zig
10
star
30

waveform

Generates nice Unicode rendered waveforms.
Zig
9
star
31

OpenWorld.Engine

A C# game engine based on OpenGL and OpenTK.
C#
9
star
32

zig-tracer

A small raytracer written in zig.
Zig
9
star
33

WaveFunctionCollapse

A just-for-fun implementation of 2D wave function collapse
Zig
9
star
34

SLF

The Simple Linking Format
Zig
8
star
35

zig-assimp

Open Asset Importer Library built with Zig
C
8
star
36

OpenCL

An open source OpenCL wrapper written in C#. Usable with all .NET versions since 2.0.
C#
7
star
37

ZigPaint

A simple paint application written in Zig. Used to create an OpenGL loader/wrapper and a minimal UI system.
Zig
7
star
38

zyclone

A game engine modelled after the Acknex A8 engine which is used for Gamestudio A8.
Zig
7
star
39

lua

Fork of Lua with support for build.zig
C
6
star
40

zig-build-chapter-2

Files for the zig build explained series
C
6
star
41

TIS-100

A real word implementation of the fantastic TIS-100 CPU by Zachtronics.
VHDL
5
star
42

Crayos

Global Game Jam 2024 Game
Go
5
star
43

acknext

A game engine prototype loosely inspired on the Acknex A8 engine.
Logos
4
star
44

SQEditor

ShadeQ Level Editor for Lite-C
C
4
star
45

turtlefont

A small vector graphics font file format with an example font.
Zig
4
star
46

cg-workbench

Live shader and graphics coding tool
C
4
star
47

zig-sg4f-playground

A playground to try out different stuff with a propietary LPC1786 hardware
Zig
4
star
48

zig-ihex

An intel hex loader written in Zig
Zig
3
star
49

ESOPUNKS

Implementation of the EXA programming language by Zachtronics
Zig
3
star
50

SmallscaleCI

A very tiny CI implementation for self-hosted runners
Shell
3
star
51

TUST

Scripting Library and Game Templates for Gamestudio A8
C
3
star
52

PandorOS

Another attempt to create a small operating system. This time, more features, less fancy code.
C
3
star
53

asciitable

A very basic tool that just prints the ascii table
Zig
3
star
54

AckNET

A .NET wrapper for the Acknex Engine.
C#
3
star
55

LoLa-csharp

Logic Language, a small embeddable scripting language meant for user-based script input in games
C#
3
star
56

ashet.computer

A self-made computer platform
Lua
2
star
57

zig-kms-dri

Experiments with KMS and DRI. Who needs X11/Wayland anyways?!
Zig
2
star
58

Retro-FPS

Oldschoolish first person shooter.
C
2
star
59

zig-ode

Zig ODE sdk
Zig
2
star
60

cbm-tools

A small collection of CBM computer related tools
Zig
2
star
61

pkg

Project and library package manager. Similar to linux package managers but for libraries and project templates.
C#
2
star
62

maps

Multiple Audio Playback Streams - A basic audio mixing library
Zig
2
star
63

psi

A work-in-progress programming language, focused on a kind of crazy, but "well" considered concept...
C#
2
star
64

trainOS

An operating system with everything built custom.
Makefile
2
star
65

WMB

Gamestudio WMB level loader in C++17
C++
2
star
66

zig-mbedtls

A mbedtls build wrapper for Zig build
C
2
star
67

I2P.Sam

C# Interface to the I2P SAM protocol.
C#
2
star
68

Uml2Cpp

Write your own classes with an easy to use modeling language and convert your code to C++. The generated source is prepared for the use with Qt and an example file explains how to use the script.
Lua
2
star
69

ShaderCore

ShaderCore is a shader library for OpenTK and OpenGL 4.0 or larger. It provides single shader files that have conditional compilation, include files, default shader and a shader class system. This provides flexible shader code with much lesser redundtant code to be written.
C#
2
star
70

weekend-raytracer

Just a tiny raytracer in several languages
C++
1
star
71

hyperdoc

A hyperlinked rich text format
Zig
1
star
72

depmake

Simple build system made for trainOS
C#
1
star
73

lola-vscode

LoLa extension for VSCode
1
star
74

SDL3-Api-Generator-Example

C
1
star
75

PeopleDoOpenGL

Made at Nordlicht 2018, teaching people OpenGL
C
1
star
76

ker

A really small C++ library that provides some basic collections and value types.
C++
1
star
77

ecp5-quickstart

A blinky template for a full ECP5 verilog workflow including simulation, synthesis and programming
Verilog
1
star
78

MidiV

A midi visualization tool
C++
1
star
79

fraxinus

Small simple terminal emulation library
Zig
1
star
80

TerraForm

A feature based terrain editor
C++
1
star
81

VoxelizedRenderer

Simple uniform grid voxel renderer with OpenCL, written in C#.
C#
1
star
82

minitest

A minimal C++ testing framework in 101 LOC
C++
1
star
83

ggj-2021

Untitled Game for Global Game Jam
Lua
1
star
84

gemini-web-bridge

Serving simple web files with support for gemini translation
Lua
1
star
85

zfx-logbot

IRC LogBot made for #zfx, #lost on irc.euirc.net
Lua
1
star
86

DasOS

DasOS is a research project which contains prototypes for different parts regarding OS development like kernels, virtual machines, file formats and systems.
C
1
star
87

KernelTemplate

A pretty primitive kernel base with physical and virtual memory management and a console.
C
1
star
88

bullshit-bingo

BULLSHIT!
Lua
1
star
89

avr-tutorial

Contains some basic examples on how to set up an AVR project
TeX
1
star
90

navmesh

A navmesh implementation in zig
Zig
1
star
91

CodersNotepad

Spiritual clone of ProgrammersNotepad 2 made with Qt.
C++
1
star
92

NextMMO

An RPGMaker styled multiplayer game focused on, well, nothing special.
JavaScript
1
star
93

BlocksWorld

BlocksWorld is an attempt to create a small game that provides a creativity environment where players can build their own (small) worlds.
C#
1
star
94

DbusAvrLink

A dbus (TI calculator protocol) implementiation for AVRs.
Assembly
1
star
95

Sharpsole

C# goes scripting! A C# console compile-and-execute tool. Compiles one or more files into a in-memory assembly and runs it immediately.
C#
1
star
96

libgamestudio

A library that decodes file formats used by the Gamestudio/Acknex engine
Zig
1
star
97

tools.mq32.de

A collection of small, web-based tools
HTML
1
star
98

Lylios

A small pathtracer, nothing special really
C++
1
star
99

link.zig-concept-art

A concept for a replacement for linker scripts
Zig
1
star
100

LOST

LOST Programming Language
1
star