PDA

View Full Version : FBO not being rendered?



zweifel
02-03-2010, 10:56 AM
I created a FBO and it has GL_FRAMEBUFFER_COMPLETE_EXT. And I binded a texture created to store the depth buffer with:
glTexImage2D( GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, shadow_map_width, shadow_map_height, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_BYTE, 0);

I can attach the whole creation code if necessary, the problem is when I try to render to the FBO I got actually a complete white depth buffer :confused:

Here is the code for rendering to the FBO:



glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, shader->shadow_fbo);

glViewport(0,0, SCREEN_WIDTH*2, SCREEN_HEIGHT*2);
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );

glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();


glCullFace(GL_FRONT);


//drawing for shadow
glTranslatef (0.0f, -35.0f, -300.0f + zoom);

//set the initial position of the mesh
glRotatef( 45.0f, 1.0f, 0.0f, 0.0f );

glRotatef(0.0f + view_angle, 0.0f, 1.0f, 0.0f );

//moving the map by the movement of the mouse
glTranslatef(main_player->map_x, 0.0f , main_player->map_y);

glPushMatrix();
world->drawVisibleCharactersSimplistically(main_player->map_x, main_player->map_y);

glPopMatrix();

glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);

glViewport(0,0, window_width, window_height);

//Enabling color write (previously disabled for light POV z-buffer rendering)
glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);


.......(here goes normal scene rendering, which is OK)


I tested the complete scene above rendering to the screen and I got normal results. (Notice that the scene above does not have normals or textures attached to it, I am guessing this information is disconsidered by the depth buffer and this way I am making things faster by drawing only the vertices).

zweifel
02-03-2010, 07:57 PM
Solved! The problem was with the near clipping plane. I was playing around with the perspective and I end up changing it and voila!


From



gluPerspective( 45.0f, ratio, 0.1f, 10000.0f );



To



gluPerspective( 45.0f, ratio, 100, 4000);



So it was the depth buffer precision after all...
Is there any better way to solve the depth buffer precision?