README.md 2.37 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
It lets you implement complex effects over images and components, in the Virtual DOM descriptive paradigm.
6

Earle Castledine's avatar
Earle Castledine committed
7
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!
8

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

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

Gaëtan Renaudeau's avatar
Gaëtan Renaudeau committed
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 42 43
### 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)

44 45
## Focus

Earle Castledine's avatar
Earle Castledine committed
46
- **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.
47
- **Performance**
Earle Castledine's avatar
Earle Castledine committed
48
- **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
49
- **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
50
- **Support for images** as a texture uniform.
51 52
- **Support for UIView rasterisation** as a texture uniform.

Gaëtan Renaudeau's avatar
Gaëtan Renaudeau committed
53 54
## Installation

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

57
**Install the dependency from your React Native application:**
Gaëtan Renaudeau's avatar
Gaëtan Renaudeau committed
58 59 60 61 62

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

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

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


68
## Influence / Credits
Gaëtan Renaudeau's avatar
Gaëtan Renaudeau committed
69 70 71 72

- [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)
73 74

## Documentation
Gaëtan Renaudeau's avatar
Gaëtan Renaudeau committed
75 76

![Index](./docs)