FBO question!

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

Dunno… work fine here…
If you post some code we can help you.

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.

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

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?

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?

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?

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!

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

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. 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.

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