README.md 2.28 KB
Newer Older
1 2
# gl-react-native

Gaëtan Renaudeau's avatar
Gaëtan Renaudeau committed
3
OpenGL bindings for react-native to implement complex effects over images and components, in VDOM descriptive paradigm.
4

Earle Castledine's avatar
Earle Castledine committed
5
More technically, `gl-react-native` allows you to write a [fragment shader](https://www.opengl.org/wiki/Fragment_Shader) that covers a View. The shader can render: generated graphics/demos, effects on top of images, effects over any UI content... anything you can imagine!
6

Gaëtan Renaudeau's avatar
Gaëtan Renaudeau committed
7
**There's also a React version [`gl-react`](http://github.com/ProjectSeptemberInc/gl-react) with the same API.**
8

Gaëtan Renaudeau's avatar
Gaëtan Renaudeau committed
9 10
[![](docs/examples/simple.gif)](./Examples/Simple)[![](docs/examples/advancedeffects.gif)](./Examples/AdvancedEffects)

Gaëtan Renaudeau's avatar
Gaëtan Renaudeau committed
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
### HelloGL Gist

```js
const React = require("react-native");
const GL = require("gl-react-native");

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}
    />;
  }
}
```

![](docs/examples/1.jpg)

42 43
## Focus

Earle Castledine's avatar
Earle Castledine committed
44
- **Virtual DOM and immutable** paradigm: OpenGL is a low level imperative and mutable API. This library takes the best of it and exposes it in an immutable, descriptive way.
45
- **Performance**
Earle Castledine's avatar
Earle Castledine committed
46
- **Developer experience**: the application doesn't crash on bugs - it uses React Native error message to display GLSL errors, with Live Reload support to make experimenting with effects easy.
Earle Castledine's avatar
Earle Castledine committed
47
- **Uniform bindings**: bindings from JavaScript objects to OpenGL GLSL language types (bool, int, float, vec2, vec3, vec4, mat2, mat3, mat4, sampler2D...)
Earle Castledine's avatar
Earle Castledine committed
48
- **Support for images** as a texture uniform.
49 50
- **Support for UIView rasterisation** as a texture uniform.

Gaëtan Renaudeau's avatar
Gaëtan Renaudeau committed
51 52
## Installation

53
a few steps are required to install `gl-react-native`:
Gaëtan Renaudeau's avatar
Gaëtan Renaudeau committed
54

Gaëtan Renaudeau's avatar
typo  
Gaëtan Renaudeau committed
55
**Install the dependency to your React Native application:**
Gaëtan Renaudeau's avatar
Gaëtan Renaudeau committed
56 57 58 59 60

```
npm i --save gl-react-native
```

61
**Configure your React Native Application:**
Gaëtan Renaudeau's avatar
Gaëtan Renaudeau committed
62 63 64 65

![](docs/install-steps.png)


66
## Influence / Credits
Gaëtan Renaudeau's avatar
Gaëtan Renaudeau committed
67 68 69 70

- [stack.gl](http://stack.gl/) approach
- [GLSL.io](http://glsl.io/) and [Diaporama](https://github.com/gre/diaporama)
- Source code of [React Native](https://github.com/facebook/react-native)
71 72

## Documentation
Gaëtan Renaudeau's avatar
Gaëtan Renaudeau committed
73

Gaëtan Renaudeau's avatar
Gaëtan Renaudeau committed
74
...soon... link to gitbooks