The Basics
A 1D texture has either width or height but not both. Such a 1D texture is only a pixel wide or high. An image with multiple 1D texture is basically a line of pixels. 1D textures are very simple (and quick) to render. There is a single OpenGL function for defining 1D textures, glTexImage1D, with 8 arguments for specification purposes :
void glTexImage1D(GLenum target, GLint level, GLint components, GLsizei width, GLint border, GLenum format, GLenum type, const GLvoid *pixels)
These secifies the actual size of the texture image. The border parameter as well as value controls the number of border pixels and can be a value of 0, 1 or 2. This specifies which texture is to be defined and there is only one argument for 1D texture images - it must be GL_TEXTURE_1D. This specifies the level of detail of texture images, usually 0 but can be a different value for mipmapped textures. This specifies the number of color values to be used for each and every pixel. For RGB as well as RGBA texture images, the values of 3 and 4 are used respectively, while a value of 1 is what is used for color index textures. This specifies the type of color values to expect. The color values are : GL_COLOR_INDEX - pixel values are color indices We can also have red and blue component swapping in Windows and SGI OpenGL implementations, which are GL_BGR_EXT and GL_BGRA_EXT (in OpenGL 1.2, these are standard formats of GL_BGR and GL_BGRA). 2D textures has both width as well as height and are more than a pixel wide or high (such as 256x256). They can be loaded from a Windows Bitmap (.BMP) file as well as other file types such as Zsoft Paintbrush (.PCX) or Truevision Targa (.TGA). A structure such as a building that require complex surface geometry can be very expensive in terms of processing time – instead, we can now use simpler geometry but achieve a higher degree of realism by using 2D textures in such a case. Other uses for 2D textures can be for things such as clouds. For the definition of 2D texture images, glTexImage2D is called. In addition to all the 1D texture image arguments above, an additional height argument (GLsizei height) is used and the value must be in the power of two. 3D textures, also known as volume textures, require support by the hardware. These are used generally for scanning programs (like MRIs). The most important drawback of having 3D textures is the amount of memory 3D textures can take up – a simple 256x256x256 luminance-alpha 3D texture image rendered at 640x480 at 32bits with double buffering (where image to be displayed is assembled in memory then placed on the screen in a single update operation, rather than building the image primitive-by-primitive on the screen; primitives are 2D polygonal shapes) plus a z-buffer will gobble up 20MB [math : 256x256x256 * 1 byte (alpha=1 byte) + framebuffer @ 640x480 * 4 bytes (32bit=4 bytes) * 3 (double buffer + z-buffer = 3) = approx 20MB]. |