Slightly weirder render-to-texture problem.

Started by djork, July 20, 2006, 19:45:25

Previous topic - Next topic

djork

I am tearing my freaking hair out!

Here are my renderToTexture, preRender, and postRender methods.  I've got a few other things going on, but it's as streamlined and simple as possible, really.  There is a render method called between pre and post.  I'm trying to copy the top-left corner (covered by the red X) to the texture and slap that on a quad in front of a freshly-cleared screen.

Anyway... what's happening is, well, nothing.  If I turn off my postRender method it looks like I would expect it to.



But when I turn on on postRender I get a nice white (or whatever the last color happened to be set to) quad filling the whole screen, with no texture.



private void renderToTexture(int texture)
{
	GL11.glColor4f(1f, 1f, 1f, 1f);
	GL11.glBindTexture(GL11.GL_TEXTURE_2D, texture);
	GL11.glCopyTexSubImage2D(GL11.GL_TEXTURE_2D, 0, 0, 0, 0, 0, 512, 512);
}

private void preRender()
{
	GL11.glClear(GL11.GL_DEPTH_BUFFER_BIT | GL11.GL_COLOR_BUFFER_BIT);
}

private void postRender()
{
		renderToTexture(screenTexture);

	GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);

	GL11.glBindTexture(GL11.GL_TEXTURE_2D, screenTexture);

	GL11.glEnable(GL11.GL_TEXTURE_2D);

	GL11.glBegin(GL11.GL_QUADS);
	{
		GL11.glTexCoord2f(0f, gameHeight / 512f); // bottom-left
		GL11.glVertex2f(0f, displayWidth);
	
		GL11.glTexCoord2f(gameWidth / 512f, gameHeight / 512f); // bottom-right
		GL11.glVertex2f(displayWidth, displayHeight);
	
		GL11.glTexCoord2f(gameWidth / 512f, 0f); // top-right
		GL11.glVertex2f(displayWidth, 0f);
	
		GL11.glTexCoord2f(0f, 0f); // top-left
		GL11.glVertex2f(0f, 0f);
	}
	GL11.glEnd();

	GL11.glDisable(GL11.GL_TEXTURE_2D);
}

elias4444

I just went through this the other day...

First off, with your coordinates at 0,0 - I believe you're capturing from the bottom left corner of the screen, and then up and over 512. Remember that the capture coordinates are window coordinates.

Also (and this is the thing that got me), make sure the texture you're copying into isn't mipmapped. If you don't match the level to the right settings for your mipmap, you get nothing. I recommend just making a standard texture (using GL_LINEAR for your MAG filter), and then using that.

Hope that helps.  :)
=-=-=-=-=-======-=-=-=-=-=-
http://www.tommytwisters.com

djork

Hmm.  It appears that my textures are all just plain-Jane textures with no mip-mapping or anything of that sort.  I should mention that this is all in orthographic projection, and I use the flipped Y axis (+ is down, - is up).  So... that's why I was trying to start at 0, 0 and go 512 down and right from there.

Fool Running

It looks like texturing is disabled except when you are rendering after the renderToTexture() function call. I think (not sure :) ) that texturing has to be enabled when you copy the image to the texture.

That's the only thing I can see :lol:
Programmers will, one day, rule the world... and the world won't notice until its too late.Just testing the marquee option ;D