From 24a2a946b35279605e645349bd6b82e9e60aac88 Mon Sep 17 00:00:00 2001
From: Normand Briere <nbriere@noware.ca>
Date: Wed, 14 Aug 2019 23:35:34 -0400
Subject: [PATCH] Fix textures in jar.

---
 CameraPane.java |   46 +++++++++++++++++++++++++++++++++++-----------
 1 files changed, 35 insertions(+), 11 deletions(-)

diff --git a/CameraPane.java b/CameraPane.java
index df28651..ebdca60 100644
--- a/CameraPane.java
+++ b/CameraPane.java
@@ -110,7 +110,11 @@
     //private Mat4f spotlightTransform = new Mat4f();
     //private Mat4f spotlightInverseTransform = new Mat4f();
     static GLContext glcontext = null;
-    /*static*/ com.sun.opengl.util.texture.Texture cubemap;
+    /*static*/ com.sun.opengl.util.texture.Texture cubemap; // Either custom or rgb
+    /*static*/ com.sun.opengl.util.texture.Texture cubemapcustom;
+    /*static*/ com.sun.opengl.util.texture.Texture cubemaprgb;
+    boolean transformMode;
+    
     boolean reverseUP = false;
     static boolean frozen = false;
     boolean enablebackspace = false; // patch for back buffer refresh
@@ -188,15 +192,16 @@
     
     private File defaultDirectory = javax.swing.filechooser.FileSystemView.getFileSystemView().getDefaultDirectory();
 
-    public void LoadSkybox(String name, String ext, boolean mipmap) throws GLException
+    public com.sun.opengl.util.texture.Texture LoadSkybox(String name, String ext, boolean mipmap) throws GLException
     {
         try
         {
-            cubemap = LoadCubemap(getClass().getClassLoader(), name, ext, mipmap);
+            return LoadCubemap(getClass().getClassLoader(), name, ext, mipmap);
         } catch (IOException e)
         {
             System.out.println("NAME = " + name);
             e.printStackTrace(); // throw new RuntimeException(e);
+            return null;
         }
     }
     
@@ -2512,7 +2517,7 @@
                     com.sun.opengl.util.texture.TextureIO.newTextureData(
                     getClass().getClassLoader().getResourceAsStream(name),
                     true,
-                    com.sun.opengl.util.texture.TextureIO.PNG);
+                    GetFormat(name)); // com.sun.opengl.util.texture.TextureIO.PNG);
         } catch (java.io.IOException e)
         {
             throw new javax.media.opengl.GLException(e);
@@ -9233,6 +9238,8 @@
 
     void LoadEnvy(int which)
     {
+        assert(false);
+        
         String name;
         String ext;
 
@@ -11077,18 +11084,34 @@
 //
 //        newenvy = -1;
         
-        if (object.skyboxname != null)
+        if (transformMode) // object.skyboxname != null && object.skyboxname.equals("cubemaps/default-skyboxes/rgb"))
         {
-            if (!object.skyboxname.equals(this.loadedskyboxname))
+            if (cubemaprgb == null)
             {
-                LoadSkybox(object.skyboxname + "/", object.skyboxext, false);
-                loadedskyboxname = object.skyboxname;
+                cubemaprgb = LoadSkybox("cubemaps/default-skyboxes/rgb" + "/", "jpg", false);
             }
+            
+            cubemap = cubemaprgb;
         }
         else
         {
-            cubemap = null;
-            loadedskyboxname = null;
+            if (object.skyboxname != null)
+            {
+                if (!object.skyboxname.equals(this.loadedskyboxname))
+                {
+                    if (cubemap != null && cubemap != cubemaprgb)
+                        cubemap.dispose();
+                    cubemapcustom = LoadSkybox(object.skyboxname + "/", object.skyboxext, false);
+                    loadedskyboxname = object.skyboxname;
+                }
+            }
+            else
+            {
+                cubemapcustom = null;
+                loadedskyboxname = null;
+            }
+            
+            cubemap = cubemapcustom;
         }
         
         ratio = ((double) getWidth()) / getHeight();
@@ -16769,7 +16792,8 @@
         gl.glDisable(GL.GL_TEXTURE_GEN_R);
 
         cubemap.disable();
-        ////cubemap.unbind();
+        //cubemap.dispose();
+        
         if (CULLFACE)
         {
             gl.glEnable(gl.GL_CULL_FACE);

--
Gitblit v1.6.2