2.0b7 Skybox - not working
in
Core Library Questions
•
10 months ago
Trying to create a skybox in the new 2.0x build. Here is the code, translated from 1.5, but it's not working. Am I doing something wrong or is this a bug?
Here is zip of the sketch, which includes the image files.
Here is zip of the sketch, which includes the image files.
- import processing.opengl.PGraphicsOpenGL;
- import javax.media.opengl.GL2;
- import com.jogamp.opengl.util.texture.Texture;
- import com.jogamp.opengl.util.texture.TextureIO;
- import com.jogamp.opengl.util.texture.awt.AWTTextureIO;
- import javax.media.opengl.GLProfile;
- import java.io.File;
- import javax.imageio.ImageIO;
- // set skybox filename without orientation part here...
- String skyboxName = "besiege";
- PGraphicsOpenGL pgl;
- GL2 gl;
- int skybox;
- void setup()
- {
- size(600, 500, OPENGL);
- pgl = (PGraphicsOpenGL) g;
- gl = g.beginPGL().gl.getGL2();
- noStroke();
- loadSkybox(skyboxName, ".png");
- pgl.beginPGL();
- skybox = gl.glGenLists(1);
- gl.glNewList(skybox, GL2.GL_COMPILE);
- gl.glFrontFace(GL2.GL_CCW);
- gl.glEnable(GL2.GL_CULL_FACE);
- TexturedCube();
- gl.glDisable(GL2.GL_CULL_FACE);
- gl.glEndList();
- pgl.endPGL();
- float fov = PI/3.0;
- float cameraZ = (height/2.0) / tan(fov/2.0);
- perspective(fov, float(width)/float(height), cameraZ/10.0, cameraZ*200.0);
- // gl.glEnable(GL.GL_CULL_FACE);
- }
- void draw()
- {
- background(0);
- pgl.beginPGL();
- gl.glCallList( skybox );
- pgl.endPGL();
- fill(255);
- pushMatrix();
- translate(width/2,height/2,0);
- sphere(20);
- popMatrix();
- }
- float p = 40000; // half skybox size
- float m = -p;
- // create cube edges
- PVector P000 = new PVector (m,m,m);
- PVector P010 = new PVector (m,p,m);
- PVector P110 = new PVector (p,p,m);
- PVector P100 = new PVector (p,m,m);
- PVector P001 = new PVector (m,m,p);
- PVector P011 = new PVector (m,p,p);
- PVector P111 = new PVector (p,p,p);
- PVector P101 = new PVector (p,m,p);
- Texture tex1,tex2,tex3,tex4,tex5,tex6; // texture images
- // load six skybox images as cube texture
- void loadSkybox(String skyboxName, String fExt)
- {
- try {
- tex1 = AWTTextureIO.newTexture(GLProfile.getDefault(), ImageIO.read(new File(dataPath(skyboxName + "_front" + fExt))), true);
- tex2 = AWTTextureIO.newTexture(GLProfile.getDefault(), ImageIO.read(new File(dataPath(skyboxName + "_back" + fExt))), true);
- tex3 = AWTTextureIO.newTexture(GLProfile.getDefault(), ImageIO.read(new File(dataPath(skyboxName + "_left" + fExt))), true);
- tex4 = AWTTextureIO.newTexture(GLProfile.getDefault(), ImageIO.read(new File(dataPath(skyboxName + "_right" + fExt))), true);
- tex5 = AWTTextureIO.newTexture(GLProfile.getDefault(), ImageIO.read(new File(dataPath(skyboxName + "_bottom" + fExt))), true);
- tex6 = AWTTextureIO.newTexture(GLProfile.getDefault(), ImageIO.read(new File(dataPath(skyboxName + "_top" + fExt))), true);
- }
- catch (IOException e) {
- println( e);
- }
- //textureMode(NORMALIZED);
- }
- // Assign six texture to the six cube faces
- void TexturedCube()
- {
- TexturedCubeSide (P100, P000, P010, P110, tex1); // -Z "front" face
- TexturedCubeSide (P001, P101, P111, P011, tex2); // +Z "back" face
- TexturedCubeSide (P000, P001, P011, P010, tex3); // -X "left" face
- TexturedCubeSide (P101, P100, P110, P111, tex4); // +X "right" face
- TexturedCubeSide (P110, P010, P011, P111, tex5); // +Y "base" face
- TexturedCubeSide (P101, P001, P000, P100, tex6); // -Y "top" face
- }
- // create a cube side given by 4 edge vertices and a texture
- void TexturedCubeSide(PVector P1, PVector P2, PVector P3, PVector P4, Texture tex)
- {
- tex.enable(gl);
- tex.bind(gl);
- gl.glBegin(GL2.GL_QUADS);
- gl.glTexCoord2f(1.0f, 0.0f);
- gl.glVertex3f(P1.x, P1.y, P1.z);
- gl.glTexCoord2f(0.0f, 0.0f);
- gl.glVertex3f(P2.x, P2.y, P2.z);
- gl.glTexCoord2f(0.0f, 1.0f);
- gl.glVertex3f(P3.x, P3.y, P3.z);
- gl.glTexCoord2f(1.0f, 1.0f);
- gl.glVertex3f(P4.x, P4.y, P4.z);
- gl.glEnd();
- tex.disable(gl);
- }
1