PDA

View Full Version : problems with FBO and DL? *SOLVED



Dragon89
02-04-2007, 03:58 AM
are there any known problems with using FBOs and displaylists?

when i render to the FBO using glCallList all i get is the bakground color... while if i dont use glCallList and render "manually" it works fine...?

zeoverlord
02-04-2007, 02:36 PM
Not all openGL commands can be used within a display list, most of these commands returns some data or binds some buffers.
I found this in the fbo documentation, it might explain things.

"Certain commands, when called while compiling a display list, are
not compiled into the display list but are executed immediately.
These are: ..., GenFramebuffersEXT, BindFramebufferEXT,
DeleteFramebuffersEXT, CheckFramebufferStatusEXT,
GenRenderbuffersEXT, BindRenderbufferEXT, DeleteRenderbuffersEXT,
RenderbufferStorageEXT, FramebufferTexture1DEXT,
FramebufferTexture2DEXT, FramebufferTexture3DEXT,
FramebufferRenderbufferEXT, GenerateMipmapEXT..." I would advise against using display lists on todays hardware as there are better ways of getting higher performance (like VBO) then display lists.

Dragon89
02-04-2007, 11:58 PM
im not calling the fbo in the display list...


FBO.Init(1024);

Terrain->Render(); // works!!

FBO.Begin();

Terrain->Render();

FBO.End();

MapShader.Use();
MapShader.ShaderProgram->sendUniform("texture", 10);
glMatrixMode (GL_PROJECTION);
glPushMatrix ();
glLoadIdentity ();

glBegin (GL_QUADS);
glMultiTexCoord2f(GL_TEXTURE0, 0, 0);
glVertex3i (-1, -1, -1);
glMultiTexCoord2f(GL_TEXTURE0, 1, 0);
glVertex3i (1, -1, -1);
glMultiTexCoord2f(GL_TEXTURE0, 1, 1);
glVertex3i (1, 1, -1);
glMultiTexCoord2f(GL_TEXTURE0, 0, 1);
glVertex3i (-1, 1, -1);
glEnd ();

glPopMatrix ();
glMatrixMode (GL_MODELVIEW);

MapShader.Disable();
__________________________

void Init(int _size)
{
size = _size;

glActiveTexture(GL_TEXTURE10);

// Setup our FBO
glGenFramebuffersEXT(1, &fbo);
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo);

// Create the render buffer for depth
glGenRenderbuffersEXT(1, &depthBuffer);
glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, depthBuffer);
glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT, size, size);

// Now setup a texture to render to
glGenTextures(1, &img);
glBindTexture(GL_TEXTURE_2D, img);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, size, size, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
// glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
//glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);


// And attach it to the FBO so we can render to it
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, img, 0);

// Attach the depth render buffer to the FBO as it's depth attachment
glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, depthBuffer);

glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); // Unbind the FBO for now

GLenum status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT);
}

void Begin()
{
glPolygonMode( GL_FRONT_AND_BACK, GL_FILL );

glActiveTexture(GL_TEXTURE10);
glBindTexture(GL_TEXTURE_2D, img);

// First we bind the FBO so we can render to it
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo);

// Save the view port and set it to the size of the texture
glPushAttrib(GL_VIEWPORT_BIT);
glViewport(0,0,size,size);

// Then render as normal
// Today's scene is a wonderful multi-coloured spinning cube ;)

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear Screen And Depth Buffer
glLoadIdentity();

glClearColor( 0.0f, 0.f, 0.0f, 1.0f );
}

void End()
{
// Restore old view port and set rendering back to default frame buffer
glPopAttrib();
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);


}

_________________________________
however if i do it like this.. to just render a fullscreen texture... it works just fine


FBO.Begin()
MapShader.Use();
MapShader.ShaderProgram->sendUniform("texture", 2);
glMatrixMode (GL_PROJECTION);
glPushMatrix ();
glLoadIdentity ();

glBegin (GL_QUADS);
glMultiTexCoord2f(GL_TEXTURE0, 0, 0);
glVertex3i (-1, -1, -1);
glMultiTexCoord2f(GL_TEXTURE0, 1, 0);
glVertex3i (1, -1, -1);
glMultiTexCoord2f(GL_TEXTURE0, 1, 1);
glVertex3i (1, 1, -1);
glMultiTexCoord2f(GL_TEXTURE0, 0, 1);
glVertex3i (-1, 1, -1);
glEnd ();

glPopMatrix ();
glMatrixMode (GL_MODELVIEW);

MapShader.Disable;
FBO.End()

jide
02-05-2007, 03:23 AM
This, to my point of view, should not happend. FBO is just a logical buffer, so is just like a normal say back buffer.

Try a glFinish at the end of your fbo's rendering code.

Surely other people here will be able to enlight you more than I did.

Dragon89
02-08-2007, 01:02 PM
sry for answering this late..

ive tried glFinish() but at no success... if i draw a fullscreenquad to the FBO i can render the FBO texture.. if i render the terrain to the FBO.. i cant render it... its like the terrain is being totally ignored and i get the bakground color instead

ive tried removing the DL lists.. and jsut render it without.. but i still get the same results...

EDIT:: maybe the terain is moved outside the camera when im using FBO? im moving the terrain 100000 units on the xz plane in the vertex shader... does the FBO affect the shaders in anyway?

EDIT2::

ive move the terrain back to the origin and nwo i get some in my FBO texture.. but its totay misoriented.. for some reason the camera isnt properly positioned during the FBO rendering.. whats causing this?

EDIT3::

Solved it by calling gluLookAt in the FBO rendering