Based on the 9th article, this paper adds texture mapping function to the cube.
Texture Mapping
Texture Mapping in OpenGL is a fairly straightforward concept. Every texture is no but an image of some sort. Texture mapping is basically applying a texture to a surface. Textures can be 1 D, 2D or even 3D. A 1D texture is a image with either a width or a height, not both. They are not very useful. 2d textures have both width and height and are very. 3D textures are called Volume textures and are used in medical imaging to applications for viewing CAT, MRI, and other 3D SCA Ns. We'll look on using 2D textures in OpenGL as they are the most widely used in 3D Graphics.
Windows Bitmap Files
Images in Windows are typically stored in bitmap files. These images can is used as textures that would be applied to OpenGL surfaces. But before use them for texture mapping applications We-convert should to a OpenGL format. So we essentially have to read a Windows Bitmap into OpenGL image. We can use the auxiliary library to does so. It takes care the trouble involved in performing this conversion. Once a texture map is read into memory, individual elements are called, texels-like-image ' s just element s are called pixels. We wouldn ' t be dealing with these texels as we would being using the Aux library routine Auxdibimageloada to perform the Conv Ersion for us. Also, we need to make sure this image dimensions are a power of 2. OpenGL images that "we are going to" as a texture must have of a power of 2. Thus 32X32, 64x64, 128X64 etc. are all valid the image sizes to be used as texture.
Defining 2D Textures
To define a 2D texture image into OpenGL we call glteximage2d (when we are not using mipmapping).
Mipmapping
When texture mapping are used with animation scaling of images cause some visual artifacts. This can is avoided by generating textures of various sizes from a large original texture and letting OpenGL automatically Switch between the textures of various sizes. This is called mipmapping and the individual textures are called technique. We can use the function glubuild2dmipmaps to construct a series of mipmaps.
Texture Modes
OpenGL defines three texturing modes for different types of rendering. The is gl_modulate, which modulates of the current lighting and color information with the texture image. Gl_decal is the second mode which only uses the texture image. Color and lighting information would not affect the texture ' s appearance. The last mode was Gl_blend, in which the texture image is blended with the current texture color and the current lighting a nd color information.
Texture Filters
OpenGL uses texture filters to interpolate between the texture pixels. IT provides two types of texture filters:the minification filter (gl_texture_min_filter) for polygons smaller than the Te Xture image and the magnification filter (gl_texture_mag_filter) for polygons that are larger the than image. We ' ll look at how we'll use this later in the tutorial.
Texture coordinates
Texture coordinates associate a particular location in the texture image with vertices in a polygon. These coordinates determine to the texture is mapped onto the polygon. Texture coordinates lie between 0.0 and 1.0 in the case of 2D textures.
Texture Wrapping
When texture outside the range of 0.0 to 1.0, they are either clamped to the surface or repeated. This can is specified by setting the gl_texture_wrap_* parameter appropriately, to either Gl_clamp or Gl_repeat.
Texture Objects
Texture objects are a way of loading and maintaining multiple textures in memory without loading them all time before the Y are used. They are an optimization feature introduced recently in OpenGL.