The purpose in the below code is to grab the frame buffer, send it to the current texture as luminance values, and then modulate the texture onto a quad that fills the viewport. The idea being that the frame buffer is just replaced by the same image, but as luminance values in the color specified by redColor, greenColor, and blueColor. I know the texture gets loaded, because the code thats been commented out shows that the texture changes when the input frame buffer is changed. Problem is, this doesn’t work … it shows the quad, but only in the color, without the texture modulation. Anyone know what I might be missing?
int[] viewportInfo = new int[4];
g.glGetIntegerv(g.GL_VIEWPORT, viewportInfo,0);
g.glDrawBuffer(g.GL_BACK);
g.glReadBuffer(g.GL_BACK);
//setup texture environment and enable
g.glEnable(g.GL_TEXTURE_2D);
g.glTexEnvf(g.GL_TEXTURE_ENV, g.GL_TEXTURE_ENV_MODE,g.GL_MODULATE);
//Grab whole scene into current texture in luminance mode
g.glCopyTexImage2D(g.GL_TEXTURE_2D, 0, g.GL_LUMINANCE, viewportInfo[0], viewportInfo[1], viewportInfo[2], viewportInfo[3], 0);
g.glClear(g.GL_COLOR_BUFFER_BIT|g.GL_DEPTH_BUFFER_BIT);
g.glDisable(g.GL_DEPTH_TEST);
g.glDisable(g.GL_CULL_FACE);
//Draw single quad filling screen with the texture mapped onto it, modulating the color
g.glColor3f(this.colorRed,this.colorGreen,this.colorBlue);
g.glMatrixMode(g.GL_PROJECTION);
g.glLoadIdentity();
g.glMatrixMode(g.GL_MODELVIEW);
g.glLoadIdentity();
/* TODO remove diagnostic code
FloatBuffer imageBuff = FloatBuffer.allocate(viewportInfo[2]*viewportInfo[3]);
g.glGetTexImage(g.GL_TEXTURE_2D,0,g.GL_LUMINANCE,g.GL_FLOAT,imageBuff);
float[] fla = imageBuff.array();int count = 0;
for (float f : fla) {
if (f!=0)
count++;
}
System.err.println("number of non-zero elements="+count);
*/
g.glBegin(g.GL_QUADS);
//lower-left
g.glTexCoord2f(0,0);
g.glVertex2f(-1,-1);
//lower-right
g.glTexCoord2f(1,0);
g.glVertex2f(1,-1);
//upper-right
g.glTexCoord2f(1,1);
g.glVertex2f(1,1);
//upper-left
g.glTexCoord2f(0,1);
g.glVertex2f(-1,1);
g.glEnd();
g.glPopAttrib();