OpenGL ES: Determining Texels in a Fragment

Discussion in 'iOS Programming' started by Blakeasd, May 29, 2013.

  1. Blakeasd macrumors 6502a

    Joined:
    Dec 29, 2009
    #1
    Hello, Consider the following quote from this OpenGL ES for iOS Book:

    And this quote:

    My question is how does one determine how many texels are in an image and how large those texels are. If I'm not mistaken 1 texel != 1 pixel, so you can't determine the number of texels by counting pixels. For example, the second quote describes an image with alternation black and white texels. How would you know if your image is composed of black and white texels.... who defines the texel size??
     
  2. Duncan C macrumors 6502a

    Duncan C

    Joined:
    Jan 21, 2008
    Location:
    Northern Virginia
    #2
    Here's my understanding:

    The term pixels means dots on the screen.

    OpenGL uses the term "texels" to talk about dots in a source image (texture.) At display time, a texture gets mapped onto a 2D or 3D shape, and there is no longer a one-to-one mapping between texels and pixels.

    Most of us think of pixels and texels interchangeably, but in OpenGL terms, they are not interchangeable.

    A bitmap image is a grid of dots. The number of texels is simply image heightxwidth.

    An image does not have a size, and so the dots on the image do not have a size. They're data. If you map the texture directly onto the screen, where 1 texel takes 1 pixel, then at that moment, each texel is displayed at the size of a screen pixel.

    However, with OpenGL that's the exception rather than the rule. Usually you scale textures, wrap them around shapes, rotate them, skew them, etc, in ways that mean there is no single mapping from texel size to pixel size.
     
  3. Blakeasd thread starter macrumors 6502a

    Joined:
    Dec 29, 2009
    #3
    Thanks.. What would the bounds of the texel be though? Take this for example: There is a 2x2 pixel image: 2 white pixels and 2 black pixels. If I drew this image to an OpenGL 4x4 square would 1 texel == 1 pixel? Furthermore, If I drew this with the mode being
    Code:
    GL_LINEAR
    what would this end up looking like?

    Thanks!
     
  4. Duncan C macrumors 6502a

    Duncan C

    Joined:
    Jan 21, 2008
    Location:
    Northern Virginia
    #4
    I don't do enough OpenGL to know the results of the different drawing modes off the top of my head. I'd have to go crack a manual or fire up a test program.

    I would expect a 2x2 TEXEL texture drawn into an 4x4 PIXEL viewport would stretch the texture to twice the size, so each texel would occupy 2x2 pixels.

    I suggest you do both things I mentioned (Read a good book on OpenGL ES 2.0, and find a simple GLKit based demo program and start modifying it.)
     
  5. Blakeasd thread starter macrumors 6502a

    Joined:
    Dec 29, 2009
    #5
    Ahhhhhh!!! I think I've finally got it! I'm actually asking this question in accompaniment with an OpenGL ES 2 book that I'm reading. It is admittedly pretty confusing.

    Thanks a Million!!!
     
  6. Duncan C macrumors 6502a

    Duncan C

    Joined:
    Jan 21, 2008
    Location:
    Northern Virginia
    #6
    If you're studying OpenGL and your head isn't exploding, you are not paying attention.
     

Share This Page