Anyone used FBOs?

Started by
3 comments, last by GameDev.net 18 years, 10 months ago
I'm trying to use frame buffer objects in my app, and I'm having some major difficulties. This is the code I'm using, which is copied directly from an Nvidia presentation:

#define TEX_SIZE	512

#define CHECK_FRAMEBUFFER_STATUS() 
{ 
	GLenum status; 
	status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT); 
	switch(status) { 
		case GL_FRAMEBUFFER_COMPLETE_EXT: 
		std::cout << "Framebuffer status = complete" << std::endl; 
			break; 
		case GL_FRAMEBUFFER_UNSUPPORTED_EXT: 
		std::cout << "Framebuffer status = UNSUPPORTED" << std::endl; 
			break; 
		case GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT: 
		std::cout << "Framebuffer status = GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT" << std::endl; 
			break; 
		case GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT: 
		std::cout << "Framebuffer status = GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT" << std::endl; 
			break; 
		case GL_FRAMEBUFFER_INCOMPLETE_DUPLICATE_ATTACHMENT_EXT: 
		std::cout << "Framebuffer status = GL_FRAMEBUFFER_INCOMPLETE_DUPLICATE_ATTACHMENT_EXT" << std::endl; 
			break; 
		case GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT: 
		std::cout << "Framebuffer status = GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT" << std::endl; 
			break; 
		case GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT: 
		std::cout << "Framebuffer status = GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT" << std::endl; 
			break; 
		case GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER_EXT: 
		std::cout << "Framebuffer status = GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER_EXT" << std::endl; 
			break; 
		case GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT: 
		std::cout << "Framebuffer status = GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT" << std::endl; 
			break; 
		default: 
		printf ("return == 0x%x\n", status); 
			/* programming error; will fail on all hardware */
			assert(0); 
	} 
}

(The above source has the backslashes after each line, but it doesn't work with the source tag properly so I removed them)

...

	GLuint fb, depth_rb, tex;
	
	// create objects
	glGenFramebuffersEXT(1, &fb); // frame buffer
	glGenRenderbuffersEXT(1, &depth_rb); // render buffer
	glGenTextures(1, &tex); // texture
	
	glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fb);
	
	// initialize texture
	glBindTexture(GL_TEXTURE_2D, tex);
	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, TEX_SIZE, TEX_SIZE, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
	
	// (set texture parameters here)
	// attach texture to framebuffercolor buffer
	glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, tex, 0);

	// initialize depth renderbuffer
	glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, depth_rb);
	glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT24, TEX_SIZE, TEX_SIZE);
	
	// attach renderbuffer to framebuffer depth buffer
	glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, depth_rb);

	CHECK_FRAMEBUFFER_STATUS();


Remember, this is copied directly from an Nvidia presentation, so in theory it SHOULD work. Unfortunately, CHECK_FRAMEBUFFER_STATUS() prints out that it is unsupported! I have a GeForce 6800 GT and the latest beta drivers (forceware 77.50!). Anyone have any ideas?
Advertisement
I'm gonna bump this, I'm still having trouble with it :|
Since no one has tried to help on this, I'll offer the only thing I know on the subject. It looks like you're only trying to attach a depth buffer to the FBO (I may be wrong, I've never even worked with FBOs). Well, I read this is currently not supported, in order to attach a depth buffer you also have to attach a color buffer otherwise it will fail unsupported.
Have you got an active gl render context when you call the macro?
Also another note - why are you using a macro? That should just be a normal function that returns void.
Im using FBO correctly. Probably you didn't specified the texture parameters (in the gdc presentation they didn't):

glGenTextures(1, &texture);
glBindTexture(GL_TEXTURE_2D, texture);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);

and remember that the size must be equal between all renderbuffers (RB) and internal types between texture and RB must also be the sime.

If that doesn't help contact me: promag@di.uminho.pt

This topic is closed to new replies.

Advertisement