​OPENGL TEXTURE DIFFERENCE BETWEEN GL_LINEAR AND GL_NEAREST​


Suppose a picture of size 3 pixels x 3 pixels, which a zoom result to this :

GL_NEAREST 和 GL_LINEAR_html

Zoom on the 3x3 picture

Texture 'pixels' are called texels. A texel is associated with a color and correspond to a region on the UV system (texture coordinate system). Texels are represented in the following pictures.

The texture associated of this picture can be represented by the picture shown below.

GL_NEAREST 和 GL_LINEAR_html_02

Texture texels

In most cases, the uv coordinate read on the texture does not correspond to a texel center. It is generaly between two texels.

To determine the uv color, there are different ways :

  • Pick up the the closest texel, and use its color (GL_NEAREST). This is equivalent to zooming on the picture.
  • Linear interpolation of the color between the two closest texels (GL_LINEAR)

GL_NEAREST 和 GL_LINEAR_html_03 GL_NEAREST 和 GL_LINEAR_html_04

GL_NEAREST & GL_LINEAR

Here is the result of these two methods :

GL_NEAREST 和 GL_LINEAR_html_05

Zoom on the original picture (4x4 pixels)

GL_NEAREST 和 GL_LINEAR_html_05 GL_NEAREST 和 GL_LINEAR_html_07

GL_NEAREST vs GL_LINEAR