• Stars
    star
    1,540
  • Rank 30,382 (Top 0.6 %)
  • Language
    Rust
  • License
    Apache License 2.0
  • Created almost 5 years ago
  • Updated about 2 months ago

Reviews

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

Repository Details

Cross platform rendering in Rust

Miniquad

Github Actions Docs Crates.io version Discord chat Matrix

Miniquad is a manifestation of a dream in a world where we do not need a deep dependencies tree and thousands lines of code to draw things with a computer.

Miniquad aims to provide a graphics abstraction that works the same way on any platform with a GPU, being as light weight as possible while covering as many machines as possible.

Supported Platforms

  • Windows, OpenGL 3, OpenGL 2.2;
  • Linux, OpenGL 2.2, OpenGL 3, GLES 2, GLES 3;
  • macOS, OpenGL 3, Metal;
  • iOS, GLES 2, GLES 3, Metal;
  • WASM, WebGL 1 - tested on iOS Safari, Firefox, Chrome;
  • Android, GLES 2, GLES 3.

Examples

Imgur

examples/quad.rs: web demo
examples/offscreen.rs: web demo

PonasKovas/miniquad-mandelbrot: web demo

Building examples

Linux

cargo run --example quad

On NixOS Linux you can use shell.nix to start a development environment where Miniquad can be built and run.

Windows

# both MSVC and GNU target is supported:
rustup target add x86_64-pc-windows-msvc
# or
rustup target add x86_64-pc-windows-gnu

cargo run --example quad

WASM

rustup target add wasm32-unknown-unknown
cargo build --example quad --target wasm32-unknown-unknown

And then use the following .html to load .wasm:

index.html
<html lang="en">

<head>
    <meta charset="utf-8">
    <title>TITLE</title>
    <style>
        html,
        body,
        canvas {
            margin: 0px;
            padding: 0px;
            width: 100%;
            height: 100%;
            overflow: hidden;
            position: absolute;
            background: black;
            z-index: 0;
        }
    </style>
</head>

<body>
    <canvas id="glcanvas" tabindex='1'></canvas>
    <!-- Minified and statically hosted version of https://github.com/not-fl3/miniquad/blob/master/native/sapp-wasm/js/gl.js -->
    <script src="https://not-fl3.github.io/miniquad-samples/gl.js"></script>
    <script>load("quad.wasm");</script> <!-- Your compiled wasm file -->
</body>

</html>

One of the ways to server static .wasm and .html:

cargo install basic-http-server
basic-http-server .

Android

Recommended way to build for android is using Docker.
miniquad uses slightly modifed version of cargo-apk

docker run --rm -v $(pwd)":/root/src" -w /root/src notfl3/cargo-apk cargo quad-apk build --example quad

APK file will be in target/android-artifacts/(debug|release)/apk

With "log-impl" enabled all log calls will be forwarded to adb console. No code modifications for Android required, everything should just works.

iOS

To run on the simulator:

mkdir MyGame.app
cargo build --target x86_64-apple-ios --release
cp target/release/mygame MyGame.app
# only if the game have any assets
cp -r assets MyGame.app
cat > MyGame.app/Info.plist << EOF
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleExecutable</key>
<string>mygame</string>
<key>CFBundleIdentifier</key>
<string>com.mygame</string>
<key>CFBundleName</key>
<string>mygame</string>
<key>CFBundleVersion</key>
<string>1</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
</dict>
</plist>
EOF

xcrun simctl install booted MyGame.app/
xcrun simctl launch booted com.mygame

For details and instructions on provisioning for real iphone, check https://macroquad.rs/articles/ios/

Cross Compilation

# windows target from linux host:
# this is how windows builds are tested from linux machine:
rustup target add x86_64-pc-windows-gnu
cargo run --example quad --target x86_64-pc-windows-gnu

Goals

  • Fast compilation time. Right now it is ~5s from "cargo clean" for both desktop and web.

  • Cross platform. Amount of platform specific user code required should be kept as little as possible.

  • Low-end devices support.

  • Hackability. Working on your own game, highly probable some hardware incompability will be found. Working around that kind of bugs should be easy, implementation details should not be hidden under layers of abstraction.

  • Forkability. Each platform implementation is, usually, just one pure Rust file. And this file is very copy-paste friendly - it doesnt use any miniquad specific abstractions. It is very easy to just copy some part of miniquad's platform implementation and use it standalone.

Non-goals

  • Ultimate type safety. Library should be entirely safe in Rust's definition of safe - no UB or memory unsafety. But correct GPU state is not type guaranteed. Feel free to provide safety abstraction in the user code then!

  • High-end API, like Vulkan/DirectX 12. Take a look on gfx-rs or vulkano instead!

Platinum sponsors

Miniquad is supported by:

More Repositories

1

macroquad

Cross-platform game engine in Rust.
Rust
3,266
star
2

nanoserde

Serialisation library with zero dependencies
Rust
687
star
3

quad-snd

Cross-platform audio for Rust
Rust
110
star
4

egui-miniquad

Rust
78
star
5

tinyecs

[DEPRECATED] Rusty entity-component-system
Rust
62
star
6

bulletrs

Bullet Physics wrapper for the Rust language.
Rust
49
star
7

megaui

DEPRECATED in favor of macroquad::ui
Rust
38
star
8

rie

REPL-like interactive code editor
Rust
29
star
9

gameoff-2019

Rust
15
star
10

tinyprof

Simple frame profiler
Rust
14
star
11

quad-rand

Rust
13
star
12

quad-net

Rust
13
star
13

awesomium-rs

WIP rust bindings for Awesomium browser
Rust
11
star
14

quad-gl

Rust
11
star
15

nanoshredder

Rust
11
star
16

isalive

Project pulse monitor with Rust backend and Elm frontend
Elm
10
star
17

nanogltf

Rust
8
star
18

megaui-macroquad

DEPRECATED in favor of macroquad::ui
Rust
7
star
19

particles-editor

Rust
7
star
20

quad-android-playground

Rust
7
star
21

platformer-book

6
star
22

miniquad_text_rusttype

Rust
6
star
23

nanoserde-bench

Rust
5
star
24

ld44

Rust
5
star
25

miniquad-js-interop-demo

Rust
5
star
26

ld46

Rust
5
star
27

imgui-miniquad-render

Rust
5
star
28

sapp-jsutils

Rust
5
star
29

rust-swag

5
star
30

macroquad-website

Automatically generated site with all macroquad examples
HTML
5
star
31

miniquad-samples

JavaScript
4
star
32

cargo-webquad

Rust
4
star
33

sloop

Rust
4
star
34

hale-sample

Rust
2
star
35

rays

Ray tracing
Rust
2
star
36

macroquad-sample-project

Rust
2
star
37

sloop-example-projects

Rust
2
star
38

megaui_test

Rust
1
star
39

coldspace

Play with static-topology frp.
Haskell
1
star
40

example-android-fileopen

Java
1
star
41

tinypreprocessor

Rust
1
star
42

nanoimage

Rust
1
star
43

tinyprof-imgui

Rust
1
star
44

incremental_bug

Rust
1
star
45

AllocaFail

Rust
1
star
46

pong

The most correct pong ever
Idris
1
star
47

tinyprof-termion

Rust
1
star
48

not-fl3.github.io

1
star
49

squarebug

Rust
1
star
50

Notebot

Haskell
1
star
51

example-android-bluetooth

Rust
1
star
52

quad-androidx

Rust
1
star
53

quad-bt

1
star
54

derivebug

Rust
1
star
55

teapot

temporary repo for emscripten tests
JavaScript
1
star
56

test-sys

Rust
1
star
57

advent-of-code-2018

Haskell
1
star
58

acontrol

Web time tracking tool.
Haskell
1
star