

GL_LINEAR: Returns the weighted average of the 4 pixels surrounding the given coordinates.GL_NEAREST: Returns the pixel that is closest to the coordinates.This process is called filtering and the following methods are available: OpenGL offers various methods to decide on the sampled color when this happens. This happens when a texture image is stretched beyond its original size or when it's sized down.

Since texture coordinates are resolution independent, they won't always match a pixel exactly. This operation will set the border color to red. GlTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, color) If you use GL_CLAMP_TO_BORDER and you want to change the border color, you need to change the value of GL_TEXTURE_BORDER_COLOR by passing an RGBA float array: float color = GlTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT) Īs before, the i here indicates the type of the value you want to specify. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT) Texture parameter are changed with the glTexParameter* functions as demonstrated here. The wrapping can be set per coordinate, where the equivalent of (x,y,z) in texture coordinates is called (s,t,r). These explanations may still be a bit cryptic and since OpenGL is all about graphics, let's see what all of these cases actually look like: GL_CLAMP_TO_BORDER: The coordinates that fall outside the range will be given a specified border color.GL_CLAMP_TO_EDGE: The coordinate will simply be clamped between 0 and 1.GL_MIRRORED_REPEAT: The texture will also be repeated, but it will be mirrored when the integer part of the coordinate is odd.GL_REPEAT: The integer part of the coordinate will be ignored and a repeating pattern is formed.The first thing you'll have to consider is how the texture should be sampled when a coordinate outside the range of 0 to 1 is given. OpenGL offers you many options to control how this sampling is done, of which the common ones will be discussed here. There are different ways to approach this problem, each being appropriate for different scenarios. The operation that uses these texture coordinates to retrieve color information from the pixels is called sampling.

These coordinates range from 0.0 to 1.0 where (0,0) is conventionally the bottom-left corner and (1,1) is the top-right corner of the texture image. The pixels in the texture will be addressed using texture coordinates during drawing operations. Since images are 2D arrays of pixels, it will be bound to the GL_TEXTURE_2D target. Just like other objects, textures have to be bound to apply operations to them. This article will pay attention to the use of textures for images, but the principles generally apply to all kinds of textures. An example of another use for textures is storing terrain information. It's possible to have 1D, 2D and even 3D textures, which can be used to store bulk data on the GPU. Textures are typically used for images to decorate 3D models, but in reality they can be used to store many different kinds of data. It shouldn't be a surprise at this point what this function is called. Just like VBOs and VAOs, textures are objects that need to be generated first by calling a function.
