From afd8a66df2483f6daa9840cb6e09e06d362cf800 Mon Sep 17 00:00:00 2001 From: codeanticode Date: Fri, 13 Sep 2013 19:25:37 -0400 Subject: [PATCH] added GLW library for native window output using NEWT --- java/libraries/glw/.classpath | 8 ++ java/libraries/glw/.gitignore | 1 + java/libraries/glw/.project | 17 ++++ java/libraries/glw/build.xml | 31 +++++++ .../glw/examples/BigWindow/BigWindow.pde | 13 +++ .../libraries/glw/src/processing/glw/GLW.java | 6 ++ .../glw/src/processing/glw/PGraphics2D.java | 10 ++ .../glw/src/processing/glw/PGraphics3D.java | 10 ++ .../glw/src/processing/glw/PGraphicsGLW.java | 36 +++++++ .../glw/src/processing/glw/PNEWT.java | 93 +++++++++++++++++++ 10 files changed, 225 insertions(+) create mode 100644 java/libraries/glw/.classpath create mode 100644 java/libraries/glw/.gitignore create mode 100644 java/libraries/glw/.project create mode 100755 java/libraries/glw/build.xml create mode 100644 java/libraries/glw/examples/BigWindow/BigWindow.pde create mode 100644 java/libraries/glw/src/processing/glw/GLW.java create mode 100644 java/libraries/glw/src/processing/glw/PGraphics2D.java create mode 100644 java/libraries/glw/src/processing/glw/PGraphics3D.java create mode 100644 java/libraries/glw/src/processing/glw/PGraphicsGLW.java create mode 100644 java/libraries/glw/src/processing/glw/PNEWT.java diff --git a/java/libraries/glw/.classpath b/java/libraries/glw/.classpath new file mode 100644 index 000000000..614f216d5 --- /dev/null +++ b/java/libraries/glw/.classpath @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/java/libraries/glw/.gitignore b/java/libraries/glw/.gitignore new file mode 100644 index 000000000..5e56e040e --- /dev/null +++ b/java/libraries/glw/.gitignore @@ -0,0 +1 @@ +/bin diff --git a/java/libraries/glw/.project b/java/libraries/glw/.project new file mode 100644 index 000000000..2a1ccb06f --- /dev/null +++ b/java/libraries/glw/.project @@ -0,0 +1,17 @@ + + + processing-glw + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/java/libraries/glw/build.xml b/java/libraries/glw/build.xml new file mode 100755 index 000000000..d33336574 --- /dev/null +++ b/java/libraries/glw/build.xml @@ -0,0 +1,31 @@ + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/java/libraries/glw/examples/BigWindow/BigWindow.pde b/java/libraries/glw/examples/BigWindow/BigWindow.pde new file mode 100644 index 000000000..8536365f2 --- /dev/null +++ b/java/libraries/glw/examples/BigWindow/BigWindow.pde @@ -0,0 +1,13 @@ +import processing.nwin.*; + +void setup() { + size(2560, 1440, NWin.P2D); + frameRate(180); +} + +void draw() { + background(255, 0, 0); + + fill(255); + text("FPS: " + frameRate, mouseX, mouseY); +} diff --git a/java/libraries/glw/src/processing/glw/GLW.java b/java/libraries/glw/src/processing/glw/GLW.java new file mode 100644 index 000000000..c45805cb6 --- /dev/null +++ b/java/libraries/glw/src/processing/glw/GLW.java @@ -0,0 +1,6 @@ +package processing.glw; + +public interface GLW { + static final String P2D = "processing.glw.PGraphics2D"; + static final String P3D = "processing.glw.PGraphics3D"; +} diff --git a/java/libraries/glw/src/processing/glw/PGraphics2D.java b/java/libraries/glw/src/processing/glw/PGraphics2D.java new file mode 100644 index 000000000..b28f93f31 --- /dev/null +++ b/java/libraries/glw/src/processing/glw/PGraphics2D.java @@ -0,0 +1,10 @@ +package processing.glw; + +import processing.opengl.PGL; +import processing.opengl.PGraphicsOpenGL; + +public class PGraphics2D extends processing.opengl.PGraphics2D { + protected PGL createPGL(PGraphicsOpenGL pg) { + return new PNEWT(pg); + } +} diff --git a/java/libraries/glw/src/processing/glw/PGraphics3D.java b/java/libraries/glw/src/processing/glw/PGraphics3D.java new file mode 100644 index 000000000..c4e011a98 --- /dev/null +++ b/java/libraries/glw/src/processing/glw/PGraphics3D.java @@ -0,0 +1,10 @@ +package processing.glw; + +import processing.opengl.PGL; +import processing.opengl.PGraphicsOpenGL; + +public class PGraphics3D extends processing.opengl.PGraphics3D { + protected PGL createPGL(PGraphicsOpenGL pg) { + return new PNEWT(pg); + } +} diff --git a/java/libraries/glw/src/processing/glw/PGraphicsGLW.java b/java/libraries/glw/src/processing/glw/PGraphicsGLW.java new file mode 100644 index 000000000..d436454c2 --- /dev/null +++ b/java/libraries/glw/src/processing/glw/PGraphicsGLW.java @@ -0,0 +1,36 @@ +/* -*- 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.glw; + +import processing.opengl.PGL; +import processing.opengl.PGraphicsOpenGL; + +/** + * LWJGL renderer. + * + */ +public class PGraphicsGLW extends PGraphicsOpenGL { + protected PGL createPGL(PGraphicsOpenGL pg) { + return new PNEWT(pg); + } +} diff --git a/java/libraries/glw/src/processing/glw/PNEWT.java b/java/libraries/glw/src/processing/glw/PNEWT.java new file mode 100644 index 000000000..61922b288 --- /dev/null +++ b/java/libraries/glw/src/processing/glw/PNEWT.java @@ -0,0 +1,93 @@ +/* -*- 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.glw; + + +import javax.media.opengl.GLCapabilities; +import javax.media.opengl.GLProfile; + +import com.jogamp.newt.opengl.GLWindow; +import com.jogamp.newt.event.WindowAdapter; +import com.jogamp.newt.event.WindowEvent; + +import processing.opengl.PGraphicsOpenGL; +import processing.opengl.PJOGL; + +public class PNEWT extends PJOGL { + + static { + WINDOW_TOOLKIT = NEWT; + EVENTS_TOOLKIT = NEWT; + USE_FBOLAYER_BY_DEFAULT = false; + USE_JOGL_FBOLAYER = false; + } + + + public PNEWT(PGraphicsOpenGL pg) { + super(pg); + } + + + protected void initSurface(int antialias) { + if (profile == null) { + profile = GLProfile.getDefault(); + } else { + window.removeGLEventListener(listener); + pg.parent.remove(canvasNEWT); + } + + // Setting up the desired capabilities; + GLCapabilities caps = new GLCapabilities(profile); + caps.setAlphaBits(REQUESTED_ALPHA_BITS); + caps.setDepthBits(REQUESTED_DEPTH_BITS); + caps.setStencilBits(REQUESTED_STENCIL_BITS); + + if (1 < antialias) { + caps.setSampleBuffers(true); + caps.setNumSamples(antialias); + } else { + caps.setSampleBuffers(false); + } + fboLayerRequested = false; + + window = GLWindow.create(caps); + window.setSize(pg.width, pg.height); + window.setVisible(true); + pg.parent.frame.setVisible(false); + + canvas = canvasNEWT; + canvasAWT = null; + + window.addWindowListener(new WindowAdapter() { + @Override + public void windowDestroyNotify(final WindowEvent e) { + System.exit(0); + } + }); + + registerListeners(); + } + + +}