|
@@ -7,71 +7,22 @@ import org.lwjgl.opengl.GL30;
|
|
|
import org.lwjgl.util.vector.Matrix4f;
|
|
|
|
|
|
import eu.tankernn.gameEngine.entities.Camera;
|
|
|
-import eu.tankernn.gameEngine.models.RawModel;
|
|
|
import eu.tankernn.gameEngine.renderEngine.DisplayManager;
|
|
|
import eu.tankernn.gameEngine.renderEngine.Loader;
|
|
|
|
|
|
public class SkyboxRenderer {
|
|
|
- private static final float SIZE = 500f;
|
|
|
private static final int DAY_LENGTH = 24000;
|
|
|
|
|
|
- private static final float[] VERTICES = {
|
|
|
- -SIZE, SIZE, -SIZE,
|
|
|
- -SIZE, -SIZE, -SIZE,
|
|
|
- SIZE, -SIZE, -SIZE,
|
|
|
- SIZE, -SIZE, -SIZE,
|
|
|
- SIZE, SIZE, -SIZE,
|
|
|
- -SIZE, SIZE, -SIZE,
|
|
|
-
|
|
|
- -SIZE, -SIZE, SIZE,
|
|
|
- -SIZE, -SIZE, -SIZE,
|
|
|
- -SIZE, SIZE, -SIZE,
|
|
|
- -SIZE, SIZE, -SIZE,
|
|
|
- -SIZE, SIZE, SIZE,
|
|
|
- -SIZE, -SIZE, SIZE,
|
|
|
-
|
|
|
- SIZE, -SIZE, -SIZE,
|
|
|
- SIZE, -SIZE, SIZE,
|
|
|
- SIZE, SIZE, SIZE,
|
|
|
- SIZE, SIZE, SIZE,
|
|
|
- SIZE, SIZE, -SIZE,
|
|
|
- SIZE, -SIZE, -SIZE,
|
|
|
-
|
|
|
- -SIZE, -SIZE, SIZE,
|
|
|
- -SIZE, SIZE, SIZE,
|
|
|
- SIZE, SIZE, SIZE,
|
|
|
- SIZE, SIZE, SIZE,
|
|
|
- SIZE, -SIZE, SIZE,
|
|
|
- -SIZE, -SIZE, SIZE,
|
|
|
-
|
|
|
- -SIZE, SIZE, -SIZE,
|
|
|
- SIZE, SIZE, -SIZE,
|
|
|
- SIZE, SIZE, SIZE,
|
|
|
- SIZE, SIZE, SIZE,
|
|
|
- -SIZE, SIZE, SIZE,
|
|
|
- -SIZE, SIZE, -SIZE,
|
|
|
-
|
|
|
- -SIZE, -SIZE, -SIZE,
|
|
|
- -SIZE, -SIZE, SIZE,
|
|
|
- SIZE, -SIZE, -SIZE,
|
|
|
- SIZE, -SIZE, -SIZE,
|
|
|
- -SIZE, -SIZE, SIZE,
|
|
|
- SIZE, -SIZE, SIZE
|
|
|
- };
|
|
|
+ private static final String[] TEXTURE_FILES = {"alps_rt", "alps_lf", "alps_up", "alps_dn", "alps_bk", "alps_ft"};
|
|
|
+ private static final String[] NIGHT_TEXTURE_FILES = {"midnight_rt", "midnight_lf", "midnight_up", "midnight_dn", "midnight_bk", "midnight_ft"};
|
|
|
|
|
|
- private static String[] TEXTURE_FILES = {"alps_rt", "alps_lf", "alps_up", "alps_dn", "alps_bk", "alps_ft"};
|
|
|
- private static String[] NIGHT_TEXTURE_FILES = {"midnight_rt", "midnight_lf", "midnight_up", "midnight_dn", "midnight_bk", "midnight_ft"};
|
|
|
-
|
|
|
- private RawModel cube;
|
|
|
- private int texture;
|
|
|
- private int nightTexture;
|
|
|
+ private CubeMap dayCube, nightCube;
|
|
|
private SkyboxShader shader;
|
|
|
private float time = 0;
|
|
|
|
|
|
public SkyboxRenderer(Loader loader, Matrix4f projectionmatrix) {
|
|
|
- cube = loader.loadToVAO(VERTICES, 3);
|
|
|
- texture = loader.loadCubeMap(TEXTURE_FILES, "skybox/");
|
|
|
- nightTexture = loader.loadCubeMap(NIGHT_TEXTURE_FILES, "skybox/");
|
|
|
+ dayCube = new CubeMap(TEXTURE_FILES, "skybox/", loader);
|
|
|
+ nightCube = new CubeMap(NIGHT_TEXTURE_FILES, "skybox/", loader);
|
|
|
shader = new SkyboxShader();
|
|
|
shader.start();
|
|
|
shader.connectTextureUnits();
|
|
@@ -83,10 +34,10 @@ public class SkyboxRenderer {
|
|
|
shader.start();
|
|
|
shader.loadViewMatrix(camera);
|
|
|
shader.loadFogColor(r, g, b);
|
|
|
- GL30.glBindVertexArray(cube.getVaoID());
|
|
|
+ GL30.glBindVertexArray(dayCube.getCube().getVaoID());
|
|
|
GL20.glEnableVertexAttribArray(0);
|
|
|
bindTextures();
|
|
|
- GL11.glDrawArrays(GL11.GL_TRIANGLES, 0, cube.getVertexCount());
|
|
|
+ GL11.glDrawArrays(GL11.GL_TRIANGLES, 0, dayCube.getCube().getVertexCount());
|
|
|
GL20.glDisableVertexAttribArray(0);
|
|
|
GL30.glBindVertexArray(0);
|
|
|
shader.stop();
|
|
@@ -104,20 +55,20 @@ public class SkyboxRenderer {
|
|
|
int texture2;
|
|
|
float blendFactor;
|
|
|
if (time >= 0 && time < morning) {
|
|
|
- texture1 = nightTexture;
|
|
|
- texture2 = nightTexture;
|
|
|
+ texture1 = nightCube.getTexture();
|
|
|
+ texture2 = nightCube.getTexture();
|
|
|
blendFactor = (time - 0) / (morning - 0);
|
|
|
} else if (time >= morning && time < noon) {
|
|
|
- texture1 = nightTexture;
|
|
|
- texture2 = texture;
|
|
|
+ texture1 = nightCube.getTexture();
|
|
|
+ texture2 = dayCube.getTexture();
|
|
|
blendFactor = (time - morning) / (noon - morning);
|
|
|
} else if (time >= noon && time < evening) {
|
|
|
- texture1 = texture;
|
|
|
- texture2 = texture;
|
|
|
+ texture1 = dayCube.getTexture();
|
|
|
+ texture2 = dayCube.getTexture();
|
|
|
blendFactor = (time - noon) / (evening - noon);
|
|
|
} else {
|
|
|
- texture1 = texture;
|
|
|
- texture2 = nightTexture;
|
|
|
+ texture1 = dayCube.getTexture();
|
|
|
+ texture2 = nightCube.getTexture();
|
|
|
blendFactor = (time - evening) / (DAY_LENGTH - evening);
|
|
|
}
|
|
|
|
|
@@ -127,4 +78,8 @@ public class SkyboxRenderer {
|
|
|
GL11.glBindTexture(GL13.GL_TEXTURE_CUBE_MAP, texture2);
|
|
|
shader.loadBlendFactor(blendFactor);
|
|
|
}
|
|
|
+
|
|
|
+ public CubeMap getCubeMap() {
|
|
|
+ return dayCube;
|
|
|
+ }
|
|
|
}
|