Creating and Using Texture Objects
  • glBindTexture() creates and uses texture objects

  •  

     
     
     
     
     
     
     

    void init(void)

       glClearColor (0.0, 0.0, 0.0, 0.0);
       glShadeModel(GL_FLAT);
       glEnable(GL_DEPTH_TEST);

       makeCheckImages();
       glPixelStorei(GL_UNPACK_ALIGNMENT, 1);

       glGenTextures(2, texName);
       glBindTexture(GL_TEXTURE_2D, texName[0]);
       glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
       glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
       glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,
                       GL_NEAREST);
       glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
                       GL_NEAREST);
       glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, checkImageWidth,
                    checkImageHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE,
                    checkImage);

       glBindTexture(GL_TEXTURE_2D, texName[1]);
       glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
       glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
       glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,
                       GL_NEAREST);
       glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
                       GL_NEAREST);
       glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL); 
       glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, checkImageWidth,
                    checkImageHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE,
                    otherImage);
       glEnable(GL_TEXTURE_2D);
    }
     
     
     
     


 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

 

  Creating and Using Texture Objects (cont)

     void display(void)
    {
       glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
       glBindTexture(GL_TEXTURE_2D, texName[0]);
       glBegin(GL_QUADS);
       glTexCoord2f(0.0, 0.0); glVertex3f(-2.0, -1.0, 0.0);
       glTexCoord2f(0.0, 1.0); glVertex3f(-2.0, 1.0, 0.0);
        glTexCoord2f(1.0, 1.0); glVertex3f(0.0, 1.0, 0.0);
       glTexCoord2f(1.0, 0.0); glVertex3f(0.0, -1.0, 0.0);
       glEnd();
       glBindTexture(GL_TEXTURE_2D, texName[1]);
       glBegin(GL_QUADS);
       glTexCoord2f(0.0, 0.0); glVertex3f(1.0, -1.0, 0.0);
       glTexCoord2f(0.0, 1.0); glVertex3f(1.0, 1.0, 0.0);
       glTexCoord2f(1.0, 1.0); glVertex3f(2.41421, 1.0, -1.41421);
       glTexCoord2f(1.0, 0.0); glVertex3f(2.41421, -1.0, -1.41421);
       glEnd();
       glFlush();
    }
     
  • Question:  Why is one texture red and the other white?
  • NOTE! Texture data and properties may be changed after the texture is re-bound
  • Mipmaps are all placed in a single texture object
  • Texture objects may be removed with glDeleteTextures()

  •  

     
     
     
     
     
     
     
     
     
     
     


 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

 

  A Working Set of Resident Textures
  • NOTE!  Not all OpenGL implementations support working sets!
  • Use glGetTexParameter(GL_TEXTURE_RESIDENT) to determine if a texture is resident
    • Multiple textures may be queried with glAreTexturesResident()
  • In order to maximize performance, you should be aware of the architecture of your system as you develop or port your application
    •  Example:  on systems w/o resident texture support ALL textures are considered resident (!)

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

 

  Texture Residence Strategies

    Image from http://www.xbox.com/games/halo/_default.htm
  • For vis sim/gaming always reference resident textures
    • Re-structure the textures if there is not enough TRAM
    • De-resolute or repeat textures is necessary
    • Use glTexSubImage() to "piggyback" textures together in memory
  • Delete textures as they are not needed
  • Assign priorities to textures to increase the likelihood that they are resident
    • Use glPrioritizeTextures()

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

 

  Texture Functions
  • glTexEnv() is used to determine how the texture is applied to the existing polygon color
  • Four different modes
    • DECAL
    • MODULATE
    • BLEND
    • REPLACE

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

 

  Assigning Texture Coordinates
  • Hey! Use a modeler ...

Image from http://www.haptek.com

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

 

  Repeating and Clamping Textures
  • If texture coordinates go beyond [0, 1] then the texture data is either clamped or repeated
  • Use glTexParameter() to define
  • 2x2 array wraps to the opposite edge when repeating
  • If a border is defined, then it's value is used in the weighting
    • Otherwise GL_TEXTURE_BORDER_COLOR is used

     
  •  NOTE!  Use an alpha of 0.0 if you are clamping the texture to leave the rest of the object unaffected

  •  

     
     
     
     
     
     
     
     
     
     
     


 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

 

  Automatic Texture Coordinate Generation
  • Texture coordinates may be automagically calulated for contour lines or environment mapping

  •  

     
     
     
     
     
     


    Image from http://www.sgi.com/grafica/texmap/index.html
     
     
     
     
     
     
     


 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

 

  End of Presentation
  • Fin 9

  •  

     
     
     
     
     
     
     
     
     

  •  

  •  

     
     
     
     
     
     
     
     
     
     
     


 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

 

  End of Presentation
  • Fin 10

  •  

     
     
     
     
     
     
     
     
     

  •  

  •