.. | .. |
---|
110 | 110 | //private Mat4f spotlightTransform = new Mat4f(); |
---|
111 | 111 | //private Mat4f spotlightInverseTransform = new Mat4f(); |
---|
112 | 112 | static GLContext glcontext = null; |
---|
113 | | - /*static*/ com.sun.opengl.util.texture.Texture cubemap; |
---|
| 113 | + /*static*/ com.sun.opengl.util.texture.Texture cubemap; // Either custom or rgb |
---|
| 114 | + /*static*/ com.sun.opengl.util.texture.Texture cubemapcustom; |
---|
| 115 | + /*static*/ com.sun.opengl.util.texture.Texture cubemaprgb; |
---|
| 116 | + boolean transformMode; |
---|
| 117 | + |
---|
114 | 118 | boolean reverseUP = false; |
---|
115 | 119 | static boolean frozen = false; |
---|
116 | 120 | boolean enablebackspace = false; // patch for back buffer refresh |
---|
.. | .. |
---|
173 | 177 | static boolean doublesided = false; // true; // reversed normals are awful for conformance |
---|
174 | 178 | boolean anisotropy = true; |
---|
175 | 179 | boolean softshadow = true; // slower but better false; |
---|
176 | | - boolean opacityhalo = false; |
---|
| 180 | + boolean opacityhalo = false; // reverse the halo effect (e.g. glass) |
---|
177 | 181 | |
---|
178 | 182 | boolean macromode = false; |
---|
179 | 183 | |
---|
.. | .. |
---|
187 | 191 | } |
---|
188 | 192 | |
---|
189 | 193 | private File defaultDirectory = javax.swing.filechooser.FileSystemView.getFileSystemView().getDefaultDirectory(); |
---|
| 194 | + |
---|
| 195 | + public com.sun.opengl.util.texture.Texture LoadSkybox(String name, String ext, boolean mipmap) throws GLException |
---|
| 196 | + { |
---|
| 197 | + try |
---|
| 198 | + { |
---|
| 199 | + return LoadCubemap(getClass().getClassLoader(), name, ext, mipmap); |
---|
| 200 | + } catch (IOException e) |
---|
| 201 | + { |
---|
| 202 | + System.out.println("NAME = " + name); |
---|
| 203 | + e.printStackTrace(); // throw new RuntimeException(e); |
---|
| 204 | + return null; |
---|
| 205 | + } |
---|
| 206 | + } |
---|
190 | 207 | |
---|
191 | 208 | void SetAsGLRenderer(boolean b) |
---|
192 | 209 | { |
---|
.. | .. |
---|
1485 | 1502 | gl.glVertex3f((float) pv.x, (float) pv.y, (float) pv.z); |
---|
1486 | 1503 | } |
---|
1487 | 1504 | |
---|
| 1505 | + float[] colorV = new float[4]; |
---|
| 1506 | + |
---|
1488 | 1507 | void SetColor(Object3D obj, Vertex p0) |
---|
1489 | 1508 | { |
---|
1490 | 1509 | CameraPane display = this; |
---|
.. | .. |
---|
1552 | 1571 | { |
---|
1553 | 1572 | return; |
---|
1554 | 1573 | } |
---|
1555 | | - |
---|
1556 | | - float[] colorV = new float[3]; |
---|
1557 | 1574 | |
---|
1558 | 1575 | if (false) // marked) |
---|
1559 | 1576 | { |
---|
.. | .. |
---|
2500 | 2517 | com.sun.opengl.util.texture.TextureIO.newTextureData( |
---|
2501 | 2518 | getClass().getClassLoader().getResourceAsStream(name), |
---|
2502 | 2519 | true, |
---|
2503 | | - com.sun.opengl.util.texture.TextureIO.PNG); |
---|
| 2520 | + GetFormat(name)); // com.sun.opengl.util.texture.TextureIO.PNG); |
---|
2504 | 2521 | } catch (java.io.IOException e) |
---|
2505 | 2522 | { |
---|
2506 | 2523 | throw new javax.media.opengl.GLException(e); |
---|
.. | .. |
---|
8346 | 8363 | // else |
---|
8347 | 8364 | // if (!texname.startsWith("/")) |
---|
8348 | 8365 | // texname = "/Users/nbriere/Textures/" + texname; |
---|
8349 | | - if (!FileExists(texname)) |
---|
| 8366 | + if (!FileExists(texname) && !texname.startsWith("@")) |
---|
8350 | 8367 | { |
---|
8351 | 8368 | texname = fallbackTextureName; |
---|
8352 | 8369 | } |
---|
.. | .. |
---|
8429 | 8446 | new Exception().printStackTrace(); |
---|
8430 | 8447 | } else |
---|
8431 | 8448 | { |
---|
| 8449 | + if (texname.startsWith("@")) |
---|
| 8450 | + { |
---|
| 8451 | + // texturecache = textures.get(texname); // suspicious |
---|
| 8452 | + if (texturecache == null) |
---|
| 8453 | + texturecache = new CacheTexture(GetResourceTexture(texname.substring(1), bump),resolution); |
---|
| 8454 | + else |
---|
| 8455 | + new Exception().printStackTrace(); |
---|
| 8456 | + } else |
---|
| 8457 | + { |
---|
8432 | 8458 | if (textureon) |
---|
8433 | 8459 | { |
---|
8434 | 8460 | String cachename = texname; |
---|
.. | .. |
---|
8488 | 8514 | texturecache = new CacheTexture(texturedata,resolution); |
---|
8489 | 8515 | //texture = GetTexture(tex, bump); |
---|
8490 | 8516 | } |
---|
| 8517 | + } |
---|
8491 | 8518 | } |
---|
8492 | 8519 | //} |
---|
8493 | 8520 | } |
---|
.. | .. |
---|
8756 | 8783 | |
---|
8757 | 8784 | gl.glGetIntegerv(GL.GL_MAX_TEXTURE_STACK_DEPTH, temp, 0); |
---|
8758 | 8785 | MAXSTACK = temp[0]; |
---|
8759 | | - System.out.println("GL_MAX_TEXTURE_STACK_DEPTH = " + MAXSTACK); |
---|
| 8786 | + if (Globals.DEBUG) |
---|
| 8787 | + System.out.println("GL_MAX_TEXTURE_STACK_DEPTH = " + MAXSTACK); |
---|
8760 | 8788 | gl.glGetIntegerv(GL.GL_MAX_MODELVIEW_STACK_DEPTH, temp, 0); |
---|
8761 | 8789 | MAXSTACK = temp[0]; |
---|
8762 | | - System.out.println("GL_MAX_MODELVIEW_STACK_DEPTH = " + MAXSTACK); |
---|
| 8790 | + if (Globals.DEBUG) |
---|
| 8791 | + System.out.println("GL_MAX_MODELVIEW_STACK_DEPTH = " + MAXSTACK); |
---|
8763 | 8792 | |
---|
8764 | 8793 | // Use debug pipeline |
---|
8765 | 8794 | //drawable.setGL(new DebugGL(gl)); // |
---|
.. | .. |
---|
8767 | 8796 | gl = drawable.getGL(); // |
---|
8768 | 8797 | |
---|
8769 | 8798 | GL gl3 = getGL(); |
---|
8770 | | - System.out.println("INIT GL IS: " + gl.getClass().getName()); |
---|
| 8799 | + if (Globals.DEBUG) |
---|
| 8800 | + System.out.println("INIT GL IS: " + gl.getClass().getName()); |
---|
8771 | 8801 | |
---|
8772 | 8802 | |
---|
8773 | 8803 | //float pos[] = { 100, 100, 100, 0 }; |
---|
.. | .. |
---|
8932 | 8962 | |
---|
8933 | 8963 | if (cubemap == null) |
---|
8934 | 8964 | { |
---|
8935 | | - LoadEnvy(5); |
---|
| 8965 | + //LoadEnvy(1); |
---|
8936 | 8966 | } |
---|
8937 | 8967 | |
---|
8938 | 8968 | //cubemap.enable(); |
---|
.. | .. |
---|
9208 | 9238 | |
---|
9209 | 9239 | void LoadEnvy(int which) |
---|
9210 | 9240 | { |
---|
| 9241 | + assert(false); |
---|
| 9242 | + |
---|
9211 | 9243 | String name; |
---|
9212 | 9244 | String ext; |
---|
9213 | 9245 | |
---|
.. | .. |
---|
9219 | 9251 | cubemap = null; |
---|
9220 | 9252 | return; |
---|
9221 | 9253 | case 1: |
---|
9222 | | - name = "cubemaps/box_"; |
---|
9223 | | - ext = "png"; |
---|
| 9254 | + name = "cubemaps/rgb/"; |
---|
| 9255 | + ext = "jpg"; |
---|
9224 | 9256 | reverseUP = false; |
---|
9225 | 9257 | break; |
---|
9226 | 9258 | case 2: |
---|
9227 | | - name = "cubemaps/uffizi_"; |
---|
9228 | | - ext = "png"; |
---|
9229 | | - break; // reverseUP = true; break; |
---|
| 9259 | + name = "cubemaps/uffizi/"; |
---|
| 9260 | + ext = "jpg"; |
---|
| 9261 | + reverseUP = false; |
---|
| 9262 | + break; |
---|
9230 | 9263 | case 3: |
---|
9231 | | - name = "cubemaps/CloudyHills_"; |
---|
9232 | | - ext = "tga"; |
---|
| 9264 | + name = "cubemaps/CloudyHills/"; |
---|
| 9265 | + ext = "jpg"; |
---|
9233 | 9266 | reverseUP = false; |
---|
9234 | 9267 | break; |
---|
9235 | 9268 | case 4: |
---|
9236 | | - name = "cubemaps/cornell_"; |
---|
| 9269 | + name = "cubemaps/cornell/"; |
---|
9237 | 9270 | ext = "png"; |
---|
9238 | 9271 | reverseUP = false; |
---|
9239 | 9272 | break; |
---|
| 9273 | + case 5: |
---|
| 9274 | + name = "cubemaps/skycube/"; |
---|
| 9275 | + ext = "jpg"; |
---|
| 9276 | + reverseUP = false; |
---|
| 9277 | + break; |
---|
| 9278 | + case 6: |
---|
| 9279 | + name = "cubemaps/SaintLazarusChurch3/"; |
---|
| 9280 | + ext = "jpg"; |
---|
| 9281 | + reverseUP = false; |
---|
| 9282 | + break; |
---|
| 9283 | + case 7: |
---|
| 9284 | + name = "cubemaps/Sodermalmsallen/"; |
---|
| 9285 | + ext = "jpg"; |
---|
| 9286 | + reverseUP = false; |
---|
| 9287 | + break; |
---|
| 9288 | + case 8: |
---|
| 9289 | + name = "cubemaps/Sodermalmsallen2/"; |
---|
| 9290 | + ext = "jpg"; |
---|
| 9291 | + reverseUP = false; |
---|
| 9292 | + break; |
---|
| 9293 | + case 9: |
---|
| 9294 | + name = "cubemaps/UnionSquare/"; |
---|
| 9295 | + ext = "jpg"; |
---|
| 9296 | + reverseUP = false; |
---|
| 9297 | + break; |
---|
9240 | 9298 | default: |
---|
9241 | | - name = "cubemaps/rgb_"; |
---|
9242 | | - ext = "png"; /*mipmap = true;*/ reverseUP = false; |
---|
| 9299 | + name = "cubemaps/box/"; |
---|
| 9300 | + ext = "png"; /*mipmap = true;*/ |
---|
| 9301 | + reverseUP = false; |
---|
9243 | 9302 | break; |
---|
9244 | 9303 | } |
---|
9245 | | - |
---|
9246 | | - try |
---|
9247 | | - { |
---|
9248 | | - cubemap = LoadCubemap(getClass().getClassLoader(), name, ext, mipmap); |
---|
9249 | | - } catch (IOException e) |
---|
9250 | | - { |
---|
9251 | | - throw new RuntimeException(e); |
---|
9252 | | - } |
---|
| 9304 | + |
---|
| 9305 | + LoadSkybox(name, ext, mipmap); |
---|
9253 | 9306 | } |
---|
9254 | 9307 | |
---|
9255 | 9308 | public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) |
---|
.. | .. |
---|
9281 | 9334 | static double[] model = new double[16]; |
---|
9282 | 9335 | double[] camera2light = new double[16]; |
---|
9283 | 9336 | double[] light2camera = new double[16]; |
---|
9284 | | - int newenvy = -1; |
---|
9285 | | - boolean envyoff = true; // false; |
---|
| 9337 | + |
---|
| 9338 | + //int newenvy = -1; |
---|
| 9339 | + //boolean envyoff = false; |
---|
| 9340 | + |
---|
| 9341 | + String loadedskyboxname; |
---|
| 9342 | + |
---|
9286 | 9343 | cVector light0 = new cVector(0, 0, 0); // 1,3,2); |
---|
9287 | 9344 | //float[] light0 = { 0,0,0 }; |
---|
9288 | 9345 | cVector dirlight = new cVector(0, 0, 1); // 1,3,2); |
---|
.. | .. |
---|
9762 | 9819 | rati = 1 / rati; |
---|
9763 | 9820 | gl.glOrtho(-skyscale / rati, skyscale / rati, -skyscale, skyscale, 0.001, 1000); |
---|
9764 | 9821 | } |
---|
9765 | | - assert (newenvy == -1); |
---|
| 9822 | + |
---|
| 9823 | + //assert (newenvy == -1); |
---|
| 9824 | + |
---|
9766 | 9825 | gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB); |
---|
9767 | 9826 | gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB); |
---|
9768 | | - DrawSkyBox(gl); |
---|
| 9827 | + DrawSkyBox(gl, (float)rati); |
---|
9769 | 9828 | gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB); |
---|
9770 | 9829 | gl.glEnable(GL.GL_VERTEX_PROGRAM_ARB); |
---|
9771 | 9830 | accPerspective(gl, renderCamera.shaper_fovy / ratio, |
---|
.. | .. |
---|
10802 | 10861 | |
---|
10803 | 10862 | if (wait) |
---|
10804 | 10863 | { |
---|
10805 | | - Sleep(500); |
---|
| 10864 | + Sleep(200); // blocks everything |
---|
10806 | 10865 | |
---|
10807 | 10866 | wait = false; |
---|
10808 | 10867 | } |
---|
.. | .. |
---|
11018 | 11077 | gl.glOrtho(-skyscale / ratio, skyscale / ratio, -skyscale, skyscale, 0.001, 1000); |
---|
11019 | 11078 | } |
---|
11020 | 11079 | |
---|
11021 | | - if (newenvy > -1) |
---|
| 11080 | +// if (newenvy > -1) |
---|
| 11081 | +// { |
---|
| 11082 | +// LoadEnvy(newenvy); |
---|
| 11083 | +// } |
---|
| 11084 | +// |
---|
| 11085 | +// newenvy = -1; |
---|
| 11086 | + |
---|
| 11087 | + if (transformMode) // object.skyboxname != null && object.skyboxname.equals("cubemaps/default-skyboxes/rgb")) |
---|
11022 | 11088 | { |
---|
11023 | | - LoadEnvy(newenvy); |
---|
| 11089 | + if (cubemaprgb == null) |
---|
| 11090 | + { |
---|
| 11091 | + cubemaprgb = LoadSkybox("cubemaps/default-skyboxes/rgb" + "/", "jpg", false); |
---|
| 11092 | + } |
---|
| 11093 | + |
---|
| 11094 | + cubemap = cubemaprgb; |
---|
11024 | 11095 | } |
---|
11025 | | - |
---|
11026 | | - newenvy = -1; |
---|
11027 | | - |
---|
| 11096 | + else |
---|
| 11097 | + { |
---|
| 11098 | + if (object.skyboxname != null) |
---|
| 11099 | + { |
---|
| 11100 | + if (!object.skyboxname.equals(this.loadedskyboxname)) |
---|
| 11101 | + { |
---|
| 11102 | + if (cubemap != null && cubemap != cubemaprgb) |
---|
| 11103 | + cubemap.dispose(); |
---|
| 11104 | + cubemapcustom = LoadSkybox(object.skyboxname + "/", object.skyboxext, false); |
---|
| 11105 | + loadedskyboxname = object.skyboxname; |
---|
| 11106 | + } |
---|
| 11107 | + } |
---|
| 11108 | + else |
---|
| 11109 | + { |
---|
| 11110 | + cubemapcustom = null; |
---|
| 11111 | + loadedskyboxname = null; |
---|
| 11112 | + } |
---|
| 11113 | + |
---|
| 11114 | + cubemap = cubemapcustom; |
---|
| 11115 | + } |
---|
| 11116 | + |
---|
11028 | 11117 | ratio = ((double) getWidth()) / getHeight(); |
---|
11029 | 11118 | //System.out.println("ratio = " + ratio); |
---|
11030 | 11119 | |
---|
.. | .. |
---|
11040 | 11129 | |
---|
11041 | 11130 | if (!IsFrozen() && !ambientOcclusion) |
---|
11042 | 11131 | { |
---|
11043 | | - DrawSkyBox(gl); |
---|
| 11132 | + DrawSkyBox(gl, (float)ratio); |
---|
11044 | 11133 | } |
---|
11045 | 11134 | |
---|
11046 | 11135 | //if (selection_view == -1) |
---|
.. | .. |
---|
11326 | 11415 | |
---|
11327 | 11416 | // if (cam != lightCamera) |
---|
11328 | 11417 | //for (int count = parentcam.GetTransformCount(); --count>=0;) |
---|
11329 | | - LA.xformDir(lightposition, parentcam.GlobalTransform(), lightposition); // may 2013 |
---|
| 11418 | + LA.xformDir(lightposition, parentcam.GlobalTransformInv(), lightposition); // may 2013 |
---|
11330 | 11419 | } |
---|
11331 | 11420 | |
---|
11332 | 11421 | LA.xformDir(lightposition, cam.toScreen, lightposition); |
---|
.. | .. |
---|
12400 | 12489 | |
---|
12401 | 12490 | //gl.glProgramEnvParameter4fvARB(GL.GL_FRAGMENT_PROGRAM_ARB, 127, lightParams, 0); |
---|
12402 | 12491 | |
---|
12403 | | - String program = |
---|
| 12492 | + String programmin = |
---|
12404 | 12493 | // Min shader |
---|
12405 | 12494 | "!!ARBfp1.0\n" + |
---|
12406 | 12495 | "PARAM zero123 = { 0.0, 1.0, 2, 1.25 };" + |
---|
.. | .. |
---|
12451 | 12540 | //"SUB ndotl.y, zero123.y, ndotl.y;" + |
---|
12452 | 12541 | //"MUL ndotl.y, ndotl.y, pow2.z;" + |
---|
12453 | 12542 | |
---|
12454 | | - "MAX ndotl.x, ndotl.x, ndotl.y;" + // Ambient |
---|
| 12543 | + //"MAX ndotl.x, ndotl.x, ndotl.y;" + // Ambient |
---|
| 12544 | + //"MAX ndotl.x, ndotl.x, pow2.y;" + // Ambient |
---|
12455 | 12545 | |
---|
12456 | 12546 | // Pigment |
---|
12457 | 12547 | "TEX temp, fragment.texcoord[0], texture[0], 2D;" + |
---|
.. | .. |
---|
12466 | 12556 | "MOV result.color, temp;" + |
---|
12467 | 12557 | "END"; |
---|
12468 | 12558 | |
---|
12469 | | - String program2 = |
---|
| 12559 | + String programmax = |
---|
12470 | 12560 | "!!ARBfp1.0\n" + |
---|
12471 | 12561 | |
---|
12472 | 12562 | //"OPTION ARB_fragment_program_shadow;" + |
---|
.. | .. |
---|
12991 | 13081 | // display shadow only (fakedepth == 0) |
---|
12992 | 13082 | "SUB temp.x, half.x, shadow.x;" + |
---|
12993 | 13083 | "MOV temp.y, -params5.z;" + // params6.x;" + |
---|
12994 | | - "SLT temp.z, temp.y, -one2048th.x;" + |
---|
| 13084 | + "SLT temp.z, temp.y, -c256i.x;" + |
---|
12995 | 13085 | "SUB temp.y, one.x, temp.z;" + |
---|
12996 | 13086 | "MUL temp.x, temp.x, temp.y;" + |
---|
12997 | 13087 | "KIL temp.x;" + |
---|
.. | .. |
---|
13322 | 13412 | //once = true; |
---|
13323 | 13413 | } |
---|
13324 | 13414 | |
---|
| 13415 | + String program = programmax; |
---|
| 13416 | + |
---|
| 13417 | + if (Globals.MINSHADER) |
---|
| 13418 | + { |
---|
| 13419 | + program = programmin; |
---|
| 13420 | + } |
---|
| 13421 | + |
---|
13325 | 13422 | System.out.print("Program #" + mode + "; instructions = " + program.split(";").length + "; length = " + program.length()); |
---|
13326 | 13423 | System.out.println(" - " + (mode >> 3) + " lights; " + ((mode & 2) == 2 ? "anisoUV " : "") + ((mode & 4) == 4 ? "SoftShadow " : "")); |
---|
13327 | 13424 | loadProgram(gl, GL.GL_FRAGMENT_PROGRAM_ARB, program); |
---|
.. | .. |
---|
14571 | 14668 | MODIFIERS |= COMMAND; |
---|
14572 | 14669 | /**/ |
---|
14573 | 14670 | if((mod&SHIFT) == SHIFT) |
---|
14574 | | - manipCamera.RotatePosition(0, -speed); |
---|
14575 | | - else |
---|
14576 | 14671 | manipCamera.BackForth(0, -speed*delta, 0); // getWidth()); |
---|
| 14672 | + else |
---|
| 14673 | + manipCamera.RotatePosition(0, -speed); |
---|
14577 | 14674 | /**/ |
---|
14578 | 14675 | if ((mod & SHIFT) == SHIFT) |
---|
14579 | 14676 | { |
---|
.. | .. |
---|
14592 | 14689 | MODIFIERS |= COMMAND; |
---|
14593 | 14690 | /**/ |
---|
14594 | 14691 | if((mod&SHIFT) == SHIFT) |
---|
14595 | | - manipCamera.RotatePosition(0, speed); |
---|
14596 | | - else |
---|
14597 | 14692 | manipCamera.BackForth(0, speed*delta, 0); // getWidth()); |
---|
| 14693 | + else |
---|
| 14694 | + manipCamera.RotatePosition(0, speed); |
---|
14598 | 14695 | /**/ |
---|
14599 | 14696 | if ((mod & SHIFT) == SHIFT) |
---|
14600 | 14697 | { |
---|
.. | .. |
---|
15315 | 15412 | OCCLUSION_CULLING ^= true; |
---|
15316 | 15413 | System.out.println("OCCLUSION CULLING = " + OCCLUSION_CULLING); |
---|
15317 | 15414 | break; |
---|
15318 | | - case '0': envyoff ^= true; repaint(); break; |
---|
| 15415 | + //case '0': envyoff ^= true; repaint(); break; |
---|
15319 | 15416 | case '1': |
---|
15320 | 15417 | case '2': |
---|
15321 | 15418 | case '3': |
---|
15322 | 15419 | case '4': |
---|
15323 | 15420 | case '5': |
---|
15324 | | - newenvy = Character.getNumericValue(key); |
---|
15325 | | - repaint(); |
---|
15326 | | - break; |
---|
15327 | 15421 | case '6': |
---|
15328 | 15422 | case '7': |
---|
15329 | 15423 | case '8': |
---|
15330 | 15424 | case '9': |
---|
15331 | | - BGcolor = (key - '6')/3.f; |
---|
| 15425 | + if (true) // envyoff) |
---|
| 15426 | + { |
---|
| 15427 | + BGcolor = (key - '1')/8.f; |
---|
| 15428 | + } |
---|
| 15429 | + else |
---|
| 15430 | + { |
---|
| 15431 | + //newenvy = Character.getNumericValue(key); |
---|
| 15432 | + } |
---|
15332 | 15433 | repaint(); |
---|
15333 | 15434 | break; |
---|
15334 | 15435 | case '!': |
---|
.. | .. |
---|
16033 | 16134 | gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2); |
---|
16034 | 16135 | break; |
---|
16035 | 16136 | case Object3D.hitScale: gr.setColor(Color.cyan); |
---|
16036 | | - gr.drawLine(X, Y, 0, 0); |
---|
| 16137 | + gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2); |
---|
16037 | 16138 | break; |
---|
16038 | 16139 | } |
---|
16039 | 16140 | |
---|
.. | .. |
---|
16519 | 16620 | private /*static*/ boolean firstime; |
---|
16520 | 16621 | private /*static*/ cVector newView = new cVector(); |
---|
16521 | 16622 | private static final String[] suffixes = {"posx", "negx", "posy", "negy", "posz", "negz"}; |
---|
| 16623 | + private static final String[] suffixes2 = {"east", "west", "top", "bottom", "north", "south"}; |
---|
| 16624 | + private static final String[] suffixes3 = {"ft", "bk", "up", "dn", "rt", "lf"}; |
---|
16522 | 16625 | private static final int[] targets = {GL.GL_TEXTURE_CUBE_MAP_POSITIVE_X, |
---|
16523 | 16626 | GL.GL_TEXTURE_CUBE_MAP_NEGATIVE_X, |
---|
16524 | 16627 | GL.GL_TEXTURE_CUBE_MAP_POSITIVE_Y, |
---|
.. | .. |
---|
16531 | 16634 | { |
---|
16532 | 16635 | com.sun.opengl.util.texture.Texture cubemap = TextureIO.newTexture(GL.GL_TEXTURE_CUBE_MAP); |
---|
16533 | 16636 | |
---|
| 16637 | + int usedsuf = 0; |
---|
| 16638 | + |
---|
16534 | 16639 | for (int i = 0; i < suffixes.length; i++) |
---|
16535 | 16640 | { |
---|
16536 | | - String resourceName = basename + suffixes[i] + "." + suffix; |
---|
16537 | | - TextureData data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName), |
---|
16538 | | - mipmapped, |
---|
16539 | | - FileUtil.getFileSuffix(resourceName)); |
---|
16540 | | - if (data == null) |
---|
| 16641 | + String[] suffixe = suffixes; |
---|
| 16642 | + String[] fallback = suffixes2; |
---|
| 16643 | + String[] fallfallback = suffixes3; |
---|
| 16644 | + |
---|
| 16645 | + for (int c=usedsuf; --c>=0;) |
---|
16541 | 16646 | { |
---|
16542 | | - throw new IOException("Unable to load texture " + resourceName); |
---|
| 16647 | +// String[] temp = suffixe; |
---|
| 16648 | +// suffixe = fallback; |
---|
| 16649 | +// fallback = fallfallback; |
---|
| 16650 | +// fallfallback = temp; |
---|
16543 | 16651 | } |
---|
| 16652 | + |
---|
| 16653 | + String resourceName = basename + suffixe[i] + "." + suffix; |
---|
| 16654 | + TextureData data; |
---|
| 16655 | + |
---|
| 16656 | + try |
---|
| 16657 | + { |
---|
| 16658 | + data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName), |
---|
| 16659 | + mipmapped, |
---|
| 16660 | + FileUtil.getFileSuffix(resourceName)); |
---|
| 16661 | + } |
---|
| 16662 | + catch (Exception e) |
---|
| 16663 | + { |
---|
| 16664 | + try |
---|
| 16665 | + { |
---|
| 16666 | + resourceName = basename + fallback[i] + "." + suffix; |
---|
| 16667 | + data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName), |
---|
| 16668 | + mipmapped, |
---|
| 16669 | + FileUtil.getFileSuffix(resourceName)); |
---|
| 16670 | + } |
---|
| 16671 | + catch (Exception e2) |
---|
| 16672 | + { |
---|
| 16673 | + resourceName = basename + fallfallback[i] + "." + suffix; |
---|
| 16674 | + data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName), |
---|
| 16675 | + mipmapped, |
---|
| 16676 | + FileUtil.getFileSuffix(resourceName)); |
---|
| 16677 | + } |
---|
| 16678 | + } |
---|
| 16679 | + |
---|
16544 | 16680 | //System.out.println("Target = " + targets[i]); |
---|
16545 | 16681 | cubemap.updateImage(data, targets[i]); |
---|
16546 | 16682 | } |
---|
16547 | 16683 | |
---|
16548 | 16684 | return cubemap; |
---|
16549 | 16685 | } |
---|
| 16686 | + |
---|
16550 | 16687 | int bigsphere = -1; |
---|
16551 | 16688 | |
---|
16552 | 16689 | float BGcolor = 0.5f; |
---|
16553 | 16690 | |
---|
16554 | | - private void DrawSkyBox(GL gl) |
---|
| 16691 | + float ambientLight[] = {1f, 1f, 1f, 1.0f}; |
---|
| 16692 | + |
---|
| 16693 | + private void DrawSkyBox(GL gl, float ratio) |
---|
16555 | 16694 | { |
---|
16556 | | - if (envyoff || cubemap == null) |
---|
| 16695 | + if (//envyoff || |
---|
| 16696 | + WIREFRAME || |
---|
| 16697 | + cubemap == null) |
---|
16557 | 16698 | { |
---|
16558 | 16699 | gl.glClearColor(BGcolor, BGcolor, BGcolor, 1); |
---|
16559 | 16700 | gl.glClear(gl.GL_COLOR_BUFFER_BIT); |
---|
.. | .. |
---|
16568 | 16709 | // Compensates for ExaminerViewer's modification of modelview matrix |
---|
16569 | 16710 | gl.glMatrixMode(GL.GL_MODELVIEW); |
---|
16570 | 16711 | gl.glLoadIdentity(); |
---|
| 16712 | + gl.glScalef(1,ratio,1); |
---|
16571 | 16713 | |
---|
| 16714 | +// colorV[0] = 2; |
---|
| 16715 | +// colorV[1] = 2; |
---|
| 16716 | +// colorV[2] = 2; |
---|
| 16717 | +// colorV[3] = 1; |
---|
| 16718 | +// gl.glDisable(gl.GL_COLOR_MATERIAL); |
---|
| 16719 | +// gl.glMaterialfv(gl.GL_FRONT_AND_BACK, gl.GL_AMBIENT, colorV, 0); |
---|
| 16720 | +// |
---|
| 16721 | +// gl.glLightModelfv(gl.GL_LIGHT_MODEL_AMBIENT, ambientLight, 0); |
---|
| 16722 | + |
---|
16572 | 16723 | //gl.glActiveTexture(GL.GL_TEXTURE1); |
---|
16573 | 16724 | //gl.glDisable(GL.GL_TEXTURE_CUBE_MAP); |
---|
16574 | 16725 | |
---|
.. | .. |
---|
16600 | 16751 | { |
---|
16601 | 16752 | gl.glScalef(1.0f, -1.0f, 1.0f); |
---|
16602 | 16753 | } |
---|
| 16754 | + gl.glScalef(-1.0f, 1.0f, 1.0f); |
---|
16603 | 16755 | gl.glMultMatrixd(viewrot_1, 0); |
---|
16604 | 16756 | gl.glTranslatef(0, 0, 0.5f); // (float)lightCamera.Distance()); // 0.5f); |
---|
16605 | 16757 | //viewer.updateInverseRotation(gl); |
---|
.. | .. |
---|
16640 | 16792 | gl.glDisable(GL.GL_TEXTURE_GEN_R); |
---|
16641 | 16793 | |
---|
16642 | 16794 | cubemap.disable(); |
---|
16643 | | - ////cubemap.unbind(); |
---|
| 16795 | + //cubemap.dispose(); |
---|
| 16796 | + |
---|
16644 | 16797 | if (CULLFACE) |
---|
16645 | 16798 | { |
---|
16646 | 16799 | gl.glEnable(gl.GL_CULL_FACE); |
---|
.. | .. |
---|
16858 | 17011 | //new Exception().printStackTrace(); |
---|
16859 | 17012 | System.out.println("select buffer init"); |
---|
16860 | 17013 | // Use debug pipeline |
---|
16861 | | - drawable.setGL(new DebugGL(drawable.getGL())); |
---|
| 17014 | + //drawable.setGL(new DebugGL(drawable.getGL())); |
---|
16862 | 17015 | |
---|
16863 | 17016 | GL gl = drawable.getGL(); |
---|
16864 | 17017 | |
---|
.. | .. |
---|
17404 | 17557 | gl.glFlush(); |
---|
17405 | 17558 | |
---|
17406 | 17559 | /**/ |
---|
17407 | | - gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_DEPTH_COMPONENT, GL.GL_FLOAT, occlusionsizebuffer); |
---|
| 17560 | + gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_DEPTH_COMPONENT, GL.GL_FLOAT, occlusiondepthbuffer); |
---|
17408 | 17561 | |
---|
17409 | | - float[] pixels = occlusionsizebuffer.array(); |
---|
| 17562 | + float[] depths = occlusiondepthbuffer.array(); |
---|
17410 | 17563 | |
---|
| 17564 | + gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_BGRA, GL.GL_UNSIGNED_INT_8_8_8_8_REV, occlusioncolorbuffer); |
---|
| 17565 | + |
---|
| 17566 | + int[] pixels = selectsizebuffer.array(); |
---|
| 17567 | + |
---|
17411 | 17568 | double r = 0, g = 0, b = 0; |
---|
17412 | 17569 | |
---|
17413 | 17570 | double count = 0; |
---|
.. | .. |
---|
17418 | 17575 | |
---|
17419 | 17576 | double FACTOR = 1; |
---|
17420 | 17577 | |
---|
17421 | | - for (int i = 0; i < pixels.length; i++) |
---|
| 17578 | + for (int i = 0; i < depths.length; i++) |
---|
17422 | 17579 | { |
---|
17423 | 17580 | int x = i / OCCLUSION_SIZE - OCCLUSION_SIZE / 2; |
---|
17424 | 17581 | int y = i % OCCLUSION_SIZE - OCCLUSION_SIZE / 2; |
---|
.. | .. |
---|
17501 | 17658 | |
---|
17502 | 17659 | double scale = ray.z; // 1; // cos |
---|
17503 | 17660 | |
---|
17504 | | - float depth = pixels[newindex]; |
---|
| 17661 | + float depth = depths[newindex]; |
---|
17505 | 17662 | |
---|
17506 | 17663 | /* |
---|
17507 | 17664 | int newindex2 = (x + 1) * OCCLUSION_SIZE + y; |
---|
.. | .. |
---|
17698 | 17855 | static IntBuffer AAbuffer; // = IntBuffer.allocate(MAX_SIZE*MAX_SIZE); |
---|
17699 | 17856 | static IntBuffer bigAAbuffer; |
---|
17700 | 17857 | static java.nio.FloatBuffer histogram = BufferUtil.newFloatBuffer(HISTOGRAM_SIZE * 3); |
---|
17701 | | - static IntBuffer texturesizebuffer = IntBuffer.allocate(TEX_SIZE * TEX_SIZE); |
---|
| 17858 | + //static IntBuffer texturesizebuffer = IntBuffer.allocate(TEX_SIZE * TEX_SIZE); |
---|
17702 | 17859 | static IntBuffer selectsizebuffer = IntBuffer.allocate(SELECT_SIZE * SELECT_SIZE); |
---|
17703 | 17860 | static java.nio.FloatBuffer pointselectsizebuffer = java.nio.FloatBuffer.allocate(SELECT_SIZE * SELECT_SIZE); |
---|
17704 | 17861 | //static IntBuffer occlusionsizebuffer = IntBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE); |
---|
17705 | | - static java.nio.FloatBuffer occlusionsizebuffer = java.nio.FloatBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE); |
---|
| 17862 | + static java.nio.FloatBuffer occlusiondepthbuffer = java.nio.FloatBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE); |
---|
| 17863 | + |
---|
| 17864 | + static IntBuffer occlusioncolorbuffer = IntBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE); |
---|
| 17865 | + |
---|
17706 | 17866 | static BufferedImage bufimage = new BufferedImage(TEX_SIZE, TEX_SIZE, BufferedImage.TYPE_INT_RGB); |
---|
17707 | 17867 | static BufferedImage textest = new cBufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB); |
---|
17708 | 17868 | static java.util.Vector<BufferedImage> billboards = new java.util.Vector<BufferedImage>(); |
---|