1 / 17

Mipmaps in OpenGL

Mipmaps in OpenGL. Lecture 33 Wed, Dec 3, 2003. Defining Mipmaps. If the mipmaps have already been created, then we define them as textures using the glTexImage2D() function, specifying the mipmap level. glTexImage2D(GL_TEXTURE_2D, level , GL_RGB, width, height, 0, GL_RGB,

egraham
Download Presentation

Mipmaps in OpenGL

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Mipmaps in OpenGL Lecture 33 Wed, Dec 3, 2003

  2. Defining Mipmaps • If the mipmaps have already been created, then we define them as textures using the glTexImage2D() function, specifying the mipmap level. glTexImage2D(GL_TEXTURE_2D, level, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, ptr);

  3. Example of Defining Mipmaps • Suppose we have a 64  64 image, a 32  32 image, and so on, down to a 1  1 image and we want to create mipmaps from them. • We make repeated calls to glTexImage2D(), passing the level, size of the image, and a pointer to the image.

  4. Example of Defining Mipmaps glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 64, 64, 0, GL_RGB, GL_UNSIGNED_BYTE, image64); glTexImage2D(GL_TEXTURE_2D, 1, GL_RGB, 32, 32, 0, GL_RGB, GL_UNSIGNED_BYTE, image32); // And so on… glTexImage2D(GL_TEXTURE_2D, 6, GL_RGB, 1, 1, 0, GL_RGB, GL_UNSIGNED_BYTE, image1);

  5. Building Mipmaps Automatically • An option is to let OpenGL build the mipmaps for us. • To create mipmaps from level 0 to a 1  1, write glBuild2DMipmaps(GL_TEXTURE_2D, GL_RGB, width, height, GL_RGB, GL_UNSIGNED_BYTE, ptr);

  6. Minification Filters with Mipmaps • If we are using mipmaps, then we need to specify whether we want to use the nearest mipmap or use a weighted average of the nearest two mipmaps. • This choice is independent of how we select a texel or texels from a single mipmap.

  7. Minification Filters with Mipmaps • To choose the nearest texel and the nearest mipmap, write glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);

  8. Minification Filters with Mipmaps • To choose the nearest texel and interpolate the mipmaps, write glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_LINEAR);

  9. Minification Filters with Mipmaps • To interpolate the texels and choose the nearest mipmap, write glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);

  10. Minification Filters with Mipmaps • To interpolate the texels and interpolate the mipmaps, write glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);

  11. Texture Objects • To improve efficiency when working with more than one texture, we may create the textures and store them as texture objects. • A texture object has a texture name which is an unsigned integer.

  12. Texture Objects • The values of these integers are used internally. • We should let OpenGL choose the values for us. const int NUM_TEXTURES = 10; unsigned int textureName[NUM_TEXTURES]; glGenTextures(NUM_TEXTURES, textureName);

  13. Texture Objects • When first creating a texture, we may bind it to a texture name. • Whatever texture commands follow will be associated with this texture name. glBindTexture(GL_TEXTURE_2D, textureName[i]); // Define a texture…

  14. Texture Objects • Later, when the texture is to be used, make another call to glBindTextures(). • OpenGL will see that this texture object has already been bound. • Thus, it will retrieve the texture information and use it. glBindTexture(GL_TEXTURE_2D, textureName[i]); // Assign texture coordinates to vertices…

  15. Texture Objects • When we are finished with the texture objects, we may delete them, in order to recycle the memory. glDeleteTextures(GL_TEXTURE_2D, textureName); // Don’t use textureName anymore…

  16. Enabling and Disabling Textures • Finally, we need to enable textures. • This would typically be done in the display() function. glEnable(GL_TEXTURE_2D); // Draw stuff… glDisable(GL_TEXTURE_2D);

  17. Examples • TextureDemo.cpp • MipmapDemo.cpp • RgbImage.cpp

More Related