Hi Andres, I can't seem to get it working. Its not the texture that is a problem, but I would like to send the opengl primitives to the offscreen buffer. Can I do that? My code is below and its not working. Am I doing it wrong? or is it a bug?
If I comment out the beginDraw and endDraw commands, then the quads are rendered straight to screen as expected - and the ellipses are not visible (again as expected). But when the functions are in I don't see the quads at all, just the ellipses - and they are white not colored. Maybe I understood the whole thing incorrectly, do I need to get a GL per offscreen texture? if so how do I do that? I saw that GLTexture has a gl field, but its protected. Or should the beginDraw() just bind the FBO so all following commands go straight there?
Thanks for your help!
Code:
import processing.opengl.*;
import javax.media.opengl.*;
import codeanticode.glgraphics.*;
GLGraphics glg1, glg2;
float mixFactor = 0.5;
PGraphicsOpenGL pgl;
GL gl;
int dlQuad; // display list for quads
void setup() {
size(640, 480, GLConstants.GLGRAPHICS);
msaInitGL();
glg1 = new GLGraphics(300, 300, this, true);
glg2 = new GLGraphics(200, 100, this, true);
}
void draw() {
background(0);
msaBeginGL();
glg1.beginDraw();
gl.glColor4f( 1, 0, 0, random(1));
drawQuad(random(0, glg1.width), random(0, glg1.height), random(20));
glg1.ellipse(random(0, glg1.width), random(0, glg1.height), random(50), random(50));
glg1.endDraw();
glg2.beginDraw();
gl.glColor4f( 0, 1, 0, random(1));
drawQuad(random(0, glg2.width), random(0, glg2.height), random(20));
glg2.ellipse(random(0, glg2.width), random(0, glg2.height), random(50), random(50));
glg2.endDraw();
msaEndGL();
// We mix the images together and scale them so the occupy the entire screen.
tint(1, 1 - mixFactor);
image(glg1.getTexture(), 0, 0, width, height);
tint(1, mixFactor);
image(glg2.getTexture(), 0, 0, width, height);
}
void mouseDragged() {
mixFactor = float(mouseX) / width;
}
void msaInitGL() {
colorMode( RGB, 1.0 ); // to make colors 0..1 (not 0..255)
pgl = (PGraphicsOpenGL) g; // processings opengl graphics object
gl = pgl.beginGL(); // JOGL's GL object
gl.setSwapInterval(1);
msaCreateQuadDisplayList(); // create a display list for drawing quads
gl.glDisable(GL.GL_DEPTH_TEST); // disable any use of zbuffer
gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA); // set blend mode to normal alpha
gl.glEnable( GL.GL_TEXTURE_2D ); // enable texturing
pgl.endGL();
}
// create quad display list
void msaCreateQuadDisplayList() {
dlQuad = gl.glGenLists(1);
gl.glNewList(dlQuad, GL.GL_COMPILE);
gl.glBegin(GL.GL_QUADS);
gl.glTexCoord2f(0, 0);
gl.glVertex2f( -1, -1);
gl.glTexCoord2f(1, 0);
gl.glVertex2f( 1, -1);
gl.glTexCoord2f(1, 1);
gl.glVertex2f( 1, 1);
gl.glTexCoord2f(0, 1);
gl.glVertex2f(-1, 1);
gl.glEnd();
gl.glEndList();
}
void msaBeginGL() {
pgl = (PGraphicsOpenGL) g; // processings opengl graphics object
gl = pgl.beginGL(); // JOGL's GL object
}
void msaEndGL() {
pgl.endGL();
}
void drawQuad(float x, float y, float radius) {
gl.glPushMatrix();
gl.glTranslatef(x, y, 0);
gl.glScalef( radius, radius, 1 );
gl.glCallList( dlQuad );
gl.glPopMatrix();
}