PDA

View Full Version : FBO question!



Golgoth
02-13-2008, 12:18 PM
Hi all!

When rendering whit an FBO active... everything disappears(nothing seems to be written into the frame buffer)... is this intended to work that way?

what can I do to prevent this from happening and still drawing to the FBO?

thx

yooyo
02-13-2008, 12:22 PM
Dunno... work fine here...
If you post some code we can help you.

Zengar
02-13-2008, 12:43 PM
You mean that nothing appears on the screen? In this case, yes, it is the indended function of FBO: it allows you to render to an offscreen target leaving your window framebuffer untouched.

zed
02-13-2008, 03:06 PM
yes as zengar saiz thats the ways its intended

to output to different places FBO/main window see
ARB_draw_buffers (part of opengl 2.0)
alternatively u can quickly copy from a FBO to the main window with framebuffer_blit

Golgoth
02-13-2008, 04:32 PM
Oki great!

well, the steps I m doing looks like this:

1 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
2 glClearColor();
3 SetFrameBuffer
4 Render 3d
5 UnsetFrameBuffer
6 Render 2d
7 SwapBuffers

I did swap step 1,2 and 3 in any order possible…

here is the actual routines:



void PBuffer::Set()
{
if (m_BufferId == 0)
{
/// Texures buffer.
glGenFramebuffersEXT(1, &m_BufferId);
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_BufferId);

/// Color texture.
GenerateTexture(m_FrameTexture);
DisableTexture(m_FrameTexture);
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, m_FrameTexture->GetDimension(), m_FrameTexture->GetId(), 0);
AX6_OPENGL_CHECK_FRAME_BUFFER_STATUS();

/// Depth texture.
GenerateTexture(m_DepthTexture);
DisableTexture(m_DepthTexture);
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, m_DepthTexture->GetDimension(), m_DepthTexture->GetId(), 0);
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_STENCIL_ATTACHMENT_EXT, m_DepthTexture->GetDimension(), m_DepthTexture->GetId(), 0);
AX6_OPENGL_CHECK_FRAME_BUFFER_STATUS();
}
else
{
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_BufferId);
}
}

void PBuffer::Unset()
{
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
}

I know the process is correct because I display the 3d objects on a textured 2d plane. But beside the plane, the actual 3d elements are not visible.

any idea what am I missing here?

Zengar
02-13-2008, 04:50 PM
I still don't understand your problem. What is not visible? What do you mean by 'render 3d, 2d'? Are you drawing to a texture and that using that texture to draw a plane?

Mark Shaxted
02-13-2008, 04:59 PM
I know the process is correct because I display the 3d objects on a textured 2d plane. But beside the plane, the actual 3d elements are not visible.

any idea what am I missing here?


Are you saying that you render some 3d geometry to an FBO. You then use this to texture a quad? Assuming this is correct, what are you seeing on the screen?

Golgoth
02-13-2008, 07:27 PM
Are you saying that you render some 3d geometry to an FBO. You then use this to texture a quad?

yes exactly, every 3d objects are showing fine on the textured quad but disappear from the main frame buffer.


yes as zengar saiz thats the ways its intended

It answered my question… now I m going to try the framebuffer_blit to make the main frame buffer visible again as zed mentioned.

Basically I want a find an alternative for glReadPixels to export a quicktime movie of the entire gl context.

So I’m taking it one step at the time.

-First, render to texture without losing the main frame buffer.

-find a way to access the FBO data directly.

-send the FBO data to QuickTime.

Im not sure its a good idea but im digging it!

thx for your inputs gentlemen!

Golgoth
02-13-2008, 08:29 PM
hummm... regarding the blit function... I came up with a starter:



void PBuffer::Set()
{
if (m_TextureBufferId == 0)
{
/// Texures buffer.
glGenFramebuffersEXT(1, &m_TextureBufferId);
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_TextureBufferId);

/// Color texture.
GenerateTexture(m_FrameTexture);
DisableTexture(m_FrameTexture);
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, m_FrameTexture->GetDimension(), m_FrameTexture->GetId(), 0);
AX6_OPENGL_CHECK_FRAME_BUFFER_STATUS();

/// Depth texture.
GenerateTexture(m_DepthTexture);
DisableTexture(m_DepthTexture);
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, m_DepthTexture->GetDimension(), m_DepthTexture->GetId(), 0);
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_STENCIL_ATTACHMENT_EXT, m_DepthTexture->GetDimension(), m_DepthTexture->GetId(), 0);
AX6_OPENGL_CHECK_FRAME_BUFFER_STATUS();
}
else
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_TextureBufferId);
}

void PBuffer::Unset()
{
glBindFramebufferEXT(GL_READ_FRAMEBUFFER_EXT, m_TextureBufferId);
glDrawBuffer(GL_COLOR_ATTACHMENT0_EXT);
glBlitFramebufferEXT(0, 0, m_Width, m_Height, 0, 0, m_Width, m_Height, GL_COLOR_BUFFER_BIT, GL_NEAREST);

glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
}

I m having a hard time finding any good references that really fits my needs... It is not working as it is obviously but how close am I? if it is not too much to ask. thx

Chris Lux
02-14-2008, 01:08 AM
Basically I want a find an alternative for glReadPixels to export a quicktime movie of the entire gl context.

So I’m taking it one step at the time.

-First, render to texture without losing the main frame buffer.

-find a way to access the FBO data directly.

-send the FBO data to QuickTime.

Im not sure its a good idea but im digging it!
if you want access to your framebuffer data, i only see two ways: glReadPixels or glGetTexImage and possibly both in combination with pixel buffer objects (PBO) (ARB_pixel_buffer_object (http://www.opengl.org/registry/specs/ARB/pixel_buffer_object.txt). With a PBO you render to the FBOs bound textures and then bind the PBO and do a glGetTexImage OR you do a glReadPixels. But using this you have to get the image data out of the PBO. The advantage is that you can do this while rendering the next frame (asynchronous transfer).

But if you want access to the framebuffer content you have to use glReadPixels (or glGetTexImage) anyways, there is no magic extension that transfers the content to your host memory for you.

zed
02-14-2008, 12:14 PM
i think i understand better what u want now, i thought you wanted to render to multiple FBOs at once

i think now
u wanna render to a FBO (with color texture attachment to it) + then render this texture to the main window?
if so thats straight forward see the FBO spec example code 1
at the end of it just draw a fullscreen quad

edit -> actually reading Chris Lux's post, yes hes right, FBOs really dont help with this situation