added GLW library for native window output using NEWT

This commit is contained in:
codeanticode
2013-09-13 19:25:37 -04:00
parent fab8555160
commit afd8a66df2
10 changed files with 225 additions and 0 deletions

View File

@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry combineaccessrules="false" kind="src" path="/processing-core"/>
<classpathentry kind="lib" path="/processing-core/library/jogl-all.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>

1
java/libraries/glw/.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
/bin

View File

@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>processing-glw</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>

31
java/libraries/glw/build.xml Executable file
View File

@@ -0,0 +1,31 @@
<?xml version="1.0"?>
<project name="Processing GLW Library" default="build">
<target name="clean" description="Clean the build directories">
<delete dir="bin" />
<delete file="library/glw.jar" />
</target>
<target name="compile" description="Compile sources">
<condition property="core-built">
<available file="../../../core/library/core.jar; ../../../core/library/jogl-all.jar" />
</condition>
<fail unless="core-built" message="Please build the core library first and make sure it sits in ../../../core/library/core.jar" />
<mkdir dir="bin" />
<javac source="1.6"
target="1.6"
srcdir="src" destdir="bin"
encoding="UTF-8"
includeAntRuntime="false"
classpath="../../../core/library/core.jar"
nowarn="true"
compiler="org.eclipse.jdt.core.JDTCompilerAdapter">
<compilerclasspath path="../../mode/ecj.jar" />
</javac>
</target>
<target name="build" depends="compile" description="Build OpenGL LWJGL library">
<jar basedir="bin" destfile="library/glw.jar" />
</target>
</project>

View File

@@ -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);
}

View File

@@ -0,0 +1,6 @@
package processing.glw;
public interface GLW {
static final String P2D = "processing.glw.PGraphics2D";
static final String P3D = "processing.glw.PGraphics3D";
}

View File

@@ -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);
}
}

View File

@@ -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);
}
}

View File

@@ -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);
}
}

View File

@@ -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();
}
}