Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Texture coordinate interpolation  (Read 2273 times)

0 Members and 1 Guest are viewing this topic.

Jabberwocky

  • Full Member
  • ***
  • Posts: 157
    • View Profile
Texture coordinate interpolation
« on: February 28, 2016, 08:11:01 am »
Hi all,

A question for any OpenGL gurus among you:

Does OpenGL expose the functions it uses to interpolate a texture coordinate across a primitive?

I'm looking for a function which would do something like this:

sf::Vector2f InterpolateTexCoord(const std::vector<sf::Vertex>& primitive, sf::Vector2f p)
{
   // Examine the texture coordinates of primitive, and calculate the
   // interpolated texture coordinate for point p
}
 

... in other words, exactly what OpenGL does internally when calculating the color of a fragment from a texture.  Or when OpenGL passes the interpolated uv coordinate to a fragment shader.

Ideally, the function could handle either quads or triangles.  But I could get by with just one or the other, if necessary.

Thanks!
« Last Edit: February 28, 2016, 08:15:04 am by Jabberwocky »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Texture coordinate interpolation
« Reply #1 on: February 28, 2016, 08:25:55 am »
If you ignore perspective correction, that only happens in 3D, I think it's just a simple bilinear interpolation. Regarding quads, they are just treated as two triangles.
Laurent Gomila - SFML developer

Jabberwocky

  • Full Member
  • ***
  • Posts: 157
    • View Profile
Re: Texture coordinate interpolation
« Reply #2 on: February 28, 2016, 09:03:50 am »
Thanks Laurent.

I'd been looking at bilinear interpolation articles on google.  I was having some difficulty because many relate to rotating or scaling an image.  These articles assume the image is "square".  Unlike an OpenGL primitive or an SFML::VertexArray tri/quad, which may stretch the texture.

I'll keep checking it out.  But I was hoping to find an OpenGL function "shortcut".  ;)  I guess maybe there isn't one.