removed jogl library

This commit is contained in:
codeanticode
2015-05-14 18:22:18 -04:00
parent c0514c3d35
commit 3ffb541309
17 changed files with 0 additions and 3788 deletions

View File

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

View File

@@ -1 +0,0 @@
bin

View File

@@ -1,17 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>processing-jogl</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>

View File

@@ -1,32 +0,0 @@
<?xml version="1.0"?>
<project name="Processing JOGL Library" default="build">
<target name="clean" description="Clean the build directories">
<delete dir="bin" />
<delete file="library/opengl-jogl.jar" />
</target>
<target name="compile" description="Compile sources">
<condition property="core-built">
<available file="../../../core/library/core.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.7"
target="1.7"
srcdir="src" destdir="bin"
encoding="UTF-8"
includeAntRuntime="false"
classpath="../../../core/library/core.jar; library/jogl-all.jar; library/gluegen-rt.jar.jar"
nowarn="true"
compiler="org.eclipse.jdt.core.JDTCompilerAdapter">
<compilerclasspath path="../../mode/org.eclipse.jdt.core.jar;
../../mode/jdtCompilerAdapter.jar" />
</javac>
</target>
<target name="build" depends="compile" description="Build JOGL library">
<jar basedir="bin" destfile="library/opengl-jogl.jar" />
</target>
</project>

View File

@@ -1,13 +0,0 @@
import processing.jogl.*;
void setup() {
size(4000, 2000, JOGL.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);
}

View File

@@ -1,31 +0,0 @@
import processing.jogl.*;
PGraphics pg;
void setup() {
size(400, 400, JOGL.P2D);
pg = createGraphics(400, 400, JOGL.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);
}

View File

@@ -1,28 +0,0 @@
import processing.jogl.*;
PShape cube;
void setup() {
size(400, 400, JOGL.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();
}

View File

@@ -1 +0,0 @@
/jogl-java-src.zip

View File

@@ -1,10 +0,0 @@
# If you want to support more platforms, visit jogamp.org to get the
# natives libraries for the platform in question (i.e. Solaris).
name = OpenGL
application.macosx=core.jar,jogl-all.jar,gluegen-rt.jar,jogl-all-natives-macosx-universal.jar,gluegen-rt-natives-macosx-universal.jar
application.windows32=core.jar,jogl-all.jar,gluegen-rt.jar,jogl-all-natives-windows-i586.jar,gluegen-rt-natives-windows-i586.jar
application.windows64=core.jar,jogl-all.jar,gluegen-rt.jar,jogl-all-natives-windows-amd64.jar,gluegen-rt-natives-windows-amd64.jar
application.linux32=core.jar,jogl-all.jar,gluegen-rt.jar,jogl-all-natives-linux-i586.jar,gluegen-rt-natives-linux-i586.jar
application.linux64=core.jar,jogl-all.jar,gluegen-rt.jar,jogl-all-natives-linux-amd64.jar,gluegen-rt-natives-linux-amd64.jar

View File

@@ -1,8 +0,0 @@
package processing.jogl;
public interface JOGL {
static final String P2D = "processing.jogl.PGraphics2D";
static final String P3D = "processing.jogl.PGraphics3D";
static final String P2D_2X = "processing.jogl.PGraphics2D2X";
static final String P3D_2X = "processing.jogl.PGraphics3D2X";
}

View File

@@ -1,37 +0,0 @@
/* -*- mode: java; c-basic-offset: 2; indent-tabs-mode: nil -*- */
/*
Part of the Processing project - http://processing.org
Copyright (c) 2012 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.jogl;
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 PJOGL(pg);
}
@Override
public PSurface createSurface() { // ignore
return new PSurfaceJOGL(this);
}
}

View File

@@ -1,37 +0,0 @@
/* -*- mode: java; c-basic-offset: 2; indent-tabs-mode: nil -*- */
/*
Part of the Processing project - http://processing.org
Copyright (c) 2012 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.jogl;
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 PJOGL(pg);
}
@Override
public PSurface createSurface() { // ignore
return new PSurfaceJOGL(this);
}
}

View File

@@ -1,37 +0,0 @@
/* -*- mode: java; c-basic-offset: 2; indent-tabs-mode: nil -*- */
/*
Part of the Processing project - http://processing.org
Copyright (c) 2012 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.jogl;
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 PJOGL(pg);
}
@Override
public PSurface createSurface() { // ignore
return new PSurfaceJOGL(this);
}
}

View File

@@ -1,37 +0,0 @@
/* -*- mode: java; c-basic-offset: 2; indent-tabs-mode: nil -*- */
/*
Part of the Processing project - http://processing.org
Copyright (c) 2012 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.jogl;
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 PJOGL(pg);
}
@Override
public PSurface createSurface() { // ignore
return new PSurfaceJOGL(this);
}
}

View File

@@ -1,42 +0,0 @@
/* -*- mode: java; c-basic-offset: 2; indent-tabs-mode: nil -*- */
/*
Part of the Processing project - http://processing.org
Copyright (c) 2004-13 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.jogl;
import processing.core.*;
import processing.opengl.PGL;
import processing.opengl.PGraphicsOpenGL;
/**
* LWJGL renderer.
*
*/
public class PGraphicsJOGL extends PGraphicsOpenGL {
protected PGL createPGL(PGraphicsOpenGL pg) {
return new PJOGL(pg);
}
@Override
public PSurface createSurface() { // ignore
return new PSurfaceJOGL(this);
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -1,818 +0,0 @@
package processing.jogl;
import java.awt.Component;
//import java.awt.Dimension;
import java.awt.Point;
//import java.awt.Frame;
import java.awt.Rectangle;
import java.util.ArrayList;
import com.jogamp.nativewindow.NativeSurface;
import com.jogamp.nativewindow.ScalableSurface;
import com.jogamp.opengl.GLAnimatorControl;
import com.jogamp.opengl.GLAutoDrawable;
import com.jogamp.opengl.GLCapabilities;
import com.jogamp.opengl.GLEventListener;
import com.jogamp.opengl.GLException;
import com.jogamp.opengl.GLProfile;
import com.jogamp.nativewindow.MutableGraphicsConfiguration;
import com.jogamp.newt.Display;
import com.jogamp.newt.MonitorDevice;
import com.jogamp.newt.NewtFactory;
import com.jogamp.newt.Screen;
import com.jogamp.newt.awt.NewtCanvasAWT;
import com.jogamp.newt.event.InputEvent;
import com.jogamp.newt.event.WindowAdapter;
import com.jogamp.newt.event.WindowEvent;
import com.jogamp.newt.opengl.GLWindow;
import com.jogamp.opengl.util.FPSAnimator;
import processing.core.PApplet;
import processing.core.PConstants;
import processing.core.PGraphics;
import processing.core.PImage;
import processing.core.PSurface;
import processing.event.KeyEvent;
import processing.event.MouseEvent;
import processing.opengl.PGraphicsOpenGL;
import processing.opengl.PGL;
public class PSurfaceJOGL implements PSurface {
/** Selected GL profile */
public static GLProfile profile;
PJOGL pgl;
GLWindow window;
// Frame frame;
FPSAnimator animator;
Rectangle screenRect;
PApplet sketch;
PGraphics graphics;
int sketchX;
int sketchY;
int sketchWidth;
int sketchHeight;
MonitorDevice displayDevice;
Throwable drawException;
Object waitObject = new Object();
NewtCanvasAWT canvas;
public PSurfaceJOGL(PGraphics graphics) {
this.graphics = graphics;
this.pgl = (PJOGL) ((PGraphicsOpenGL)graphics).pgl;
}
public void initOffscreen(PApplet sketch) {
this.sketch = sketch;
sketchWidth = sketch.sketchWidth();
sketchHeight = sketch.sketchHeight();
if (window != null) {
canvas = new NewtCanvasAWT(window);
canvas.setBounds(0, 0, window.getWidth(), window.getHeight());
// canvas.setBackground(new Color(pg.backgroundColor, true));
canvas.setFocusable(true);
}
}
public void initFrame(PApplet sketch, int backgroundColor,
int deviceIndex, boolean fullScreen,
boolean spanDisplays) {
this.sketch = sketch;
Display display = NewtFactory.createDisplay(null);
display.addReference();
Screen screen = NewtFactory.createScreen(display, 0);
screen.addReference();
ArrayList<MonitorDevice> monitors = new ArrayList<MonitorDevice>();
for (int i = 0; i < screen.getMonitorDevices().size(); i++) {
MonitorDevice monitor = screen.getMonitorDevices().get(i);
System.out.println("Monitor " + monitor.getId() + " ************");
System.out.println(monitor.toString());
System.out.println(monitor.getViewportInWindowUnits());
System.out.println(monitor.getViewport());
monitors.add(monitor);
}
System.out.println("*******************************");
if (deviceIndex >= 0) { // if -1, use the default device
if (deviceIndex < monitors.size()) {
displayDevice = monitors.get(deviceIndex);
} else {
System.err.format("Display %d does not exist, " +
"using the default display instead.", deviceIndex);
for (int i = 0; i < monitors.size(); i++) {
System.err.format("Display %d is %s\n", i, monitors.get(i));
}
}
}
if (profile == null) {
if (PJOGL.PROFILE == 2) {
try {
profile = GLProfile.getGL2ES1();
} catch (GLException ex) {
profile = GLProfile.getMaxFixedFunc(true);
}
} else if (PJOGL.PROFILE == 3) {
try {
profile = GLProfile.getGL2GL3();
} catch (GLException ex) {
profile = GLProfile.getMaxProgrammable(true);
}
if (!profile.isGL3()) {
PGraphics.showWarning("Requested profile GL3 but is not available, got: " + profile);
}
} else if (PJOGL.PROFILE == 4) {
try {
profile = GLProfile.getGL4ES3();
} catch (GLException ex) {
profile = GLProfile.getMaxProgrammable(true);
}
if (!profile.isGL4()) {
PGraphics.showWarning("Requested profile GL4 but is not available, got: " + profile);
}
} else throw new RuntimeException(PGL.UNSUPPORTED_GLPROF_ERROR);
}
// Setting up the desired capabilities;
GLCapabilities caps = new GLCapabilities(profile);
caps.setAlphaBits(PGL.REQUESTED_ALPHA_BITS);
caps.setDepthBits(PGL.REQUESTED_DEPTH_BITS);
caps.setStencilBits(PGL.REQUESTED_STENCIL_BITS);
// caps.setPBuffer(false);
// caps.setFBO(false);
pgl.reqNumSamples = graphics.quality;
caps.setSampleBuffers(true);
caps.setNumSamples(pgl.reqNumSamples);
caps.setBackgroundOpaque(true);
caps.setOnscreen(true);
pgl.capabilities = caps;
System.err.println("0. create window");
window = GLWindow.create(screen, caps);
sketchWidth = sketch.sketchWidth();
sketchHeight = sketch.sketchHeight();
if (displayDevice == null) {
displayDevice = window.getMainMonitor();
}
sketchX = displayDevice.getViewportInWindowUnits().getX();
sketchY = displayDevice.getViewportInWindowUnits().getY();
int screenWidth = screen.getWidth();
int screenHeight = screen.getHeight();
screenRect = spanDisplays ? new Rectangle(0, 0, screen.getWidth(), screen.getHeight()) :
new Rectangle(0, 0, displayDevice.getViewportInWindowUnits().getWidth(),
displayDevice.getViewportInWindowUnits().getHeight());
sketch.displayWidth = screenRect.width;
sketch.displayHeight = screenRect.height;
// 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;
}
// window..setBackground(new Color(backgroundColor, true));
window.setSize(sketchWidth, sketchHeight);
System.out.println("deviceIndex: " + deviceIndex);
System.out.println(displayDevice);
System.out.println("Screen res " + screenWidth + "x" + screenHeight);
// This example could be useful:
// com.jogamp.opengl.test.junit.newt.mm.TestScreenMode01cNEWT
if (fullScreen) {
PApplet.hideMenuBar();
if (spanDisplays) {
window.setFullscreen(monitors);
} else {
window.setFullscreen(true);
}
}
float[] reqSurfacePixelScale;
if (graphics.is2X()) {
// Retina
reqSurfacePixelScale = new float[] { ScalableSurface.AUTOMAX_PIXELSCALE,
ScalableSurface.AUTOMAX_PIXELSCALE };
// pgl.pixel_scale = 2;
} else {
// Non-retina
reqSurfacePixelScale = new float[] { ScalableSurface.IDENTITY_PIXELSCALE,
ScalableSurface.IDENTITY_PIXELSCALE };
// pgl.pixel_scale = 1;
}
window.setSurfaceScale(reqSurfacePixelScale);
NEWTMouseListener mouseListener = new NEWTMouseListener();
window.addMouseListener(mouseListener);
NEWTKeyListener keyListener = new NEWTKeyListener();
window.addKeyListener(keyListener);
NEWTWindowListener winListener = new NEWTWindowListener();
window.addWindowListener(winListener);
DrawListener drawlistener = new DrawListener();
window.addGLEventListener(drawlistener);
System.err.println("1. create animator");
animator = new FPSAnimator(window, 60);
drawException = null;
animator.setUncaughtExceptionHandler(new GLAnimatorControl.UncaughtExceptionHandler() {
@Override
public void uncaughtException(final GLAnimatorControl animator,
final GLAutoDrawable drawable,
final Throwable cause) {
synchronized (waitObject) {
// System.err.println("Caught exception: " + cause.getMessage());
drawException = cause;
waitObject.notify();
}
}
});
new Thread(new Runnable() {
public void run() {
synchronized (waitObject) {
try {
if (drawException == null) waitObject.wait();
} catch (InterruptedException e) {
e.printStackTrace();
}
// System.err.println("Caught exception: " + drawException.getMessage());
if (drawException instanceof RuntimeException) {
throw (RuntimeException)drawException.getCause();
} else {
throw new RuntimeException(drawException.getCause());
}
}
}
}).start();
window.addWindowListener(new WindowAdapter() {
@Override
public void windowDestroyNotify(final WindowEvent e) {
animator.stop();
PSurfaceJOGL.this.sketch.exit();
window.destroy();
}
});
window.setVisible(true);
System.err.println("4. set visible");
/*
try {
EventQueue.invokeAndWait(new Runnable() {
public void run() {
window.setVisible(true);
System.err.println("1. set visible");
}});
} catch (Exception ex) {
// error setting the window visible, should quit...
}
*/
// frame = new DummyFrame();
// return frame;
}
@Override
public void setTitle(String title) {
window.setTitle(title);
}
@Override
public void setVisible(boolean visible) {
window.setVisible(visible);
}
@Override
public void setResizable(boolean resizable) {
// TODO Auto-generated method stub
}
private void setFrameCentered() {
// Can't use frame.setLocationRelativeTo(null) because it sends the
// frame to the main display, which undermines the --display setting.
int sketchX = displayDevice.getViewportInWindowUnits().getX();
int sketchY = displayDevice.getViewportInWindowUnits().getY();
System.err.println("just center on the screen at " + sketchX + screenRect.x + (screenRect.width - sketchWidth) / 2 + ", " +
sketchY + screenRect.y + (screenRect.height - sketchHeight) / 2);
System.err.println(" Display starts at " + sketchX + ", " + sketchY);
System.err.println(" Screen rect pos: " + screenRect.x + ", " + screenRect.y);
System.err.println(" Screen rect w/h: " + screenRect.width + ", " + screenRect.height);
System.err.println(" Sketch w/h: " + sketchWidth + ", " + sketchHeight);
int w = sketchWidth;
int h = sketchHeight;
if (graphics.is2X()) {
w /= 2;
h /= 2;
}
window.setPosition(sketchX + screenRect.x + (screenRect.width - w) / 2,
sketchY + screenRect.y + (screenRect.height - h) / 2);
}
@Override
public void placeWindow(int[] location, int[] editorLocation) {
// Dimension dim = new Dimension(sketchWidth, sketchHeight);
// int contentW = Math.max(sketchWidth, MIN_WINDOW_WIDTH);
// int contentH = Math.max(sketchHeight, MIN_WINDOW_HEIGHT);
if (location != null) {
System.err.println("place window at " + location[0] + ", " + location[1]);
// a specific location was received from the Runner
// (applet has been run more than once, user placed window)
// frame.setLocation(location[0], location[1]);
window.setPosition(location[0], location[1]);
} else if (editorLocation != null) {
System.err.println("place window at editor location " + editorLocation[0] + ", " + editorLocation[1]);
int locationX = editorLocation[0] - 20;
int locationY = editorLocation[1];
if (locationX - window.getWidth() > 10) {
// if it fits to the left of the window
window.setPosition(locationX - window.getWidth(), 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.getWidth() > sketch.displayWidth - 33) ||
(locationY + window.getHeight() > sketch.displayHeight - 33)) {
// otherwise center on screen
locationX = (sketch.displayWidth - window.getWidth()) / 2;
locationY = (sketch.displayHeight - window.getHeight()) / 2;
}
window.setPosition(locationX, locationY);
}
} else { // just center on screen
setFrameCentered();
}
Point frameLoc = new Point(window.getX(), window.getY());
if (frameLoc.y < 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
window.setPosition(frameLoc.x, 30);
}
// canvas.setBounds((contentW - sketchWidth)/2,
// (contentH - sketchHeight)/2,
// sketchWidth, sketchHeight);
}
boolean presentMode = false;
float offsetX;
float offsetY;
public void placePresent(int stopColor) {
if (sketchWidth < screenRect.width || sketchHeight < screenRect.height) {
System.err.println("Present mode");
// 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();
}
}
public void setupExternalMessages() {
// TODO Auto-generated method stub
}
public void startThread() {
if (animator != null) {
System.err.println("5. start animator");
animator.start();
if (0 < sketchX && 0 < sketchY) {
System.err.println("5.1 set inital window position");
window.setPosition(sketchX, sketchY);
sketchX = sketchY = 0;
}
// animator.getThread().setName("Processing-GL-draw");
}
}
public void pauseThread() {
if (animator != null) {
animator.pause();
}
}
public void resumeThread() {
if (animator != null) {
animator.resume();
}
}
public boolean stopThread() {
if (animator != null) {
return animator.stop();
} else {
return false;
}
}
public boolean isStopped() {
if (animator != null) {
return !animator.isAnimating();
} else {
return true;
}
}
public void setSize(int width, int height) {
// if (frame != null) {
System.err.println("3. set size");
sketchWidth = sketch.width = width;
sketchHeight = sketch.height = height;
graphics.setSize(width, height);
// }
}
public Component getComponent() {
return canvas;
}
public void setSmooth(int level) {
pgl.reqNumSamples = level;
GLCapabilities caps = new GLCapabilities(profile);
caps.setAlphaBits(PGL.REQUESTED_ALPHA_BITS);
caps.setDepthBits(PGL.REQUESTED_DEPTH_BITS);
caps.setStencilBits(PGL.REQUESTED_STENCIL_BITS);
caps.setSampleBuffers(true);
caps.setNumSamples(pgl.reqNumSamples);
caps.setBackgroundOpaque(true);
caps.setOnscreen(true);
NativeSurface target = window.getNativeSurface();
MutableGraphicsConfiguration config = (MutableGraphicsConfiguration) target.getGraphicsConfiguration();
config.setChosenCapabilities(caps);
}
public void setFrameRate(float fps) {
if (animator != null) {
animator.stop();
animator.setFPS((int)fps);
pgl.setFps(fps);
animator.start();
}
}
public void requestFocus() {
window.requestFocus();
}
class DrawListener implements GLEventListener {
public void display(GLAutoDrawable drawable) {
pgl.getGL(drawable);
// System.out.println(" - " + sketch.frameCount);
sketch.handleDraw();
if (sketch.frameCount == 1) {
requestFocus();
}
}
public void dispose(GLAutoDrawable drawable) {
pgl.getGL(drawable);
sketch.dispose();
if (sketch.exitCalled()) {
sketch.exitActual();
}
}
public void init(GLAutoDrawable drawable) {
System.err.println("2. init drawable");
pgl.getGL(drawable);
pgl.init(drawable);
sketch.start();
// setSize(sketchWidth, sketchHeight);
int c = graphics.backgroundColor;
pgl.clearColor(((c >> 16) & 0xff) / 255f,
((c >> 8) & 0xff) / 255f,
((c >> 0) & 0xff) / 255f,
((c >> 24) & 0xff) / 255f);
pgl.clear(PGL.COLOR_BUFFER_BIT);
}
public void reshape(GLAutoDrawable drawable, int x, int y, int w, int h) {
final float[] valReqSurfacePixelScale = window.getRequestedSurfaceScale(new float[2]);
final float[] hasSurfacePixelScale = window.getCurrentSurfaceScale(new float[2]);
final float[] nativeSurfacePixelScale = window.getMaximumSurfaceScale(new float[2]);
System.err.println("[set PixelScale post]: "+
valReqSurfacePixelScale[0]+"x"+valReqSurfacePixelScale[1]+" (val) -> "+
hasSurfacePixelScale[0]+"x"+hasSurfacePixelScale[1]+" (has), "+
nativeSurfacePixelScale[0]+"x"+nativeSurfacePixelScale[1]+" (native)");
System.out.println("reshape: " + w + ", " + h);
pgl.getGL(drawable);
if (!graphics.is2X() && 1 < hasSurfacePixelScale[0]) {
setSize(w/2, h/2);
} else {
setSize(w, h);
}
}
}
protected class NEWTWindowListener implements com.jogamp.newt.event.WindowListener {
public NEWTWindowListener() {
super();
}
@Override
public void windowGainedFocus(com.jogamp.newt.event.WindowEvent arg0) {
// pg.parent.focusGained(null);
}
@Override
public void windowLostFocus(com.jogamp.newt.event.WindowEvent arg0) {
// pg.parent.focusLost(null);
}
@Override
public void windowDestroyNotify(com.jogamp.newt.event.WindowEvent arg0) {
}
@Override
public void windowDestroyed(com.jogamp.newt.event.WindowEvent arg0) {
}
@Override
public void windowMoved(com.jogamp.newt.event.WindowEvent arg0) {
}
@Override
public void windowRepaint(com.jogamp.newt.event.WindowUpdateEvent arg0) {
}
@Override
public void windowResized(com.jogamp.newt.event.WindowEvent arg0) { }
}
// NEWT mouse listener
protected class NEWTMouseListener extends com.jogamp.newt.event.MouseAdapter {
public NEWTMouseListener() {
super();
}
@Override
public void mousePressed(com.jogamp.newt.event.MouseEvent e) {
nativeMouseEvent(e, MouseEvent.PRESS);
}
@Override
public void mouseReleased(com.jogamp.newt.event.MouseEvent e) {
nativeMouseEvent(e, MouseEvent.RELEASE);
}
@Override
public void mouseClicked(com.jogamp.newt.event.MouseEvent e) {
nativeMouseEvent(e, MouseEvent.CLICK);
}
@Override
public void mouseDragged(com.jogamp.newt.event.MouseEvent e) {
nativeMouseEvent(e, MouseEvent.DRAG);
}
@Override
public void mouseMoved(com.jogamp.newt.event.MouseEvent e) {
nativeMouseEvent(e, MouseEvent.MOVE);
}
@Override
public void mouseWheelMoved(com.jogamp.newt.event.MouseEvent e) {
nativeMouseEvent(e, MouseEvent.WHEEL);
}
@Override
public void mouseEntered(com.jogamp.newt.event.MouseEvent e) {
nativeMouseEvent(e, MouseEvent.ENTER);
}
@Override
public void mouseExited(com.jogamp.newt.event.MouseEvent e) {
nativeMouseEvent(e, MouseEvent.EXIT);
}
}
// NEWT key listener
protected class NEWTKeyListener extends com.jogamp.newt.event.KeyAdapter {
public NEWTKeyListener() {
super();
}
@Override
public void keyPressed(com.jogamp.newt.event.KeyEvent e) {
nativeKeyEvent(e, KeyEvent.PRESS);
}
@Override
public void keyReleased(com.jogamp.newt.event.KeyEvent e) {
nativeKeyEvent(e, KeyEvent.RELEASE);
}
public void keyTyped(com.jogamp.newt.event.KeyEvent e) {
nativeKeyEvent(e, KeyEvent.TYPE);
}
}
protected void nativeMouseEvent(com.jogamp.newt.event.MouseEvent nativeEvent,
int peAction) {
int modifiers = nativeEvent.getModifiers();
int peModifiers = modifiers &
(InputEvent.SHIFT_MASK |
InputEvent.CTRL_MASK |
InputEvent.META_MASK |
InputEvent.ALT_MASK);
int peButton = 0;
if ((modifiers & InputEvent.BUTTON1_MASK) != 0) {
peButton = PConstants.LEFT;
} else if ((modifiers & InputEvent.BUTTON2_MASK) != 0) {
peButton = PConstants.CENTER;
} else if ((modifiers & InputEvent.BUTTON3_MASK) != 0) {
peButton = PConstants.RIGHT;
}
if (PApplet.platform == PConstants.MACOSX) {
//if (nativeEvent.isPopupTrigger()) {
if ((modifiers & InputEvent.CTRL_MASK) != 0) {
peButton = PConstants.RIGHT;
}
}
int peCount = 0;
if (peAction == MouseEvent.WHEEL) {
peCount = nativeEvent.isShiftDown() ? (int)nativeEvent.getRotation()[0] :
(int)nativeEvent.getRotation()[1];
} else {
peCount = nativeEvent.getClickCount();
}
if (presentMode) {
if (20 < nativeEvent.getX() && nativeEvent.getX() < 20 + 100 &&
screenRect.height - 70 < nativeEvent.getY() && nativeEvent.getY() < screenRect.height - 20) {
System.err.println("clicked on exit button");
// if (externalMessages) {
// System.err.println(PApplet.EXTERNAL_QUIT);
// System.err.flush(); // important
// }
animator.stop();
PSurfaceJOGL.this.sketch.exit();
window.destroy();
}
}
final float[] hasSurfacePixelScale = window.getCurrentSurfaceScale(new float[2]);
int x = nativeEvent.getX() - (int)offsetX;
int y = nativeEvent.getY() - (int)offsetY;
if (!graphics.is2X() && 1 < hasSurfacePixelScale[0]) {
x /= 2;
y /= 2;
}
MouseEvent me = new MouseEvent(nativeEvent, nativeEvent.getWhen(),
peAction, peModifiers,
x, y,
peButton,
peCount);
sketch.postEvent(me);
}
protected void nativeKeyEvent(com.jogamp.newt.event.KeyEvent nativeEvent,
int peAction) {
int peModifiers = nativeEvent.getModifiers() &
(InputEvent.SHIFT_MASK |
InputEvent.CTRL_MASK |
InputEvent.META_MASK |
InputEvent.ALT_MASK);
short code = nativeEvent.getKeyCode();
char keyChar;
int keyCode;
if (isPCodedKey(code)) {
keyCode = mapToPConst(code);
keyChar = PConstants.CODED;
} else {
keyCode = code;
keyChar = nativeEvent.getKeyChar();
}
// From http://jogamp.org/deployment/v2.1.0/javadoc/jogl/javadoc/com/jogamp/newt/event/KeyEvent.html
// public final short getKeySymbol()
// Returns the virtual key symbol reflecting the current keyboard layout.
// public final short getKeyCode()
// Returns the virtual key code using a fixed mapping to the US keyboard layout.
// In contrast to key symbol, key code uses a fixed US keyboard layout and therefore is keyboard layout independent.
// E.g. virtual key code VK_Y denotes the same physical key regardless whether keyboard layout QWERTY or QWERTZ is active. The key symbol of the former is VK_Y, where the latter produces VK_Y.
KeyEvent ke = new KeyEvent(nativeEvent, nativeEvent.getWhen(),
peAction, peModifiers,
keyChar,
keyCode);
// nativeEvent.getKeySymbol());
sketch.postEvent(ke);
}
// Why do we need this mapping?
// Relevant discussion and links here:
// http://forum.jogamp.org/Newt-wrong-keycode-for-key-td4033690.html#a4033697
// (I don't think this is a complete solution).
private static int mapToPConst(short code) {
if (code == com.jogamp.newt.event.KeyEvent.VK_UP) {
return PConstants.UP;
} else if (code == com.jogamp.newt.event.KeyEvent.VK_DOWN) {
return PConstants.DOWN;
} else if (code == com.jogamp.newt.event.KeyEvent.VK_LEFT) {
return PConstants.LEFT;
} else if (code == com.jogamp.newt.event.KeyEvent.VK_RIGHT) {
return PConstants.RIGHT;
} else if (code == com.jogamp.newt.event.KeyEvent.VK_ALT) {
return PConstants.ALT;
} else if (code == com.jogamp.newt.event.KeyEvent.VK_CONTROL) {
return PConstants.CONTROL;
} else if (code == com.jogamp.newt.event.KeyEvent.VK_SHIFT) {
return PConstants.SHIFT;
}
return code;
}
private static boolean isPCodedKey(short code) {
return code == com.jogamp.newt.event.KeyEvent.VK_UP ||
code == com.jogamp.newt.event.KeyEvent.VK_DOWN ||
code == com.jogamp.newt.event.KeyEvent.VK_LEFT ||
code == com.jogamp.newt.event.KeyEvent.VK_RIGHT ||
code == com.jogamp.newt.event.KeyEvent.VK_ALT ||
code == com.jogamp.newt.event.KeyEvent.VK_CONTROL ||
code == com.jogamp.newt.event.KeyEvent.VK_SHIFT;
}
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
public void setCursor(int kind) {
System.err.println("Cursor types not supported in OpenGL, provide your cursor image");
}
public void setCursor(PImage image, int hotspotX, int hotspotY) {
final Display disp = window.getScreen().getDisplay();
disp.createNative();
// BufferedImage jimg = (BufferedImage)image.getNative();
// IntBuffer buf = IntBuffer.wrap(jimg.getRGB(0, 0, jimg.getWidth(), jimg.getHeight(),
// null, 0, jimg.getWidth()));
//
// final PixelRectangle pixelrect = new PixelRectangle.GenericPixelRect(srcFmt, new Dimension(width, height),
// srcStrideBytes, srcIsGLOriented, srcPixels);
//
// PointerIcon pi = disp.createPointerIcon(PixelRectangle pixelrect,
// hotspotX,
// hotspotY);
//
// window.setPointerIcon(pi);
}
public void showCursor() {
window.setPointerVisible(true);
}
public void hideCursor() {
window.setPointerVisible(false);
}
}