-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSkybox.java
More file actions
155 lines (115 loc) · 3.93 KB
/
Skybox.java
File metadata and controls
155 lines (115 loc) · 3.93 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
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
package planetsWars;
import javax.media.opengl.GL2;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.File;
import com.jogamp.opengl.util.texture.*;
public class Skybox extends VBOModel {
Material material;
public Skybox(GL2 gl) {
super(gl, 108, 36);
this.useCubemap = true;
try {
//Texture texture = TextureIO.newTexture(new File("Textures/spacebox.jpg"), false);
this.setTexture(cubeMap(gl, new String[]{
"Textures/skybox/1.jpg",
"Textures/skybox/2.jpg",
"Textures/skybox/3.jpg",
"Textures/skybox/4.jpg",
"Textures/skybox/5.jpg",
"Textures/skybox/6.jpg",
}));
} catch (FileNotFoundException e) {
e.printStackTrace();
return;
} catch (Exception e) {
e.printStackTrace();
return;
}
material = new Material();
material.setShininess(new float[] {
1.0f, 1.0f, 1.0f
});
prepare(gl);
}
@Override
public void build() {
for (int i=0; i<vertices.length; i+=3) {
vertices[i] = ((i/3)/4%2)-0.5;
vertices[i+1] = ((i/3)/2%2)-0.5;
vertices[i+2] = ((i/3)%2)-0.5;
}
vertices = new double[] {
-0.5, -0.5, -0.5,
-0.5, -0.5, 0.5,
0.5, -0.5, 0.5,
-0.5, -0.5, -0.5,
0.5, -0.5, 0.5,
0.5, -0.5, -0.5,
-0.5, 0.5, -0.5,
0.5, 0.5, 0.5,
-0.5, 0.5, 0.5,
-.5, .5, -.5,
.5, .5, -.5,
.5, .5, .5,
-.5, .5, .5,
.5, -.5, .5,
-.5, -.5, .5,
-.5, .5, .5,
.5, .5, .5,
.5, -.5, .5,
.5, .5, .5,
.5, -.5, -.5,
.5, -.5, .5,
.5, .5, .5,
.5, .5, -.5,
.5, -.5, -.5,
.5, .5, -.5,
-.5, -.5, -.5,
.5, -.5, -.5,
.5, .5, -.5,
-.5, .5, -.5,
-.5, -.5, -.5,
-.5, .5, -.5,
-.5, -.5, .5,
-.5, -.5, -.5,
-.5, .5, -.5,
-.5, .5, .5,
-.5, -.5, .5,
};
for (int i=0; i<edges.length; i++) {
edges[i] = i;
}
}
@Override
public void display(GL2 gl) {
gl.glDisable(GL2.GL_LIGHTING);
gl.glDisable(GL2.GL_DEPTH_TEST);
gl.glDepthMask(false);
material.displayMaterial(gl);
//gl.glScaled(10.0, 10.0, 10.0);
super.display(gl);
gl.glDepthMask(true);
gl.glEnable(GL2.GL_DEPTH_TEST);
gl.glEnable(GL2.GL_LIGHTING);
}
private Texture cubeMap(GL2 gl, String[] files) throws Exception {
if (files.length != 6)
throw new Exception(
"Nombre d'images insuffisant pour créer la cubeMap");
Texture tex = TextureIO.newTexture(GL2.GL_TEXTURE_CUBE_MAP);
tex.updateImage(gl, TextureIO.newTextureData(gl.getGLProfile(),
new File(files[0]), true, null), GL2.GL_TEXTURE_CUBE_MAP_POSITIVE_X);
tex.updateImage(gl, TextureIO.newTextureData(gl.getGLProfile(),
new File(files[1]), true, null), GL2.GL_TEXTURE_CUBE_MAP_NEGATIVE_X);
tex.updateImage(gl, TextureIO.newTextureData(gl.getGLProfile(),
new File(files[2]), true, null), GL2.GL_TEXTURE_CUBE_MAP_POSITIVE_Y);
tex.updateImage(gl, TextureIO.newTextureData(gl.getGLProfile(),
new File(files[3]), true, null), GL2.GL_TEXTURE_CUBE_MAP_NEGATIVE_Y);
tex.updateImage(gl, TextureIO.newTextureData(gl.getGLProfile(),
new File(files[4]), true, null), GL2.GL_TEXTURE_CUBE_MAP_POSITIVE_Z);
tex.updateImage(gl, TextureIO.newTextureData(gl.getGLProfile(),
new File(files[5]), true, null), GL2.GL_TEXTURE_CUBE_MAP_NEGATIVE_Z);
return tex;
}
}