gl-react/Examples/Simple/HelloGL.js
Gaëtan Renaudeau 8271600843 Fixes #19: implement a captureFrame(cb) method on GL.View
Usage:

render() {
  <GL.View ref="view" ... />
}

capture () {
  this.refs.view.captureFrame(data64 => ...);
}
2015-10-01 10:20:35 +02:00

35 lines
801 B
JavaScript

const React = require("react");
const GL = require("gl-react");
const shaders = GL.Shaders.create({
helloGL: {
frag: `
precision highp float;
varying vec2 uv; // This variable vary in all pixel position (normalized from vec2(0.0,0.0) to vec2(1.0,1.0))
void main () { // This function is called FOR EACH PIXEL
gl_FragColor = vec4(uv.x, uv.y, 0.5, 1.0); // red vary over X, green vary over Y, blue is 50%, alpha is 100%.
}
`
}
});
class HelloGL extends GL.Component {
render () {
const { width, height } = this.props;
return <GL.View
shader={shaders.helloGL}
width={width}
height={height}
ref="view"
/>;
}
captureFrame () {
const view = this.refs.view;
return view.captureFrame.apply(view, arguments);
}
}
module.exports = HelloGL;