-
Notifications
You must be signed in to change notification settings - Fork 1
/
basic.js
58 lines (50 loc) · 1.24 KB
/
basic.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
var createWindow = require('./sys/createWindow');
var Program = require('./glu/Program');
var VertexArray = require('./glu/VertexArray');
var Context = require('./glu/Context');
var ClearCommand = require('./glu/ClearCommand');
var DrawCommand = require('./glu/DrawCommand');
var VERT_SRC = '\
attribute vec2 position; \
void main() { \
gl_Position = vec4(position, 0.0, 1.0); \
} \
';
var FRAG_SRC = '\
void main() { \
gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0); \
} \
';
createWindow({
settings: {
width: 1280,
height: 720
},
init: function() {
var gl = this.gl;
this.context = new Context(gl);
this.quadProgram = new Program(gl, VERT_SRC, FRAG_SRC);
this.quadVA = new VertexArray(gl);
this.quadVA.addAttribute('position', [
-1, 1, 1, 1, 1,-1,
-1, 1, 1,-1, -1,-1
], { size: 2 });
this.clearCmd = new ClearCommand({
color: [0.2, 0.2, 0.2, 1.0],
depth: true
});
this.quadDrawCmd = new DrawCommand({
vertexArray: this.quadVA,
program: this.quadProgram,
renderState: {
depthTest: {
enabled: true
}
}
});
},
draw: function() {
this.clearCmd.execute(this.context);
this.quadDrawCmd.execute(this.context);
}
})