PDA

View Full Version : Texture mapping distortion :(



UmerLaton
04-02-2012, 01:52 PM
Hi everybody,
Im working with texture in opengl. I can upload texture to and object and everything looks great when doing it on a perfect quad or polygon but when working with a irregular polygon(not the same dimensions)I get a distorted texture :(

I believe its something with texture coordinates with my polygon or something abut mipmaps?I kn ow that everything in opengl is made up from triangles,but how can I get rid of that distortion ?Should i have more texture coordinates?

Thanks

Umer

UmerLaton
04-02-2012, 01:53 PM
ohh osryy i added an image so you guys can see what am going through :(

ZbuffeR
04-02-2012, 02:05 PM
I guess this old page should help you :
http://www.xyzw.us/~cass/qcoord/

UmerLaton
04-02-2012, 06:38 PM
Hi ZbuffeR,
thanks for the link! I think Im understanding what is happening but im not totally sure how to make it work. I grab some code from the example in teh link were i think everything is happening but i got some questions about the code:
{
float tx = scale_texcoord * top;
glBegin(GL_QUADS);

glTexCoord2f(-1, -1);
glVertex2f (-1, -1);

glTexCoord4f(-tx, tx, 0, tx);
glVertex2f (-top, 1);

glTexCoord4f( tx, tx, 0, tx);
glVertex2f ( top, 1);

glTexCoord2f( 1, -1);
glVertex2f ( 1, -1);

glEnd();
}

why is he just applying gltexcoord4f() only to the top points?what happens if you change the coordinates from the bottom?

Thanks for your help!

Umer.

overlay
04-02-2012, 09:28 PM
Depending on how old is the OpenGL implementation you have available on your machine you may solve this issue with:

glHint(GL_PERSPECTIVE_CORRECTION_HINT,GL_NICEST);

This is deprecated since 3.0.

UmerLaton
04-03-2012, 07:39 AM
Hi overlay,
I got opengl v2.1 . I do have that glHint() but nothing changes :(.
Do you have any sample about texture coordinates. Im still a bit confused about how the coordinates work [glTexCoord4f(s,t,r,q)]

again thanks everybody for the help :).

ZbuffeR
04-03-2012, 08:08 AM
Depending on how old is the OpenGL implementation you have available on your machine you may solve this issue with:

glHint(GL_PERSPECTIVE_CORRECTION_HINT,GL_NICEST);

This is deprecated since 3.0.

This is a prerequisite, but not sufficient, read again the cass page.

UmerLaton
04-03-2012, 02:14 PM
Hi ZbuffeR,

I read the cass page again but I cant make it work :(... Im confuse on how gltexcoord4f(s,t,r,q) works ! Im still getting that unpleasant image! I tried to copy part of his code but I got the same distortion ;(.. Could you please help me with a sample about gltexcoord4f?

Again thanks for your time!

ZbuffeR
04-04-2012, 01:48 AM
Did you run the demo provided on the page ?
Did it work ? If not, either your hardware/driver do not support this, or the demo is bogus.

EDIT: I compiled and the demo on Linux nivida, no problem here and works as advertised (had to remove a bunch of non-used lines from the glh_linear.h to make my compiler happy).

UmerLaton
04-13-2012, 01:44 PM
Hi ZbuffeR,
sorry couldnt post this before :( Im still stuck in this, I mean ,I made the sample work...... My problem is i cant totally understand glTexCoord4f(s,t,r,q)... The sample is fine when the top is the same value for each top coordinate. I want to put each one of the quad coordinates and have a irregular quad and map my texture into that polygon! Thanks for your time and Illw ait for your comments.