Figured it out... wish this was somehow automatically included in Processing. Have to load the matrix (not sure if it is in each draw or just once in the setup). As described by Andres:
You have to do the glLoadMatrixf() call manually because the OpenGL renderer only uses functions available in the GLES2 API, and all the matrix-related functions are gone in GLES2 (and GL 3.2+).
- 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;
- float[] projMatrix;
- float[] mvMatrix;
- // set skybox filename without orientation part here...
- String skyboxName = "besiege";
- PGraphicsOpenGL pg;
- GL2 gl;
- int skybox;
- float a = 0.0;
- void setup()
- {
- size(600, 500, OPENGL);
- pg = (PGraphicsOpenGL) g;
- gl = g.beginPGL().gl.getGL2();
- noStroke(); // comment it to see cube edges
- loadSkybox(skyboxName, ".png");
- pg.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();
- pg.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);
- projMatrix = new float[16];
- mvMatrix = new float[16];
- // gl.glEnable(GL.GL_CULL_FACE);
- }
- void draw()
- {
- background(0);
- loadMatrix();
- pg.beginPGL();
- gl.glCallList( skybox );
- pg.endPGL();
- fill(255);
- pushMatrix();
- translate(width/2,height/2,0);
- sphere(20);
- popMatrix();
- //println("FPS: "+ frameRate);
- }
- 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);
- }
- void loadMatrix() {
- gl.glMatrixMode(GL2.GL_PROJECTION);
- projMatrix[0] = pg.projection.m00;
- projMatrix[1] = pg.projection.m10;
- projMatrix[2] = pg.projection.m20;
- projMatrix[3] = pg.projection.m30;
- projMatrix[4] = pg.projection.m01;
- projMatrix[5] = pg.projection.m11;
- projMatrix[6] = pg.projection.m21;
- projMatrix[7] = pg.projection.m31;
- projMatrix[8] = pg.projection.m02;
- projMatrix[9] = pg.projection.m12;
- projMatrix[10] = pg.projection.m22;
- projMatrix[11] = pg.projection.m32;
- projMatrix[12] = pg.projection.m03;
- projMatrix[13] = pg.projection.m13;
- projMatrix[14] = pg.projection.m23;
- projMatrix[15] = pg.projection.m33;
- gl.glLoadMatrixf(projMatrix, 0);
- gl.glMatrixMode(GL2.GL_MODELVIEW);
- mvMatrix[0] = pg.modelview.m00;
- mvMatrix[1] = pg.modelview.m10;
- mvMatrix[2] = pg.modelview.m20;
- mvMatrix[3] = pg.modelview.m30;
- mvMatrix[4] = pg.modelview.m01;
- mvMatrix[5] = pg.modelview.m11;
- mvMatrix[6] = pg.modelview.m21;
- mvMatrix[7] = pg.modelview.m31;
- mvMatrix[8] = pg.modelview.m02;
- mvMatrix[9] = pg.modelview.m12;
- mvMatrix[10] = pg.modelview.m22;
- mvMatrix[11] = pg.modelview.m32;
- mvMatrix[12] = pg.modelview.m03;
- mvMatrix[13] = pg.modelview.m13;
- mvMatrix[14] = pg.modelview.m23;
- mvMatrix[15] = pg.modelview.m33;
- gl.glLoadMatrixf(mvMatrix, 0);
- }