Skip to content

Commit b8a689f

Browse files
committed
Merge branch 'master' of github.com:processing/processing
2 parents 55fb0d1 + ff87d1f commit b8a689f

File tree

3 files changed

+81
-15
lines changed

3 files changed

+81
-15
lines changed

core/src/processing/opengl/PGraphicsOpenGL.java

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5240,10 +5240,17 @@ protected void lightNormal(int num, float dx, float dy, float dz) {
52405240
float nz =
52415241
dx*modelviewInv.m02 + dy*modelviewInv.m12 + dz*modelviewInv.m22;
52425242

5243-
float invn = 1.0f / PApplet.dist(0, 0, 0, nx, ny, nz);
5244-
lightNormal[3 * num + 0] = invn * nx;
5245-
lightNormal[3 * num + 1] = invn * ny;
5246-
lightNormal[3 * num + 2] = invn * nz;
5243+
float d = PApplet.dist(0, 0, 0, nx, ny, nz);
5244+
if (0 < d) {
5245+
float invn = 1.0f / d;
5246+
lightNormal[3 * num + 0] = invn * nx;
5247+
lightNormal[3 * num + 1] = invn * ny;
5248+
lightNormal[3 * num + 2] = invn * nz;
5249+
} else {
5250+
lightNormal[3 * num + 0] = 0;
5251+
lightNormal[3 * num + 1] = 0;
5252+
lightNormal[3 * num + 2] = 0;
5253+
}
52475254
}
52485255

52495256

java/libraries/lwjgl/src/processing/lwjgl/PLWJGL.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1240,19 +1240,19 @@ public void uniform1iv(int location, int count, IntBuffer v) {
12401240
}
12411241

12421242
public void uniform2iv(int location, int count, IntBuffer v) {
1243-
v.limit(count);
1243+
v.limit(2 * count);
12441244
GL20.glUniform2(location, v);
12451245
v.clear();
12461246
}
12471247

12481248
public void uniform3iv(int location, int count, IntBuffer v) {
1249-
v.limit(count);
1249+
v.limit(3 * count);
12501250
GL20.glUniform3(location, v);
12511251
v.clear();
12521252
}
12531253

12541254
public void uniform4iv(int location, int count, IntBuffer v) {
1255-
v.limit(count);
1255+
v.limit(4 * count);
12561256
GL20.glUniform4(location, v);
12571257
v.clear();
12581258
}
@@ -1264,19 +1264,19 @@ public void uniform1fv(int location, int count, FloatBuffer v) {
12641264
}
12651265

12661266
public void uniform2fv(int location, int count, FloatBuffer v) {
1267-
v.limit(count);
1267+
v.limit(2 * count);
12681268
GL20.glUniform2(location, v);
12691269
v.clear();
12701270
}
12711271

12721272
public void uniform3fv(int location, int count, FloatBuffer v) {
1273-
v.limit(count);
1273+
v.limit(3 * count);
12741274
GL20.glUniform3(location, v);
12751275
v.clear();
12761276
}
12771277

12781278
public void uniform4fv(int location, int count, FloatBuffer v) {
1279-
v.limit(count);
1279+
v.limit(4 * count);
12801280
GL20.glUniform4(location, v);
12811281
v.clear();
12821282
}

java/libraries/lwjgl/src/processing/lwjgl/PSurfaceLWJGL.java

Lines changed: 64 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,18 @@
66
import java.awt.GraphicsConfiguration;
77
import java.awt.GraphicsDevice;
88
import java.awt.GraphicsEnvironment;
9+
import java.awt.Image;
10+
import java.awt.Point;
911
import java.awt.Rectangle;
12+
import java.awt.Toolkit;
1013
import java.awt.geom.Rectangle2D;
14+
import java.awt.image.BufferedImage;
15+
import java.awt.image.MemoryImageSource;
16+
import java.nio.IntBuffer;
1117

18+
import org.lwjgl.BufferUtils;
1219
import org.lwjgl.LWJGLException;
20+
import org.lwjgl.input.Cursor;
1321
import org.lwjgl.input.Keyboard;
1422
import org.lwjgl.input.Mouse;
1523
import org.lwjgl.opengl.Display;
@@ -40,6 +48,11 @@ public class PSurfaceLWJGL implements PSurface {
4048
PLWJGL pgl;
4149

4250
boolean fullScreenRequested;
51+
52+
int cursorType = PConstants.ARROW; // cursor type
53+
boolean cursorVisible = true; // cursor visibility flag
54+
Cursor invisibleCursor;
55+
4356
// ........................................................
4457

4558
// Event handling
@@ -307,24 +320,68 @@ public void blit() {
307320
@Override
308321
public void setCursor(int kind) {
309322
// TODO Auto-generated method stub
323+
if (PApplet.platform == PConstants.MACOSX && kind == PConstants.MOVE) {
324+
kind = PConstants.HAND;
325+
}
326+
java.awt.Cursor cursor0 = java.awt.Cursor.getPredefinedCursor(kind);
327+
328+
329+
// Cursor cursor1 = Cursor(cursor0.,
330+
// int height,
331+
// int xHotspot,
332+
// int yHotspot,
333+
// int numImages,
334+
// java.nio.IntBuffer images,
335+
// java.nio.IntBuffer delays);
336+
337+
338+
// Mouse.setNativeCursor(cursor1);
339+
cursorVisible = true;
340+
this.cursorType = kind;
310341

311342
}
312343

313344
@Override
314345
public void setCursor(PImage image, int hotspotX, int hotspotY) {
315-
// TODO Auto-generated method stub
316-
346+
BufferedImage jimg = (BufferedImage)image.getNative();
347+
IntBuffer buf = IntBuffer.wrap(jimg.getRGB(0, 0, jimg.getWidth(), jimg.getHeight(),
348+
null, 0, jimg.getWidth()));
349+
try {
350+
Cursor cursor = new Cursor(jimg.getWidth(), jimg.getHeight(),
351+
hotspotX, hotspotY, 1, buf, null);
352+
Mouse.setNativeCursor(cursor);
353+
cursorVisible = true;
354+
} catch (LWJGLException e) {
355+
// TODO Auto-generated catch block
356+
e.printStackTrace();
357+
}
317358
}
318359

319360
@Override
320361
public void showCursor() {
321-
// TODO Auto-generated method stub
322-
362+
// if (!cursorVisible) {
363+
// cursorVisible = true;
364+
// Mouse.setCursor(Cursor.getPredefinedCursor(cursorType));
365+
// }
323366
}
324367

325368
@Override
326369
public void hideCursor() {
327-
// TODO Auto-generated method stub
370+
if (invisibleCursor == null) {
371+
try {
372+
invisibleCursor = new Cursor(1, 1, 0, 0, 1, BufferUtils.createIntBuffer(1), null);
373+
} catch (LWJGLException e1) {
374+
// TODO Auto-generated catch block
375+
e1.printStackTrace();
376+
}
377+
}
378+
try {
379+
Mouse.setNativeCursor(invisibleCursor);
380+
cursorVisible = false;
381+
} catch (LWJGLException e) {
382+
// TODO Auto-generated catch block
383+
e.printStackTrace();
384+
}
328385
}
329386

330387
class AnimationThread extends Thread {
@@ -693,6 +750,8 @@ public void requestStop() {
693750
// To complete later...
694751
// http://docs.oracle.com/javase/6/docs/api/java/awt/event/KeyEvent.html
695752
// http://processing.org/reference/keyCode.html
753+
// This might be very useful:
754+
// http://gtge.googlecode.com/svn/trunk/GTGE%20Add-Ons/src/com/golden/gamedev/engine/lwjgl/LWJGLInput.java
696755
protected int LWJGLtoAWTCode(int code) {
697756
switch (code) {
698757
case Keyboard.KEY_0:

0 commit comments

Comments
 (0)