1

I've got a textured 4 corner polygon that I'm currently drawing using two triangles and GL_TRIANGLE_STRIP. The right side needs to be taller, and this messes things up. There's a noticeable difference where the triangles intersect in the middle, how do I clear something like this up?

I think I need some sort of affine transform, or to subdivide into even more triangles, but I'm not sure.

screenshot: https://i.stack.imgur.com/ehW84.png

example code:

float x = rect.origin.x;
float y = rect.origin.y;
float w = x + rect.size.width;
float h = y + rect.size.height;
V2fT2f quad[4] = {
    //x  y
    { x, y, 0, 1 },//bottom left
    { w, y-0.2, 1, 1 },//bottom right
    { x, h, 0, 0 },//top left
    { w, h+0.2, 1, 0 },//top right
};
glEnable(GL_TEXTURE_2D);
glEnableClientState(GL_VERTEX_ARRAY);
glBindTexture(GL_TEXTURE_2D,texID);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);glErrorCheck();
glVertexPointer  (2, GL_FLOAT, sizeof(V2fT2f), &quad[0].x);
glTexCoordPointer(2, GL_FLOAT, sizeof(V2fT2f), &quad[0].s);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
John Coates
  • 476
  • 1
  • 6
  • 14
  • Some code and a screenshot would help - without it people will find it harder to help you. – Ani May 21 '12 at 18:17
  • Are you trying to get a cover flow like effect? If yes, you have set up a perspective projection, correct? – Ani May 21 '12 at 18:28
  • It sounds like you're trying to do this in OpenGL ES 1.1, but I present a 2.0 shader and transformation matrix that accomplishes a perspective effect in this answer: http://stackoverflow.com/a/10458680/19679 . I don't see the kind of texture coordinate interpolation errors you're encountering here in my case. – Brad Larson May 22 '12 at 01:47

1 Answers1

0

In any case to get that effect with a transformation - you will need a perspective projection set up.

After you've done that, here are your vertices (these form a rectangle of width and height)

  1. X: centerX - halfWidth, Y: y - HalfHeight, Tu: 0, Tv: 0
  2. X: centerX - halfWidth, Y: y + HalfHeight, Tu: 0, Tv: 1
  3. X: centerX + halfWidth, Y: y + HalfHeight, Tu: 1, Tv: 1
  4. X: centerX + halfWidth, Y: y - HalfHeight, Tu: 1, Tv: 0

Enclose this inside a glRotatef(angle, 0, 1, 0) - rotate by angle degrees around the Y axis

and that should give you what you need.

Ani
  • 10,826
  • 3
  • 27
  • 46
  • by perspective projection you mean glMatrixMode(GL_PROJECTION); correct? – John Coates May 21 '12 at 19:07
  • That only sets the name of the matrix you want. You also have to set up the values using something like gluPerspective (http://www.opengl.org/sdk/docs/man/xhtml/gluPerspective.xml) and view it using gluLookAt (http://www.opengl.org/sdk/docs/man/xhtml/gluLookAt.xml) – Ani May 21 '12 at 20:20