Automatic TexCoord Generation question

I am playing around with auto texcoord generation and it works fine, except when I try to rotate 45 degrees. If I rotate 90 degree increments the texture image looks fine. Any ideas what may be wrong?
Thanks

float texCoord[16] = {1.0f, 0.0f, 0.0f, 0.0f,
	  					  0.0f, 1.0f, 0.0f, 0.0f,
						  0.0f, 0.0f, 1.0f, 0.0f,
						  0.0f, 0.0f, 0.0f, 1.0f};

	glActiveTexture(GL_TEXTURE1);

	glTexGenfv(GL_S, GL_OBJECT_PLANE, &texCoord[0]);
	glTexGenfv(GL_T, GL_OBJECT_PLANE, &texCoord[4]);
	glTexGenfv(GL_R, GL_OBJECT_PLANE, &texCoord[8]);
	glTexGenfv(GL_Q, GL_OBJECT_PLANE, &texCoord[12]);

	glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
	glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
	glTexGeni(GL_R, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
	glTexGeni(GL_Q, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);

	glEnable(GL_TEXTURE_GEN_S);
	glEnable(GL_TEXTURE_GEN_T);
	glEnable(GL_TEXTURE_GEN_R);
	glEnable(GL_TEXTURE_GEN_Q);

	glMatrixMode(GL_TEXTURE);
	glLoadIdentity();
	glRotatef(90.0f, 0.0f, 0.0f, 1.0f);
	glMatrixMode(GL_MODELVIEW);

	glEnable(GL_TEXTURE_2D);
	glBindTexture(GL_TEXTURE_2D, texture[0]);
	glBegin(GL_QUADS);
		/*glTexCoord2fv(&texCoord[0]);*/ glVertex3f(0.0f, 0.0f, 0.0f);
		/*glTexCoord2fv(&texCoord[4]);*/ glVertex3f(1.0f, 0.0f, 0.0f);
		/*glTexCoord2fv(&texCoord[8]);*/ glVertex3f(1.0f, 1.0f, 0.0f);
		/*glTexCoord2fv(&texCoord[12]);*/ glVertex3f(0.0f, 1.0f, 0.0f);
	
	glEnd();	

	glMatrixMode(GL_TEXTURE);
	glLoadIdentity();
	glRotatef(225.0f, 0.0f, 0.0f, 1.0f);
	glMatrixMode(GL_MODELVIEW);
	glTranslatef(-1.0f, 0.0f, 0.0f);

	glBegin(GL_QUADS);
		glVertex3f(0.0f, 0.0f, 0.0f);
		glVertex3f(1.0f, 0.0f, 0.0f);
		glVertex3f(1.0f, 1.0f, 0.0f);
		glVertex3f(0.0f, 1.0f, 0.0f);
	glEnd();	

	glDisable(GL_TEXTURE_2D);

	glDisable(GL_TEXTURE_GEN_S);
	glDisable(GL_TEXTURE_GEN_T);
	glDisable(GL_TEXTURE_GEN_R);
	glDisable(GL_TEXTURE_GEN_Q);

Hmm now that I think about it, it seems that the texture doesn’t rotate at the absolute position but relative to some other point on the texture. So am I correct in thinking that I need the center of the texture coordinates and rotate them? Anyway I am not sure how to do this other than trig a circle for the s,t values?

The texture will always rotate around the (0,0) texture coordinate. When rotating exactly 90 degrees and using GL_REPEAT, you won’t notice that.

To rotate around an arbitrary point (s,t) , do the same as with geometry: Translate the point to (0,0), rotate, then translate back.

Hmm not sure that’s the problem, here is a screenshot of the issue

the arrow points to the left when at zero and when at 90 it points down like so on the right, now the left image is hosed up when at 45 degrees…

Now that I look at it again, I don’t think this is possible… If you have texture of lets says 1024x1024 and you rotate the image so it stays 1to1 at 45degrees this new position will end up being 1449x1449

Hmm not sure that’s the problem, here is a screenshot of the issue
That screenshot only confirmed what Overmind wrote - your texture is being rotated around it’s corner.
So add glTranslate before and after glRotate to offset texture coordinates by 0.5.

Well I’ll be! :slight_smile: Always learning something new. Thanks a bunch Overmind and k_szczech that worked.

Here is a new screenshot. What can I do about the corners top right and bottom left…

The effect you now see is exactly what you describe in one of your previous posts. The rotated texture does not fit exactly on the polygon. There is something cut off at the edges, and there is some additional space in the corners that falls outside of the texture.

You have two possibilities.

  1. Set the wrap mode to clamp. Then the space outside the texture will be filled with the border color (or edge color, for clamp to edge).

  2. Make the unrotated texture coordinates smaller (at least [0.15,0.85]). This uses a smaller part of the texture in the unrotated case. Then there is enough texture left to cover the whole polygon even when it’s rotated.