• Advertisement
Sign in to follow this  

FBO problem.

This topic is 3651 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'm trying to get FBOs setup and display a simple example of them. I'm trying to render a simple scene to a texture, and then render that texture onto a square. FBO setup:
//
	// set up FBO
	//
	// FBO
	glGenFramebuffersEXT(1, &FramebufferObject);
	glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, FramebufferObject);

	//glEnable (GL_TEXTURE_2D);
	// texture
	glGenTextures(1, &FramebufferImage);
	glBindTexture(GL_TEXTURE_2D, FramebufferImage);
	glTexImage2D(GL_TEXTURE_2D, 0, 3,  512, 512, 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_NEAREST);
	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
	//glDisable(GL_TEXTURE_2D);

	// render buffer
	glGenRenderbuffersEXT(1, &FramebufferRender);
	glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, FramebufferRender);
	glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT, 512, 512);
	
	glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, FramebufferRender);
	glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, FramebufferImage, 0);
CheckFBOStatus ();


The CheckFBOStatus returns ok. Rendering:
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);	// Clear Screen And Depth Buffer
	glLoadIdentity();

	GLfloat r = SoundInfo->waveform [0][1] / 255.0;
	GLfloat g = SoundInfo->waveform [0][151] / 255.0;
	GLfloat b = SoundInfo->waveform [0][301] / 255.0;

	//
	// renders this to a texture (FBO)
	//
	glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, FramebufferObject);
	glPushAttrib(GL_VIEWPORT_BIT);
	glViewport(0,0,512, 512);

	glTranslatef(0.0f,0.0f,-6.0f);

	glBegin(GL_TRIANGLES);
		glColor3f(r,0.0f,0.0f);			// Set The Color To Red
		glVertex3f( 0.0f, 1.0f, 0.0f);			// Move Up One Unit From Center (Top Point

		glColor3f(0.0f,g,0.0f);			// Set The Color To Green
		glVertex3f(-1.0f,-1.0f, 0.0f);			// Left And Down One Unit (Bottom Left)

		glColor3f(0.0f,0,b);			// Set The Color To Blue
		glVertex3f( 1.0f,-1.0f, 0.0f);			// Right And Down One Unit (Bottom Right)
	glEnd();

	glPopAttrib();
	glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
	//
	// end rendering to texture
	//

	// now render the texture
//	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);	// Clear Screen And Depth Buffer
//	glLoadIdentity();

	glClearColor(0.5f, 0.5f, 0.5f, 0.5f);

	
	glTranslatef(0.0f,0.0f,-6.0f);
	glRotatef (rY,0,1,0);
	rY++;

	glEnable(GL_TEXTURE_2D);
	glBindTexture (GL_TEXTURE_2D, FramebufferImage);

	glBegin(GL_QUADS);
		glTexCoord2f(0.0f, 0.0f);
		glVertex3f(-3.0f, -3.0f,  0.0f);

		glTexCoord2f(1.0f, 0.0f);
		glVertex3f( 3.0f, -3.0f,  0.0f);

		glTexCoord2f(1.0f, 1.0f);
		glVertex3f( 3.0f,  3.0f,  0.0f);

		glTexCoord2f(0.0f, 1.0f);
		glVertex3f(-3.0f,  3.0f,  0.0f);
	glEnd();						// Done Drawing A Quad
	glDisable(GL_TEXTURE_2D);


It does render to a texture, and the texture does get rendered onto the square... But for some odd reason, it only renders the last color used to the FBO. So in this example, you only see a little bit of blue, when each corner of the triangle should have a different color. It's hard to find examples of how to get this working right. Anyone know why it's only rendering the last color used to the FBO? Shoot, I guess I should also ask if I'm even using FBOs correctly. -Chris

Share this post


Link to post
Share on other sites
Advertisement
Please close this thread, the problem wasn't with my FBO, it was with me trying to remember how to texture correctly.

glColorf(1,1,1);

duh

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement