forked from edwardsjohnmartin/MagPhyx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsquare.js
55 lines (43 loc) · 1.45 KB
/
square.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
var Square = function() {
// 2 3
// *---------*
// | |
// | |
// | |
// *---------*
// 0 1
var vertices = [
vec4(-0.5, -0.5, 0.0, 1.0),
vec4( 0.5, -0.5, 0.0, 1.0),
vec4(-0.5, 0.5, 0.0, 1.0),
vec4( 0.5, 0.5, 0.0, 1.0),
];
this.numVertices = vertices.length;
var vertexColors = [
vec4(1.0, 1.0, 1.0, 1.0), // white
vec4(1.0, 0.0, 0.0, 1.0), // red
vec4(0.0, 1.0, 0.0, 1.0), // green
vec4(0.0, 0.0, 1.0, 1.0), // blue
];
var texCoords = [
vec2(0, 0),
vec2(1, 0),
vec2(0, 1),
vec2(1, 1),
];
this.vBuffer = gl.createBuffer();
gl.bindBuffer(gl.ARRAY_BUFFER, this.vBuffer);
gl.bufferData(gl.ARRAY_BUFFER, flatten(vertices), gl.STATIC_DRAW);
// gl.vertexAttribPointer(program.vertexLoc, 4, gl.FLOAT, false, 0, 0);
// gl.enableVertexAttribArray(program.vertexLoc);
this.cBuffer = gl.createBuffer();
gl.bindBuffer(gl.ARRAY_BUFFER, this.cBuffer);
gl.bufferData(gl.ARRAY_BUFFER, flatten(vertexColors), gl.STATIC_DRAW);
// gl.vertexAttribPointer(program.colorLoc, 4, gl.FLOAT, false, 0, 0);
// gl.enableVertexAttribArray(program.colorLoc);
this.tBuffer = gl.createBuffer();
gl.bindBuffer(gl.ARRAY_BUFFER, this.tBuffer);
gl.bufferData(gl.ARRAY_BUFFER, flatten(texCoords), gl.STATIC_DRAW);
// gl.vertexAttribPointer(program.texCoordLoc, 2, gl.FLOAT, false, 0, 0);
// gl.enableVertexAttribArray(program.texCoordLoc);
}