-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGLTest.js
87 lines (64 loc) · 1.62 KB
/
GLTest.js
1
2
3
4
5
6
7
8
9
10
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import React from 'react';
import {StyleSheet, Text, View} from 'react-native';
import {GLView} from 'expo-gl';
//import {THREE} from 'expo-three';
//import ExpoTHREE from 'expo-three';
const vertSrc = `
void main(void) {
gl_Position = vec4(0.5, 0.0, 0.0, 1.0);
gl_PointSize = 120.0;
}
`;
const fragSrc = `
void main(void) {
gl_FragColor = vec4(0.0,0.0,0.0,1.0);
}
`;
let _initialized = false;
// lol
export default class GLTest extends React.Component {
render() {
return (
<View style={styles.container}>
<GLView
style={{width: 320, height: 320}}
onContextCreate={this._onContextCreate}
/>
</View>
);
}
componentDidMount() {
//THREE.suppressExpoWarnings(true);
}
_onContextCreate = gl => {
if (_initialized) {
return;
}
gl.viewport(0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight);
gl.clearColor(0, 1, 1, 1);
// Compile vertex and fragment shader
const vert = gl.createShader(gl.VERTEX_SHADER);
gl.shaderSource(vert, vertSrc);
gl.compileShader(vert);
const frag = gl.createShader(gl.FRAGMENT_SHADER);
gl.shaderSource(frag, fragSrc);
gl.compileShader(frag);
// Link together into a program
const program = gl.createProgram();
gl.attachShader(program, vert);
gl.attachShader(program, frag);
gl.linkProgram(program);
gl.useProgram(program);
gl.clear(gl.COLOR_BUFFER_BIT);
gl.drawArrays(gl.POINTS, 0, 1);
gl.flush();
gl.endFrameEXP();
_initialized = true;
};
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
},
});