glCopyTexSubImage2D squishing images? [resolved]

Started by
12 comments, last by Hew T 19 years, 4 months ago
The Demo (Requires windows.h) I'm having this odd problem with glCopyTexSubImage2D where it seems as though the function is squishing the captured framebuffer image towards the bottom of the texture it is storing to. Here's an image to illustrate what I mean: This is a simply paint program. The cursor is a white diffuse sphere image and when you left click, the program copies everything from the framebuffer to a constantly updated texture, then renders the updated texture as a screen-aligned quad. That big line in the middle of the screen is the result of simply holding down "left click" while keeping the pointer stationary. As you can see, glCopyTexSubImage2D is grabbing the old image and stretching (or compressing, whichever you prefer) the image downward, resulting in the streak. Likewise, you can see near the bottome how a bunch of scribbles have been squished over time. Has anyone encountered anything similar to this before? I looked at parameters for glPixelStore and glPixelTransfer, but none of them seem like they would affect this at all. To create my initial texture, I call glCopyTexImage2D, and the width and height parameters are the same throughout the program, and are the same for both CopyTex calls, so it should be working, as far as I can tell. [Edited by - OpenGLAaron on November 25, 2004 1:26:34 AM]
Advertisement
Post code - specifically, your render segment and the part containing the glCopyTexImage2D. I suspect something like not glLoadIdentity'ing in the right place (or not at all), but it's really hard to give you any suggestions without code.

Regards,

Hew T.
///////////////////////////////////////////////////////////////////////////////// draw the screen aligned quad and cursor brush to the backbuffer///////////////////////////////////////////////////////////////////////////////{	glClearColor(0.0,0.0,0.0,0.0);	glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );	glMatrixMode(GL_PROJECTION);	glLoadIdentity();	glOrtho(-1,1,-1,1,-1000,1000);	glMatrixMode( GL_MODELVIEW );	glLoadIdentity();	glDisable(GL_LIGHTING);	glPolygonMode(GL_FRONT, GL_FILL);	///////////////////////////////////////////////////////////////////////////////	// draw the screen-aligned quad	///////////////////////////////////////////////////////////////////////////////	glActiveTextureARB(GL_TEXTURE1_ARB);	glDisable(GL_TEXTURE_2D);	glActiveTextureARB(GL_TEXTURE2_ARB);	glDisable(GL_TEXTURE_2D);	if (firstRun)	{		glActiveTextureARB(GL_TEXTURE0_ARB);		glDisable(GL_TEXTURE_2D);		firstRun = false;	}	else	{		glActiveTextureARB(GL_TEXTURE0_ARB);		glEnable(GL_TEXTURE_2D);		glBindTexture(GL_TEXTURE_2D, updateTex);		glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);	}	glColor3f(0.0,0.0,0.0);	drawQuad();	///////////////////////////////////////////////////////////////////////////////	// this draws the actual brush	///////////////////////////////////////////////////////////////////////////////	float texSize = 64.0/512.0;	glTranslatef(mousePos3D.m_x,mousePos3D.m_y,5);	glScalef(texSize,texSize,texSize);	glActiveTextureARB(GL_TEXTURE0_ARB);	glDisable(GL_TEXTURE_2D);	glColor3f(1.0,1.0,1.0);	glutSolidSphere(0.4,16,3);	glEnable(GL_LIGHTING);	///////////////////////////////////////////////////////////////////////////////	// on a left mouse click, copy the "paint texture" over the existing texture	///////////////////////////////////////////////////////////////////////////////	if (leftClick)	{		glReadBuffer(GL_BACK);		glBindTexture(GL_TEXTURE_2D, updateTex);		glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, WIDTH, HEIGHT);	}}///////////////////////////////////////////////////////////////////////////////// draw the updated texture after the copytexsubimage call///////////////////////////////////////////////////////////////////////////////{	glClearColor(0.0,0.0,0.0,0.0);	glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );	glMatrixMode(GL_PROJECTION);	glLoadIdentity();	glOrtho(-1,1,-1,1,-1000,1000);	glMatrixMode( GL_MODELVIEW );	glLoadIdentity();	glDisable(GL_LIGHTING);	glPolygonMode(GL_FRONT, GL_FILL);	//draw the updated texture	glActiveTextureARB(GL_TEXTURE2_ARB);	glDisable(GL_TEXTURE_2D);	glActiveTextureARB(GL_TEXTURE1_ARB);	glDisable(GL_TEXTURE_2D);	glActiveTextureARB(GL_TEXTURE0_ARB);	glEnable(GL_TEXTURE_2D);	glBindTexture(GL_TEXTURE_2D,updateTex);	drawQuad();	glEnable(GL_LIGHTING);}



This is my drawing function. The two segments of curly braces are actually nested within an encompassing pair, I just include them to clarify code.
Thanks for taking a look.

Woops, forgot the glCopyTexImage2D part.

	glReadBuffer(GL_BACK);	glGenTextures(1, &updateTex);	glBindTexture(GL_TEXTURE_2D, updateTex);	glCopyTexImage2D(GL_TEXTURE_2D,0,GL_RGB,0,0,WIDTH,HEIGHT,0);	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);	glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);	glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);	glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);	glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);


And I just have that last segment in my initialization function.

[Edited by - OpenGLAaron on November 24, 2004 10:24:46 PM]
Firstly, using the "source" tags when posting code is good. The FAQ can tell you how.

First look - can't see anything obviously wrong. I'd like to know what happens in your "drawQuad" routine - if the routine is not drawing to the entire screen properly, it could result in the effect you're experiencing.

Regards,

Hew T.
I was using source tags... Sorta. I'm used to using tags, and I assumed it was the same here. If you looked closely, you would have seen that the formatting was slightly different between my [ code ] tags. Nevertheless, I fixed it to what it should have been from the start. Sorry. :P<br><br>Here's my drawQuad function. Pretty straightforward, really:<br><!--STARTSCRIPT--><!--source lang="cpp"--><div class="source"><pre><br><span class="cpp-keyword">void</span> drawQuad()<br>{<br> glBegin(GL_QUADS);<br> {<br> glNormal3f(<span class="cpp-number">0</span>,<span class="cpp-number">0</span>,<span class="cpp-number">1</span>);<br><br> glMultiTexCoord2fARB(GL_TEXTURE0, <span class="cpp-number">0</span>,<span class="cpp-number">0</span>);<br> glMultiTexCoord2fARB(GL_TEXTURE1, <span class="cpp-number">0</span>,<span class="cpp-number">0</span>);<br> glMultiTexCoord2fARB(GL_TEXTURE2, <span class="cpp-number">0</span>,<span class="cpp-number">0</span>);<br> glVertex3f(-<span class="cpp-number">1</span>,-<span class="cpp-number">1</span>,<span class="cpp-number">0</span>);<br><br> glMultiTexCoord2fARB(GL_TEXTURE0, <span class="cpp-number">1</span>,<span class="cpp-number">0</span>);<br> glMultiTexCoord2fARB(GL_TEXTURE1, <span class="cpp-number">1</span>,<span class="cpp-number">0</span>);<br> glMultiTexCoord2fARB(GL_TEXTURE2, <span class="cpp-number">1</span>,<span class="cpp-number">0</span>);<br> glVertex3f(<span class="cpp-number">1</span>,-<span class="cpp-number">1</span>,<span class="cpp-number">0</span>);<br><br> glMultiTexCoord2fARB(GL_TEXTURE0, <span class="cpp-number">1</span>,<span class="cpp-number">1</span>);<br> glMultiTexCoord2fARB(GL_TEXTURE1, <span class="cpp-number">1</span>,<span class="cpp-number">1</span>);<br> glMultiTexCoord2fARB(GL_TEXTURE2, <span class="cpp-number">1</span>,<span class="cpp-number">1</span>);<br> glVertex3f(<span class="cpp-number">1</span>,<span class="cpp-number">1</span>,<span class="cpp-number">0</span>);<br><br> glMultiTexCoord2fARB(GL_TEXTURE0, <span class="cpp-number">0</span>,<span class="cpp-number">1</span>);<br> glMultiTexCoord2fARB(GL_TEXTURE1, <span class="cpp-number">0</span>,<span class="cpp-number">1</span>);<br> glMultiTexCoord2fARB(GL_TEXTURE2, <span class="cpp-number">0</span>,<span class="cpp-number">1</span>);<br> glVertex3f(-<span class="cpp-number">1</span>,<span class="cpp-number">1</span>,<span class="cpp-number">0</span>);<br> }<br> glEnd();<br>}<br><br></pre></div><!--ENDSCRIPT--><br>[edit] man, I'm a typo monster.<br>[edit 2] Just updated the code a bit, removed some things I don't need anymore.
I can't understand the exact problem from the screenshot, can you post a screenshot (or drawing) on how it is supposed to look?
Anyway, unless your screen size is a power of 2, then you might have some strange results. How big is the screen (x,y) and how big is the texture?
The screen size is 512 x 512 and the texture size is the same. Maybe I could send you the executable and then you could get a better idea of what's wrong. Actually, I could just post it on my website and anyone could try it out. Give me a few...

Okay, here it is:
http://members.shaw.ca/radrider/painter.zip
What happens if you remove:
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);	glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);	glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);	glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);	glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
When I remove those, the screen is just blank, but white.
I've had problems before where not defining the minification and magnification resulted in the texture not working at all.
Hmm. I tried leaving just the minification and magnification settings in, but it does the same thing.
I tried to run your application, but it needs glut, and I don't have it (and I am too tired right now to go and find it). Anyway, try this: Remove (comment out) all the code in the program except for the code that copies the image to the texture and then make a simple code that displays that texture, but without any fancy things such as multitexxturing, polygon offset, etc. See where the problem is.

This topic is closed to new replies.

Advertisement