Skip to content

Commit b8f4e75

Browse files
committed
added GLW library for native window output using NEWT
1 parent cd1fe41 commit b8f4e75

File tree

10 files changed

+225
-0
lines changed

10 files changed

+225
-0
lines changed

java/libraries/glw/.classpath

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<classpath>
3+
<classpathentry kind="src" path="src"/>
4+
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
5+
<classpathentry combineaccessrules="false" kind="src" path="/processing-core"/>
6+
<classpathentry kind="lib" path="/processing-core/library/jogl-all.jar"/>
7+
<classpathentry kind="output" path="bin"/>
8+
</classpath>

java/libraries/glw/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/bin

java/libraries/glw/.project

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<projectDescription>
3+
<name>processing-glw</name>
4+
<comment></comment>
5+
<projects>
6+
</projects>
7+
<buildSpec>
8+
<buildCommand>
9+
<name>org.eclipse.jdt.core.javabuilder</name>
10+
<arguments>
11+
</arguments>
12+
</buildCommand>
13+
</buildSpec>
14+
<natures>
15+
<nature>org.eclipse.jdt.core.javanature</nature>
16+
</natures>
17+
</projectDescription>

java/libraries/glw/build.xml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?xml version="1.0"?>
2+
<project name="Processing GLW Library" default="build">
3+
4+
<target name="clean" description="Clean the build directories">
5+
<delete dir="bin" />
6+
<delete file="library/glw.jar" />
7+
</target>
8+
9+
<target name="compile" description="Compile sources">
10+
<condition property="core-built">
11+
<available file="../../../core/library/core.jar; ../../../core/library/jogl-all.jar" />
12+
</condition>
13+
<fail unless="core-built" message="Please build the core library first and make sure it sits in ../../../core/library/core.jar" />
14+
15+
<mkdir dir="bin" />
16+
<javac source="1.6"
17+
target="1.6"
18+
srcdir="src" destdir="bin"
19+
encoding="UTF-8"
20+
includeAntRuntime="false"
21+
classpath="../../../core/library/core.jar"
22+
nowarn="true"
23+
compiler="org.eclipse.jdt.core.JDTCompilerAdapter">
24+
<compilerclasspath path="../../mode/ecj.jar" />
25+
</javac>
26+
</target>
27+
28+
<target name="build" depends="compile" description="Build OpenGL LWJGL library">
29+
<jar basedir="bin" destfile="library/glw.jar" />
30+
</target>
31+
</project>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import processing.nwin.*;
2+
3+
void setup() {
4+
size(2560, 1440, NWin.P2D);
5+
frameRate(180);
6+
}
7+
8+
void draw() {
9+
background(255, 0, 0);
10+
11+
fill(255);
12+
text("FPS: " + frameRate, mouseX, mouseY);
13+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package processing.glw;
2+
3+
public interface GLW {
4+
static final String P2D = "processing.glw.PGraphics2D";
5+
static final String P3D = "processing.glw.PGraphics3D";
6+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package processing.glw;
2+
3+
import processing.opengl.PGL;
4+
import processing.opengl.PGraphicsOpenGL;
5+
6+
public class PGraphics2D extends processing.opengl.PGraphics2D {
7+
protected PGL createPGL(PGraphicsOpenGL pg) {
8+
return new PNEWT(pg);
9+
}
10+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package processing.glw;
2+
3+
import processing.opengl.PGL;
4+
import processing.opengl.PGraphicsOpenGL;
5+
6+
public class PGraphics3D extends processing.opengl.PGraphics3D {
7+
protected PGL createPGL(PGraphicsOpenGL pg) {
8+
return new PNEWT(pg);
9+
}
10+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/* -*- mode: java; c-basic-offset: 2; indent-tabs-mode: nil -*- */
2+
3+
/*
4+
Part of the Processing project - http://processing.org
5+
6+
Copyright (c) 2004-12 Ben Fry and Casey Reas
7+
8+
This library is free software; you can redistribute it and/or
9+
modify it under the terms of the GNU Lesser General Public
10+
License version 2.1 as published by the Free Software Foundation.
11+
12+
This library is distributed in the hope that it will be useful,
13+
but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15+
Lesser General Public License for more details.
16+
17+
You should have received a copy of the GNU Lesser General
18+
Public License along with this library; if not, write to the
19+
Free Software Foundation, Inc., 59 Temple Place, Suite 330,
20+
Boston, MA 02111-1307 USA
21+
*/
22+
23+
package processing.glw;
24+
25+
import processing.opengl.PGL;
26+
import processing.opengl.PGraphicsOpenGL;
27+
28+
/**
29+
* LWJGL renderer.
30+
*
31+
*/
32+
public class PGraphicsGLW extends PGraphicsOpenGL {
33+
protected PGL createPGL(PGraphicsOpenGL pg) {
34+
return new PNEWT(pg);
35+
}
36+
}
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
/* -*- mode: java; c-basic-offset: 2; indent-tabs-mode: nil -*- */
2+
3+
/*
4+
Part of the Processing project - http://processing.org
5+
6+
Copyright (c) 2011-12 Ben Fry and Casey Reas
7+
8+
This library is free software; you can redistribute it and/or
9+
modify it under the terms of the GNU Lesser General Public
10+
License as published by the Free Software Foundation; either
11+
version 2.1 of the License, or (at your option) any later version.
12+
13+
This library is distributed in the hope that it will be useful,
14+
but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16+
Lesser General Public License for more details.
17+
18+
You should have received a copy of the GNU Lesser General
19+
Public License along with this library; if not, write to the
20+
Free Software Foundation, Inc., 59 Temple Place, Suite 330,
21+
Boston, MA 02111-1307 USA
22+
*/
23+
24+
package processing.glw;
25+
26+
27+
import javax.media.opengl.GLCapabilities;
28+
import javax.media.opengl.GLProfile;
29+
30+
import com.jogamp.newt.opengl.GLWindow;
31+
import com.jogamp.newt.event.WindowAdapter;
32+
import com.jogamp.newt.event.WindowEvent;
33+
34+
import processing.opengl.PGraphicsOpenGL;
35+
import processing.opengl.PJOGL;
36+
37+
public class PNEWT extends PJOGL {
38+
39+
static {
40+
WINDOW_TOOLKIT = NEWT;
41+
EVENTS_TOOLKIT = NEWT;
42+
USE_FBOLAYER_BY_DEFAULT = false;
43+
USE_JOGL_FBOLAYER = false;
44+
}
45+
46+
47+
public PNEWT(PGraphicsOpenGL pg) {
48+
super(pg);
49+
}
50+
51+
52+
protected void initSurface(int antialias) {
53+
if (profile == null) {
54+
profile = GLProfile.getDefault();
55+
} else {
56+
window.removeGLEventListener(listener);
57+
pg.parent.remove(canvasNEWT);
58+
}
59+
60+
// Setting up the desired capabilities;
61+
GLCapabilities caps = new GLCapabilities(profile);
62+
caps.setAlphaBits(REQUESTED_ALPHA_BITS);
63+
caps.setDepthBits(REQUESTED_DEPTH_BITS);
64+
caps.setStencilBits(REQUESTED_STENCIL_BITS);
65+
66+
if (1 < antialias) {
67+
caps.setSampleBuffers(true);
68+
caps.setNumSamples(antialias);
69+
} else {
70+
caps.setSampleBuffers(false);
71+
}
72+
fboLayerRequested = false;
73+
74+
window = GLWindow.create(caps);
75+
window.setSize(pg.width, pg.height);
76+
window.setVisible(true);
77+
pg.parent.frame.setVisible(false);
78+
79+
canvas = canvasNEWT;
80+
canvasAWT = null;
81+
82+
window.addWindowListener(new WindowAdapter() {
83+
@Override
84+
public void windowDestroyNotify(final WindowEvent e) {
85+
System.exit(0);
86+
}
87+
});
88+
89+
registerListeners();
90+
}
91+
92+
93+
}

0 commit comments

Comments
 (0)