From 453316cd587e4f6b3f191c2c1e226ca0466ef855 Mon Sep 17 00:00:00 2001 From: codeanticode Date: Thu, 21 Jun 2012 04:20:53 +0000 Subject: [PATCH] making offscreen surfaces opaque --- .../opengl/src/processing/opengl/PGL.java | 5 +++++ .../src/processing/opengl/PGraphicsOpenGL.java | 16 +++++++++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) 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();