mirror of
https://github.com/gre/gl-react.git
synced 2026-01-18 16:16:59 +00:00
gl-react
WebGL bindings for react to implement complex graphics and image effects, in VDOM descriptive paradigm.
HelloGL Gist
const React = require("react");
const GL = require("gl-react");
const shaders = GL.Shaders.create({
helloGL: {
frag: `
precision highp float;
varying vec2 uv;
void main () {
gl_FragColor = vec4(uv.x, uv.y, 0.5, 1.0);
}`
}
});
class HelloGL extends React.Component {
render () {
const { width, height } = this.props;
return <GL.View
shader={shaders.helloGL}
width={width}
height={height}
/>;
}
}
Installation
npm i --save gl-react
Docs and difference with gl-react-native
gl-react adopts the same API of gl-react-native, therefore you can read
gl-react-native documentation.
However, here are the few differences:
Texture format
Instead of adopting React Native {uri: "http://..."} format, you can simply set a "http:..." as a texture uniform, the {uri} format is still supported for compatibility purpose.
GL.Target support
GL.Target have a more limited support because the web does not allow to draw DOM element in Canvas.
Only one child is supported per GL.Target and it MUST be either: an <img />, a <video /> or a <canvas />.
You might want to take a look at react-canvas for drawing content.
Advanced Effects demo
Languages
JavaScript
96.3%
CSS
2.4%
GLSL
0.8%
Shell
0.3%
HTML
0.2%

