PDA

View Full Version : Weird GL_QUAD problem



janhorn
01-22-2002, 09:04 PM
Hi,

If I try and create a textured polygon with the one end squashed, it creates it as if its two triangles with a bad line dividing them.

glBegin(GL_QUADS);
glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -0.5f, 1.0f);
glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -1.0f, 1.0f);
glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f, 1.0f, 1.0f);
glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f, 0.5f, 1.0f);
glEnd();

Why does it look like two triangles and how can I create a proper squashed on the one side quad ?

JimmyT
01-23-2002, 02:00 AM
It's probably because you're sqaushing the texture at one end. Try changing your texture coords to the following :

glBegin(GL_QUADS);
glTexCoord2f(0.0f, 0.25f); glVertex3f(-1.0f, -0.5f, 1.0f);
glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -1.0f, 1.0f);
glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f, 1.0f, 1.0f);
glTexCoord2f(0.0f, 0.75f); glVertex3f(-1.0f, 0.5f, 1.0f);
glEnd();

This will 'cut out' a section of the texture that fits the quad rather than compressing the whole texture at one end to fit.

janhorn
01-23-2002, 02:47 AM
I do want to squash the texture, but I dont want it to appear as two seperate triangles.

harsman
01-23-2002, 04:08 AM
First of all, if the OpenGL implementation triangulates your quad, the way it splits it into triangles is implementation dependant. So you might wan't to use triangles instead. Secondly, to fix this problem which has to do with the way OpenGL computes the texture coords slopes, you'll probably have to use the q texture coordinate. See this (http://www.r3.nu/~cass/qcoord/) tutorial.

janhorn
01-23-2002, 04:47 AM
Yes ! Thanks harsman. That is exactly the tut I needed http://www.opengl.org/discussion_boards/ubb/smile.gif