diff --git a/java/libraries/opengl/src/processing/opengl/PGL.java b/java/libraries/opengl/src/processing/opengl/PGL.java index 1d85d9dc8..a998dd75a 100644 --- a/java/libraries/opengl/src/processing/opengl/PGL.java +++ b/java/libraries/opengl/src/processing/opengl/PGL.java @@ -1288,6 +1288,11 @@ public class PGL { gl.glClearStencil(s); } + + public void glColorMask(boolean wr, boolean wg, boolean wb, boolean wa) { + gl.glColorMask(wr, wg, wb, wa); + } + public void glClearColor(float r, float g, float b, float a) { gl.glClearColor(r, g, b, a); diff --git a/java/libraries/opengl/src/processing/opengl/PGraphicsOpenGL.java b/java/libraries/opengl/src/processing/opengl/PGraphicsOpenGL.java index fd3e4fbf4..6b3ef5b3b 100644 --- a/java/libraries/opengl/src/processing/opengl/PGraphicsOpenGL.java +++ b/java/libraries/opengl/src/processing/opengl/PGraphicsOpenGL.java @@ -1645,7 +1645,21 @@ public class PGraphicsOpenGL extends PGraphics { } popFramebuffer(); - + + // Make the offscreen color buffer opaque so it doesn't show + // the background when drawn on the main surface. + if (offscreenMultisample) { + pushFramebuffer(); + setFramebuffer(offscreenFramebuffer); + } + pgl.glColorMask(false, false, false, true); + pgl.glClearColor(0, 0, 0, 1); + pgl.glClear(PGL.GL_COLOR_BUFFER_BIT); + pgl.glColorMask(true, true, true, true); + if (offscreenMultisample) { + popFramebuffer(); + } + pgl.endOffscreenDraw(pgPrimary.clearColorBuffer0); pgPrimary.restoreGL();