Mirroring the framebuffer

Hi,

I have a situation where I would like to mirror my framebuffer (which is 1024 x 1024) horizontally.

I’m using the following code but it’s not working, all I get is a white screen.

	glEnable(GL_TEXTURE_2D);

	GLuint id;
	glGenTextures(1, &id);
	glBindTexture(GL_TEXTURE_2D, id);	
	glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 0, 0, 1024, 1024, 0);	
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
	glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
 
	glDisable(GL_DEPTH_TEST);
	glDepthMask(GL_FALSE);
	glDisable(GL_CULL_FACE);
	glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
	glDisable(GL_LIGHTING);
	glDisable(GL_FOG);
	glDisable(GL_COLOR_MATERIAL);
	glDisable(GL_BLEND);

	glMatrixMode(GL_PROJECTION);
	glPushMatrix();
	glLoadIdentity();

	glMatrixMode(GL_MODELVIEW);
	glPushMatrix();
	glLoadIdentity();

	glBegin(GL_TRIANGLES);	
	{			
		glTexCoord2f(1.0f, 0.0f);
		glVertex2f(-1.0f, -1.0f);
		
		glTexCoord2f(-1.0f, 0.0f);		
		glVertex2f(3.0f, -1.0f);
		
		glTexCoord2f(1.0f, 2.0f);
		glVertex2f(-1.0f, 3.0f);
	}
	glEnd();	

	glMatrixMode(GL_PROJECTION);
	glPopMatrix();	
	
	glMatrixMode(GL_MODELVIEW);	
	glPopMatrix();	

	glDeleteTextures(1, &id);

Ideas?

/A.B.

Seems the texture definition is not complete.
What I’m missing is texture sampling mode.
In OpenGL the default min. filter is mipmap
and your code doesnt load all mipmap levels.

Put following after glBindTexture:

  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);

If texture were not complete, he would get black screen, not white one. Seems like nothing is rendered - otherwise brinck would see something.

brinck, what is your clear color? Are you sure, that if you disable texturing - then triangle would render correctly? May be, it is somehow clipped?

@Jackis: If texture is not complete then the texture is effectively disabled. It means the polygon is rendered without a texture. In most cases the result is white.

@mfort: AFAIK, if texture is not complete, result of texture look-up is (0,0,0,1). It is said so in FP specification. Maybe, it is not so for fixed pipeline, should see.

in fixed function (look at his code) it’s white if you leave the default filter params, I know it, mfort knows it, everyone knows it.

@brinck, @mfort
Escuse me, I was mistaken - with fixed pipeline uncomplete texture lookups are abandonned, you are totally right. I forgot about that - didn’t use FFP for years. I was guided by ARB_fragment_program specification, where it is said

(23) What is the result of a sample from an incomplete texture?
RESOLVED: The result of a sample from an incomplete texture is the constant vector (0,0,0,1). The benefit of defining the result to be a constant is that broken apps are guaranteed to generate unexpected (black) results from their bad samples.

@knackered
As people say: “If you are so clever - so why aren’t you a Bentley car owner yet?”

Thanks alot guys, I will try it out when I get back to work on monday.

/A.B.

Originally posted by Jackis:
“If you are so clever - so why aren’t you a Bentley car owner yet?”
wtf? wtf is Bentley? (not that i care, but … wtf?)

tanzanite

sorry for off-topic. Bentley is one of british hand-made cars manufacturer.

Well, if the price of the car you drive is any indication of how clever you are, my handle has never been more apt.

It’s a kind of humouristic proverb.