forked from nathanctung/MoonRunner
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtexture.js
118 lines (109 loc) · 6.48 KB
/
texture.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
// set up texture variables
function initTextures() {
// Ground Texture
groundTexture = gl.createTexture();
groundTexture.image = new Image();
groundTexture.image.onload = function(){
gl.bindTexture(gl.TEXTURE_2D, groundTexture); // bind texture as current texture to use
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, groundTexture.image); // upload texture image to GPU
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST); // parameters for scaling up
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST); // parameters for scaling down
gl.bindTexture(gl.TEXTURE_2D, null);
}
// groundTexture.image.src = "./Images/moonsurface_4096.png";
groundTexture.image.src = moonImage.src;
// Space Texture
spaceTexture = gl.createTexture();
spaceTexture.image = new Image();
spaceTexture.image.onload = function(){
gl.bindTexture(gl.TEXTURE_2D, spaceTexture); // bind texture as current texture to use
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, spaceTexture.image); // upload texture image to GPU
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST); // parameters for scaling up
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST); // parameters for scaling down
gl.bindTexture(gl.TEXTURE_2D, null);
}
// spaceTexture.image.src = "./Images/space.gif";
spaceTexture.image.src = space.src;
// Planet Texture
planetTexture = gl.createTexture();
planetTexture.image = new Image();
planetTexture.image.onload = function(){
gl.bindTexture(gl.TEXTURE_2D, planetTexture); // bind texture as current texture to use
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, planetTexture.image); // upload texture image to GPU
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST); // parameters for scaling up
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST); // parameters for scaling down
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE); // prevent wrapped s coordinates (repeating)
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE); // prevent wrapped t coordinates
gl.bindTexture(gl.TEXTURE_2D, null);
}
// planetTexture.image.src = "./Images/planet.png";
planetTexture.image.src = planetImage.src;
// Debris Texture
debrisTexture = gl.createTexture();
debrisTexture.image = new Image();
debrisTexture.image.onload = function(){
gl.bindTexture(gl.TEXTURE_2D, debrisTexture); // bind texture as current texture to use
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, debrisTexture.image); // upload texture image to GPU
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST); // parameters for scaling up
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST); // parameters for scaling down
gl.bindTexture(gl.TEXTURE_2D, null);
}
// debrisTexture.image.src = "./Images/asteroid.jpg";
debrisTexture.image.src = asteroidImage.src;
// Heart Texture
heartTexture = gl.createTexture();
heartTexture.image = new Image();
heartTexture.image.onload = function(){
gl.bindTexture(gl.TEXTURE_2D, heartTexture); // bind texture as current texture to use
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, heartTexture.image); // upload texture image to GPU
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST); // parameters for scaling up
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST); // parameters for scaling down
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE); // prevent wrapped s coordinates (repeating)
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE); // prevent wrapped t coordinates
gl.bindTexture(gl.TEXTURE_2D, null);
}
// heartTexture.image.src = "./Images/heart.jpg";
heartTexture.image.src = heartImage.src;
// Health Texture
healthTexture = gl.createTexture();
healthTexture.image = new Image();
healthTexture.image.onload = function(){
gl.bindTexture(gl.TEXTURE_2D, healthTexture); // bind texture as current texture to use
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, healthTexture.image); // upload texture image to GPU
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST); // parameters for scaling up
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST); // parameters for scaling down
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE); // prevent wrapped s coordinates (repeating)
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE); // prevent wrapped t coordinates
gl.bindTexture(gl.TEXTURE_2D, null);
}
// healthTexture.image.src = "./Images/health.png";
healthTexture.image.src = healthImage.src;
// Flag Texture
flagTexture = gl.createTexture();
flagTexture.image = new Image();
flagTexture.image.onload = function(){
gl.bindTexture(gl.TEXTURE_2D, flagTexture); // bind texture as current texture to use
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, flagTexture.image); // upload texture image to GPU
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST); // parameters for scaling up
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST); // parameters for scaling down
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE); // prevent wrapped s coordinates (repeating)
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE); // prevent wrapped t coordinates
gl.bindTexture(gl.TEXTURE_2D, null);
}
// flagTexture.image.src = "./Images/flag_inverse.png";
flagTexture.image.src = flagImage.src;
// Slow Texture
slowTexture = gl.createTexture();
slowTexture.image = new Image();
slowTexture.image.onload = function(){
gl.bindTexture(gl.TEXTURE_2D, slowTexture); // bind texture as current texture to use
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, slowTexture.image); // upload texture image to GPU
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST); // parameters for scaling up
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST); // parameters for scaling down
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE); // prevent wrapped s coordinates (repeating)
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE); // prevent wrapped t coordinates
gl.bindTexture(gl.TEXTURE_2D, null);
}
// slowTexture.image.src = "./Images/slow_inverse.png";
slowTexture.image.src = slowImage.src;
}