From a8bb95b5dcc569b090b2f869c33d417d223acc4d Mon Sep 17 00:00:00 2001 From: codeanticode Date: Fri, 20 Feb 2015 16:44:16 -0500 Subject: [PATCH] removed LWJGL library --- java/libraries/lwjgl/.classpath | 9 - java/libraries/lwjgl/.gitignore | 1 - java/libraries/lwjgl/.project | 17 - java/libraries/lwjgl/build.xml | 32 - .../lwjgl/examples/LargeStage/LargeStage.pde | 13 - .../examples/OffscreenTest/OffscreenTest.pde | 31 - .../examples/RestartTest/RestartTest.pde | 28 - java/libraries/lwjgl/library/.gitignore | 1 - .../lwjgl/src/processing/lwjgl/LWJGL.java | 8 - .../src/processing/lwjgl/PGraphics2D.java | 15 - .../src/processing/lwjgl/PGraphics2D2X.java | 15 - .../src/processing/lwjgl/PGraphics3D.java | 15 - .../src/processing/lwjgl/PGraphics3D2X.java | 15 - .../src/processing/lwjgl/PGraphicsLWJGL.java | 43 - .../lwjgl/src/processing/lwjgl/PLWJGL.java | 1542 ----------------- .../src/processing/lwjgl/PSurfaceLWJGL.java | 1138 ------------ 16 files changed, 2923 deletions(-) delete mode 100644 java/libraries/lwjgl/.classpath delete mode 100644 java/libraries/lwjgl/.gitignore delete mode 100644 java/libraries/lwjgl/.project delete mode 100644 java/libraries/lwjgl/build.xml delete mode 100644 java/libraries/lwjgl/examples/LargeStage/LargeStage.pde delete mode 100644 java/libraries/lwjgl/examples/OffscreenTest/OffscreenTest.pde delete mode 100644 java/libraries/lwjgl/examples/RestartTest/RestartTest.pde delete mode 100644 java/libraries/lwjgl/library/.gitignore delete mode 100644 java/libraries/lwjgl/src/processing/lwjgl/LWJGL.java delete mode 100644 java/libraries/lwjgl/src/processing/lwjgl/PGraphics2D.java delete mode 100644 java/libraries/lwjgl/src/processing/lwjgl/PGraphics2D2X.java delete mode 100644 java/libraries/lwjgl/src/processing/lwjgl/PGraphics3D.java delete mode 100644 java/libraries/lwjgl/src/processing/lwjgl/PGraphics3D2X.java delete mode 100644 java/libraries/lwjgl/src/processing/lwjgl/PGraphicsLWJGL.java delete mode 100644 java/libraries/lwjgl/src/processing/lwjgl/PLWJGL.java delete mode 100644 java/libraries/lwjgl/src/processing/lwjgl/PSurfaceLWJGL.java diff --git a/java/libraries/lwjgl/.classpath b/java/libraries/lwjgl/.classpath deleted file mode 100644 index 9e3626c94..000000000 --- a/java/libraries/lwjgl/.classpath +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - - - diff --git a/java/libraries/lwjgl/.gitignore b/java/libraries/lwjgl/.gitignore deleted file mode 100644 index ba077a403..000000000 --- a/java/libraries/lwjgl/.gitignore +++ /dev/null @@ -1 +0,0 @@ -bin diff --git a/java/libraries/lwjgl/.project b/java/libraries/lwjgl/.project deleted file mode 100644 index c83f47a87..000000000 --- a/java/libraries/lwjgl/.project +++ /dev/null @@ -1,17 +0,0 @@ - - - processing-lwjgl - - - - - - org.eclipse.jdt.core.javabuilder - - - - - - org.eclipse.jdt.core.javanature - - diff --git a/java/libraries/lwjgl/build.xml b/java/libraries/lwjgl/build.xml deleted file mode 100644 index 6f3f926c9..000000000 --- a/java/libraries/lwjgl/build.xml +++ /dev/null @@ -1,32 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/java/libraries/lwjgl/examples/LargeStage/LargeStage.pde b/java/libraries/lwjgl/examples/LargeStage/LargeStage.pde deleted file mode 100644 index 6d619bc15..000000000 --- a/java/libraries/lwjgl/examples/LargeStage/LargeStage.pde +++ /dev/null @@ -1,13 +0,0 @@ -import processing.lwjgl.*; - -void setup() { - size(4000, 2000, LWJGL.P3D); -} - -void draw() { - background(255, 0, 0); - line(0, 0, width, height); - line(0, height, width, 0); - println(mouseX, mouseY); - ellipse(mouseX, mouseY, 50, 50); -} \ No newline at end of file diff --git a/java/libraries/lwjgl/examples/OffscreenTest/OffscreenTest.pde b/java/libraries/lwjgl/examples/OffscreenTest/OffscreenTest.pde deleted file mode 100644 index 31a666cf5..000000000 --- a/java/libraries/lwjgl/examples/OffscreenTest/OffscreenTest.pde +++ /dev/null @@ -1,31 +0,0 @@ -import processing.lwjgl.*; - -PGraphics pg; - -void setup() { - size(400, 400, LWJGL.P2D); - - pg = createGraphics(400, 400, LWJGL.P2D); - pg.smooth(4); -} - -void draw() { - background(0); - - pg.beginDraw(); - pg.background(255, 0, 0); - pg.ellipse(mouseX, mouseY, 100, 100); - pg.endDraw(); - - image(pg, 0, 0, 400, 400); -} - -void keyPressed() { - if (key == '1') pg.smooth(1); - else if (key == '2') pg.smooth(2); - else if (key == '3') pg.smooth(4); - else if (key == '4') pg.smooth(8); - else if (key == '5') pg.smooth(16); - else if (key == '6') pg.smooth(32); -} - diff --git a/java/libraries/lwjgl/examples/RestartTest/RestartTest.pde b/java/libraries/lwjgl/examples/RestartTest/RestartTest.pde deleted file mode 100644 index 7c0a40ae8..000000000 --- a/java/libraries/lwjgl/examples/RestartTest/RestartTest.pde +++ /dev/null @@ -1,28 +0,0 @@ -import processing.lwjgl.*; - -PShape cube; - -void setup() { - size(400, 400, LWJGL.P3D); - smooth(); - - cube = createShape(BOX, 100); -} - -void draw() { - background(120); - - lights(); - - translate(mouseX, mouseY); - rotateX(frameCount * 0.01f); - rotateY(frameCount * 0.01f); - - shape(cube); -} - -void keyPressed() { - // Changing the smooth configuration restarts the OpenGL surface. - // Automatically recreates all the current GL resources. - noSmooth(); -} diff --git a/java/libraries/lwjgl/library/.gitignore b/java/libraries/lwjgl/library/.gitignore deleted file mode 100644 index 87db85248..000000000 --- a/java/libraries/lwjgl/library/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/opengl-lwjgl.jar diff --git a/java/libraries/lwjgl/src/processing/lwjgl/LWJGL.java b/java/libraries/lwjgl/src/processing/lwjgl/LWJGL.java deleted file mode 100644 index ece360de9..000000000 --- a/java/libraries/lwjgl/src/processing/lwjgl/LWJGL.java +++ /dev/null @@ -1,8 +0,0 @@ -package processing.lwjgl; - -public interface LWJGL { - static final String P2D = "processing.lwjgl.PGraphics2D"; - static final String P3D = "processing.lwjgl.PGraphics3D"; - static final String P2D_2X = "processing.lwjgl.PGraphics2D2X"; - static final String P3D_2X = "processing.lwjgl.PGraphics3D2X"; -} diff --git a/java/libraries/lwjgl/src/processing/lwjgl/PGraphics2D.java b/java/libraries/lwjgl/src/processing/lwjgl/PGraphics2D.java deleted file mode 100644 index 3fce79e14..000000000 --- a/java/libraries/lwjgl/src/processing/lwjgl/PGraphics2D.java +++ /dev/null @@ -1,15 +0,0 @@ -package processing.lwjgl; - -import processing.core.PSurface; -import processing.opengl.PGL; -import processing.opengl.PGraphicsOpenGL; - -public class PGraphics2D extends processing.opengl.PGraphics2D { - protected PGL createPGL(PGraphicsOpenGL pg) { - return new PLWJGL(pg); - } - @Override - public PSurface createSurface() { // ignore - return new PSurfaceLWJGL(this); - } -} diff --git a/java/libraries/lwjgl/src/processing/lwjgl/PGraphics2D2X.java b/java/libraries/lwjgl/src/processing/lwjgl/PGraphics2D2X.java deleted file mode 100644 index 213dd5bf5..000000000 --- a/java/libraries/lwjgl/src/processing/lwjgl/PGraphics2D2X.java +++ /dev/null @@ -1,15 +0,0 @@ -package processing.lwjgl; - -import processing.core.PSurface; -import processing.opengl.PGL; -import processing.opengl.PGraphicsOpenGL; - -public class PGraphics2D2X extends processing.opengl.PGraphics2D2X { - protected PGL createPGL(PGraphicsOpenGL pg) { - return new PLWJGL(pg); - } - @Override - public PSurface createSurface() { // ignore - return new PSurfaceLWJGL(this); - } -} diff --git a/java/libraries/lwjgl/src/processing/lwjgl/PGraphics3D.java b/java/libraries/lwjgl/src/processing/lwjgl/PGraphics3D.java deleted file mode 100644 index d85da6938..000000000 --- a/java/libraries/lwjgl/src/processing/lwjgl/PGraphics3D.java +++ /dev/null @@ -1,15 +0,0 @@ -package processing.lwjgl; - -import processing.core.PSurface; -import processing.opengl.PGL; -import processing.opengl.PGraphicsOpenGL; - -public class PGraphics3D extends processing.opengl.PGraphics3D { - protected PGL createPGL(PGraphicsOpenGL pg) { - return new PLWJGL(pg); - } - @Override - public PSurface createSurface() { // ignore - return new PSurfaceLWJGL(this); - } -} diff --git a/java/libraries/lwjgl/src/processing/lwjgl/PGraphics3D2X.java b/java/libraries/lwjgl/src/processing/lwjgl/PGraphics3D2X.java deleted file mode 100644 index 41b8ac951..000000000 --- a/java/libraries/lwjgl/src/processing/lwjgl/PGraphics3D2X.java +++ /dev/null @@ -1,15 +0,0 @@ -package processing.lwjgl; - -import processing.core.PSurface; -import processing.opengl.PGL; -import processing.opengl.PGraphicsOpenGL; - -public class PGraphics3D2X extends processing.opengl.PGraphics3D2X { - protected PGL createPGL(PGraphicsOpenGL pg) { - return new PLWJGL(pg); - } - @Override - public PSurface createSurface() { // ignore - return new PSurfaceLWJGL(this); - } -} diff --git a/java/libraries/lwjgl/src/processing/lwjgl/PGraphicsLWJGL.java b/java/libraries/lwjgl/src/processing/lwjgl/PGraphicsLWJGL.java deleted file mode 100644 index 60cda24ac..000000000 --- a/java/libraries/lwjgl/src/processing/lwjgl/PGraphicsLWJGL.java +++ /dev/null @@ -1,43 +0,0 @@ -/* -*- mode: java; c-basic-offset: 2; indent-tabs-mode: nil -*- */ - -/* - Part of the Processing project - http://processing.org - - Copyright (c) 2004-12 Ben Fry and Casey Reas - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License version 2.1 as published by the Free Software Foundation. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General - Public License along with this library; if not, write to the - Free Software Foundation, Inc., 59 Temple Place, Suite 330, - Boston, MA 02111-1307 USA - */ - -package processing.lwjgl; - -import processing.core.PSurface; -import processing.opengl.PGL; -import processing.opengl.PGraphicsOpenGL; - - -/** - * LWJGL renderer. - * - */ -public class PGraphicsLWJGL extends PGraphicsOpenGL { - protected PGL createPGL(PGraphicsOpenGL pg) { - return new PLWJGL(pg); - } - - @Override - public PSurface createSurface() { // ignore - return new PSurfaceLWJGL(this); - } -} diff --git a/java/libraries/lwjgl/src/processing/lwjgl/PLWJGL.java b/java/libraries/lwjgl/src/processing/lwjgl/PLWJGL.java deleted file mode 100644 index 42f632e56..000000000 --- a/java/libraries/lwjgl/src/processing/lwjgl/PLWJGL.java +++ /dev/null @@ -1,1542 +0,0 @@ -/* -*- mode: java; c-basic-offset: 2; indent-tabs-mode: nil -*- */ - -/* - Part of the Processing project - http://processing.org - - Copyright (c) 2011-12 Ben Fry and Casey Reas - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General - Public License along with this library; if not, write to the - Free Software Foundation, Inc., 59 Temple Place, Suite 330, - Boston, MA 02111-1307 USA -*/ - -package processing.lwjgl; - -import java.awt.Canvas; -import java.awt.Font; -import java.awt.FontMetrics; -import java.awt.Shape; -import java.awt.font.FontRenderContext; -import java.awt.font.GlyphVector; -import java.awt.geom.PathIterator; -import java.nio.Buffer; -import java.nio.ByteBuffer; -import java.nio.FloatBuffer; -import java.nio.IntBuffer; -import java.nio.ShortBuffer; - -import org.lwjgl.BufferUtils; -import org.lwjgl.opengl.ARBES2Compatibility; -import org.lwjgl.opengl.Display; -import org.lwjgl.opengl.EXTFramebufferObject; -import org.lwjgl.opengl.EXTTextureFilterAnisotropic; -import org.lwjgl.opengl.GL11; -import org.lwjgl.opengl.GL12; -import org.lwjgl.opengl.GL13; -import org.lwjgl.opengl.GL14; -import org.lwjgl.opengl.GL15; -import org.lwjgl.opengl.GL20; -import org.lwjgl.opengl.GL30; -import org.lwjgl.opengl.GL31; -import org.lwjgl.util.glu.GLU; -import org.lwjgl.util.glu.GLUtessellator; -import org.lwjgl.util.glu.GLUtessellatorCallbackAdapter; - -import processing.opengl.PGL; -import processing.opengl.PGraphicsOpenGL; - -/** - * Processing-OpenGL abstraction layer. LWJGL implementation. - * - * Some issues: - * http://lwjgl.org/forum/index.php/topic,4711.0.html - * http://www.java-gaming.org/topics/cannot-add-mouselistener-to-java-awt-canvas-with-lwjgl-on-windows/24650/view.html - * - */ -public class PLWJGL extends PGL { - // ........................................................ - - // Public members to access the underlying GL objects and canvas - - /** GLU interface **/ - public static GLU glu; - - /** The canvas where OpenGL rendering takes place */ - public static Canvas canvas; - - // ........................................................ - - // Utility buffers to copy projection/modelview matrices to GL - - protected FloatBuffer projMatrix; - protected FloatBuffer mvMatrix; - - // ........................................................ - - // Static initialization for some parameters that need to be different for - // LWJGL - - static { - MIN_DIRECT_BUFFER_SIZE = 16; - INDEX_TYPE = GL11.GL_UNSIGNED_SHORT; - } - - - /////////////////////////////////////////////////////////// - - // Initialization, finalization - - - public PLWJGL(PGraphicsOpenGL pg) { - super(pg); - if (glu == null) glu = new GLU(); - } - - - public Canvas getCanvas() { - return canvas; - } - - -// protected void setFps(float fps) { -// if (!setFps || targetFps != fps) { -// if (60 < fps) { -// // Disables v-sync -// System.err.println("Disabling VSync"); -// Display.setVSyncEnabled(false); -//// Display.sync((int)fps); -// } else { -// Display.setVSyncEnabled(true); -// } -// targetFps = currentFps = fps; -// setFps = true; -// } -// } - -/* - protected void initSurface(int antialias) { - if (canvas != null) { - keyPoller.requestStop(); - mousePoller.requestStop(); - - try { - Display.setParent(null); - } catch (LWJGLException e) { - e.printStackTrace(); - } - Display.destroy(); - - pg.parent.remove(canvas); - } - - canvas = new Canvas(); - canvas.setFocusable(true); - canvas.requestFocus(); - canvas.setBackground(new Color(pg.backgroundColor, true)); - canvas.setBounds(0, 0, pg.parent.width, pg.parent.height); - - pg.parent.setLayout(new BorderLayout()); - pg.parent.add(canvas, BorderLayout.CENTER); - - try { - DisplayMode[] modes = Display.getAvailableDisplayModes(); - int bpp = 0; - for (int i = 0; i < modes.length; i++) { - bpp = PApplet.max(modes[i].getBitsPerPixel(), bpp); - } - - PixelFormat format; - if (USE_FBOLAYER_BY_DEFAULT) { - format = new PixelFormat(bpp, REQUESTED_ALPHA_BITS, - REQUESTED_DEPTH_BITS, - REQUESTED_STENCIL_BITS, 1); - reqNumSamples = qualityToSamples(antialias); - fboLayerRequested = true; - } else { - format = new PixelFormat(bpp, REQUESTED_ALPHA_BITS, - REQUESTED_DEPTH_BITS, - REQUESTED_STENCIL_BITS, antialias); - fboLayerRequested = false; - } - - Display.setDisplayMode(new DisplayMode(pg.parent.width, pg.parent.height)); - int argb = pg.backgroundColor; - float r = ((argb >> 16) & 0xff) / 255.0f; - float g = ((argb >> 8) & 0xff) / 255.0f; - float b = ((argb) & 0xff) / 255.0f; - Display.setInitialBackground(r, g, b); - Display.setParent(canvas); - Display.create(format); - - // Might be useful later to specify the context attributes. - // http://lwjgl.org/javadoc/org/lwjgl/opengl/ContextAttribs.html -// ContextAttribs contextAtrributes = new ContextAttribs(4, 0); -// contextAtrributes.withForwardCompatible(true); -// contextAtrributes.withProfileCore(true); -// Display.create(pixelFormat, contextAtrributes); - } catch (LWJGLException e) { - e.printStackTrace(); - } - - glContext = Display.getDrawable().hashCode(); - - registerListeners(); - - fboLayerCreated = false; - fboLayerInUse = false; - firstFrame = true; - setFps = false; - } -*/ - -// protected void reinitSurface() { } - - -// protected void registerListeners() { -// keyPoller = new KeyPoller(pg.parent); -// keyPoller.start(); -// -// mousePoller = new MousePoller(pg.parent); -// mousePoller.start(); -// } - - - /////////////////////////////////////////////////////////// - - // Frame rendering - - -// protected boolean canDraw() { -// return pg.initialized && pg.parent.isDisplayable(); -// } -// - -// protected void requestFocus() { } - - -// protected void requestDraw() { -// if (pg.initialized) { -// glThread = Thread.currentThread(); -// pg.parent.handleDraw(); -// Display.update(); -// } -// } -// -// -// protected void swapBuffers() { -// try { -// Display.swapBuffers(); -// } catch (LWJGLException e) { -// e.printStackTrace(); -// } -// } - - - @Override - protected void beginGL() { - if (projMatrix == null) { - projMatrix = allocateFloatBuffer(16); - } - GL11.glMatrixMode(GL11.GL_PROJECTION); - projMatrix.rewind(); - projMatrix.put(pg.projection.m00); - projMatrix.put(pg.projection.m10); - projMatrix.put(pg.projection.m20); - projMatrix.put(pg.projection.m30); - projMatrix.put(pg.projection.m01); - projMatrix.put(pg.projection.m11); - projMatrix.put(pg.projection.m21); - projMatrix.put(pg.projection.m31); - projMatrix.put(pg.projection.m02); - projMatrix.put(pg.projection.m12); - projMatrix.put(pg.projection.m22); - projMatrix.put(pg.projection.m32); - projMatrix.put(pg.projection.m03); - projMatrix.put(pg.projection.m13); - projMatrix.put(pg.projection.m23); - projMatrix.put(pg.projection.m33); - projMatrix.rewind(); - GL11.glLoadMatrix(projMatrix); - - if (mvMatrix == null) { - mvMatrix = allocateFloatBuffer(16); - } - GL11.glMatrixMode(GL11.GL_MODELVIEW); - mvMatrix.rewind(); - mvMatrix.put(pg.modelview.m00); - mvMatrix.put(pg.modelview.m10); - mvMatrix.put(pg.modelview.m20); - mvMatrix.put(pg.modelview.m30); - mvMatrix.put(pg.modelview.m01); - mvMatrix.put(pg.modelview.m11); - mvMatrix.put(pg.modelview.m21); - mvMatrix.put(pg.modelview.m31); - mvMatrix.put(pg.modelview.m02); - mvMatrix.put(pg.modelview.m12); - mvMatrix.put(pg.modelview.m22); - mvMatrix.put(pg.modelview.m32); - mvMatrix.put(pg.modelview.m03); - mvMatrix.put(pg.modelview.m13); - mvMatrix.put(pg.modelview.m23); - mvMatrix.put(pg.modelview.m33); - mvMatrix.rewind(); - GL11.glLoadMatrix(mvMatrix); - } - - - /////////////////////////////////////////////////////////// - - // Utility functions - - - protected static ByteBuffer allocateDirectByteBuffer(int size) { - return BufferUtils.createByteBuffer(size); - } - - - protected static ShortBuffer allocateDirectShortBuffer(int size) { - return BufferUtils.createShortBuffer(size); - } - - - protected static IntBuffer allocateDirectIntBuffer(int size) { - return BufferUtils.createIntBuffer(size); - } - - - protected static FloatBuffer allocateDirectFloatBuffer(int size) { - return BufferUtils.createFloatBuffer(size); - } - - - @Override - protected int getFontAscent(Object font) { - return pg.getFontMetrics((Font) font).getAscent(); - } - - - @Override - protected int getFontDescent(Object font) { - return pg.getFontMetrics((Font) font).getDescent(); - } - - - @Override - protected int getTextWidth(Object font, char buffer[], int start, int stop) { - // maybe should use one of the newer/fancier functions for this? - int length = stop - start; - FontMetrics metrics = pg.getFontMetrics((Font) font); - return metrics.charsWidth(buffer, start, length); - } - - - @Override - protected Object getDerivedFont(Object font, float size) { - return ((Font) font).deriveFont(size); - } - - - /////////////////////////////////////////////////////////// - - // Tessellator interface - - - protected Tessellator createTessellator(TessellatorCallback callback) { - return new Tessellator(callback); - } - - - protected class Tessellator implements PGL.Tessellator { - protected GLUtessellator tess; - protected TessellatorCallback callback; - protected GLUCallback gluCallback; - - public Tessellator(TessellatorCallback callback) { - this.callback = callback; - tess = GLU.gluNewTess(); - gluCallback = new GLUCallback(); - - tess.gluTessCallback(GLU.GLU_TESS_BEGIN, gluCallback); - tess.gluTessCallback(GLU.GLU_TESS_END, gluCallback); - tess.gluTessCallback(GLU.GLU_TESS_VERTEX, gluCallback); - tess.gluTessCallback(GLU.GLU_TESS_COMBINE, gluCallback); - tess.gluTessCallback(GLU.GLU_TESS_ERROR, gluCallback); - } - - public void beginPolygon() { - tess.gluTessBeginPolygon(null); - } - - public void endPolygon() { - tess.gluTessEndPolygon(); - } - - public void setWindingRule(int rule) { - tess.gluTessProperty(GLU.GLU_TESS_WINDING_RULE, rule); - } - - public void beginContour() { - tess.gluTessBeginContour(); - } - - public void endContour() { - tess.gluTessEndContour(); - } - - public void addVertex(double[] v) { - tess.gluTessVertex(v, 0, v); - } - - protected class GLUCallback extends GLUtessellatorCallbackAdapter { - @Override - public void begin(int type) { - callback.begin(type); - } - - @Override - public void end() { - callback.end(); - } - - @Override - public void vertex(Object data) { - callback.vertex(data); - } - - @Override - public void combine(double[] coords, Object[] data, - float[] weight, Object[] outData) { - callback.combine(coords, data, weight, outData); - } - - @Override - public void error(int errnum) { - callback.error(errnum); - } - } - } - - - protected String tessError(int err) { - return GLU.gluErrorString(err); - } - - - /////////////////////////////////////////////////////////// - - // Font outline - - - static { - SHAPE_TEXT_SUPPORTED = true; - SEG_MOVETO = PathIterator.SEG_MOVETO; - SEG_LINETO = PathIterator.SEG_LINETO; - SEG_QUADTO = PathIterator.SEG_QUADTO; - SEG_CUBICTO = PathIterator.SEG_CUBICTO; - SEG_CLOSE = PathIterator.SEG_CLOSE; - } - - - protected FontOutline createFontOutline(char ch, Object font) { - return new FontOutline(ch, (Font) font); - } - - - protected class FontOutline implements PGL.FontOutline { - PathIterator iter; - - public FontOutline(char ch, Font font) { - char textArray[] = new char[] { ch }; - FontRenderContext frc = pg.getFontRenderContext(font); - GlyphVector gv = font.createGlyphVector(frc, textArray); - Shape shp = gv.getOutline(); - iter = shp.getPathIterator(null); - } - - public boolean isDone() { - return iter.isDone(); - } - - public int currentSegment(float coords[]) { - return iter.currentSegment(coords); - } - - public void next() { - iter.next(); - } - } - - - /////////////////////////////////////////////////////////// - - // Constants - - static { - FALSE = GL11.GL_FALSE; - TRUE = GL11.GL_TRUE; - - INT = GL11.GL_INT; - BYTE = GL11.GL_BYTE; - SHORT = GL11.GL_SHORT; - FLOAT = GL11.GL_FLOAT; - BOOL = GL20.GL_BOOL; - UNSIGNED_INT = GL11.GL_UNSIGNED_INT; - UNSIGNED_BYTE = GL11.GL_UNSIGNED_BYTE; - UNSIGNED_SHORT = GL11.GL_UNSIGNED_SHORT; - - RGB = GL11.GL_RGB; - RGBA = GL11.GL_RGBA; - ALPHA = GL11.GL_ALPHA; - LUMINANCE = GL11.GL_LUMINANCE; - LUMINANCE_ALPHA = GL11.GL_LUMINANCE_ALPHA; - - UNSIGNED_SHORT_5_6_5 = GL12.GL_UNSIGNED_SHORT_5_6_5; - UNSIGNED_SHORT_4_4_4_4 = GL12.GL_UNSIGNED_SHORT_4_4_4_4; - UNSIGNED_SHORT_5_5_5_1 = GL12.GL_UNSIGNED_SHORT_5_5_5_1; - - RGBA4 = GL11.GL_RGBA4; - RGB5_A1 = GL11.GL_RGB5_A1; - RGB565 = ARBES2Compatibility.GL_RGB565; - RGB8 = GL11.GL_RGB8; - RGBA8 = GL11.GL_RGBA8; - ALPHA8 = GL11.GL_ALPHA8; - - READ_ONLY = GL15.GL_READ_ONLY; - WRITE_ONLY = GL15.GL_WRITE_ONLY; - READ_WRITE = GL15.GL_READ_WRITE; - - TESS_WINDING_NONZERO = GLU.GLU_TESS_WINDING_NONZERO; - TESS_WINDING_ODD = GLU.GLU_TESS_WINDING_ODD; - - GENERATE_MIPMAP_HINT = GL14.GL_GENERATE_MIPMAP_HINT; - FASTEST = GL11.GL_FASTEST; - NICEST = GL11.GL_NICEST; - DONT_CARE = GL11.GL_DONT_CARE; - - VENDOR = GL11.GL_VENDOR; - RENDERER = GL11.GL_RENDERER; - VERSION = GL11.GL_VERSION; - EXTENSIONS = GL11.GL_EXTENSIONS; - SHADING_LANGUAGE_VERSION = GL20.GL_SHADING_LANGUAGE_VERSION; - - MAX_SAMPLES = GL30.GL_MAX_SAMPLES; - SAMPLES = GL13.GL_SAMPLES; - - ALIASED_LINE_WIDTH_RANGE = GL12.GL_ALIASED_LINE_WIDTH_RANGE; - ALIASED_POINT_SIZE_RANGE = GL12.GL_ALIASED_POINT_SIZE_RANGE; - - DEPTH_BITS = GL11.GL_DEPTH_BITS; - STENCIL_BITS = GL11.GL_STENCIL_BITS; - - CCW = GL11.GL_CCW; - CW = GL11.GL_CW; - - VIEWPORT = GL11.GL_VIEWPORT; - - ARRAY_BUFFER = GL15.GL_ARRAY_BUFFER; - ELEMENT_ARRAY_BUFFER = GL15.GL_ELEMENT_ARRAY_BUFFER; - - MAX_VERTEX_ATTRIBS = GL20.GL_MAX_VERTEX_ATTRIBS; - - STATIC_DRAW = GL15.GL_STATIC_DRAW; - DYNAMIC_DRAW = GL15.GL_DYNAMIC_DRAW; - STREAM_DRAW = GL15.GL_STREAM_DRAW; - - BUFFER_SIZE = GL15.GL_BUFFER_SIZE; - BUFFER_USAGE = GL15.GL_BUFFER_USAGE; - - POINTS = GL11.GL_POINTS; - LINE_STRIP = GL11.GL_LINE_STRIP; - LINE_LOOP = GL11.GL_LINE_LOOP; - LINES = GL11.GL_LINES; - TRIANGLE_FAN = GL11.GL_TRIANGLE_FAN; - TRIANGLE_STRIP = GL11.GL_TRIANGLE_STRIP; - TRIANGLES = GL11.GL_TRIANGLES; - - CULL_FACE = GL11.GL_CULL_FACE; - FRONT = GL11.GL_FRONT; - BACK = GL11.GL_BACK; - FRONT_AND_BACK = GL11.GL_FRONT_AND_BACK; - - POLYGON_OFFSET_FILL = GL11.GL_POLYGON_OFFSET_FILL; - - UNPACK_ALIGNMENT = GL11.GL_UNPACK_ALIGNMENT; - PACK_ALIGNMENT = GL11.GL_PACK_ALIGNMENT; - - TEXTURE_2D = GL11.GL_TEXTURE_2D; - TEXTURE_RECTANGLE = GL31.GL_TEXTURE_RECTANGLE; - - TEXTURE_BINDING_2D = GL11.GL_TEXTURE_BINDING_2D; - TEXTURE_BINDING_RECTANGLE = GL31.GL_TEXTURE_BINDING_RECTANGLE; - - MAX_TEXTURE_SIZE = GL11.GL_MAX_TEXTURE_SIZE; - TEXTURE_MAX_ANISOTROPY = EXTTextureFilterAnisotropic.GL_TEXTURE_MAX_ANISOTROPY_EXT; - MAX_TEXTURE_MAX_ANISOTROPY = EXTTextureFilterAnisotropic.GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT; - - MAX_VERTEX_TEXTURE_IMAGE_UNITS = GL20.GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS; - MAX_TEXTURE_IMAGE_UNITS = GL20.GL_MAX_TEXTURE_IMAGE_UNITS; - MAX_COMBINED_TEXTURE_IMAGE_UNITS = GL20.GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS; - - NUM_COMPRESSED_TEXTURE_FORMATS = GL13.GL_NUM_COMPRESSED_TEXTURE_FORMATS; - COMPRESSED_TEXTURE_FORMATS = GL13.GL_COMPRESSED_TEXTURE_FORMATS; - - NEAREST = GL11.GL_NEAREST; - LINEAR = GL11.GL_LINEAR; - LINEAR_MIPMAP_NEAREST = GL11.GL_LINEAR_MIPMAP_NEAREST; - LINEAR_MIPMAP_LINEAR = GL11.GL_LINEAR_MIPMAP_LINEAR; - - CLAMP_TO_EDGE = GL12.GL_CLAMP_TO_EDGE; - REPEAT = GL11.GL_REPEAT; - - TEXTURE0 = GL13.GL_TEXTURE0; - TEXTURE1 = GL13.GL_TEXTURE1; - TEXTURE2 = GL13.GL_TEXTURE2; - TEXTURE3 = GL13.GL_TEXTURE3; - TEXTURE_MIN_FILTER = GL11.GL_TEXTURE_MIN_FILTER; - TEXTURE_MAG_FILTER = GL11.GL_TEXTURE_MAG_FILTER; - TEXTURE_WRAP_S = GL11.GL_TEXTURE_WRAP_S; - TEXTURE_WRAP_T = GL11.GL_TEXTURE_WRAP_T; - TEXTURE_WRAP_R = GL12.GL_TEXTURE_WRAP_R; - - TEXTURE_CUBE_MAP = GL13.GL_TEXTURE_CUBE_MAP; - TEXTURE_CUBE_MAP_POSITIVE_X = GL13.GL_TEXTURE_CUBE_MAP_POSITIVE_X; - TEXTURE_CUBE_MAP_POSITIVE_Y = GL13.GL_TEXTURE_CUBE_MAP_POSITIVE_Y; - TEXTURE_CUBE_MAP_POSITIVE_Z = GL13.GL_TEXTURE_CUBE_MAP_POSITIVE_Z; - TEXTURE_CUBE_MAP_NEGATIVE_X = GL13.GL_TEXTURE_CUBE_MAP_NEGATIVE_X; - TEXTURE_CUBE_MAP_NEGATIVE_Y = GL13.GL_TEXTURE_CUBE_MAP_NEGATIVE_Y; - TEXTURE_CUBE_MAP_NEGATIVE_Z = GL13.GL_TEXTURE_CUBE_MAP_NEGATIVE_Z; - - VERTEX_SHADER = GL20.GL_VERTEX_SHADER; - FRAGMENT_SHADER = GL20.GL_FRAGMENT_SHADER; - INFO_LOG_LENGTH = GL20.GL_INFO_LOG_LENGTH; - SHADER_SOURCE_LENGTH = GL20.GL_SHADER_SOURCE_LENGTH; - COMPILE_STATUS = GL20.GL_COMPILE_STATUS; - LINK_STATUS = GL20.GL_LINK_STATUS; - VALIDATE_STATUS = GL20.GL_VALIDATE_STATUS; - SHADER_TYPE = GL20.GL_SHADER_TYPE; - DELETE_STATUS = GL20.GL_DELETE_STATUS; - - FLOAT_VEC2 = GL20.GL_FLOAT_VEC2; - FLOAT_VEC3 = GL20.GL_FLOAT_VEC3; - FLOAT_VEC4 = GL20.GL_FLOAT_VEC4; - FLOAT_MAT2 = GL20.GL_FLOAT_MAT2; - FLOAT_MAT3 = GL20.GL_FLOAT_MAT3; - FLOAT_MAT4 = GL20.GL_FLOAT_MAT4; - INT_VEC2 = GL20.GL_INT_VEC2; - INT_VEC3 = GL20.GL_INT_VEC3; - INT_VEC4 = GL20.GL_INT_VEC4; - BOOL_VEC2 = GL20.GL_BOOL_VEC2; - BOOL_VEC3 = GL20.GL_BOOL_VEC3; - BOOL_VEC4 = GL20.GL_BOOL_VEC4; - SAMPLER_2D = GL20.GL_SAMPLER_2D; - SAMPLER_CUBE = GL20.GL_SAMPLER_CUBE; - - LOW_FLOAT = ARBES2Compatibility.GL_LOW_FLOAT; - MEDIUM_FLOAT = ARBES2Compatibility.GL_MEDIUM_FLOAT; - HIGH_FLOAT = ARBES2Compatibility.GL_HIGH_FLOAT; - LOW_INT = ARBES2Compatibility.GL_LOW_INT; - MEDIUM_INT = ARBES2Compatibility.GL_MEDIUM_INT; - HIGH_INT = ARBES2Compatibility.GL_HIGH_INT; - - CURRENT_VERTEX_ATTRIB = GL20.GL_CURRENT_VERTEX_ATTRIB; - - VERTEX_ATTRIB_ARRAY_BUFFER_BINDING = GL15.GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING; - VERTEX_ATTRIB_ARRAY_ENABLED = GL20.GL_VERTEX_ATTRIB_ARRAY_ENABLED; - VERTEX_ATTRIB_ARRAY_SIZE = GL20.GL_VERTEX_ATTRIB_ARRAY_SIZE; - VERTEX_ATTRIB_ARRAY_STRIDE = GL20.GL_VERTEX_ATTRIB_ARRAY_STRIDE; - VERTEX_ATTRIB_ARRAY_TYPE = GL20.GL_VERTEX_ATTRIB_ARRAY_TYPE; - VERTEX_ATTRIB_ARRAY_NORMALIZED = GL20.GL_VERTEX_ATTRIB_ARRAY_NORMALIZED; - VERTEX_ATTRIB_ARRAY_POINTER = GL20.GL_VERTEX_ATTRIB_ARRAY_POINTER; - - BLEND = GL11.GL_BLEND; - ONE = GL11.GL_ONE; - ZERO = GL11.GL_ZERO; - SRC_ALPHA = GL11.GL_SRC_ALPHA; - DST_ALPHA = GL11.GL_DST_ALPHA; - ONE_MINUS_SRC_ALPHA = GL11.GL_ONE_MINUS_SRC_ALPHA; - ONE_MINUS_DST_COLOR = GL11.GL_ONE_MINUS_DST_COLOR; - ONE_MINUS_SRC_COLOR = GL11.GL_ONE_MINUS_SRC_COLOR; - DST_COLOR = GL11.GL_DST_COLOR; - SRC_COLOR = GL11.GL_SRC_COLOR; - - SAMPLE_ALPHA_TO_COVERAGE = GL13.GL_SAMPLE_ALPHA_TO_COVERAGE; - SAMPLE_COVERAGE = GL13.GL_SAMPLE_COVERAGE; - - KEEP = GL11.GL_KEEP; - REPLACE = GL11.GL_REPLACE; - INCR = GL11.GL_INCR; - DECR = GL11.GL_DECR; - INVERT = GL11.GL_INVERT; - INCR_WRAP = GL14.GL_INCR_WRAP; - DECR_WRAP = GL14.GL_DECR_WRAP; - NEVER = GL11.GL_NEVER; - ALWAYS = GL11.GL_ALWAYS; - - EQUAL = GL11.GL_EQUAL; - LESS = GL11.GL_LESS; - LEQUAL = GL11.GL_LEQUAL; - GREATER = GL11.GL_GREATER; - GEQUAL = GL11.GL_GEQUAL; - NOTEQUAL = GL11.GL_NOTEQUAL; - - FUNC_ADD = GL14.GL_FUNC_ADD; - FUNC_MIN = GL14.GL_MIN; - FUNC_MAX = GL14.GL_MAX; - FUNC_REVERSE_SUBTRACT = GL14.GL_FUNC_REVERSE_SUBTRACT; - FUNC_SUBTRACT = GL14.GL_FUNC_SUBTRACT; - - DITHER = GL11.GL_DITHER; - - CONSTANT_COLOR = GL11.GL_CONSTANT_COLOR; - CONSTANT_ALPHA = GL11.GL_CONSTANT_ALPHA; - ONE_MINUS_CONSTANT_COLOR = GL11.GL_ONE_MINUS_CONSTANT_COLOR; - ONE_MINUS_CONSTANT_ALPHA = GL11.GL_ONE_MINUS_CONSTANT_ALPHA; - SRC_ALPHA_SATURATE = GL11.GL_SRC_ALPHA_SATURATE; - - SCISSOR_TEST = GL11.GL_SCISSOR_TEST; - STENCIL_TEST = GL11.GL_STENCIL_TEST; - DEPTH_TEST = GL11.GL_DEPTH_TEST; - DEPTH_WRITEMASK = GL11.GL_DEPTH_WRITEMASK; - ALPHA_TEST = GL11.GL_ALPHA_TEST; - - COLOR_BUFFER_BIT = GL11.GL_COLOR_BUFFER_BIT; - DEPTH_BUFFER_BIT = GL11.GL_DEPTH_BUFFER_BIT; - STENCIL_BUFFER_BIT = GL11.GL_STENCIL_BUFFER_BIT; - - FRAMEBUFFER = GL30.GL_FRAMEBUFFER; - COLOR_ATTACHMENT0 = GL30.GL_COLOR_ATTACHMENT0; - COLOR_ATTACHMENT1 = GL30.GL_COLOR_ATTACHMENT1; - COLOR_ATTACHMENT2 = GL30.GL_COLOR_ATTACHMENT2; - COLOR_ATTACHMENT3 = GL30.GL_COLOR_ATTACHMENT3; - RENDERBUFFER = GL30.GL_RENDERBUFFER; - DEPTH_ATTACHMENT = GL30.GL_DEPTH_ATTACHMENT; - STENCIL_ATTACHMENT = GL30.GL_STENCIL_ATTACHMENT; - READ_FRAMEBUFFER = GL30.GL_READ_FRAMEBUFFER; - DRAW_FRAMEBUFFER = GL30.GL_DRAW_FRAMEBUFFER; - - DEPTH24_STENCIL8 = GL30.GL_DEPTH24_STENCIL8; - - DEPTH_COMPONENT = GL11.GL_DEPTH_COMPONENT; - DEPTH_COMPONENT16 = GL14.GL_DEPTH_COMPONENT16; - DEPTH_COMPONENT24 = GL14.GL_DEPTH_COMPONENT24; - DEPTH_COMPONENT32 = GL14.GL_DEPTH_COMPONENT32; - - STENCIL_INDEX = GL11.GL_STENCIL_INDEX; - STENCIL_INDEX1 = GL30.GL_STENCIL_INDEX1; - STENCIL_INDEX4 = GL30.GL_STENCIL_INDEX4; - STENCIL_INDEX8 = GL30.GL_STENCIL_INDEX8; - - DEPTH_STENCIL = GL30.GL_DEPTH_STENCIL; - - FRAMEBUFFER_COMPLETE = GL30.GL_FRAMEBUFFER_COMPLETE; - FRAMEBUFFER_INCOMPLETE_ATTACHMENT = GL30.GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT; - FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT = GL30.GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT; - FRAMEBUFFER_INCOMPLETE_DIMENSIONS = EXTFramebufferObject.GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT; - FRAMEBUFFER_INCOMPLETE_FORMATS = EXTFramebufferObject.GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT; - FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER = GL30.GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER; - FRAMEBUFFER_INCOMPLETE_READ_BUFFER = GL30.GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER; - FRAMEBUFFER_UNSUPPORTED = GL30.GL_FRAMEBUFFER_UNSUPPORTED; - - FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE = GL30.GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE; - FRAMEBUFFER_ATTACHMENT_OBJECT_NAME = GL30.GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME; - FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL = GL30.GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL; - FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE = GL30.GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE; - - RENDERBUFFER_WIDTH = GL30.GL_RENDERBUFFER_WIDTH; - RENDERBUFFER_HEIGHT = GL30.GL_RENDERBUFFER_HEIGHT; - RENDERBUFFER_RED_SIZE = GL30.GL_RENDERBUFFER_RED_SIZE; - RENDERBUFFER_GREEN_SIZE = GL30.GL_RENDERBUFFER_GREEN_SIZE; - RENDERBUFFER_BLUE_SIZE = GL30.GL_RENDERBUFFER_BLUE_SIZE; - RENDERBUFFER_ALPHA_SIZE = GL30.GL_RENDERBUFFER_ALPHA_SIZE; - RENDERBUFFER_DEPTH_SIZE = GL30.GL_RENDERBUFFER_DEPTH_SIZE; - RENDERBUFFER_STENCIL_SIZE = GL30.GL_RENDERBUFFER_STENCIL_SIZE; - RENDERBUFFER_INTERNAL_FORMAT = GL30.GL_RENDERBUFFER_INTERNAL_FORMAT; - - MULTISAMPLE = GL13.GL_MULTISAMPLE; - POINT_SMOOTH = GL11.GL_POINT_SMOOTH; - LINE_SMOOTH = GL11.GL_LINE_SMOOTH; - POLYGON_SMOOTH = GL11.GL_POLYGON_SMOOTH; - } - - /////////////////////////////////////////////////////////// - - // Special Functions - - public void flush() { - GL11.glFlush(); - } - - public void finish() { - GL11.glFinish(); - } - - public void hint(int target, int hint) { - GL11.glHint(target, hint); - } - - /////////////////////////////////////////////////////////// - - // State and State Requests - - public void enable(int value) { - if (-1 < value) { - GL11.glEnable(value); - } - } - - public void disable(int value) { - if (-1 < value) { - GL11.glDisable(value); - } - } - - public void getBooleanv(int value, IntBuffer data) { - if (-1 < value) { - if (byteBuffer.capacity() < data.capacity()) { - byteBuffer = allocateDirectByteBuffer(data.capacity()); - } - GL11.glGetBoolean(value, byteBuffer); - for (int i = 0; i < data.capacity(); i++) { - data.put(i, byteBuffer.get(i)); - } - } else { - fillIntBuffer(data, 0, data.capacity() - 1, 0); - } - } - - public void getIntegerv(int value, IntBuffer data) { - if (-1 < value) { - GL11.glGetInteger(value, data); - } else { - fillIntBuffer(data, 0, data.capacity() - 1, 0); - } - } - - public void getFloatv(int value, FloatBuffer data) { - if (-1 < value) { - GL11.glGetFloat(value, data); - } else { - fillFloatBuffer(data, 0, data.capacity() - 1, 0); - } - } - - public boolean isEnabled(int value) { - return GL11.glIsEnabled(value); - } - - public String getString(int name) { - return GL11.glGetString(name); - } - - /////////////////////////////////////////////////////////// - - // Error Handling - - public int getError() { - return GL11.glGetError(); - } - - public String errorString(int err) { - return GLU.gluErrorString(err); - } - - ////////////////////////////////////////////////////////////////////////////// - - // Buffer Objects - - public void genBuffers(int n, IntBuffer buffers) { - GL15.glGenBuffers(buffers); - } - - public void deleteBuffers(int n, IntBuffer buffers) { - GL15.glDeleteBuffers(buffers); - } - - public void bindBuffer(int target, int buffer) { - GL15.glBindBuffer(target, buffer); - } - - public void bufferData(int target, int size, Buffer data, int usage) { - if (data == null) { - FloatBuffer empty = BufferUtils.createFloatBuffer(size); - GL15.glBufferData(target, empty, usage); - } else { - if (data instanceof ByteBuffer) { - GL15.glBufferData(target, (ByteBuffer)data, usage); - } else if (data instanceof ShortBuffer) { - GL15.glBufferData(target, (ShortBuffer)data, usage); - } else if (data instanceof IntBuffer) { - GL15.glBufferData(target, (IntBuffer)data, usage); - } else if (data instanceof FloatBuffer) { - GL15.glBufferData(target, (FloatBuffer)data, usage); - } - } - } - - public void bufferSubData(int target, int offset, int size, Buffer data) { - if (data instanceof ByteBuffer) { - GL15.glBufferSubData(target, offset, (ByteBuffer)data); - } else if (data instanceof ShortBuffer) { - GL15.glBufferSubData(target, offset, (ShortBuffer)data); - } else if (data instanceof IntBuffer) { - GL15.glBufferSubData(target, offset, (IntBuffer)data); - } else if (data instanceof FloatBuffer) { - GL15.glBufferSubData(target, offset, (FloatBuffer)data); - } - } - - public void isBuffer(int buffer) { - GL15.glIsBuffer(buffer); - } - - public void getBufferParameteriv(int target, int value, IntBuffer data) { - if (-1 < value) { - int res = GL15.glGetBufferParameteri(target, value); - data.put(0, res); - } else { - data.put(0, 0); - } - } - - public ByteBuffer mapBuffer(int target, int access) { - return GL15.glMapBuffer(target, access, null); - } - - public ByteBuffer mapBufferRange(int target, int offset, int length, int access) { - return GL30.glMapBufferRange(target, offset, length, access, null); - } - - public void unmapBuffer(int target) { - GL15.glUnmapBuffer(target); - } - - ////////////////////////////////////////////////////////////////////////////// - - // Viewport and Clipping - - public void depthRangef(float n, float f) { - GL11.glDepthRange(n, f); - } - - public void viewport(int x, int y, int w, int h) { - float f = Display.getPixelScaleFactor(); - GL11.glViewport((int)(f * x), (int)(f * y), (int)f * w, (int)(f * h)); - } - - ////////////////////////////////////////////////////////////////////////////// - - // Reading Pixels - - protected void readPixelsImpl(int x, int y, int width, int height, int format, int type, Buffer buffer) { - GL11.glReadPixels(x, y, width, height, format, type, (IntBuffer)buffer); - } - - ////////////////////////////////////////////////////////////////////////////// - - // Vertices - - public void vertexAttrib1f(int index, float value) { - GL20.glVertexAttrib1f(index, value); - } - - public void vertexAttrib2f(int index, float value0, float value1) { - GL20.glVertexAttrib2f(index, value0, value1); - } - - public void vertexAttrib3f(int index, float value0, float value1, float value2) { - GL20.glVertexAttrib3f(index, value0, value1, value2); - } - - public void vertexAttrib4f(int index, float value0, float value1, float value2, float value3) { - GL20.glVertexAttrib4f(index, value0, value1, value2, value3); - } - - public void vertexAttrib1fv(int index, FloatBuffer values) { - GL20.glVertexAttrib1f(index, values.get()); - } - - public void vertexAttrib2fv(int index, FloatBuffer values) { - GL20.glVertexAttrib2f(index, values.get(), values.get()); - } - - public void vertexAttrib3fv(int index, FloatBuffer values) { - GL20.glVertexAttrib3f(index, values.get(), values.get(), values.get()); - } - - public void vertexAttri4fv(int index, FloatBuffer values) { - GL20.glVertexAttrib4f(index, values.get(), values.get(), values.get(), values.get()); - } - - public void vertexAttribPointer(int index, int size, int type, boolean normalized, int stride, int offset) { - GL20.glVertexAttribPointer(index, size, type, normalized, stride, offset); - } - - public void vertexAttribPointer(int index, int size, int type, boolean normalized, int stride, Buffer data) { - if (type == UNSIGNED_INT) { - GL20.glVertexAttribPointer(index, size, true, normalized, stride, (IntBuffer)data); - } else if (type == UNSIGNED_BYTE) { - GL20.glVertexAttribPointer(index, size, true, normalized, stride, (ByteBuffer)data); - } else if (type == UNSIGNED_SHORT) { - GL20.glVertexAttribPointer(index, size, true, normalized, stride, (ShortBuffer)data); - } else if (type == FLOAT) { - GL20.glVertexAttribPointer(index, size, normalized, stride, (FloatBuffer)data); - } - } - - public void enableVertexAttribArray(int index) { - GL20.glEnableVertexAttribArray(index); - } - - public void disableVertexAttribArray(int index) { - GL20.glDisableVertexAttribArray(index); - } - - public void drawArrays(int mode, int first, int count) { - GL11.glDrawArrays(mode, first, count); - } - - public void drawElements(int mode, int count, int type, int offset) { - GL11.glDrawElements(mode, count, type, offset); - } - - public void drawElements(int mode, int count, int type, Buffer indices) { - if (type == UNSIGNED_INT) { - GL11.glDrawElements(mode, (IntBuffer)indices); - } else if (type == UNSIGNED_BYTE) { - GL11.glDrawElements(mode, (ByteBuffer)indices); - } else if (type == UNSIGNED_SHORT) { - GL11.glDrawElements(mode, (ShortBuffer)indices); - } - } - - ////////////////////////////////////////////////////////////////////////////// - - // Rasterization - - public void lineWidth(float width) { - GL11.glLineWidth(width); - } - - public void frontFace(int dir) { - GL11.glFrontFace(dir); - } - - public void cullFace(int mode) { - GL11.glCullFace(mode); - } - - public void polygonOffset(float factor, float units) { - GL11.glPolygonOffset(factor, units); - } - - ////////////////////////////////////////////////////////////////////////////// - - // Pixel Rectangles - - public void pixelStorei(int pname, int param) { - GL11.glPixelStorei(pname, param); - } - - /////////////////////////////////////////////////////////// - - // Texturing - - public void texImage2D(int target, int level, int internalFormat, int width, int height, int border, int format, int type, Buffer data) { - GL11.glTexImage2D(target, level, internalFormat, width, height, border, format, type, (IntBuffer)data); - } - - public void copyTexImage2D(int target, int level, int internalFormat, int x, int y, int width, int height, int border) { - GL11.glCopyTexImage2D(target, level, internalFormat, x, y, width, height, border); - } - - public void texSubImage2D(int target, int level, int xOffset, int yOffset, int width, int height, int format, int type, Buffer data) { - GL11.glTexSubImage2D(target, level, xOffset, yOffset, width, height, format, type, (IntBuffer)data); - } - - public void copyTexSubImage2D(int target, int level, int xOffset, int yOffset, int x, int y, int width, int height) { - GL11.glCopyTexSubImage2D(target, level, x, y, xOffset, yOffset, width, height); - } - - public void compressedTexImage2D(int target, int level, int internalFormat, int width, int height, int border, int imageSize, Buffer data) { - GL13.glCompressedTexImage2D(target, level, internalFormat, width, height, border, (ByteBuffer)data); - } - - public void compressedTexSubImage2D(int target, int level, int xOffset, int yOffset, int width, int height, int format, int imageSize, Buffer data) { - GL13.glCompressedTexSubImage2D(target, level, xOffset, yOffset, width, height, format, (ByteBuffer)data); - } - - public void texParameteri(int target, int pname, int param) { - GL11.glTexParameteri(target, pname, param); - } - - public void texParameterf(int target, int pname, float param) { - GL11.glTexParameterf(target, pname, param); - } - - public void texParameteriv(int target, int pname, IntBuffer params) { - GL11.glTexParameteri(target, pname, params.get()); - } - - public void texParameterfv(int target, int pname, FloatBuffer params) { - GL11.glTexParameterf(target, pname, params.get()); - } - - public void generateMipmap(int target) { - GL30.glGenerateMipmap(target); - } - - public void genTextures(int n, IntBuffer textures) { - GL11.glGenTextures(textures); - } - - public void deleteTextures(int n, IntBuffer textures) { - GL11.glDeleteTextures(textures); - } - - public void getTexParameteriv(int target, int pname, IntBuffer params) { - GL11.glGetTexParameter(target, pname, params); - } - - public void getTexParameterfv(int target, int pname, FloatBuffer params) { - GL11.glGetTexParameter(target, pname, params); - } - - public boolean isTexture(int texture) { - return GL11.glIsTexture(texture); - } - - protected void activeTextureImpl(int texture) { - GL13.glActiveTexture(texture); - } - - protected void bindTextureImpl(int target, int texture) { - GL11.glBindTexture(target, texture); - } - - /////////////////////////////////////////////////////////// - - // Shaders and Programs - - public int createShader(int type) { - return GL20.glCreateShader(type); - } - - public void shaderSource(int shader, String source) { - GL20.glShaderSource(shader, source); - } - - public void compileShader(int shader) { - GL20.glCompileShader(shader); - } - - public void releaseShaderCompiler() { - throw new RuntimeException(String.format(MISSING_GLFUNC_ERROR, "glReleaseShaderCompiler()")); - } - - public void deleteShader(int shader) { - GL20.glDeleteShader(shader); - } - - public void shaderBinary(int count, IntBuffer shaders, int binaryFormat, Buffer binary, int length) { - throw new RuntimeException(String.format(MISSING_GLFUNC_ERROR, "glShaderBinary()")); - } - - public int createProgram() { - return GL20.glCreateProgram(); - } - - public void attachShader(int program, int shader) { - GL20.glAttachShader(program, shader); - } - - public void detachShader(int program, int shader) { - GL20.glDetachShader(program, shader); - } - - public void linkProgram(int program) { - GL20.glLinkProgram(program); - } - - public void useProgram(int program) { - GL20.glUseProgram(program); - } - - public void deleteProgram(int program) { - GL20.glDeleteProgram(program); - } - - public String getActiveAttrib (int program, int index, IntBuffer size, IntBuffer type) { - IntBuffer typeTmp = BufferUtils.createIntBuffer(2); - String name = GL20.glGetActiveAttrib(program, index, 256, typeTmp); - size.put(typeTmp.get(0)); - type.put(typeTmp.get(1)); - return name; - } - - public int getAttribLocation(int program, String name) { - return GL20.glGetAttribLocation(program, name); - } - - public void bindAttribLocation(int program, int index, String name) { - GL20.glBindAttribLocation(program, index, name); - } - - public int getUniformLocation(int program, String name) { - return GL20.glGetUniformLocation(program, name); - } - - public String getActiveUniform(int program, int index, IntBuffer size, IntBuffer type) { - IntBuffer typeTmp = BufferUtils.createIntBuffer(2); - String name = GL20.glGetActiveUniform(program, index, 256, typeTmp); - type.put(typeTmp.get(0)); - return name; - } - - public void uniform1i(int location, int value) { - GL20.glUniform1i(location, value); - } - - public void uniform2i(int location, int value0, int value1) { - GL20.glUniform2i(location, value0, value1); - } - - public void uniform3i(int location, int value0, int value1, int value2) { - GL20.glUniform3i(location, value0, value1, value2); - } - - public void uniform4i(int location, int value0, int value1, int value2, int value3) { - GL20.glUniform4i(location, value0, value1, value2, value3); - } - - public void uniform1f(int location, float value) { - GL20.glUniform1f(location, value); - } - - public void uniform2f(int location, float value0, float value1) { - GL20.glUniform2f(location, value0, value1); - } - - public void uniform3f(int location, float value0, float value1, float value2) { - GL20.glUniform3f(location, value0, value1, value2); - } - - public void uniform4f(int location, float value0, float value1, float value2, float value3) { - GL20.glUniform4f(location, value0, value1, value2, value3); - } - - public void uniform1iv(int location, int count, IntBuffer v) { - v.limit(count); - GL20.glUniform1(location, v); - v.clear(); - } - - public void uniform2iv(int location, int count, IntBuffer v) { - v.limit(2 * count); - GL20.glUniform2(location, v); - v.clear(); - } - - public void uniform3iv(int location, int count, IntBuffer v) { - v.limit(3 * count); - GL20.glUniform3(location, v); - v.clear(); - } - - public void uniform4iv(int location, int count, IntBuffer v) { - v.limit(4 * count); - GL20.glUniform4(location, v); - v.clear(); - } - - public void uniform1fv(int location, int count, FloatBuffer v) { - v.limit(count); - GL20.glUniform1(location, v); - v.clear(); - } - - public void uniform2fv(int location, int count, FloatBuffer v) { - v.limit(2 * count); - GL20.glUniform2(location, v); - v.clear(); - } - - public void uniform3fv(int location, int count, FloatBuffer v) { - v.limit(3 * count); - GL20.glUniform3(location, v); - v.clear(); - } - - public void uniform4fv(int location, int count, FloatBuffer v) { - v.limit(4 * count); - GL20.glUniform4(location, v); - v.clear(); - } - - public void uniformMatrix2fv(int location, int count, boolean transpose, FloatBuffer mat) { - mat.limit(4); - GL20.glUniformMatrix2(location, transpose, mat); - mat.clear(); - } - - public void uniformMatrix3fv(int location, int count, boolean transpose, FloatBuffer mat) { - mat.limit(9); - GL20.glUniformMatrix3(location, transpose, mat); - mat.clear(); - } - - public void uniformMatrix4fv(int location, int count, boolean transpose, FloatBuffer mat) { - mat.limit(16); - GL20.glUniformMatrix4(location, transpose, mat); - mat.clear(); - } - - public void validateProgram(int program) { - GL20.glValidateProgram(program); - } - - public boolean isShader(int shader) { - return GL20.glIsShader(shader); - } - - public void getShaderiv(int shader, int pname, IntBuffer params) { - GL20.glGetShader(shader, pname, params); - } - - public void getAttachedShaders(int program, int maxCount, IntBuffer count, IntBuffer shaders) { - GL20.glGetAttachedShaders(program, count, shaders); - } - - public String getShaderInfoLog(int shader) { - int len = GL20.glGetShaderi(shader, GL20.GL_INFO_LOG_LENGTH); - return GL20.glGetShaderInfoLog(shader, len); - } - - public String getShaderSource(int shader) { - int len = GL20.glGetShaderi(shader, GL20.GL_SHADER_SOURCE_LENGTH); - return GL20.glGetShaderSource(shader, len); - } - - public void getShaderPrecisionFormat(int shaderType, int precisionType, IntBuffer range, IntBuffer precision) { - throw new RuntimeException(String.format(MISSING_GLFUNC_ERROR, "glGetShaderPrecisionFormat()")); - } - - public void getVertexAttribfv(int index, int pname, FloatBuffer params) { - GL20.glGetVertexAttrib(index, pname, params); - } - - public void getVertexAttribiv(int index, int pname, IntBuffer params) { - GL20.glGetVertexAttrib(index, pname, params); - } - - public void getVertexAttribPointerv(int index, int pname, ByteBuffer data) { - int len = data.capacity(); - ByteBuffer res = GL20.glGetVertexAttribPointer(index, pname, len); - data.put(res); - } - - public void getUniformfv(int program, int location, FloatBuffer params) { - GL20.glGetUniform(program, location, params); - } - - public void getUniformiv(int program, int location, IntBuffer params) { - GL20.glGetUniform(program, location, params); - } - - public boolean isProgram(int program) { - return GL20.glIsProgram(program); - } - - public void getProgramiv(int program, int pname, IntBuffer params) { - GL20.glGetProgram(program, pname, params); - } - - public String getProgramInfoLog(int program) { - int len = GL20.glGetProgrami(program, GL20.GL_INFO_LOG_LENGTH); - return GL20.glGetProgramInfoLog(program, len); - } - - /////////////////////////////////////////////////////////// - - // Per-Fragment Operations - - public void scissor(int x, int y, int w, int h) { - float f = Display.getPixelScaleFactor(); - GL11.glScissor((int)(f * x), (int)(f * y), (int)f * w, (int)(f * h)); - } - - public void sampleCoverage(float value, boolean invert) { - GL13.glSampleCoverage(value, invert); - } - - public void stencilFunc(int func, int ref, int mask) { - GL11.glStencilFunc(func, ref, mask); - } - - public void stencilFuncSeparate(int face, int func, int ref, int mask) { - GL20.glStencilFuncSeparate(face, func, ref, mask); - } - - public void stencilOp(int sfail, int dpfail, int dppass) { - GL11.glStencilOp(sfail, dpfail, dppass); - } - - public void stencilOpSeparate(int face, int sfail, int dpfail, int dppass) { - GL20.glStencilOpSeparate(face, sfail, dpfail, dppass); - } - - public void depthFunc(int func) { - GL11.glDepthFunc(func); - } - - public void blendEquation(int mode) { - GL14.glBlendEquation(mode); - } - - public void blendEquationSeparate(int modeRGB, int modeAlpha) { - GL20.glBlendEquationSeparate(modeRGB, modeAlpha); - } - - public void blendFunc(int src, int dst) { - GL11.glBlendFunc(src, dst); - } - - public void blendFuncSeparate(int srcRGB, int dstRGB, int srcAlpha, int dstAlpha) { - GL14.glBlendFuncSeparate(srcRGB, dstRGB, srcAlpha, dstAlpha); - } - - public void blendColor(float red, float green, float blue, float alpha) { - GL14.glBlendColor(red, green, blue, alpha); - } - - public void alphaFunc(int func, float ref) { - GL11.glAlphaFunc(func, ref); - } - - /////////////////////////////////////////////////////////// - - // Whole Framebuffer Operations - - public void colorMask(boolean r, boolean g, boolean b, boolean a) { - GL11.glColorMask(r, g, b, a); - } - - public void depthMask(boolean mask) { - GL11.glDepthMask(mask); - } - - public void stencilMask(int mask) { - GL11.glStencilMask(mask); - } - - public void stencilMaskSeparate(int face, int mask) { - GL20.glStencilMaskSeparate(face, mask); - } - - public void clear(int buf) { - GL11.glClear(buf); - } - - public void clearColor(float r, float g, float b, float a) { - GL11.glClearColor(r, g, b, a); - } - - public void clearDepth(float d) { - GL11.glClearDepth(d); - } - - public void clearStencil(int s) { - GL11.glClearStencil(s); - } - - /////////////////////////////////////////////////////////// - - // Framebuffers Objects - - protected void bindFramebufferImpl(int target, int framebuffer) { - GL30.glBindFramebuffer(target, framebuffer); - } - - public void deleteFramebuffers(int n, IntBuffer framebuffers) { - GL30.glDeleteFramebuffers(framebuffers); - } - - public void genFramebuffers(int n, IntBuffer framebuffers) { - GL30.glGenFramebuffers(framebuffers); - } - - public void bindRenderbuffer(int target, int renderbuffer) { - GL30.glBindRenderbuffer(target, renderbuffer); - } - - public void deleteRenderbuffers(int n, IntBuffer renderbuffers) { - GL30.glDeleteRenderbuffers(renderbuffers); - } - - public void genRenderbuffers(int n, IntBuffer renderbuffers) { - GL30.glGenRenderbuffers(renderbuffers); - } - - public void renderbufferStorage(int target, int internalFormat, int width, int height) { - GL30.glRenderbufferStorage(target, internalFormat, width, height); - } - - public void framebufferRenderbuffer(int target, int attachment, int rendbuferfTarget, int renderbuffer) { - GL30.glFramebufferRenderbuffer(target, attachment, rendbuferfTarget, renderbuffer); - } - - public void framebufferTexture2D(int target, int attachment, int texTarget, int texture, int level) { - GL30.glFramebufferTexture2D(target, attachment, texTarget, texture, level); - } - - public int checkFramebufferStatus(int target) { - return GL30.glCheckFramebufferStatus(target); - } - - public boolean isFramebuffer(int framebuffer) { - return GL30.glIsFramebuffer(framebuffer); - } - - public void getFramebufferAttachmentParameteriv(int target, int attachment, int pname, IntBuffer params) { - GL30.glGetFramebufferAttachmentParameter(target, attachment, pname, params); - } - - public boolean isRenderbuffer(int renderbuffer) { - return GL30.glIsRenderbuffer(renderbuffer); - } - - public void getRenderbufferParameteriv(int target, int pname, IntBuffer params) { - GL30.glGetRenderbufferParameter(target, pname, params); - } - - public void blitFramebuffer(int srcX0, int srcY0, int srcX1, int srcY1, int dstX0, int dstY0, int dstX1, int dstY1, int mask, int filter) { - GL30.glBlitFramebuffer(srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1, mask, filter); - } - - public void renderbufferStorageMultisample(int target, int samples, int format, int width, int height) { - GL30.glRenderbufferStorageMultisample(target, samples, format, width, height); - } - - public void readBuffer(int buf) { - GL11.glReadBuffer(buf); - } - - public void drawBuffer(int buf) { - GL11.glDrawBuffer(buf); - } - - - @Override - protected void getGL(PGL pgl) { - } -} diff --git a/java/libraries/lwjgl/src/processing/lwjgl/PSurfaceLWJGL.java b/java/libraries/lwjgl/src/processing/lwjgl/PSurfaceLWJGL.java deleted file mode 100644 index f40701b56..000000000 --- a/java/libraries/lwjgl/src/processing/lwjgl/PSurfaceLWJGL.java +++ /dev/null @@ -1,1138 +0,0 @@ -package processing.lwjgl; - -//import java.awt.BorderLayout; -import java.awt.Canvas; -import java.awt.Color; -import java.awt.Dimension; -import java.awt.Frame; -import java.awt.GraphicsConfiguration; -import java.awt.GraphicsDevice; -import java.awt.GraphicsEnvironment; -//import java.awt.Insets; -import java.awt.Rectangle; -import java.awt.geom.Rectangle2D; -import java.awt.image.BufferedImage; -import java.nio.IntBuffer; -import java.lang.reflect.Field; - -import javax.swing.JFrame; - -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; -import org.lwjgl.opengl.DisplayMode; -import org.lwjgl.opengl.PixelFormat; - -import processing.core.PApplet; -import processing.core.PConstants; -import processing.core.PGraphics; -import processing.core.PImage; -import processing.core.PSurface; -import processing.event.Event; -import processing.event.KeyEvent; -import processing.event.MouseEvent; -import processing.opengl.PGL; -import processing.opengl.PGraphicsOpenGL; - -public class PSurfaceLWJGL implements PSurface { - GraphicsDevice displayDevice; - PApplet sketch; - PGraphics graphics; - - int sketchWidth; - int sketchHeight; - - Frame frame; - // Note that x and y may not be zero, depending on the display configuration - Rectangle screenRect; - - PLWJGL pgl; - - boolean fullScreenRequested; - - int cursorType = PConstants.ARROW; // cursor type - boolean cursorVisible = true; // cursor visibility flag - Cursor invisibleCursor; - Cursor currentCursor; - - // ........................................................ - - // Event handling - - boolean externalMessages = false; - - /** Poller threads to get the keyboard/mouse events from LWJGL */ - protected static KeyPoller keyPoller; - protected static MousePoller mousePoller; - - protected static DisplayResarter restarter; - - Thread thread; - boolean paused; - Object pauseObject = new Object(); - - /** As of release 0116, frameRate(60) is called as a default */ - protected float frameRateTarget = 60; -// protected long frameRatePeriod = 1000000000L / 60L; - - PSurfaceLWJGL(PGraphics graphics) { - this.graphics = graphics; - this.pgl = (PLWJGL) ((PGraphicsOpenGL)graphics).pgl; - } - - @Override - public void initOffscreen() { - } - - @Override - public Canvas initCanvas(PApplet sketch) { - this.sketch = sketch; - - sketchWidth = sketch.sketchWidth(); - sketchHeight = sketch.sketchHeight(); - - Canvas canvas = new Canvas(); - canvas.setFocusable(true); - canvas.requestFocus(); - canvas.setBounds(0, 0, sketchWidth, sketchHeight); - try { - Display.setParent(canvas); - return canvas; - } catch (LWJGLException e) { - e.printStackTrace(); - } - return null; - } - - @Override - public Frame initFrame(PApplet sketch, Color backgroundColor, - int deviceIndex, boolean fullScreen, boolean spanDisplays) { - this.sketch = sketch; - - GraphicsEnvironment environment = - GraphicsEnvironment.getLocalGraphicsEnvironment(); - - DisplayMode desktopMode = Display.getDesktopDisplayMode(); - PApplet.println("DESKTOP MODES"); - PApplet.println(desktopMode); - PApplet.println("ALL MODES"); - try { - DisplayMode[] allModes = Display.getAvailableDisplayModes(); - for (DisplayMode mode: allModes) { - PApplet.println(mode); - } - } catch (LWJGLException e) { - e.printStackTrace(); - } - - if (deviceIndex >= 0) { // if -1, use the default device - GraphicsDevice[] devices = environment.getScreenDevices(); - if (deviceIndex < devices.length) { - displayDevice = devices[deviceIndex]; - } else { - System.err.format("Display %d does not exist, " + - "using the default display instead.", deviceIndex); - for (int i = 0; i < devices.length; i++) { - System.err.format("Display %d is %s\n", i, devices[i]); - } - } - } - if (displayDevice == null) { - displayDevice = environment.getDefaultScreenDevice(); - } - - // Need to save the window bounds at full screen, - // because pack() will cause the bounds to go to zero. - // http://dev.processing.org/bugs/show_bug.cgi?id=923 - screenRect = spanDisplays ? getDisplaySpan() : - displayDevice.getDefaultConfiguration().getBounds(); - - // Set the displayWidth/Height variables inside PApplet, so that they're - // usable and can even be returned by the sketchWidth()/Height() methods. - sketch.displayWidth = screenRect.width; - sketch.displayHeight = screenRect.height; - - sketchWidth = sketch.sketchWidth(); - sketchHeight = sketch.sketchHeight(); - - // Sketch has already requested to be the same as the screen's - // width and height, so let's roll with full screen mode. - if (screenRect.width == sketchWidth && - screenRect.height == sketchHeight) { - fullScreen = true; - } - -// if (fullScreen || spanDisplays) { - if (spanDisplays) { - sketchWidth = screenRect.width; - sketchHeight = screenRect.height; - } - - if (fullScreen) { - // Called here because the graphics device is needed before we can - // determine whether the sketch wants size(displayWidth, displayHeight), - // and getting the graphics device will be PSurface-specific. - PApplet.hideMenuBar(); - - // Useful hidden switches: - // http://wiki.lwjgl.org/index.php?title=LWJGL_Hidden_Switches - System.setProperty("org.lwjgl.opengl.Window.undecorated", "true"); - fullScreenRequested = true; - } - - if (graphics.is2X()) { - // http://forum.lwjgl.org/index.php?topic=5084.0 - System.setProperty("org.lwjgl.opengl.Display.enableHighDPI", "true"); -// pgl.pixel_scale = 2; - } - - pgl.reqNumSamples = graphics.quality; - - System.err.println("DISPLAY PARENT: " + Display.getParent()); - System.err.println("DISPLAY SMOOTH: " + pgl.reqNumSamples); - - try { - int argb = graphics.backgroundColor; - float r = ((argb >> 16) & 0xff) / 255.0f; - float g = ((argb >> 8) & 0xff) / 255.0f; - float b = ((argb) & 0xff) / 255.0f; - Display.setInitialBackground(r, g, b); - if (fullScreen) { - Display.setDisplayMode(new DisplayMode(screenRect.width, screenRect.height)); - } else { - Display.setDisplayMode(new DisplayMode(sketchWidth, sketchHeight)); - } - - System.err.println(sketchWidth + " " + sketchHeight); - if (fullScreenRequested) { - Display.setFullscreen(true); - } - } catch (LWJGLException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - - restarter = new DisplayResarter(); - restarter.start(); - - -// sketchWidth = sketch.width = sketch.sketchWidth(); -// sketchHeight = sketch.height = sketch.sketchHeight(); - - frame = new DummyFrame(); - return frame; - } - - // get the bounds for all displays - static Rectangle getDisplaySpan() { - Rectangle bounds = new Rectangle(); - GraphicsEnvironment environment = - GraphicsEnvironment.getLocalGraphicsEnvironment(); - for (GraphicsDevice device : environment.getScreenDevices()) { - for (GraphicsConfiguration config : device.getConfigurations()) { - Rectangle2D.union(bounds, config.getBounds(), bounds); - } - } - return bounds; - } - - @Override - public void setTitle(String title) { - Display.setTitle(title); - - } - - @Override - public void setVisible(boolean visible) { - // Apparently not possible: - // http://forum.lwjgl.org/index.php?topic=5388.0 - System.err.println("Sorry, cannot set visibility of window in OpenGL"); - } - - @Override - public void setResizable(boolean resizable) { - Display.setResizable(resizable); - } - - @Override - public void placeWindow(int[] location) { - if (location != null) { - // a specific location was received from the Runner - // (applet has been run more than once, user placed window) - Display.setLocation(location[0], location[1]); - } else { // just center on screen - // Can't use frame.setLocationRelativeTo(null) because it sends the - // frame to the main display, which undermines the --display setting. - setFrameCentered(); - } - - if (Display.getY() < 0) { - // Windows actually allows you to place frames where they can't be - // closed. Awesome. http://dev.processing.org/bugs/show_bug.cgi?id=1508 - Display.setLocation(Display.getX(), 30); - } - } - - @Override - public void placeWindow(int[] location, int[] editorLocation) { - if (location != null) { - // a specific location was received from the Runner - // (applet has been run more than once, user placed window) - frame.setLocation(location[0], location[1]); - } else if (editorLocation != null) { - Dimension window = new Dimension(sketchWidth, sketchHeight); - - int locationX = editorLocation[0] - 20; - int locationY = editorLocation[1]; - - if (locationX - window.width > 10) { - // if it fits to the left of the window - Display.setLocation(locationX - window.width, locationY); - - } else { // doesn't fit - // if it fits inside the editor window, - // offset slightly from upper lefthand corner - // so that it's plunked inside the text area - locationX = editorLocation[0] + 66; - locationY = editorLocation[1] + 66; - - if ((locationX + window.width > sketch.displayWidth - 33) || - (locationY + window.height > sketch.displayHeight - 33)) { - // otherwise center on screen - locationX = (sketch.displayWidth - window.width) / 2; - locationY = (sketch.displayHeight - window.height) / 2; - } - Display.setLocation(locationX, locationY); - } - } else { // just center on screen - setFrameCentered(); - } - - if (Display.getY() < 0) { - // Windows actually allows you to place frames where they can't be - // closed. Awesome. http://dev.processing.org/bugs/show_bug.cgi?id=1508 - Display.setLocation(Display.getX(), 30); - } - } - - JFrame presentFrame; - Canvas presentCanvas; - - boolean presentMode = false; - float offsetX; - float offsetY; - @Override - public void placePresent(Color stopColor) { - - if (sketchWidth < screenRect.width || sketchHeight < screenRect.height) { - System.err.println("WILL USE FBO"); - - presentMode = pgl.presentMode = true; - offsetX = pgl.offsetX = 0.5f * (screenRect.width - sketchWidth); - offsetY = pgl.offsetY = 0.5f * (screenRect.height - sketchHeight); - pgl.requestFBOLayer(); - - - -// try { -//// Display.setFullscreen(true); -// Display.setDisplayMode(new DisplayMode(screenRect.width, screenRect.height)); -// } catch (LWJGLException e1) { -// // TODO Auto-generated catch block -// e1.printStackTrace(); -// } - - /* - presentFrame = new JFrame(displayDevice.getDefaultConfiguration()); - presentFrame.getContentPane().setBackground(WINDOW_BGCOLOR); - - -// presentCanvas = new Canvas(); -// presentCanvas.setFocusable(true); -// presentCanvas.requestFocus(); -// presentCanvas.setBounds(0, 0, sketchWidth, sketchHeight); -// -// Insets insets = presentFrame.getInsets(); -// int windowW = Math.max(sketchWidth, MIN_WINDOW_WIDTH) + -// insets.left + insets.right; -// int windowH = Math.max(sketchHeight, MIN_WINDOW_HEIGHT) + -// insets.top + insets.bottom; -// presentFrame.setSize(windowW, windowH); -// presentFrame.setLayout(new BorderLayout()); -// presentFrame.add(presentCanvas, BorderLayout.CENTER); -// - presentFrame.setUndecorated(true); - presentFrame.setBounds(screenRect); - presentFrame.setVisible(true); - presentFrame.setLayout(null); - presentFrame.invalidate(); - presentFrame.setResizable(false); - presentFrame.setAlwaysOnTop(false); -// presentFrame.toBack(); - - - - if (stopColor != null) { - Label label = new Label("stop"); - label.setForeground(stopColor); - label.addMouseListener(new MouseAdapter() { - @Override - public void mousePressed(java.awt.event.MouseEvent e) { - sketch.exit(); - } - }); - presentFrame.add(label); - - Dimension labelSize = label.getPreferredSize(); - // sometimes shows up truncated on mac - //System.out.println("label width is " + labelSize.width); - labelSize = new Dimension(100, labelSize.height); - label.setSize(labelSize); - label.setLocation(20, screenRect.height - labelSize.height - 20); - } - */ - } - - - - - - /* - // After the pack(), the screen bounds are gonna be 0s - frame.setBounds(screenRect); - canvas.setBounds((screenRect.width - sketchWidth) / 2, - (screenRect.height - sketchHeight) / 2, - sketchWidth, sketchHeight); - - if (stopColor != null) { - Label label = new Label("stop"); - label.setForeground(stopColor); - label.addMouseListener(new MouseAdapter() { - @Override - public void mousePressed(java.awt.event.MouseEvent e) { - sketch.exit(); - } - }); - frame.add(label); - - Dimension labelSize = label.getPreferredSize(); - // sometimes shows up truncated on mac - //System.out.println("label width is " + labelSize.width); - labelSize = new Dimension(100, labelSize.height); - label.setSize(labelSize); - label.setLocation(20, screenRect.height - labelSize.height - 20); - } - */ - } - - @Override - public void setupExternalMessages() { - externalMessages = true; - } - - private void setFrameCentered() { - // Can't use frame.setLocationRelativeTo(null) because it sends the - // frame to the main display, which undermines the --display setting. - Display.setLocation(screenRect.x + (screenRect.width - sketchWidth) / 2, - screenRect.y + (screenRect.height - sketchHeight) / 2); - } - - @Override - public void startThread() { - if (thread == null) { - thread = new AnimationThread(); - thread.start(); - } else { - throw new IllegalStateException("Thread already started in PSurfaceLWJGL"); - } - } - - - @Override - public void pauseThread() { - PApplet.debug("PApplet.run() paused, calling object wait..."); - paused = true; - } - - // halts the animation thread if the pause flag is set - protected void checkPause() { - if (paused) { - synchronized (pauseObject) { - try { - pauseObject.wait(); -// PApplet.debug("out of wait"); - } catch (InterruptedException e) { - // waiting for this interrupt on a start() (resume) call - } - } - } -// PApplet.debug("done with pause"); - } - - - @Override - public void resumeThread() { - paused = false; - synchronized (pauseObject) { - pauseObject.notifyAll(); // wake up the animation thread - } - } - - - @Override - public boolean stopThread() { - if (thread == null) { - return false; - } - thread = null; - return true; - - } - - - @Override - public boolean isStopped() { - return thread == null; - } - - - @Override - public void setSize(int width, int height) { - if (frame != null) { - sketchWidth = sketch.width = width; - sketchHeight = sketch.height = height; - graphics.setSize(width, height); - } - } - - - boolean forceExit = false; - @Override - public void setSmooth(int level) { - System.err.println("set smooth " + level); - pgl.reqNumSamples = level; - restarter.changeRequested = true; - } - - - @Override - public void setFrameRate(float fps) { - frameRateTarget = fps; - if (60 < fps) { - // Disables v-sync - System.err.println("Disabling VSync"); - Display.setVSyncEnabled(false); - } else { - Display.setVSyncEnabled(true); - } - } - - - @Override - public void requestFocus() { - // seems there is no way of request focus on the LWJGL Display, unless - // it is parented inside a Canvas: - // http://www.java-gaming.org/index.php?topic=31158.0 - } - - - @Override - public void blit() { - // Nothing to do here - } - - @Override - public void setCursor(int kind) { - System.err.println("Sorry, cursor types not supported in OpenGL, provide your cursor image"); - } - - @Override - public void setCursor(PImage image, int hotspotX, int hotspotY) { - BufferedImage jimg = (BufferedImage)image.getNative(); - IntBuffer buf = IntBuffer.wrap(jimg.getRGB(0, 0, jimg.getWidth(), jimg.getHeight(), - null, 0, jimg.getWidth())); - try { - currentCursor = new Cursor(jimg.getWidth(), jimg.getHeight(), - hotspotX, hotspotY, 1, buf, null); - Mouse.setNativeCursor(currentCursor); - cursorVisible = true; - } catch (LWJGLException e) { - e.printStackTrace(); - } - } - - @Override - public void showCursor() { - if (!cursorVisible) { - try { - Mouse.setNativeCursor(currentCursor); - cursorVisible = true; - } catch (LWJGLException e) { - e.printStackTrace(); - } - } - } - - @Override - public void hideCursor() { - if (invisibleCursor == null) { - try { - invisibleCursor = new Cursor(1, 1, 0, 0, 1, BufferUtils.createIntBuffer(1), null); - } catch (LWJGLException e1) { - e1.printStackTrace(); - } - } - try { - Mouse.setNativeCursor(invisibleCursor); - cursorVisible = false; - } catch (LWJGLException e) { - e.printStackTrace(); - } - } - - class AnimationThread extends Thread { - - public AnimationThread() { - super("Animation Thread"); - } - - /** - * Main method for the primary animation thread. - * Painting in AWT and Swing - */ - @Override - public void run() { // not good to make this synchronized, locks things up - try { -// DisplayMode[] modes = Display.getAvailableDisplayModes(); -// for (DisplayMode mode: modes) { -// System.err.println(mode.toString()); -// } -// Display.setDisplayMode(Display.getDesktopDisplayMode()); -// -// Display.create(); -// Display.destroy(); - System.err.println("CREATE THE DISPLAY"); - PixelFormat format = new PixelFormat(PGL.REQUESTED_ALPHA_BITS, - PGL.REQUESTED_DEPTH_BITS, - PGL.REQUESTED_STENCIL_BITS, pgl.reqNumSamples); - Display.create(format); - } catch (LWJGLException e) { - e.printStackTrace(); - System.exit(0); - } - - boolean deinit = true; - - keyPoller = new KeyPoller(sketch); - keyPoller.start(); - - mousePoller = new MousePoller(sketch); - mousePoller.start(); - -// System.err.println(Mouse.getNativeCursor()); - -// long beforeTime = System.nanoTime(); -// long overSleepTime = 0L; - -// int noDelays = 0; - // Number of frames with a delay of 0 ms before the - // animation thread yields to other running threads. -// final int NO_DELAYS_PER_YIELD = 15; - - // If size un-initialized, might be a Canvas. Call setSize() here since - // we now have a parent object that this Canvas can use as a peer. -// if (graphics.image == null) { -// System.out.format("it's null, sketchW/H already set to %d %d%n", sketchWidth, sketchHeight); - setSize(sketchWidth, sketchHeight); -// System.out.format(" but now, sketchW/H changed to %d %d%n", sketchWidth, sketchHeight); -// } - - // un-pause the sketch and get rolling - sketch.start(); - - int x0 = Display.getX(); - int y0 = Display.getY(); - while ((Thread.currentThread() == thread) && !sketch.finished) { - if (Display.wasResized()) { - setSize(Display.getWidth(), Display.getHeight()); - } - pgl.setThread(thread); - checkPause(); - - - - // Don't resize the renderer from the EDT (i.e. from a ComponentEvent), - // otherwise it may attempt a resize mid-render. -// Dimension currentSize = canvas.getSize(); -// if (currentSize.width != sketchWidth || currentSize.height != sketchHeight) { -// System.err.format("need to resize from %s to %d, %d%n", currentSize, sketchWidth, sketchHeight); -// } - - // render a single frame -// if (g != null) { - sketch.handleDraw(); - Display.update(); -// } - - if (sketch.frameCount == 1) { - requestFocus(); - } - - // wait for update & paint to happen before drawing next frame - // this is necessary since the drawing is sometimes in a - // separate thread, meaning that the next frame will start - // before the update/paint is completed -// long afterTime = System.nanoTime(); -// long timeDiff = afterTime - beforeTime; -// //System.out.println("time diff is " + timeDiff); -// long sleepTime = (frameRatePeriod - timeDiff) - overSleepTime; -// -// if (sleepTime > 0) { // some time left in this cycle -// try { -// Thread.sleep(sleepTime / 1000000L, (int) (sleepTime % 1000000L)); -// noDelays = 0; // Got some sleep, not delaying anymore -// } catch (InterruptedException ex) { } -// -// overSleepTime = (System.nanoTime() - afterTime) - sleepTime; -// -// } else { // sleepTime <= 0; the frame took longer than the period -// overSleepTime = 0L; -// noDelays++; -// -// if (noDelays > NO_DELAYS_PER_YIELD) { -// Thread.yield(); // give another thread a chance to run -// noDelays = 0; -// } -// } -// beforeTime = System.nanoTime(); - Display.sync((int)frameRateTarget); - - - int x = Display.getX(); - int y = Display.getY(); - if (externalMessages && (x != x0 || y0 != y)) { - System.err.println(PApplet.EXTERNAL_MOVE + " " + x + " " + y); - System.err.flush(); // doesn't seem to help or hurt - } - x0 = x; - y0 = y; - - if (Display.isCloseRequested()) break; - if (forceExit) { - System.err.println("QUIT"); - deinit = false; - break; - } -// System.err.println(Display.isActive()); - } - - if (deinit) { - if (externalMessages) { - sketch.exit(); // don't quit, need to just shut everything down (0133) - } - - keyPoller.requestStop(); - mousePoller.requestStop(); - sketch.dispose(); // call to shutdown libs? - Display.destroy(); - - // If the user called the exit() function, the window should close, - // rather than the sketch just halting. - if (sketch.exitCalled()) { - sketch.exitActual(); - } - } - - - } - } - - @SuppressWarnings("serial") - class DummyFrame extends Frame { - - public DummyFrame() { - super(); - } - - @Override - public void setResizable(boolean resizable) { - Display.setResizable(resizable); - } - -// @Override -// public void setLocation(int x, int y) { -// Display.setLocation(x, y); -// } - - @Override - public void setVisible(boolean visible) { -// Display.isVisible() -// Display.setVisible(visible); - System.err.println("Sorry, cannot set visibility of window in OpenGL"); - } - - @Override - public void setTitle(String title) { - Display.setTitle(title); - } - } - - /////////////////////////////////////////////////////////// - - // LWJGL event handling - - - protected class KeyPoller extends Thread { - protected PApplet parent; - protected boolean stopRequested; - protected boolean[] pressedKeys; - protected char[] charCheys; - - KeyPoller(PApplet parent) { - this.parent = parent; - stopRequested = false; - try { - Keyboard.create(); - } catch (LWJGLException e) { - e.printStackTrace(); - } - } - - @Override - public void run() { - pressedKeys = new boolean[256]; - charCheys = new char[256]; - Keyboard.enableRepeatEvents(true); - while (true) { - if (stopRequested) break; - - Keyboard.poll(); - while (Keyboard.next()) { - if (stopRequested) break; - - long millis = Keyboard.getEventNanoseconds() / 1000000L; - char keyChar = Keyboard.getEventCharacter(); - int keyCode = Keyboard.getEventKey(); - - if (keyCode >= pressedKeys.length) continue; - - int modifiers = 0; - if (Keyboard.isKeyDown(Keyboard.KEY_LSHIFT) || - Keyboard.isKeyDown(Keyboard.KEY_RSHIFT)) { - modifiers |= Event.SHIFT; - } - if (Keyboard.isKeyDown(Keyboard.KEY_LCONTROL) || - Keyboard.isKeyDown(Keyboard.KEY_RCONTROL)) { - modifiers |= Event.CTRL; - } - if (Keyboard.isKeyDown(Keyboard.KEY_LMETA) || - Keyboard.isKeyDown(Keyboard.KEY_RMETA)) { - modifiers |= Event.META; - } - if (Keyboard.isKeyDown(Keyboard.KEY_LMENU) || - Keyboard.isKeyDown(Keyboard.KEY_RMENU)) { - // LWJGL maps the menu key and the alt key to the same value. - modifiers |= Event.ALT; - } - - int keyPCode = LWJGLtoAWTCode(keyCode); - if (keyChar == 0) { - keyChar = PConstants.CODED; - } - - int action = 0; - if (Keyboard.getEventKeyState()) { - action = KeyEvent.PRESS; - KeyEvent ke = new KeyEvent(null, millis, - action, modifiers, - keyChar, keyPCode); - parent.postEvent(ke); - pressedKeys[keyCode] = true; - charCheys[keyCode] = keyChar; - keyPCode = 0; - action = KeyEvent.TYPE; - } else if (pressedKeys[keyCode]) { - keyChar = charCheys[keyCode]; - pressedKeys[keyCode] = false; - action = KeyEvent.RELEASE; - } - - KeyEvent ke = new KeyEvent(null, millis, - action, modifiers, - keyChar, keyPCode); - parent.postEvent(ke); - } - try { - Thread.sleep(10); - } catch (InterruptedException e) { - // http://stackoverflow.com/questions/1024651/do-i-have-to-worry-about-interruptedexceptions-if-i-dont-interrupt-anything-mys/1024719#1024719 -// e.printStackTrace(); - Thread.currentThread().interrupt(); // restore interrupted status - break; - } - } - } - - public void requestStop() { - stopRequested = true; - } - } - - protected class DisplayResarter extends Thread { - boolean changeRequested = false; - - @Override - public void run() { - while (true) { - if (changeRequested) { - forceExit = true; - thread.interrupt(); - while (thread.isAlive()) { -// System.err.println("alive"); - Thread.yield(); - } - thread = null; - - keyPoller.requestStop(); - keyPoller.interrupt(); - while (keyPoller.isAlive()) { - Thread.yield(); - } - mousePoller.requestStop(); - mousePoller.interrupt(); - while (mousePoller.isAlive()) { - Thread.yield(); - } - - /* - System.err.println("will destroy surface"); - Display.destroy(); - try { - Display.setDisplayMode(new DisplayMode(sketchWidth, sketchHeight)); - } catch (LWJGLException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } -*/ - startThread(); - - - - changeRequested = false; - } - try { - Thread.sleep(10); - } catch (InterruptedException e) { -// e.printStackTrace(); - Thread.currentThread().interrupt(); // restore interrupted status - break; - } - } - } - } - - - protected class MousePoller extends Thread { - protected PApplet parent; - protected boolean stopRequested; - protected boolean pressed; - protected boolean inside; - protected long startedClickTime; - protected int startedClickButton; - - MousePoller(PApplet parent) { - this.parent = parent; - stopRequested = false; - try { - Mouse.create(); - } catch (LWJGLException e) { - e.printStackTrace(); - } - } - - @Override - public void run() { - while (true) { - if (stopRequested) break; - - Mouse.poll(); - while (Mouse.next()) { - if (stopRequested) break; - - long millis = Mouse.getEventNanoseconds() / 1000000L; - - int modifiers = 0; - if (Keyboard.isKeyDown(Keyboard.KEY_LSHIFT) || - Keyboard.isKeyDown(Keyboard.KEY_RSHIFT)) { - modifiers |= Event.SHIFT; - } - if (Keyboard.isKeyDown(Keyboard.KEY_LCONTROL) || - Keyboard.isKeyDown(Keyboard.KEY_RCONTROL)) { - modifiers |= Event.CTRL; - } - if (Keyboard.isKeyDown(Keyboard.KEY_LMETA) || - Keyboard.isKeyDown(Keyboard.KEY_RMETA)) { - modifiers |= Event.META; - } - if (Keyboard.isKeyDown(Keyboard.KEY_LMENU) || - Keyboard.isKeyDown(Keyboard.KEY_RMENU)) { - // LWJGL maps the menu key and the alt key to the same value. - modifiers |= Event.ALT; - } - -// PApplet.println(Mouse.getX(), Mouse.getY(), offsetX, offsetY); - int x = Mouse.getX() - (int)offsetX; - int y = sketchHeight - (Mouse.getY() - (int)offsetY); - int button = 0; - if (Mouse.isButtonDown(0)) { - button = PConstants.LEFT; - } else if (Mouse.isButtonDown(1)) { - button = PConstants.RIGHT; - } else if (Mouse.isButtonDown(2)) { - button = PConstants.CENTER; - } - - int action = 0; - if (button != 0) { - if (pressed) { - action = MouseEvent.DRAG; - } else { - action = MouseEvent.PRESS; - pressed = true; - } - } else if (pressed) { - action = MouseEvent.RELEASE; - - if (presentMode) { - if (20 < Mouse.getX() && Mouse.getX() < 20 + 100 && - 20 < Mouse.getY() && Mouse.getY() < 20 + 50) { - System.err.println("clicked on exit button"); - sketch.exit(); - } - } - - pressed = false; - } else { - action = MouseEvent.MOVE; - } - - if (inside) { - if (!Mouse.isInsideWindow()) { - inside = false; - action = MouseEvent.EXIT; - } - } else { - if (Mouse.isInsideWindow()) { - inside = true; - action = MouseEvent.ENTER; - } - } - - int count = 0; - if (Mouse.getEventButtonState()) { - startedClickTime = millis; - startedClickButton = button; - } else { - if (action == MouseEvent.RELEASE) { - boolean clickDetected = millis - startedClickTime < 500; - if (clickDetected) { - // post a RELEASE event, in addition to the CLICK event. - MouseEvent me = new MouseEvent(null, millis, action, modifiers, - x, y, button, count); - parent.postEvent(me); - action = MouseEvent.CLICK; - count = 1; - } - } - } - - MouseEvent me = new MouseEvent(null, millis, action, modifiers, - x, y, button, count); - parent.postEvent(me); - } - try { - Thread.sleep(10); - } catch (InterruptedException e) { -// e.printStackTrace(); - Thread.currentThread().interrupt(); // restore interrupted status - break; - } - } - } - - public void requestStop() { - stopRequested = true; - } - } - /** - * AWT to LWJGL key constants conversion. - */ - protected static final int[] LWJGL_KEY_CONVERSION; - /** - * Conversion LWJGL -> AWT keycode. Taken from GTGE library - * https://code.google.com/p/gtge/ - * - */ - static { - // LWJGL -> AWT conversion - // used for keypressed and keyreleased - // mapping Keyboard.KEY_ -> KeyEvent.VK_ - LWJGL_KEY_CONVERSION = new int[Keyboard.KEYBOARD_SIZE]; - - // loops through all of the registered keys in KeyEvent - Field[] keys = KeyEvent.class.getFields(); - for (int i = 0; i < keys.length; i++) { - - try { - // Converts the KeyEvent constant name to the LWJGL constant - // name - String field = "KEY_" + keys[i].getName().substring(3); - Field lwjglKey = Keyboard.class.getField(field); - - // print key mapping - // System.out.println(field + " " + lwjglKey.getInt(null) + "=" - // + keys[i].getInt(null)); - - // Sets LWJGL index to be the KeyCode value - LWJGL_KEY_CONVERSION[lwjglKey.getInt(null)] = keys[i].getInt(null); - - } catch (Exception e) { } - } - - try { - LWJGL_KEY_CONVERSION[Keyboard.KEY_BACK] = java.awt.event.KeyEvent.VK_BACK_SPACE; - LWJGL_KEY_CONVERSION[Keyboard.KEY_LBRACKET] = java.awt.event.KeyEvent.VK_BRACELEFT; - LWJGL_KEY_CONVERSION[Keyboard.KEY_RBRACKET] = java.awt.event.KeyEvent.VK_BRACERIGHT; - LWJGL_KEY_CONVERSION[Keyboard.KEY_APOSTROPHE] = java.awt.event.KeyEvent.VK_QUOTE; - LWJGL_KEY_CONVERSION[Keyboard.KEY_GRAVE] = java.awt.event.KeyEvent.VK_BACK_QUOTE; - LWJGL_KEY_CONVERSION[Keyboard.KEY_BACKSLASH] = java.awt.event.KeyEvent.VK_BACK_SLASH; - LWJGL_KEY_CONVERSION[Keyboard.KEY_CAPITAL] = java.awt.event.KeyEvent.VK_CAPS_LOCK; - LWJGL_KEY_CONVERSION[Keyboard.KEY_NUMLOCK] = java.awt.event.KeyEvent.VK_NUM_LOCK; - LWJGL_KEY_CONVERSION[Keyboard.KEY_SCROLL] = java.awt.event.KeyEvent.VK_SCROLL_LOCK; - - // two to one buttons mapping - LWJGL_KEY_CONVERSION[Keyboard.KEY_RETURN] = java.awt.event.KeyEvent.VK_ENTER; - LWJGL_KEY_CONVERSION[Keyboard.KEY_NUMPADENTER] = java.awt.event.KeyEvent.VK_ENTER; - LWJGL_KEY_CONVERSION[Keyboard.KEY_LCONTROL] = java.awt.event.KeyEvent.VK_CONTROL; - LWJGL_KEY_CONVERSION[Keyboard.KEY_RCONTROL] = java.awt.event.KeyEvent.VK_CONTROL; - LWJGL_KEY_CONVERSION[Keyboard.KEY_LSHIFT] = java.awt.event.KeyEvent.VK_SHIFT; - LWJGL_KEY_CONVERSION[Keyboard.KEY_RSHIFT] = java.awt.event.KeyEvent.VK_SHIFT; - } - catch (Exception e) { - } - } - - - protected int LWJGLtoAWTCode(int code) { - try { - return LWJGL_KEY_CONVERSION[code]; - } - catch (ArrayIndexOutOfBoundsException e) { - System.err.println("ERROR: Invalid LWJGL KeyCode " + code); - return -1; - } - } -}