Textures stretching

My textures begin to stretch whenever the polygon takes about 1/2 of screen space. The texcoords are correct. Screenshots, using a quad (tri strip) with a perlin noise texture:
Everything is ok .
Moving closer . And closer .

Any help will be greatly appreciated.

Apparently there’s still something wrong with the way you generate the texture coordinates. If you look closely you can see that the quad is divided into two triangles. The effect you see is a typical problem that results from using perspective correct texcoord interpolation instead of projective correct interpolation.

The figures at page 2 of the document at
http://developer.nvidia.com/object/Projective_Texture_Mapping.html
illustrates this problem.

Nico

As I said the quad is made using triangle strips, but I’m 100% sure that the texcoords are correct (well, every thing is correct as long as the “camera” is not getting to close).

In theory, it will always look ok if your quad is almost parrallel to your viewing plane, because in that case the projective interpolation will be a perspective interpolation due to the constant q coordinate.

Exactly how do you generate the texture coordinates,?
Do you specify them explicitely by using texcoord2f or implicitly by using texgen?
An are you using fragment shaders? If so, do you perform texture lookups with tex or txp?

N.

I’m not using projected textures, just 2D textures.

Originally posted by -NiCo-:
[b]Exactly how do you generate the texture coordinates,?
Do you specify them explicitely by using texcoord2f or implicitly by using texgen?
An are you using fragment shaders? If so, do you perform texture lookups with tex or txp?

N.[/b]
I’m using fragement programs, but my problem effects all shaded and unshaded polygons. I’m passing texcoords using VBO (glTexCoordPointer(2, GL_FLOAT, 0, SomeBufferOffset) , and they are correct. My terrain is using a fragement program and the textures are applied in the fragement program. The texture coordinates, however, are passed in an array and are interpolated wrongly, like on every other poly. :frowning:

Can you post the code where you draw the quad and specify the texcoords? Would make things a bit easier…

N.

Originally posted by -NiCo-:
[b]Can you post the code where you draw the quad and specify the texcoords? Would make things a bit easier…

N.[/b]
Here:

 

glBindTexture(GL_TEXTURE_2D,texture);
GLEnable(GL_TEXTURE_2D);
	
glBindBufferARB(GL_ARRAY_BUFFER_ARB,VBOBuffer);

glTexCoordPointer(2, GL_FLOAT, 0, BUFFER_OFFSET(0));
		
glVertexPointer(3, GL_FLOAT, 0, BUFFER_OFFSET(8*sizeof(float)));
		glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glEnableClientState(GL_VERTEX_ARRAY);	glDisableClientState(GL_NORMAL_ARRAY);
glDisableClientState(GL_COLOR_ARRAY);

glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);


glBindBufferARB(GL_ARRAY_BUFFER_ARB,0);
	 

Have you tested it without using VBO’s, just using

glBegin(GL_TRIANGLE_STRIP);
glTexcoord2f(.,.);
glVertex3f(.,.,.);

glEnd();

Does that make a difference? I’m not that experienced in using VBOs other than plain evrtex data.

N.

Originally posted by -NiCo-:
[b]Have you tested it without using VBO’s, just using

glBegin(GL_TRIANGLE_STRIP);
glTexcoord2f(.,.);
glVertex3f(.,.,.);

glEnd();

Does that make a difference? I’m not that experienced in using VBOs other than plain evrtex data.

N.[/b]
Tested it just now. No difference. :confused:

Does it make a difference if you use GL_QUAD instead of GL_TRIANGLE STRIP?

This is a long shot, but did you change the TEXTURE_MATRIX somewhere?

If you’re using texcoord2f, using tex or txp shouldn’t make a difference in your fragment program, so that can’t be the problem

N.

Looks like your texcoords are screw-up. If you want plain texture mapping set only S and T coords. Leave R and Q to 0.0.

Take a look in your fragment shader. Maybe you are change R and Q while doing some calculations, or because driver bug maybe fragment shader have some trash in R and Q.

yooyo

As you can see from the figure at page 2 of http://developer.nvidia.com/object/Projective_Texture_Mapping.html
it’s possible that your rectangle isn’t a pure rectangle but a trapezoid.
This figure also does not make use of texture coordinate generation, but explicit coordinate definition. A small difference will result in a greater distortion at closer range and oblique angles

N.

Originally posted by -NiCo-:
[b]Does it make a difference if you use GL_QUAD instead of GL_TRIANGLE STRIP?

This is a long shot, but did you change the TEXTURE_MATRIX somewhere?

If you’re using texcoord2f, using tex or txp shouldn’t make a difference in your fragment program, so that can’t be the problem

N.[/b]
GL_QUAD doesn’t makes a difference. I didn’t change the texture matrix. And as I said before my problem effects unshaded polygons as well.

Originally posted by yooyo:
[b]Looks like your texcoords are screw-up. If you want plain texture mapping set only S and T coords. Leave R and Q to 0.0.

Take a look in your fragment shader. Maybe you are change R and Q while doing some calculations, or because driver bug maybe fragment shader have some trash in R and Q.

yooyo[/b]
R and Q are 0. I’m using 2d texture coordinates.

Originally posted by -NiCo-:
[b]As you can see from the figure at page 2 of http://developer.nvidia.com/object/Projective_Texture_Mapping.html
it’s possible that your rectangle isn’t a pure rectangle but a trapezoid.
This figure also does not make use of texture coordinate generation, but explicit coordinate definition. A small difference will result in a greater distortion at closer range and oblique angles

N.[/b]
I’m using 2 triangles so it shouldn’t make a difference.

Just for kicks, add this line somewhere:

glHint( GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST );

Those pics look like my first attempts at software texture mapping long ago. :slight_smile:

Originally posted by Portal:
[b]Just for kicks, add this line somewhere:

glHint( GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST );

Those pics look like my first attempts at software texture mapping long ago. :slight_smile: [/b]
I’m already calling this. :frowning:

I’m using 2 triangles so it shouldn’t make a difference.
This has got nothing to do with using triangles.
Take a look at http://www.esat.kuleuven.ac.be/~ncorneli/

In undistorted.bmp I drew a simple perfect rectangle using standard texture coordinates. The red color represents the s coordinate for texture lookup and green the t coordinate.

In undistorted.bmp I left the texture coordinates unchanged, but put one vertex at a different position such that it isn’t a rectangle anymore. Notice the diagonal line that appears.

It’s hard to find out the problem without having seen the full code.

N.

[quote]Originally posted by -NiCo-:
[b]

 
glGenTextures(1, &(texture));	
glBindTexture(GL_TEXTURE_2D, texture);
		glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR_MIPMAP_LINEAR);	glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_LINEAR);	
			
gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGB8, width, height, GL_RED, GL_UNSIGNED_BYTE, buffer); 

VBO init code:

 
		float *Data=new float[20];

		Data[8]=-50;
		Data[9]=50;
		Data[10]=-50;
		Data[11]=50;
		Data[12]=50;
		Data[13]=-50;
		Data[14]=50;
		Data[15]=50;
		Data[16]=-50;
		Data[17]=-50;
		Data[18]=50;
		Data[19]=-50;

		Data[0]=0.0f;
		Data[1]=0.0f;
		Data[2]=1.0f;
		Data[3]=0.0f;
		Data[4]=0.0f;
		Data[5]=1.0f;
		Data[6]=1.0f;
		Data[7]=1.0f;

		glGenBuffersARB(1,&VBOBuffer);
		glBindBufferARB(GL_ARRAY_BUFFER_ARB,VBOBuffer);
		glBufferDataARB(GL_ARRAY_BUFFER_ARB,20*sizeof(float),Data,GL_STATIC_DRAW_ARB);
		glBindBufferARB(GL_ARRAY_BUFFER_ARB,0);

		delete [] Data;
 

I’ve already posted the drawing code.