Hi,
I’m having a problem with Ping-Ponging 2 FBOs (at least i think the problem is here). The resulting image is filled with dark pixels that wasn’t supposed to be there. Check the result:
http://www.geocities.com/karl_phillip/fbo_weird_result.JPG
This is what i’m doing:
void display_callback(void)
{
int i,
source = 0,
dest = 1;
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
for (i = 0; i < IT_NUM; ++i)
{
// switch source and dest for next pass
source = (source + 1) % 2;
dest = (dest + 1) % 2;
// select source: If it's the first iteration we must use "texture"
if (i == 0)
glBindTexture(texture_target, texture);
else
glBindTexture(texture_target, fbuffer[source].tex_obj);
// select destination
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbuffer[dest].fb_obj);
// #1 Cg Program
cgGLEnableProfile(cg_profile);
cgGLBindProgram(cg_program[CG_PRG_DIFF_P1]);
gl_draw_quad(IMAGE_HEIGHT, IMAGE_WIDTH, 0);
// #2 Cg Program
glEnable(GL_BLEND);
glBlendFunc(GL_ONE, GL_ONE);
cgGLBindProgram(cg_program[CG_PRG_DIFF_P2]);
gl_draw_quad(IMAGE_HEIGHT, IMAGE_WIDTH, 0);
// Add results from First and Second Cg programs
cgGLDisableProfile(cg_profile);
glBlendFunc(GL_ONE_MINUS_DST_ALPHA, GL_ONE);
gl_draw_quad(IMAGE_HEIGHT, IMAGE_WIDTH, 0);
glDisable(GL_BLEND);
}
// Copy image from dest buffer to screen
glBindTexture(texture_target, 0);
glBindTexture(texture_target, fbuffer[dest].tex_obj);
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
gl_draw_quad(IMAGE_HEIGHT, IMAGE_WIDTH, 1);
/* Bit blitting */
glutSwapBuffers();
}
Perhaps something to do with glBlendFunc() and FBOs?
However, it’s interesting to note that if i don’t use “Ping-Ponging FBOs” the result is alright. Check it out:
http://www.geocities.com/karl_phillip/no_fbo.JPG
My code WITHOUT FBOs is this:
void display_callback(void)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
cgGLEnableProfile(cg_profile);
/* Diffusion pass-One into screen buffer */
glBindTexture(texture_target, texture); /* Bind the texture with the pixels */
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
cgGLBindProgram(cg_program[CG_PRG_DIFF_P1]);
gl_draw_quad(IMAGE_HEIGHT, IMAGE_WIDTH, 0);
glEnable(GL_BLEND);
/* add the results of Diffusion pass-Two into the same buffer */
cgGLBindProgram(cg_program[CG_PRG_DIFF_P2]);
glBlendFunc(GL_ONE, GL_ONE);
gl_draw_quad(IMAGE_HEIGHT, IMAGE_WIDTH, 0);
cgGLDisableProfile(cg_profile);
glBlendFunc(GL_ONE_MINUS_DST_ALPHA, GL_ONE);
gl_draw_quad(IMAGE_HEIGHT, IMAGE_WIDTH, 0);
glDisable(GL_BLEND);
/* Bit blitting */
glutSwapBuffers();
}
Any ideias why “Dark Pixels” are invading my image when using “Ping Pong FBOs” ?
“Dark Pixels” would be a cool name for a Star Wars character
Thanks.