Render-To-Texture Problems

I have build a simple application that should run a shader, which will render a teapot to a texture and then show the result on a Quad.
The bad thing about that is, that my code doesn’t work. When I run the application there is a transparent window (you see the desktop through it).

Here’s the code of my rendering-function:

	const GLfloat emission[4] = {0.0, 0.0, 0.0, 1.0};
	const GLfloat ambient[4] = {0.1, 0.1, 0.2, 1.0};
	const GLfloat diffuse[4] = {0.8, 0.85, 1.0, 1.0};
	const GLfloat specular[4] = {0.95, 0.96, 1.0, 1.0};
	GLint shininess = 64;

	glEnable( GL_TEXTURE_2D );



	glLightfv(GL_LIGHT0, GL_POSITION, lpos);

	GLint loc;

	glEnable(GL_LIGHT0);	glEnable(GL_LIGHTING);

	loc = glGetUniformLocationARB(clearRender,"Scale");
	glBindTexture(GL_TEXTURE_RECTANGLE_ARB, fb[1].texobj);
	glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fb[1].fbobj);

	glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
	glBindTexture(GL_TEXTURE_2D, fb[1].fbobj);
		glTexCoord2i(0, 0);
		glVertex2f(-1, -1);
		glTexCoord2i(320, 0);
		glVertex2f(-1 + 2, -1);
		glTexCoord2i(320, 320);
		glVertex2f(-1 + 2, -1 + 2);
		glTexCoord2i(0, 320);
		glVertex2f(-1, -1 + 2);



I guess for you it’s easy stuff, but I am completely despaired.


When I run the application there is a transparent window

That sounds very much like OpenGL is not being properly initialized.

Hm, maybe your right, but i was able to see a white background with a black rectangle before some changes. I will check that. Besides that, instead of showing the teapot, a fully black rectangle was shown. Is there anything other wrong with this code?

Well, you was right. It was the initialization. Many thanks!

But the other problem is still there: When I am rendering there’s not a Quad with a Teapot-Texture but a full black quad. May it be because of the texture coordinates? Or is the teapot-rendering at the wrong place?

Cleared the screen, did you?

Scratch that… I see the clear call…

Well I’m out of ideas.

Uhm… maybe you didnt generate mipmaps for fbo after you finish rendering to it. When you try to use such texture (from FBO) and render it on much smaller quad, hw will try to use suitable mipmap, and that mipmap doesnt exist.

I guess thats it, because I in fact didn’t create mipmaps. Can I tell it anyhow to don’t use the mipmap?


Edit: I think there are some other things going wrong.
1.) When setting up render-to-texture:

Is fb[1].texobj the (RECT)texture you want to render to? Then you should not bind it as input texture when rendering the teapot. Instead, fb[1].texobj should be used when the FBO is initialized with a glFramebufferTexture2D() call.

And before you render the quad:

should read
glBindTexture(GL_TEXTURE_RECTANGLE_ARB, fb[1].texobj);
(You don’t have worry about mipmaps when using RECT textures)

Maybe it is easier to start over from a working implementation, here’s a good tutorial: