Function glTexParameteriv

  • glTexParameter assigns the value or values in params to the texture parameter specified as pname. target defines the target texture, either GL_TEXTURE_1D, GL_TEXTURE_2D, GL_TEXTURE_1D_ARRAY, GL_TEXTURE_2D_ARRAY, GL_TEXTURE_RECTANGLE, or GL_TEXTURE_3D. The following symbols are accepted in pname:

    • GL_TEXTURE_BASE_LEVEL Specifies the index of the lowest defined mipmap level. This is an integer value. The initial value is 0.

    • GL_TEXTURE_BORDER_COLOR The data in params specifies four values that define the border values that should be used for border texels. If a texel is sampled from the border of the texture, the values of GL_TEXTURE_BORDER_COLOR are interpreted as an RGBA color to match the texture's internal format and substituted for the non-existent texel data. If the texture contains depth components, the first component of GL_TEXTURE_BORDER_COLOR is interpreted as a depth value. The initial value is (0.0,0.0,0.0,0.0). If the values for GL_TEXTURE_BORDER_COLOR are specified with glTexParameterIiv or glTexParameterIuiv, the values are stored unmodified with an internal data type of integer. If specified with glTexParameteriv, they are converted to floating point with the following equation: 𝐟 = 2𝑐 + 1 / 2ᡇ βˆ’ 1. If specified with glTexParameterfv, they are stored unmodified as floating-point values.

    • GL_TEXTURE_COMPARE_FUNC Specifies the comparison operator used when GL_TEXTURE_COMPARE_MODE is set to GL_COMPARE_REF_TO_TEXTURE. Permissible values are:

    Texture Comparison Function Computed result
    γ…€γ…€γ…€γ…€βŽ§ 1.0𝐫 <= πƒβ‚œ
    GL_LEQUAL result = ⎨
    γ…€γ…€γ…€γ…€βŽ© 0.0𝐫 > πƒβ‚œ
    γ…€γ…€γ…€γ…€βŽ§ 1.0𝐫 >= πƒβ‚œ
    GL_GEQUAL result = ⎨
    γ…€γ…€γ…€γ…€βŽ© 0.0𝐫 < πƒβ‚œ
    γ…€γ…€γ…€γ…€βŽ§ 1.0𝐫 < πƒβ‚œ
    GL_LESS result = ⎨
    γ…€γ…€γ…€γ…€βŽ© 0.0𝐫 >= πƒβ‚œ
    γ…€γ…€γ…€γ…€βŽ§ 1.0𝐫 > πƒβ‚œ
    GL_GREATER result = ⎨
    γ…€γ…€γ…€γ…€βŽ© 0.0𝐫 <= πƒβ‚œ
    γ…€γ…€γ…€γ…€βŽ§ 1.0𝐫 = πƒβ‚œ
    GL_EQUAL result = ⎨
    γ…€γ…€γ…€γ…€βŽ© 0.0𝐫 β‰  πƒβ‚œ
    γ…€γ…€γ…€γ…€βŽ§ 1.0𝐫 β‰  πƒβ‚œ
    GL_NOTEQUAL result = ⎨
    γ…€γ…€γ…€γ…€βŽ© 0.0𝐫 = πƒβ‚œ
    GL_ALWAYS result = 1.0
    GL_NEVER result = 0.0

    where 𝐫 is the current interpolated texture coordinate, and πƒβ‚œ is the depth texture value sampled from the currently bound depth texture. result is assigned to the the red channel.

    • GL_TEXTURE_COMPARE_MODE Specifies the texture comparison mode for currently bound depth textures. That is, a texture whose internal format is GL_DEPTH_COMPONENT_*; see glTexImage2D) Permissible values are:

      • GL_COMPARE_REF_TO_TEXTURE Specifies that the interpolated and clamped 𝐫 texture coordinate should be compared to the value in the currently bound depth texture. See the discussion of GL_TEXTURE_COMPARE_FUNC for details of how the comparison is evaluated. The result of the comparison is assigned to the red channel.
      • GL_NONE Specifies that the red channel should be assigned the appropriate value from the currently bound depth texture.
    • GL_TEXTURE_LOD_BIAS params specifies a fixed bias value that is to be added to the level-of-detail parameter for the texture before texture sampling. The specified value is added to the shader-supplied bias value (if any) and subsequently clamped into the implementation-defined range [βˆ’biasβ‚˜β‚β‚“, biasβ‚˜β‚β‚“], where biasβ‚˜β‚β‚“ is the value of the implementation defined constant GL_MAX_TEXTURE_LOD_BIAS. The initial value is 0.0.

    • GL_TEXTURE_MIN_FILTER

    The texture minifying function is used whenever the level-of-detail function used when sampling from the texture determines that the texture should be minified. There are six defined minifying functions. Two of them use either the nearest texture elements or a weighted average of multiple texture elements to compute the texture value. The other four use mipmaps.

    A mipmap is an ordered set of arrays representing the same image at progressively lower resolutions. If the texture has dimensions 2ⁿ Γ— 2ᡐ, there are max(𝐧, 𝐦) + 1 mipmaps. The first mipmap is the original texture, with dimensions 2ⁿ Γ— 2ᡐ. Each subsequent mipmap has dimensions 2ᡏ⁻¹ 2ᢩ⁻¹, where 2ᡏ Γ— 2αΆ© are the dimensions of the previous mipmap, until either 𝐀 = 0 or π₯ = 0. At that point, subsequent mipmaps have dimension 1 Γ— 2ᢩ⁻¹ or 2ᡏ⁻¹ Γ— 1 until the final mipmap, which has dimension 1 Γ— 1. To define the mipmaps, call glTexImage1D, glTexImage2D, glTexImage3D, glCopyTexImage1D, or glCopyTexImage2D with the level argument indicating the order of the mipmaps. Level 0 is the original texture; level max(𝐧, 𝐦) is the final 1 Γ— 1 mipmap.

    params supplies a function for minifying the texture as one of the following:

      • GL_NEAREST Returns the value of the texture element that is nearest (in Manhattan distance) to the specified texture coordinates.
      • GL_LINEAR Returns the weighted average of the four texture elements that are closest to the specified texture coordinates. These can include items wrapped or repeated from other parts of a texture, depending on the values of GL_TEXTURE_WRAP_S and GL_TEXTURE_WRAP_T, and on the exact mapping.
      • GL_NEAREST_MIPMAP_NEAREST Chooses the mipmap that most closely matches the size of the pixel being textured and uses the GL_NEAREST criterion (the texture element closest to the specified texture coordinates) to produce a texture value.
      • GL_LINEAR_MIPMAP_NEAREST Chooses the mipmap that most closely matches the size of the pixel being textured and uses the GL_LINEAR criterion (a weighted average of the four texture elements that are closest to the specified texture coordinates) to produce a texture value.
      • GL_NEAREST_MIPMAP_LINEAR Chooses the two mipmaps that most closely match the size of the pixel being textured and uses the GL_NEAREST criterion (the texture element closest to the specified texture coordinates ) to produce a texture value from each mipmap. The final texture value is a weighted average of those two values.
      • GL_LINEAR_MIPMAP_LINEAR Chooses the two mipmaps that most closely match the size of the pixel being textured and uses the GL_LINEAR criterion (a weighted average of the texture elements that are closest to the specified texture coordinates) to produce a texture value from each mipmap. The final texture value is a weighted average of those two values.

    As more texture elements are sampled in the minification process, fewer aliasing artifacts will be apparent. While the GL_NEAREST and GL_LINEAR minification functions can be faster than the other four, they sample only one or multiple texture elements to determine the texture value of the pixel being rendered and can produce moire patterns or ragged transitions. The initial value of GL_TEXTURE_MIN_FILTER is GL_NEAREST_MIPMAP_LINEAR.

    • GL_TEXTURE_MAG_FILTER The texture magnification function is used whenever the level-of-detail function used when sampling from the texture determines that the texture should be magified. It sets the texture magnification function to either GL_NEAREST or GL_LINEAR (see below). GL_NEAREST is generally faster than GL_LINEAR, but it can produce textured images with sharper edges because the transition between texture elements is not as smooth. The initial value of GL_TEXTURE_MAG_FILTER is GL_LINEAR.

      • GL_NEAREST Returns the value of the texture element that is nearest (in Manhattan distance) to the specified texture coordinates.
      • GL_LINEAR Returns the weighted average of the texture elements that are closest to the specified texture coordinates. These can include items wrapped or repeated from other parts of a texture, depending on the values of GL_TEXTURE_WRAP_S and GL_TEXTURE_WRAP_T, and on the exact mapping.
    • GL_TEXTURE_MIN_LOD Sets the minimum level-of-detail parameter. This floating-point value limits the selection of highest resolution mipmap (lowest mipmap level). The initial value is -1000.

    • GL_TEXTURE_MAX_LOD Sets the maximum level-of-detail parameter. This floating-point value limits the selection of the lowest resolution mipmap (highest mipmap level). The initial value is 1000.

    • GL_TEXTURE_MAX_LEVEL Sets the index of the highest defined mipmap level. This is an integer value. The initial value is 1000.

    • GL_TEXTURE_SWIZZLE_R Sets the swizzle that will be applied to the 𝐫 component of a texel before it is returned to the shader. Valid values for param are GL_RED, GL_GREEN, GL_BLUE, GL_ALPHA, GL_ZERO and GL_ONE. If GL_TEXTURE_SWIZZLE_R is GL_RED, the value for 𝐫 will be taken from the first channel of the fetched texel. If GL_TEXTURE_SWIZZLE_R is GL_GREEN, the value for 𝐫 will be taken from the second channel of the fetched texel. If GL_TEXTURE_SWIZZLE_R is GL_BLUE, the value for 𝐫 will be taken from the third channel of the fetched texel. If GL_TEXTURE_SWIZZLE_R is GL_ALPHA, the value for 𝐫 will be taken from the fourth channel of the fetched texel. If GL_TEXTURE_SWIZZLE_R is GL_ZERO, the value for 𝐫 will be subtituted with 0.0. If GL_TEXTURE_SWIZZLE_R is GL_ONE, the value for 𝐫 will be subtituted with 1.0. The initial value is GL_RED.

    • GL_TEXTURE_SWIZZLE_G Sets the swizzle that will be applied to the 𝐠 component of a texel before it is returned to the shader. Valid values for param and their effects are similar to those of GL_TEXTURE_SWIZZLE_R. The initial value is GL_GREEN.

    • GL_TEXTURE_SWIZZLE_B Sets the swizzle that will be applied to the 𝐛 component of a texel before it is returned to the shader. Valid values for param and their effects are similar to those of GL_TEXTURE_SWIZZLE_R. The initial value is GL_BLUE.

    • GL_TEXTURE_SWIZZLE_A Sets the swizzle that will be applied to the 𝐚 component of a texel before it is returned to the shader. Valid values for param and their effects are similar to those of GL_TEXTURE_SWIZZLE_R. The initial value is GL_ALPHA.

    • GL_TEXTURE_SWIZZLE_RGBA Sets the swizzles that will be applied to the 𝐫, 𝐠, 𝐛, and 𝐚 components of a texel before they are returned to the shader. Valid values for params and their effects are similar to those of GL_TEXTURE_SWIZZLE_R, except that all channels are specified simultaneously. Setting the value of GL_TEXTURE_SWIZZLE_RGBA is equivalent (assuming no errors are generated) to setting the parameters of each of GL_TEXTURE_SWIZZLE_R, GL_TEXTURE_SWIZZLE_G, GL_TEXTURE_SWIZZLE_B, and GL_TEXTURE_SWIZZLE_A successively.

    • GL_TEXTURE_WRAP_S Sets the wrap parameter for texture coordinate 𝐬 to either GL_CLAMP_TO_EDGE, GL_CLAMP_TO_BORDER, GL_MIRRORED_REPEAT, or GL_REPEAT. GL_CLAMP_TO_EDGE causes 𝐬 coordinates to be clamped to the range [1/2𝐍, 1 βˆ’ 1/2𝐍], where 𝐍 is the size of the texture in the direction of clamping. GL_CLAMP_TO_BORDER evaluates 𝐬 coordinates in a similar manner to GL_CLAMP_TO_EDGE. However, in cases where clamping would have occurred in GL_CLAMP_TO_EDGE mode, the fetched texel data is substituted with the values specified by GL_TEXTURE_BORDER_COLOR. GL_REPEAT causes the integer part of the 𝐬 coordinate to be ignored; the GL uses only the fractional part, thereby creating a repeating pattern. GL_MIRRORED_REPEAT causes the 𝐬 coordinate to be set to the fractional part of the texture coordinate if the integer part of 𝐬 is even; if the integer part of 𝐬 is odd, then the 𝐬 texture coordinate is set to 1 βˆ’ frac(𝐬), where frac(𝐬) represents the fractional part of 𝐬. Initially, GL_TEXTURE_WRAP_S is set to GL_REPEAT.

    • GL_TEXTURE_WRAP_T Sets the wrap parameter for texture coordinate 𝐭 to either GL_CLAMP_TO_EDGE, GL_CLAMP_TO_BORDER, GL_MIRRORED_REPEAT, or GL_REPEAT. See the discussion under GL_TEXTURE_WRAP_S. Initially, GL_TEXTURE_WRAP_T is set to GL_REPEAT.

    • GL_TEXTURE_WRAP_R Sets the wrap parameter for texture coordinate 𝐫 to either GL_CLAMP_TO_EDGE, GL_CLAMP_TO_BORDER, GL_MIRRORED_REPEAT, or GL_REPEAT. See the discussion under GL_TEXTURE_WRAP_S. Initially, GL_TEXTURE_WRAP_R is set to GL_REPEAT.

    Parameters

    • target: number

      Specifies the target texture, which must be either GL_TEXTURE_1D, GL_TEXTURE_2D, GL_TEXTURE_3D, GL_TEXTURE_1D_ARRAY, GL_TEXTURE_2D_ARRAY, GL_TEXTURE_RECTANGLE, or GL_TEXTURE_CUBE_MAP.

    • pname: number

      Specifies the symbolic name of a texture parameter. pname can be one of the following: GL_TEXTURE_BASE_LEVEL, GL_TEXTURE_BORDER_COLOR, GL_TEXTURE_COMPARE_FUNC, GL_TEXTURE_COMPARE_MODE, GL_TEXTURE_LOD_BIAS, GL_TEXTURE_MIN_FILTER, GL_TEXTURE_MAG_FILTER, GL_TEXTURE_MIN_LOD, GL_TEXTURE_MAX_LOD, GL_TEXTURE_MAX_LEVEL, GL_TEXTURE_SWIZZLE_R, GL_TEXTURE_SWIZZLE_G, GL_TEXTURE_SWIZZLE_B, GL_TEXTURE_SWIZZLE_A, GL_TEXTURE_SWIZZLE_RGBA, GL_TEXTURE_WRAP_S, GL_TEXTURE_WRAP_T, or GL_TEXTURE_WRAP_R.

    • params: number

      Specifies a pointer to an array where the value or values of pname are stored.

    Returns void

    Summary

    set texture parameters

    Example

    Create a framebuffer object with a texture-based color attachment and a texture-based depth attachment. Using texture-based attachments allows sampling of those textures in shaders.

    // fbo_width and fbo_height are the desired width and height of the FBO.
    // For Opengl <= 4.4 or if the GL_ARB_texture_non_power_of_two extension
    // is present, fbo_width and fbo_height can be values other than 2^n for
    // some integer n.

    // Build the texture that will serve as the color attachment for the framebuffer.
    let texture_map: GLuint;
    glGenTextures(1, texture_map);
    glBindTexture(GL_TEXTURE_2D, texture_map);

    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);

    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, fbo_width, fbo_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);

    glBindTexture(GL_TEXTURE_2D, 0);

    // Build the texture that will serve as the depth attachment for the framebuffer.
    let depth_texture: GLuint;
    glGenTextures(1, depth_texture);
    glBindTexture(GL_TEXTURE_2D, depth_texture);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
    glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, fbo_width, fbo_height, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_BYTE, NULL);
    glBindTexture(GL_TEXTURE_2D, 0);

    // Build the framebuffer.
    let framebuffer: GLuint;
    glGenFramebuffers(1, framebuffer);
    glBindFramebuffer(GL_FRAMEBUFFER, framebuffer);
    glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture_map, 0);
    glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, depth_texture, 0);

    let status: GLenum = glCheckFramebufferStatus(GL_FRAMEBUFFER);
    if (status != GL_FRAMEBUFFER_COMPLETE)
    // Error

    glBindFramebuffer(GL_FRAMEBUFFER, 0);

    Example

    Create a texture object with linear mipmaps and edge clamping.

    let texture_id: GLuint;
    glGenTextures(1, texture_id);
    glBindTexture(GL_TEXTURE_2D, texture_id);

    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);

    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);

    // texture_data is the source data of your texture, in this case
    // its size is sizeof(unsigned char) * texture_width * texture_height * 4
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, texture_width, texture_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, texture_data);
    glGenerateMipmap(GL_TEXTURE_2D); // Unavailable in OpenGL 2.1, use gluBuild2DMipmaps() instead

    glBindTexture(GL_TEXTURE_2D, 0);

    Tutorial

    Songho - OpenGL Frame Buffer Object (FBO)

    Tutorial

    open.gl - Framebuffers

    Tutorial

    open.gl - Textures Objects and Parameters

    Tutorial

    opengl-tutorial.org - Tutorial 14 : Render To Texture

    Tutorial

    opengl-tutorial.org - Tutorial 16 : Shadow mapping

    Tutorial

    opengl-tutorial.org - Tutorial 5 : A Textured Cube

    See

    glTexParameter

Generated using TypeDoc