-1

Image files are rectangular, yet in a 3D environment, a rectangle will appear as an irregular quadrilateral most of the time. Consider the following image (credit to this blog):

enter image description here

Given that:

  • you already know the four vertices of the green face
  • you have access to the image file as a 2D array of color values
  • you are drawing to a screen that is a 2D array of pixels

What is the algorithm that OpenGL uses for drawing the image onto the green face?

NetherGranite
  • 1,940
  • 1
  • 14
  • 42
  • Do you mean the [attribute interpolation](https://stackoverflow.com/q/24441631/555045) or something else? – harold Sep 24 '18 at 04:28
  • In the old days it was done like this: [how to rasterize rotated rectangle (in 2d by setpixel)](https://stackoverflow.com/a/19078088/2521214) but IIRC some nowadays HW does it a bit differently using barycentric coordinates based inside triangle check and brute-forcing all the fragments of the **AABB** which is more parallel-is-able for fragment processing. On top of all this perspective correct interpolation is applied (also by HW) – Spektre Sep 24 '18 at 08:45

1 Answers1

1

The algorithm is basically (if we ignore stuff like shaders for now):

  1. break down the quadrilateral into two triangles
  2. for each triangle, compute the projection onto the image plane
  3. for each screen pixel covered by the projection of the triangle:
    1. compute the texture coordinates by interpolation from the vertices for the position to which the pixel location corresponds on the triangle.
    2. look up the texture image at the location that corresponds to the texture coordinates. Typically, some form of filtering is applied here.
    3. you have found the color for your pixel
Michael Kenzel
  • 15,508
  • 2
  • 30
  • 39