Ok, try this code:
Code:
import processing.opengl.*;
import javax.media.opengl.*;
PGraphicsOpenGL pgl;
GL gl;
int[] drawTex = { 0 };
int[] depthStencilTex = { 0 };
int[] drawFBO = { 0 };
int texWidth = 320;
int texHeight = 240;
int GL_DEPTH_STENCIL = 0x84F9;
int GL_UNSIGNED_INT_24_8 = 0x84FA;
int GL_DEPTH24_STENCIL8 = 0x88F0;
void setup()
{
size(640, 480, OPENGL);
pgl = (PGraphicsOpenGL) g;
gl = pgl.gl;
// Creating texture.
gl.glGenTextures(1, drawTex, 0);
gl.glBindTexture(GL.GL_TEXTURE_2D, drawTex[0]);
gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER, GL.GL_NEAREST);
gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_NEAREST);
gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_S, GL.GL_CLAMP);
gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_T, GL.GL_CLAMP);
gl.glTexImage2D(GL.GL_TEXTURE_2D, 0, GL.GL_RGBA, texWidth, texHeight, 0, GL.GL_BGRA, GL.GL_UNSIGNED_BYTE, null);
gl.glBindTexture(GL.GL_TEXTURE_2D, 0);
// Create packed depth+stencil texture.
gl.glGenTextures(1, depthStencilTex, 0);
gl.glBindTexture(GL.GL_TEXTURE_2D, depthStencilTex[0]);
gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER, GL.GL_LINEAR);
gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_LINEAR);
gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_S, GL.GL_REPEAT);
gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_T, GL.GL_REPEAT);
gl.glTexImage2D(GL.GL_TEXTURE_2D, 0, GL_DEPTH24_STENCIL8, 320, 240, 0, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8, null);
gl.glBindTexture(GL.GL_TEXTURE_2D, 0);
// Creating FBO.
gl.glGenFramebuffersEXT(1, drawFBO, 0);
gl.glBindFramebufferEXT(GL.GL_FRAMEBUFFER_EXT, drawFBO[0]);
gl.glFramebufferTexture2DEXT(GL.GL_FRAMEBUFFER_EXT, GL.GL_COLOR_ATTACHMENT0_EXT, GL.GL_TEXTURE_2D, drawTex[0], 0);
gl.glFramebufferTexture2DEXT(GL.GL_FRAMEBUFFER_EXT, GL.GL_DEPTH_ATTACHMENT_EXT, GL.GL_TEXTURE_2D, depthStencilTex[0], 0);
int stat = gl.glCheckFramebufferStatusEXT(GL.GL_FRAMEBUFFER_EXT);
if (stat != GL.GL_FRAMEBUFFER_COMPLETE_EXT) System.out.println("FBO error");
gl.glBindFramebufferEXT(GL.GL_FRAMEBUFFER_EXT, 0);
}
void draw()
{
PGraphicsOpenGL pgl = (PGraphicsOpenGL) g; // g may change
GL gl = pgl.beginGL(); // always use the GL object returned by beginGL
// Binding FBO.
gl.glBindFramebufferEXT(GL.GL_FRAMEBUFFER_EXT, drawFBO[0]);
// Drawing to the first color attachement of drawFBO (this is where drawTex is attached to).
gl.glDrawBuffer(GL.GL_COLOR_ATTACHMENT0_EXT);
// Clearing Z-buffer to ensure that the new elements are drawn properly.
gl.glClearColor(0f, 0f, 0f, 0.0f);
gl.glClear(GL.GL_DEPTH_BUFFER_BIT);
// Setting orthographic projection.
gl.glMatrixMode(GL.GL_PROJECTION);
gl.glPushMatrix();
gl.glLoadIdentity();
gl.glOrtho(0.0, texWidth, 0.0, texHeight, -100.0, +100.0);
gl.glMatrixMode(GL.GL_MODELVIEW);
gl.glPushMatrix();
gl.glLoadIdentity();
gl.glViewport(0, 0, texWidth, texHeight);
// Just rendering a red quad.
gl.glDisable(GL.GL_TEXTURE_2D);
gl.glColor4f(1.0, 0.0, 0.0, 1.0);
gl.glBegin(GL.GL_QUADS);
gl.glVertex2f(0.0, 0.0);
gl.glVertex2f(texWidth, 0.0);
gl.glVertex2f(texWidth, texHeight);
gl.glVertex2f(0.0, texHeight);
gl.glEnd();
gl.glMatrixMode(GL.GL_PROJECTION);
gl.glPopMatrix();
gl.glMatrixMode(GL.GL_MODELVIEW);
gl.glPopMatrix();
// Unbinding drawFBO. Now drawing to screen again.
gl.glBindFramebufferEXT(GL.GL_FRAMEBUFFER_EXT, 0);
// Setting orthographic projection.
gl.glMatrixMode(GL.GL_PROJECTION);
gl.glPushMatrix();
gl.glLoadIdentity();
gl.glOrtho(0.0, width, 0.0, height, -100.0, +100.0);
gl.glMatrixMode(GL.GL_MODELVIEW);
gl.glPushMatrix();
gl.glLoadIdentity();
gl.glViewport(0, 0, width, height);
// Drawing texture to screen.
gl.glEnable(GL.GL_TEXTURE_2D);
gl.glActiveTexture(GL.GL_TEXTURE0);
gl.glBindTexture(GL.GL_TEXTURE_2D, drawTex[0]);
gl.glBegin(GL.GL_QUADS);
gl.glTexCoord2f(0.0, 1.0);
gl.glVertex2f(0.0, 0.0);
gl.glTexCoord2f(1.0, 1.0);
gl.glVertex2f(width, 0.0);
gl.glTexCoord2f(1.0, 0.0);
gl.glVertex2f(width, height);
gl.glTexCoord2f(0.0, 0.0);
gl.glVertex2f(0.0, height);
gl.glEnd();
gl.glBindTexture(GL.GL_TEXTURE_2D, 0);
gl.glMatrixMode(GL.GL_PROJECTION);
gl.glPopMatrix();
gl.glMatrixMode(GL.GL_MODELVIEW);
gl.glPopMatrix();
pgl.endGL();
}
Should display red screen. Let me know of any errors that show up on your Mac. The only difference with the old red screen code is the addition of the packed depth+stencil texture, which makes the FBO as a complete rendering context with depth and stencil buffers. If this works fine, then the offscreen mode of glgraphics should work as well (meaning that there must be some bug somewhere right now).