-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathskybox.js
More file actions
80 lines (67 loc) · 2.66 KB
/
skybox.js
File metadata and controls
80 lines (67 loc) · 2.66 KB
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
class SkyBox {
constructor() {
// Coordinates for the skybox
this.skyBoxvBuffer = [
-1.0, 1.0, -1.0,
-1.0, -1.0, -1.0,
1.0, -1.0, -1.0,
1.0, -1.0, -1.0,
1.0, 1.0, -1.0,
-1.0, 1.0, -1.0,
-1.0, -1.0, 1.0,
-1.0, -1.0, -1.0,
-1.0, 1.0, -1.0,
-1.0, 1.0, -1.0,
-1.0, 1.0, 1.0,
-1.0, -1.0, 1.0,
1.0, -1.0, -1.0,
1.0, -1.0, 1.0,
1.0, 1.0, 1.0,
1.0, 1.0, 1.0,
1.0, 1.0, -1.0,
1.0, -1.0, -1.0,
-1.0, -1.0, 1.0,
-1.0, 1.0, 1.0,
1.0, 1.0, 1.0,
1.0, 1.0, 1.0,
1.0, -1.0, 1.0,
-1.0, -1.0, 1.0,
-1.0, 1.0, -1.0,
1.0, 1.0, -1.0,
1.0, 1.0, 1.0,
1.0, 1.0, 1.0,
-1.0, 1.0, 1.0,
-1.0, 1.0, -1.0,
-1.0, -1.0, -1.0,
-1.0, -1.0, 1.0,
1.0, -1.0, -1.0,
1.0, -1.0, -1.0,
-1.0, -1.0, 1.0,
1.0, -1.0, 1.0
];
}
loadBuffer() {
//Setup skybox
this.SkyBoxVertexPositionBuffer = gl.createBuffer();
gl.bindBuffer(gl.ARRAY_BUFFER, this.SkyBoxVertexPositionBuffer);
gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(this.skyBoxvBuffer), gl.STATIC_DRAW);
this.SkyBoxVertexPositionBuffer.itemSize = 3;
this.SkyBoxVertexPositionBuffer.numberOfItems = 36;
}
drawTriangles() {
// Bind the vertex buffer data
gl.bindBuffer(gl.ARRAY_BUFFER, this.SkyBoxVertexPositionBuffer);
gl.vertexAttribPointer(shaderProgramSkybox.vertexPositionAttribute, this.SkyBoxVertexPositionBuffer.itemSize, gl.FLOAT, false, 0, 0);
//gl.bindBuffer(gl.ARRAY_BUFFER, this.SkyBoxVertexNormalBuffer);
//gl.vertexAttribPointer(shaderProgramSkybox.vertexNormalAttribute, this.SkyBoxVertexNormalBuffer.itemSize, gl.FLOAT, false, 0, 0);
//gl.drawElements(gl.TRIANGLES, this.IndexTriBuffer.numItems, gl.UNSIGNED_INT,0);
// Bind the skybox texture
gl.activeTexture(gl.TEXTURE0);
gl.bindTexture(gl.TEXTURE_CUBE_MAP, cubeMap);
gl.uniform1i(gl.getUniformLocation(shaderProgramSkybox, "uCubeSampler"), 0);
gl.drawArrays(gl.TRIANGLES, 0, this.SkyBoxVertexPositionBuffer.numberOfItems);
}
// Don't need to generate normals for the skybox since only doing basic texture sampling
generateNormals() {
}
}