Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 5 of 5

Thread: Accessing texture data (another one...)

  1. #1
    Junior Member Regular Contributor
    Join Date
    Aug 2000
    Location
    Haifa, ISRAEL
    Posts
    101

    Accessing texture data (another one...)

    Hi guys,
    I would like to know how to access the 4 neighbor texels of a texture coordinate. In other words I want to get the 4 values around the fractional texture coordinates inorder to do my own filterring.
    How should I define the texture:
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST) or
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    What's the significance of NEAREST / LINEAR in the fragment shader?
    I would be very thanksful to get any additional information about this subject.

    Many thanks,

    Yossi

  2. #2
    Advanced Member Frequent Contributor
    Join Date
    Oct 2000
    Location
    Belgium
    Posts
    857

    Re: Accessing texture data (another one...)

    GL_NEAREST and GL_LINEAR mean the same thing they always do. You should use GL_NEAREST, and then offset your texture coordinates by 1/width and 1/height to get neighboring texels.

    -- Tom

  3. #3
    Junior Member Regular Contributor
    Join Date
    Aug 2000
    Location
    Haifa, ISRAEL
    Posts
    101

    Re: Accessing texture data (another one...)

    Thank you Tom for the answer.
    But still something isn't clear to me.
    If I get the nearest texel than the neighbors are at (1/width, 1/height) or (-1/width/, -1/height)?
    If I define the texture as GL_NEAREST I guess I lose the original fractional texture coordinates?
    Maybe if I define it as GL_LINEAR than I get the accurate fractional texture coordinates and than have an access to the neighbors that encompass the accurate coordinates.
    Hope I am clear.
    Thanks,
    Yossi

  4. #4
    Junior Member Regular Contributor
    Join Date
    Jun 2001
    Posts
    198

    Re: Accessing texture data (another one...)

    Originally posted by yossi:
    Thank you Tom for the answer.
    But still something isn't clear to me.
    If I get the nearest texel than the neighbors are at (1/width, 1/height) or (-1/width/, -1/height)?
    If I define the texture as GL_NEAREST I guess I lose the original fractional texture coordinates?
    Maybe if I define it as GL_LINEAR than I get the accurate fractional texture coordinates and than have an access to the neighbors that encompass the accurate coordinates.
    Hope I am clear.
    Thanks,
    Yossi
    Texture addressing is performed in the texture addressing units at texel fetch time. That process is completely isolated from your fragment program, i.e., the texture coordinates you see in the fragment program are always "accurate", they are never rounded/clamped or otherwise depending on the filtering mode.

    So, to answer your question, if you want to know which texel you are addressing in NEAREST mode and which are the neighbouring texels, you have to do the calculation yourself by something like taking the integer part of texcoord*TEXTURE_WIDTH (look at the OpenGL spec for the exact formula).

    Once you have that texel index, the neighbouring are 1 index away, which in 0.0f .. 1.0f range is 1/TEXTURE_WIDTH away.

    If you are bilinear filtering, then what you do is to interpolate four texels, so there's no "one texel and one neighbour", all texels are "neighbours" of your sample point (again, look at the OpenGL spec and see how the alfa & beta interpolants are calculated to perform the filtering).

  5. #5
    Junior Member Regular Contributor
    Join Date
    Aug 2000
    Location
    Haifa, ISRAEL
    Posts
    101

    Re: Accessing texture data (another one...)

    Many thanks evanGLizr for your answer. It helped me alot.

    Yossi

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •