Quantcast
Channel: Processing Forum
Viewing all articles
Browse latest Browse all 1768

2.0b7 Skybox - not working

$
0
0
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.
  1. import processing.opengl.PGraphicsOpenGL;
  2. import javax.media.opengl.GL2;
  3. import com.jogamp.opengl.util.texture.Texture;
  4. import com.jogamp.opengl.util.texture.TextureIO;
  5. import com.jogamp.opengl.util.texture.awt.AWTTextureIO;
  6. import javax.media.opengl.GLProfile;
  7. import java.io.File;
  8. import javax.imageio.ImageIO;
  9. // set skybox filename without orientation part here...
  10. String skyboxName = "besiege";  
  11. PGraphicsOpenGL pgl;
  12. GL2 gl;
  13. int skybox;
  14. void setup()
  15. {
  16.   size(600, 500, OPENGL);
  17.   pgl = (PGraphicsOpenGL) g;
  18.   gl = g.beginPGL().gl.getGL2();
  19.   noStroke();
  20.   loadSkybox(skyboxName, ".png");
  21.   pgl.beginPGL();
  22.   skybox = gl.glGenLists(1);
  23.   gl.glNewList(skybox, GL2.GL_COMPILE);
  24.  
  25.   gl.glFrontFace(GL2.GL_CCW);
  26.   gl.glEnable(GL2.GL_CULL_FACE);
  27.   TexturedCube();
  28.   gl.glDisable(GL2.GL_CULL_FACE);
  29.   gl.glEndList();
  30.   pgl.endPGL();
  31.   float fov = PI/3.0;
  32.   float cameraZ = (height/2.0) / tan(fov/2.0);
  33.   perspective(fov, float(width)/float(height), cameraZ/10.0, cameraZ*200.0);
  34.   // gl.glEnable(GL.GL_CULL_FACE);
  35. }
  36. void draw()
  37. {
  38.   background(0);
  39.   pgl.beginPGL();
  40.   gl.glCallList( skybox );
  41.   pgl.endPGL();
  42.   fill(255);
  43.   pushMatrix();
  44.   translate(width/2,height/2,0);
  45.   sphere(20);
  46.   popMatrix();
  47. }
  48. float p = 40000;   // half skybox size
  49. float m = -p;
  50. // create cube edges
  51. PVector P000 = new PVector (m,m,m);
  52. PVector P010 = new PVector (m,p,m);
  53. PVector P110 = new PVector (p,p,m);
  54. PVector P100 = new PVector (p,m,m);
  55. PVector P001 = new PVector (m,m,p);
  56. PVector P011 = new PVector (m,p,p);
  57. PVector P111 = new PVector (p,p,p);
  58. PVector P101 = new PVector (p,m,p);
  59. Texture tex1,tex2,tex3,tex4,tex5,tex6;   // texture images
  60. // load six skybox images as cube texture
  61. void loadSkybox(String skyboxName, String fExt)
  62. {
  63.   try {
  64.     tex1 = AWTTextureIO.newTexture(GLProfile.getDefault(), ImageIO.read(new File(dataPath(skyboxName + "_front" + fExt))), true);
  65.     tex2 = AWTTextureIO.newTexture(GLProfile.getDefault(), ImageIO.read(new File(dataPath(skyboxName + "_back" + fExt))), true);
  66.     tex3 = AWTTextureIO.newTexture(GLProfile.getDefault(), ImageIO.read(new File(dataPath(skyboxName + "_left" + fExt))), true);
  67.     tex4 = AWTTextureIO.newTexture(GLProfile.getDefault(), ImageIO.read(new File(dataPath(skyboxName + "_right" + fExt))), true);
  68.     tex5 = AWTTextureIO.newTexture(GLProfile.getDefault(), ImageIO.read(new File(dataPath(skyboxName + "_bottom" + fExt))), true);
  69.     tex6 = AWTTextureIO.newTexture(GLProfile.getDefault(), ImageIO.read(new File(dataPath(skyboxName + "_top" + fExt))), true);
  70.   }
  71.   catch (IOException e) {   
  72.     println( e);
  73.   }
  74.   //textureMode(NORMALIZED);
  75. }
  76. // Assign six texture to the six cube faces
  77. void TexturedCube()
  78. {
  79.   TexturedCubeSide (P100, P000, P010, P110, tex1);   // -Z "front" face
  80.   TexturedCubeSide (P001, P101, P111, P011, tex2);   // +Z "back" face
  81.   TexturedCubeSide (P000, P001, P011, P010, tex3);   // -X "left" face
  82.   TexturedCubeSide (P101, P100, P110, P111, tex4);   // +X "right" face
  83.   TexturedCubeSide (P110, P010, P011, P111, tex5);   // +Y "base" face
  84.   TexturedCubeSide (P101, P001, P000, P100, tex6);   // -Y "top" face
  85. }
  86. // create a cube side given by 4 edge vertices and a texture
  87. void TexturedCubeSide(PVector P1, PVector P2, PVector P3, PVector P4, Texture tex)
  88. {
  89.   tex.enable(gl);
  90.   tex.bind(gl);
  91.   gl.glBegin(GL2.GL_QUADS);
  92.   gl.glTexCoord2f(1.0f, 0.0f);
  93.   gl.glVertex3f(P1.x, P1.y, P1.z);
  94.   gl.glTexCoord2f(0.0f, 0.0f);
  95.   gl.glVertex3f(P2.x, P2.y, P2.z);
  96.   gl.glTexCoord2f(0.0f, 1.0f);
  97.   gl.glVertex3f(P3.x, P3.y, P3.z);
  98.   gl.glTexCoord2f(1.0f, 1.0f);
  99.   gl.glVertex3f(P4.x, P4.y, P4.z);
  100.   gl.glEnd();
  101.   tex.disable(gl);
  102. }



Viewing all articles
Browse latest Browse all 1768

Trending Articles