I was playing around with your example by simply drawing the texture to the mouse coordinates. It appears to me that everything is flipped vertically. It appears to be the framebuffer since the texCoords seem to be correct.
Code:
void draw()
{
background(0);
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);
// 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.glPushMatrix();
gl.glTranslatef(mouseX, -mouseY+height, 0);
gl.glBegin(GL.GL_QUADS);
gl.glTexCoord2f(1.0, 0.0);
gl.glVertex2f(0.0, 0.0);
gl.glTexCoord2f(0.0, 0.0);
gl.glVertex2f(100, 0.0);
gl.glTexCoord2f(0.0, 1.0);
gl.glVertex2f(100, 100);
gl.glTexCoord2f(1.0, 1.0);
gl.glVertex2f(0.0, 100);
gl.glEnd();
gl.glPopMatrix();
gl.glBindTexture(GL.GL_TEXTURE_2D, 0);
gl.glMatrixMode(GL.GL_PROJECTION);
gl.glPopMatrix();
gl.glMatrixMode(GL.GL_MODELVIEW);
gl.glPopMatrix();
pgl.endGL();
}
only if I use the negative value of mouseY everything is displayed How its intended to be. Can someone explain why this happenes?
Code:
void draw()
{
background(0);
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);
// 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.glPushMatrix();
gl.glTranslatef(mouseX, -mouseY+height, 0);
gl.glBegin(GL.GL_QUADS);
gl.glTexCoord2f(1.0, 0.0);
gl.glVertex2f(0.0, 0.0);
gl.glTexCoord2f(0.0, 0.0);
gl.glVertex2f(100, 0.0);
gl.glTexCoord2f(0.0, 1.0);
gl.glVertex2f(100, 100);
gl.glTexCoord2f(1.0, 1.0);
gl.glVertex2f(0.0, 100);
gl.glEnd();
gl.glPopMatrix();
gl.glBindTexture(GL.GL_TEXTURE_2D, 0);
gl.glMatrixMode(GL.GL_PROJECTION);
gl.glPopMatrix();
gl.glMatrixMode(GL.GL_MODELVIEW);
gl.glPopMatrix();
pgl.endGL();
}
I am on a first generation mac book pro if that matters.