From 02330f0196295684b0fe6645888385f8a5c36540 Mon Sep 17 00:00:00 2001 From: codeanticode Date: Mon, 19 Jan 2015 17:15:54 -0500 Subject: [PATCH 1/3] division by zero check --- core/src/processing/opengl/PGraphicsOpenGL.java | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/core/src/processing/opengl/PGraphicsOpenGL.java b/core/src/processing/opengl/PGraphicsOpenGL.java index 5dbc0b0bf..55e7c6d4a 100644 --- a/core/src/processing/opengl/PGraphicsOpenGL.java +++ b/core/src/processing/opengl/PGraphicsOpenGL.java @@ -5240,10 +5240,17 @@ public class PGraphicsOpenGL extends PGraphics { float nz = dx*modelviewInv.m02 + dy*modelviewInv.m12 + dz*modelviewInv.m22; - float invn = 1.0f / PApplet.dist(0, 0, 0, nx, ny, nz); - lightNormal[3 * num + 0] = invn * nx; - lightNormal[3 * num + 1] = invn * ny; - lightNormal[3 * num + 2] = invn * nz; + float d = PApplet.dist(0, 0, 0, nx, ny, nz); + if (0 < d) { + float invn = 1.0f / d; + lightNormal[3 * num + 0] = invn * nx; + lightNormal[3 * num + 1] = invn * ny; + lightNormal[3 * num + 2] = invn * nz; + } else { + lightNormal[3 * num + 0] = 0; + lightNormal[3 * num + 1] = 0; + lightNormal[3 * num + 2] = 0; + } } From 385e46c0a037715fd399ac9a09f61205f95647e5 Mon Sep 17 00:00:00 2001 From: codeanticode Date: Mon, 19 Jan 2015 17:17:58 -0500 Subject: [PATCH 2/3] fix buffer limits --- .../libraries/lwjgl/src/processing/lwjgl/PLWJGL.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/java/libraries/lwjgl/src/processing/lwjgl/PLWJGL.java b/java/libraries/lwjgl/src/processing/lwjgl/PLWJGL.java index 69a011a85..5e6691654 100644 --- a/java/libraries/lwjgl/src/processing/lwjgl/PLWJGL.java +++ b/java/libraries/lwjgl/src/processing/lwjgl/PLWJGL.java @@ -1240,19 +1240,19 @@ public class PLWJGL extends PGL { } public void uniform2iv(int location, int count, IntBuffer v) { - v.limit(count); + v.limit(2 * count); GL20.glUniform2(location, v); v.clear(); } public void uniform3iv(int location, int count, IntBuffer v) { - v.limit(count); + v.limit(3 * count); GL20.glUniform3(location, v); v.clear(); } public void uniform4iv(int location, int count, IntBuffer v) { - v.limit(count); + v.limit(4 * count); GL20.glUniform4(location, v); v.clear(); } @@ -1264,19 +1264,19 @@ public class PLWJGL extends PGL { } public void uniform2fv(int location, int count, FloatBuffer v) { - v.limit(count); + v.limit(2 * count); GL20.glUniform2(location, v); v.clear(); } public void uniform3fv(int location, int count, FloatBuffer v) { - v.limit(count); + v.limit(3 * count); GL20.glUniform3(location, v); v.clear(); } public void uniform4fv(int location, int count, FloatBuffer v) { - v.limit(count); + v.limit(4 * count); GL20.glUniform4(location, v); v.clear(); } From 906b0e5d8a827b9e7646ef7f53629fcd8c468229 Mon Sep 17 00:00:00 2001 From: codeanticode Date: Mon, 19 Jan 2015 18:07:31 -0500 Subject: [PATCH 3/3] working on the cursors --- .../src/processing/lwjgl/PSurfaceLWJGL.java | 69 +++++++++++++++++-- 1 file changed, 64 insertions(+), 5 deletions(-) diff --git a/java/libraries/lwjgl/src/processing/lwjgl/PSurfaceLWJGL.java b/java/libraries/lwjgl/src/processing/lwjgl/PSurfaceLWJGL.java index 07bd150c8..80367c96e 100644 --- a/java/libraries/lwjgl/src/processing/lwjgl/PSurfaceLWJGL.java +++ b/java/libraries/lwjgl/src/processing/lwjgl/PSurfaceLWJGL.java @@ -6,10 +6,18 @@ import java.awt.Frame; import java.awt.GraphicsConfiguration; import java.awt.GraphicsDevice; import java.awt.GraphicsEnvironment; +import java.awt.Image; +import java.awt.Point; import java.awt.Rectangle; +import java.awt.Toolkit; import java.awt.geom.Rectangle2D; +import java.awt.image.BufferedImage; +import java.awt.image.MemoryImageSource; +import java.nio.IntBuffer; +import org.lwjgl.BufferUtils; import org.lwjgl.LWJGLException; +import org.lwjgl.input.Cursor; import org.lwjgl.input.Keyboard; import org.lwjgl.input.Mouse; import org.lwjgl.opengl.Display; @@ -40,6 +48,11 @@ public class PSurfaceLWJGL implements PSurface { PLWJGL pgl; boolean fullScreenRequested; + + int cursorType = PConstants.ARROW; // cursor type + boolean cursorVisible = true; // cursor visibility flag + Cursor invisibleCursor; + // ........................................................ // Event handling @@ -307,24 +320,68 @@ public class PSurfaceLWJGL implements PSurface { @Override public void setCursor(int kind) { // TODO Auto-generated method stub + if (PApplet.platform == PConstants.MACOSX && kind == PConstants.MOVE) { + kind = PConstants.HAND; + } + java.awt.Cursor cursor0 = java.awt.Cursor.getPredefinedCursor(kind); + + +// Cursor cursor1 = Cursor(cursor0., +// int height, +// int xHotspot, +// int yHotspot, +// int numImages, +// java.nio.IntBuffer images, +// java.nio.IntBuffer delays); + + +// Mouse.setNativeCursor(cursor1); + cursorVisible = true; + this.cursorType = kind; } @Override public void setCursor(PImage image, int hotspotX, int hotspotY) { - // TODO Auto-generated method stub - + BufferedImage jimg = (BufferedImage)image.getNative(); + IntBuffer buf = IntBuffer.wrap(jimg.getRGB(0, 0, jimg.getWidth(), jimg.getHeight(), + null, 0, jimg.getWidth())); + try { + Cursor cursor = new Cursor(jimg.getWidth(), jimg.getHeight(), + hotspotX, hotspotY, 1, buf, null); + Mouse.setNativeCursor(cursor); + cursorVisible = true; + } catch (LWJGLException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } } @Override public void showCursor() { - // TODO Auto-generated method stub - +// if (!cursorVisible) { +// cursorVisible = true; +// Mouse.setCursor(Cursor.getPredefinedCursor(cursorType)); +// } } @Override public void hideCursor() { - // TODO Auto-generated method stub + if (invisibleCursor == null) { + try { + invisibleCursor = new Cursor(1, 1, 0, 0, 1, BufferUtils.createIntBuffer(1), null); + } catch (LWJGLException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } + } + try { + Mouse.setNativeCursor(invisibleCursor); + cursorVisible = false; + } catch (LWJGLException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } } class AnimationThread extends Thread { @@ -693,6 +750,8 @@ public class PSurfaceLWJGL implements PSurface { // To complete later... // http://docs.oracle.com/javase/6/docs/api/java/awt/event/KeyEvent.html // http://processing.org/reference/keyCode.html + // This might be very useful: + // http://gtge.googlecode.com/svn/trunk/GTGE%20Add-Ons/src/com/golden/gamedev/engine/lwjgl/LWJGLInput.java protected int LWJGLtoAWTCode(int code) { switch (code) { case Keyboard.KEY_0: