diff --git a/core/src/processing/opengl/PGL.java b/core/src/processing/opengl/PGL.java index 004a65b94..7bb8e7929 100644 --- a/core/src/processing/opengl/PGL.java +++ b/core/src/processing/opengl/PGL.java @@ -61,8 +61,6 @@ import processing.event.MouseEvent; import com.jogamp.newt.awt.NewtCanvasAWT; import com.jogamp.newt.event.InputEvent; -import com.jogamp.newt.event.WindowEvent; -import com.jogamp.newt.event.WindowUpdateEvent; import com.jogamp.newt.opengl.GLWindow; import com.jogamp.opengl.FBObject; import com.jogamp.opengl.util.AnimatorBase; @@ -630,6 +628,7 @@ public class PGL { canvasAWT = new GLCanvas(caps); canvasAWT.setBounds(0, 0, pg.width, pg.height); canvasAWT.setBackground(new Color(pg.backgroundColor, true)); + canvasAWT.setFocusable(true); pg.parent.setLayout(new BorderLayout()); pg.parent.add(canvasAWT, BorderLayout.CENTER); @@ -651,9 +650,7 @@ public class PGL { canvasNEWT = new NewtCanvasAWT(window); canvasNEWT.setBounds(0, 0, pg.width, pg.height); canvasNEWT.setBackground(new Color(pg.backgroundColor, true)); - - pg.parent.setLayout(new BorderLayout()); - pg.parent.add(canvasNEWT, BorderLayout.CENTER); + canvasNEWT.setFocusable(true); NEWTMouseListener mouseListener = new NEWTMouseListener(); window.addMouseListener(mouseListener); @@ -663,6 +660,9 @@ public class PGL { window.addWindowListener(winListener); canvasNEWT.addFocusListener(pg.parent); // So focus detection work. + pg.parent.setLayout(new BorderLayout()); + pg.parent.add(canvasNEWT, BorderLayout.CENTER); + capabilities = window.getChosenGLCapabilities(); canvas = canvasNEWT; canvasAWT = null; @@ -3237,6 +3237,7 @@ public class PGL { protected void nativeMouseEvent(com.jogamp.newt.event.MouseEvent nativeEvent, int peAction) { + if (!hasFocus) return; int modifiers = nativeEvent.getModifiers(); int peModifiers = modifiers & (InputEvent.SHIFT_MASK | @@ -3296,31 +3297,44 @@ public class PGL { pg.parent.postEvent(ke); } + boolean hasFocus = true; class NEWTWindowListener implements com.jogamp.newt.event.WindowListener { @Override - public void windowGainedFocus(WindowEvent arg0) { + public void windowGainedFocus(com.jogamp.newt.event.WindowEvent arg0) { + PApplet.println("window gained focus"); pg.parent.focusGained(null); + hasFocus = true; } @Override - public void windowLostFocus(WindowEvent arg0) { + public void windowLostFocus(com.jogamp.newt.event.WindowEvent arg0) { + PApplet.println("window lost focus"); pg.parent.focusLost(null); + hasFocus = false; } @Override - public void windowDestroyNotify(WindowEvent arg0) { } + public void windowDestroyNotify(com.jogamp.newt.event.WindowEvent arg0) { + PApplet.println("destroy"); + } @Override - public void windowDestroyed(WindowEvent arg0) { } + public void windowDestroyed(com.jogamp.newt.event.WindowEvent arg0) { + PApplet.println("destroyed"); + } @Override - public void windowMoved(WindowEvent arg0) { } + public void windowMoved(com.jogamp.newt.event.WindowEvent arg0) { + PApplet.println("moved"); + } @Override - public void windowRepaint(WindowUpdateEvent arg0) { } + public void windowRepaint(com.jogamp.newt.event.WindowUpdateEvent arg0) { + PApplet.println("window repaint"); + } @Override - public void windowResized(WindowEvent arg0) { } + public void windowResized(com.jogamp.newt.event.WindowEvent arg0) { } } // NEWT mouse listener diff --git a/core/src/processing/opengl/PGraphicsOpenGL.java b/core/src/processing/opengl/PGraphicsOpenGL.java index 75826ed70..8e26e9999 100644 --- a/core/src/processing/opengl/PGraphicsOpenGL.java +++ b/core/src/processing/opengl/PGraphicsOpenGL.java @@ -4971,8 +4971,8 @@ public class PGraphicsOpenGL extends PGraphics { // color buffer into it. @Override public void loadPixels() { - if (sized) { - // Something wrong going on with threading, sized can never be true if the + if (primarySurface && sized) { + // Something wrong going on with threading, sized can never be true if // all the steps in a resize happen inside the Animation thread. return; } @@ -5397,6 +5397,8 @@ public class PGraphicsOpenGL extends PGraphics { textureMode = NORMAL; boolean prevStroke = stroke; stroke = false; +// int prevBlendMode = blendMode; +// blendMode(REPLACE); PolyTexShader prevTexShader = polyTexShader; polyTexShader = (PolyTexShader) shader; beginShape(QUADS); @@ -5414,6 +5416,7 @@ public class PGraphicsOpenGL extends PGraphics { stroke = prevStroke; lights = prevLights; textureMode = prevTextureMode; +// blendMode(prevBlendMode); if (!hints[DISABLE_DEPTH_TEST]) { pgl.enable(PGL.DEPTH_TEST); diff --git a/core/src/processing/opengl/Texture.java b/core/src/processing/opengl/Texture.java index f4eacf60a..32d9a648f 100644 --- a/core/src/processing/opengl/Texture.java +++ b/core/src/processing/opengl/Texture.java @@ -328,7 +328,6 @@ public class Texture implements PConstants { public void set(int[] pixels, int x, int y, int w, int h, int format) { if (pixels == null) { - pixels = null; PGraphics.showWarning("The pixels array is null."); return; } @@ -1283,6 +1282,9 @@ public class Texture implements PConstants { // FBO copy: pg.pushFramebuffer(); pg.setFramebuffer(tempFbo); + // Clear the color buffer to make sure that the alpha of the + pgl.clearColor(0, 0, 0, 0); + pgl.clear(PGL.COLOR_BUFFER_BIT); if (scale) { // Rendering tex into "this", and scaling the source rectangle // to cover the entire destination region.