GithubHelp home page GithubHelp logo

tversteeg / miniquad Goto Github PK

View Code? Open in Web Editor NEW

This project forked from not-fl3/miniquad

0.0 2.0 0.0 2.94 MB

Cross platform rendering for Rust

License: Apache License 2.0

JavaScript 0.75% Rust 99.24% C 0.01% Objective-C 0.01%

miniquad's Introduction

Miniquad

Github Actions Crates.io version

Miniquad is safe and cross-platform rendering library focused on portability and low-end platforms support

API is highly inspired by sokol-gfx (sokol overview, 2019 update). Implementation influenced by crayon.

For context management and input on Windows/Linux(and potentially mobiles) "sokol-app" was used. And no external dependencies for WASM.

For higher level API take a look on:

good-web-game: implementation of some ggez subset on top of miniquad, made as compatibility layer to run ggez games on wasm

macroquad: raylib-like library on top of miniquad. 100loc arkanoid with macroquad

Supported platforms

  • Windows, OpenGl 3
  • Linux, OpenGl 3
  • macOS, OpenGL 3
  • WASM, WebGl1 - tested on ios safari, ff, chrome
  • Android, GLES3

Not supported, but desirable platforms

  • Android, GLES2 - work in progress.
  • Metal. For both MacOs and IOS metal rendering backend next to opengl one is highly desirable. But I just dont have any MacOs capable hardware to start working on it :/

Examples

Imgur

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

PonasKovas/miniquad-mandelbrot: web demo

Worth to mention zemeroth port and astroblasto, built with miniquad-powered good-web-game

Building examples

linux

# ubuntu system dependencies
apt install libx11-dev libxi-dev libgl1-mesa-dev

cargo run --example quad

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
<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 use slightly modifed version of cargo-apk

docker run --rm -v $(pwd)":/root/src" -w /root/src notfl3/cargo-apk cargo 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.

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.

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!

  • sokol-gfx api compatibility. While sokol is absolutely great as an API design foundation, just reimplementing sokol in rust is not a goal. The idea is to learn from sokol, but make a library in a rust way when it is possible.

miniquad's People

Contributors

not-fl3 avatar nokola avatar koalefant avatar tversteeg avatar canadaduane avatar akholetsky avatar ponaskovas avatar optozorax avatar vrixyz avatar pum-purum-pum-pum avatar akxcv avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.