/* Copyright 2010 Christian Matt
*
* This file is part of PonkOut.
*
* PonkOut is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* PonkOut is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with PonkOut. If not, see <http://www.gnu.org/licenses/>.
*/
package ponkOut.graphics;
import org.lwjgl.opengl.ARBMultitexture;
import org.lwjgl.opengl.ARBTextureCubeMap;
import org.lwjgl.opengl.GL11;
import ponkOut.graphics.resources.Texture;
import ponkOut.graphics.resources.TextureManager;
public class CubeMap {
private Texture[] tex = new Texture[6];
public CubeMap(String left, String right, String top, String bottom, String front, String back) {
TextureManager tm = TextureManager.getInstance();
tex[0] = tm.getCubeMapTexture(right, ARBTextureCubeMap.GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB);
tex[1] = tm.getCubeMapTexture(left, ARBTextureCubeMap.GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB);
tex[2] = tm.getCubeMapTexture(top, ARBTextureCubeMap.GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB);
tex[3] = tm.getCubeMapTexture(bottom, ARBTextureCubeMap.GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB);
tex[4] = tm.getCubeMapTexture(back, ARBTextureCubeMap.GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB);
tex[5] = tm.getCubeMapTexture(front, ARBTextureCubeMap.GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB);
}
/**
* update texture matrix according to camera rotation
*/
public void update(boolean reflected) {
// rotate texture matrix 1
ARBMultitexture.glActiveTextureARB(ARBMultitexture.GL_TEXTURE1_ARB);
GL11.glMatrixMode(GL11.GL_TEXTURE);
GL11.glLoadIdentity();
Camera.rotateOnly(true);
if (reflected) {
// reflect at board surface
GL11.glTranslatef(0.0f, 0.0f, Board.surfaceZPosition);
GL11.glScalef(1.0f, 1.0f, -1.0f);
GL11.glTranslatef(0.0f, 0.0f, -Board.surfaceZPosition);
}
ARBMultitexture.glActiveTextureARB(ARBMultitexture.GL_TEXTURE0_ARB);
GL11.glMatrixMode(GL11.GL_MODELVIEW);
}
/**
* Bind all 6 textures.
*
* This is not needed if only one cube map is used for every object
*/
public void bind() {
for (int i = 0; i < 6; ++i) {
tex[i].bind();
}
}
}