0.1.2 • Published 11 months ago

rapid-render v0.1.2

Weekly downloads
-
License
-
Repository
-
Last release
11 months ago

🚀 Rapid.js

A highly efficient and lightweight WebGL renderer

API Docs

stress test demo ( source code )

render demo ( source code )

custom shader demo ( source code )

mask demo ( source code )

Features

  • Fast Rendering: Render 10,000 sprites at 60fps
  • Multi-Texture Support: Batch rendering using GPU's maximum texture units
  • Graphics Drawing
  • Matrix Stack
  • Text Rendering
  • Line Drawing
  • Custom Shaders
  • Texture Clipping
  • Mask

Install

npm i rapid-render

Or use unpkg

<script src="https://unpkg.com/rapid-render/dist/rapid.umd.cjs"></script>

Import

import { Rapid } from "rapid-render"

Useage

let rapid = new Rapid({
    canvas: document.getElementById("game"),
    backgroundColor: Color.fromHex("FFFFFF")
});

// Create texture
const cat = await rapid.textures.textureFromUrl("./cat.png");
//                      R   G   B   A
const color = new Color(255, 255, 255, 255); // Or use Color.fromHex

// Call before rendering
rapid.startRender();

// Render here...

// Call after rendering
rapid.endRender();

// Set canvas size
rapid.resize(100, 100);

Render

const text = rapid.textures.createText({ text: "Hello!", fontSize: 30 })

rapid.save() // Save state
rapid.matrixStack.translate(0,0)
rapid.matrixStack.scale(1)
rapid.matrixStack.rotate(0)

// Render Sprit
rapid.renderSprite(cat, 0, 0, color) // or rapid.renderSprite(cat, 0, 0, { color })

// Rendr Graphic
const path = Vec2.FormArray([[0, 0], [100, 0], [100, 100]])
rapid.renderGraphic(0,0,{points:path, color:green})
// or
// rapid.startGraphicDraw()
// rapid.addGraphicVertex(0, 0, color)
// rapid.endGraphicDraw()

// Render Text
rapid.renderSprite(text, 200, 0)
text.setText("time:" + Math.round(time))

rapid.restore() // back to the previous saved state

Custom Shader

View demo and watch detailed shader code custom shader demo ( source code )

const vertexShaderSource = `...`
const fragmentShaderSource = `...`

const customShader = new GLShader(rapid, vertexShaderSource, fragmentShaderSource)
rapid.startRender()

rapid.renderSprite(plane, 100, 100, {
    shader: customShader, // shader
    uniforms: {
        // Set custom uniform (You can set mat3, vec2, and so on here)
        uCustomUniform: Number(costumUniformValue)
        //  uVec2Uniform: [0,2] // recognized as vec2
        //  uMat3Uniform: [
        //     [0,0,0],
        //     [0,0,0],
        //     [0,0,0],
        //  ]
        // recognized as mat3
    }
});

rapid.endRender()

Screen Shot

screen

0.1.0

11 months ago

0.1.2

11 months ago

0.1.1

11 months ago

0.0.9

11 months ago

0.0.8

11 months ago

0.0.5

11 months ago

0.0.7

11 months ago

0.0.6

11 months ago

0.0.3

1 year ago

0.0.2

1 year ago

0.0.4

1 year ago

0.0.1

1 year ago