PDA

View Full Version : no updates are rendered to the scree



Zarathustra
12-07-2007, 04:33 PM
so what my code does
a) I render the teapot to FBO 1 (in HDR)
b) I render with a tonemapping pass to FBO 2
c) I draw a quad with the info from the FBO

Now I have an angle variable at the drawing of the quad and if I press 4 or 6 on my keyboard the angle changes. And so does the avg luminance of the image so it's actually being rotated but this rotation does not show on the screen. Anyone any idea why the updated buffer is not drawn to the screen?

This is my display code

void display()
{
//Basic rendering to FBO 1
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(d*sqrt3,d*sqrt3,d*sqrt3,
0.0,0.0,0.0,
0.0,1.0,0.0);
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fb[0].fbobj);

glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
glEnable(GL_DEPTH_TEST);

bindCgPrograms();

glPushMatrix();
glRotatef(angle,0.0,1.0,0.0);
glutSolidTeapot(1.0);
glPopMatrix();

unBindCgPrograms();

glDisable(GL_DEPTH);

//Postprocessing
std::cout<<"START POSTPROCESSING"<<std::endl;
glColor3f(1, 1, 1);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
//glActiveTexture(GL_TEXTURE0);
glEnable(GL_TEXTURE_2D);

//Calculate average Luminance
float* data = (float*)malloc(fbo_width*fbo_height*sizeof(float)) ;
//glReadBuffer(GL_COLOR_ATTACHMENT0_EXT);
glReadPixels(0,0,fbo_width,fbo_height,GL_LUMINANCE ,GL_FLOAT,data);
int j =0;
std::cout<<j<<std::endl;
float subtotal = 0;
float delta = 0.001;
int t = 0;
for(int i=0; i<fbo_height*fbo_width; i++){
if(data[i] >= 0){
subtotal += log(delta + data[i]);
}
}
avg_luminance = exp(subtotal/(fbo_width*fbo_height));
std::cout<<subtotal<<std::endl;
std::cout<<avg_luminance<<std::endl;

//Render to FBO 2
glBindTexture(GL_TEXTURE_2D,fb[0].texobj);
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fb[1].fbobj);
setTonemapParam(fb[0].texobj, avg_luminance);
bindTonemapCgPrograms();
DrawFullScreenQuad(fbo_width, fbo_height);

//Render to screen
glBindTexture(GL_TEXTURE_2D, fb[1].texobj);
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
DrawFullScreenQuad(fbo_width, fbo_height);

glDisable(GL_TEXTURE_2D);
glPopMatrix();

std::cout<<"angle "<<angle<<std::endl;
glutSwapBuffers();
//glFlush();
}

Komat
12-07-2007, 08:21 PM
Anyone any idea why the updated buffer is not drawn to the screen?

The glDisable(GL_DEPTH) is incorrect, it should be glDisable(GL_DEPTH_TEST). Because of this, the depth test is still enabled during the quad drawing. The default depth function is GL_LESS so only the first quad render will succeed during the depth test.

Zarathustra
12-08-2007, 05:38 AM
Great, thanks alot!

I've been trying to solve this for over a week and something this trivial :)

plasmonster
12-08-2007, 06:08 AM
It's a good idea to call glGetError every now and again to catch pesky mistakes like that one. You can use gluErrorString to convert the returned enum to a string suitable for printing to the console.

tamlin
12-10-2007, 07:25 AM
As for GetError, something that's served me well over the years is a macro I wrap every GL call (that can set GL error) that after every GL call automatically also calls GlError and asserts if it fails. Sure, it slows the rendering path down a little but it really can save the behing when things goes south.

For an idea you could try something like the following (add another set of {} if plain C)
#define YOUR_CHECKNAME(GL_CALL) { GL_CALL; const GLenum err = glGetError(); assert(err == GL_NO_ERROR); }
that way you also get to see the error code in the debugger if/when the assert triggers.