Mipmaps in Open GL Lecture 33 Wed Dec

  • Slides: 17
Download presentation
Mipmaps in Open. GL Lecture 33 Wed, Dec 3, 2003

Mipmaps in Open. GL Lecture 33 Wed, Dec 3, 2003

Defining Mipmaps If the mipmaps have already been created, then we define them as

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

Example of Defining Mipmaps Suppose we have a 64 image, a 32 image, and

Example of Defining Mipmaps Suppose we have a 64 image, a 32 image, and so on, down to a 1 1 image and we want to create mipmaps from them. We make repeated calls to gl. Tex. Image 2 D(), passing the level, size of the image, and a pointer to the image.

Example of Defining Mipmaps gl. Tex. Image 2 D(GL_TEXTURE_2 D, 0, GL_RGB, 64, 0,

Example of Defining Mipmaps gl. Tex. Image 2 D(GL_TEXTURE_2 D, 0, GL_RGB, 64, 0, GL_RGB, GL_UNSIGNED_BYTE, image 64); gl. Tex. Image 2 D(GL_TEXTURE_2 D, 1, GL_RGB, 32, 0, GL_RGB, GL_UNSIGNED_BYTE, image 32); // And so on… gl. Tex. Image 2 D(GL_TEXTURE_2 D, 6, GL_RGB, 1, 1, 0, GL_RGB, GL_UNSIGNED_BYTE, image 1);

Building Mipmaps Automatically An option is to let Open. GL build the mipmaps for

Building Mipmaps Automatically An option is to let Open. GL build the mipmaps for us. To create mipmaps from level 0 to a 1, write gl. Build 2 DMipmaps(GL_TEXTURE_2 D, GL_RGB, width, height, GL_RGB, GL_UNSIGNED_BYTE, ptr); 1

Minification Filters with Mipmaps If we are using mipmaps, then we need to specify

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.

Minification Filters with Mipmaps To choose the nearest texel and the nearest mipmap, write

Minification Filters with Mipmaps To choose the nearest texel and the nearest mipmap, write gl. Tex. Parameteri(GL_TEXTURE_2 D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);

Minification Filters with Mipmaps To choose the nearest texel and interpolate the mipmaps, write

Minification Filters with Mipmaps To choose the nearest texel and interpolate the mipmaps, write gl. Tex. Parameteri(GL_TEXTURE_2 D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_LINEAR);

Minification Filters with Mipmaps To interpolate the texels and choose the nearest mipmap, write

Minification Filters with Mipmaps To interpolate the texels and choose the nearest mipmap, write gl. Tex. Parameteri(GL_TEXTURE_2 D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);

Minification Filters with Mipmaps To interpolate the texels and interpolate the mipmaps, write gl.

Minification Filters with Mipmaps To interpolate the texels and interpolate the mipmaps, write gl. Tex. Parameteri(GL_TEXTURE_2 D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);

Texture Objects To improve efficiency when working with more than one texture, we may

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.

Texture Objects The values of these integers are used internally. We should let Open.

Texture Objects The values of these integers are used internally. We should let Open. GL choose the values for us. const int NUM_TEXTURES = 10; unsigned int texture. Name[NUM_TEXTURES]; gl. Gen. Textures(NUM_TEXTURES, texture. Name);

Texture Objects When first creating a texture, we may bind it to a texture

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. gl. Bind. Texture(GL_TEXTURE_2 D, texture. Name[i]); // Define a texture…

Texture Objects Later, when the texture is to be used, make another call to

Texture Objects Later, when the texture is to be used, make another call to gl. Bind. Textures(). Open. GL will see that this texture object has already been bound. Thus, it will retrieve the texture information and use it. gl. Bind. Texture(GL_TEXTURE_2 D, texture. Name[i]); // Assign texture coordinates to vertices…

Texture Objects When we are finished with the texture objects, we may delete them,

Texture Objects When we are finished with the texture objects, we may delete them, in order to recycle the memory. gl. Delete. Textures(GL_TEXTURE_2 D, texture. Name); // Don’t use texture. Name anymore…

Enabling and Disabling Textures Finally, we need to enable textures. This would typically be

Enabling and Disabling Textures Finally, we need to enable textures. This would typically be done in the display() function. gl. Enable(GL_TEXTURE_2 D); // Draw stuff… gl. Disable(GL_TEXTURE_2 D);

Examples Texture. Demo. cpp Mipmap. Demo. cpp Rgb. Image. cpp

Examples Texture. Demo. cpp Mipmap. Demo. cpp Rgb. Image. cpp