Sign in to follow this  

render 2 tex with framebuffers results in black texture

This topic is 4382 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have built rendering to texture using framebuffers and renderbuffers into my application, but I always get a black texture from rendering to the framebuffer. Any idea what I might be doing wrong (need code)?
//Initialization

int ogl_create_fbuffer (ogl_fbuffer *fb, int nWidth, int nHeight)
{
if (!bRender2TextureOk)
	return 0;
glGenFramebuffersEXT (1, &fb->hBuf);
glGenTextures (1, &fb->texId);
glGenRenderbuffersEXT (1, &fb->hDepthRb);
glBindFramebufferEXT (GL_FRAMEBUFFER_EXT, fb->hBuf);
glBindTexture (GL_TEXTURE_2D, fb->texId);
if (nWidth > 0)
	fb->nWidth = nWidth;
if (nHeight > 0)
	fb->nHeight = nHeight;
#if 1
glTexImage2D (GL_TEXTURE_2D, 0, GL_RGB8, fb->nWidth, fb->nHeight, 0, GL_RGB, GL_INT, NULL);
#else
glTexImage2D (GL_TEXTURE_2D, 0, GL_RGBA8, fb->nWidth, fb->nHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
#endif
glGenerateMipmapEXT (GL_TEXTURE_2D);
glFramebufferTexture2DEXT (GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, fb->texId, 0);
glBindRenderbufferEXT (GL_RENDERBUFFER_EXT, fb->hDepthRb);
glRenderbufferStorageEXT (GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT24, fb->nWidth, fb->nHeight);
glFramebufferRenderbufferEXT (GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, fb->hDepthRb);
if (ogl_fbuffer_avail (fb) < 0)
	return fb->nStatus;
glFramebufferTexture2DEXT (GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, fb->texId, 0);
glFramebufferRenderbufferEXT (GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, fb->hDepthRb);
glBindFramebufferEXT (GL_FRAMEBUFFER_EXT, 0);
return 1;
}

// turn framebuffer on

int ogl_enable_fbuffer (ogl_fbuffer *fb)
{
glBindTexture (GL_TEXTURE_2D, 0);
glBindFramebufferEXT (GL_FRAMEBUFFER_EXT, fb->hBuf);
//glDrawBuffer (GL_FRONT);
//glReadBuffer (GL_FRONT);
return 1;
}

// turn framebuffer off
glBindFramebufferEXT (GL_FRAMEBUFFER_EXT, 0);
glBindTexture (GL_TEXTURE_2D, fb->texId);



Before rendering to the framebuffer, it is turned on. Then, the app is calling its regular rendering routine. After that, the framebuffer is turned off. Before rendering the framebuffer texture, it is bound by calling glBindTexture (GL_TEXTURE_2D, tex->fbuffer.texId); [Edited by - karx11erx on December 16, 2005 5:09:02 PM]

Share this post


Link to post
Share on other sites

This topic is 4382 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this