|
| 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