/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package computergraphicsproject.model.Scenes;
import computergraphicsproject.model.Model;
import computergraphicsproject.utilities.libraries.GLApp.glapp.GLApp;
import computergraphicsproject.utilities.libraries.GLApp.glapp.GLImage;
import org.lwjgl.opengl.GL11;
/**
*
* @author hussein
*/
public abstract class SceneModel extends Model {
private int[] skybox = null;
protected int side = 100000;
protected boolean includeSkyBox = false;
protected String[] skyPaths;
protected boolean includeCustomSkybox = false;
/**
*
*/
public void init() {
}
/**
*
*/
public abstract void render();
protected void createDefaultSkyBox() {
skybox = new int[6];
skybox[0] = GLApp.makeTexture(new GLImage("/computergraphicsproject/media/graphics/scenes/skybox1/sky01_ft.jpg"));
skybox[1] = GLApp.makeTexture(new GLImage("/computergraphicsproject/media/graphics/scenes/skybox1/sky01_bk.jpg"));
skybox[2] = GLApp.makeTexture(new GLImage("/computergraphicsproject/media/graphics/scenes/skybox1/sky01_lf.jpg"));
skybox[3] = GLApp.makeTexture(new GLImage("/computergraphicsproject/media/graphics/scenes/skybox1/sky01_rt.jpg"));
skybox[4] = GLApp.makeTexture(new GLImage("/computergraphicsproject/media/graphics/scenes/skybox1/sky01_up.jpg"));
skybox[5] = GLApp.makeTexture(new GLImage("/computergraphicsproject/media/graphics/scenes/skybox1/sky01_dn.jpg"));
}
protected void createSkybox(String[] paths) {
skybox = new int[6];
for (int i = 0; i < 6; i++) {
skybox[i] = GLApp.makeTexture(new GLImage(paths[i]));
}
}
protected void renderSkyBox() {
if (skybox == null) {
createDefaultSkyBox();
}
GL11.glPushMatrix();
GL11.glTexParameteri(
GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL11.GL_CLAMP);
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL11.GL_CLAMP);
// Enable/Disable features
GL11.glPushAttrib(GL11.GL_ENABLE_BIT);
GL11.glEnable(GL11.GL_TEXTURE_2D);
GL11.glDisable(GL11.GL_LIGHTING);
GL11.glDisable(GL11.GL_BLEND);
// Just in case we set all vertices to white.
GL11.glColor4f(1, 1, 1, 1);
// Render the front quad
GL11.glBindTexture(GL11.GL_TEXTURE_2D, skybox[2]);
GL11.glBegin(GL11.GL_QUADS);
GL11.glTexCoord2f(0, 0);
GL11.glVertex3f(getSide(), -getSide(), -getSide());
GL11.glTexCoord2f(1, 0);
GL11.glVertex3f(-getSide(), -getSide(), -getSide());
GL11.glTexCoord2f(1, 1);
GL11.glVertex3f(-getSide(), getSide(), -getSide());
GL11.glTexCoord2f(0, 1);
GL11.glVertex3f(getSide(), getSide(), -getSide());
GL11.glEnd();
// Render the left quad
GL11.glBindTexture(GL11.GL_TEXTURE_2D, skybox[0]);
GL11.glBegin(GL11.GL_QUADS);
GL11.glTexCoord2f(0, 0);
GL11.glVertex3f(getSide(), -getSide(), getSide());
GL11.glTexCoord2f(1, 0);
GL11.glVertex3f(getSide(), -getSide(), -getSide());
GL11.glTexCoord2f(1, 1);
GL11.glVertex3f(getSide(), getSide(), -getSide());
GL11.glTexCoord2f(0, 1);
GL11.glVertex3f(getSide(), getSide(), getSide());
GL11.glEnd();
// Render the back quad
GL11.glBindTexture(GL11.GL_TEXTURE_2D, skybox[3]);
GL11.glBegin(GL11.GL_QUADS);
GL11.glTexCoord2f(0, 0);
GL11.glVertex3f(-getSide(), -getSide(), getSide());
GL11.glTexCoord2f(1, 0);
GL11.glVertex3f(getSide(), -getSide(), getSide());
GL11.glTexCoord2f(1, 1);
GL11.glVertex3f(getSide(), getSide(), getSide());
GL11.glTexCoord2f(0, 1);
GL11.glVertex3f(-getSide(), getSide(), getSide());
GL11.glEnd();
// Render the right quad
GL11.glBindTexture(GL11.GL_TEXTURE_2D, skybox[1]);
GL11.glBegin(GL11.GL_QUADS);
GL11.glTexCoord2f(0, 0);
GL11.glVertex3f(-getSide(), -getSide(), -getSide());
GL11.glTexCoord2f(1, 0);
GL11.glVertex3f(-getSide(), -getSide(), getSide());
GL11.glTexCoord2f(1, 1);
GL11.glVertex3f(-getSide(), getSide(), getSide());
GL11.glTexCoord2f(0, 1);
GL11.glVertex3f(-getSide(), getSide(), -getSide());
GL11.glEnd();
// Render the top quad
GL11.glBindTexture(GL11.GL_TEXTURE_2D, skybox[4]);
GL11.glBegin(GL11.GL_QUADS);
GL11.glTexCoord2f(0, 1);
GL11.glVertex3f(-getSide(), getSide(), -getSide());
GL11.glTexCoord2f(0, 0);
GL11.glVertex3f(-getSide(), getSide(), getSide());
GL11.glTexCoord2f(1, 0);
GL11.glVertex3f(getSide(), getSide(), getSide());
GL11.glTexCoord2f(1, 1);
GL11.glVertex3f(getSide(), getSide(), -getSide());
GL11.glEnd();
// Restore enable bits and matrix
GL11.glPopAttrib();
GL11.glPopMatrix();
GL11.glBindTexture(GL11.GL_TEXTURE_2D, 0);
}
/**
* @return the side
*/
public int getSide() {
return side;
}
/**
* @param side the side to set
*/
public void setSide(int side) {
this.side = side;
}
/**
* @return the includeSkyBox
*/
public boolean isIncludeSkyBox() {
return includeSkyBox;
}
/**
* @param includeSkyBox the includeSkyBox to set
*/
public void setIncludeSkyBox(boolean includeSkyBox) {
this.includeSkyBox = includeSkyBox;
}
/**
* @return the skyPaths
*/
public String[] getSkyPaths() {
return skyPaths;
}
/**
* @param skyPaths the skyPaths to set
*/
public void setSkyPaths(String[] skyPaths) {
this.skyPaths = skyPaths;
}
/**
* @return the includeCustomSkybox
*/
public boolean isIncludeCustomSkybox() {
return includeCustomSkybox;
}
/**
* @param includeCustomSkybox the includeCustomSkybox to set
*/
public void setIncludeCustomSkybox(boolean includeCustomSkybox) {
this.includeCustomSkybox = includeCustomSkybox;
}
}
|