|
| I know of no more encouraging fact, |
| than the unquestionable ability of man, |
| to elevate his life by conscious endeavor. |
| Henry David Thoreau |
Texture mapping -- applying a graphics image, a picutre, or a pattern to a surface.
Properties of texture maps:
Steps in Texture Mapping:
Texture Names:
To start things off, we first need a texture name. This is essentially a number that OpenGL uses to index all the different textures.
GLuint texture; // allocate a texture name glGenTextures( 1, &texture );
Now that we have our texture name, we can switch between different textures we want using the function glBindTxeture. This essentially chooses what texture we are working with.
// select our current texture glBindTexture( GL_TEXTURE_2D, texture );
Texture Parameters:
Now we can begin to work on our current texture. Before we start, we should set one little texture environment state which tells OpenGL how the texture will act when it is rendered into a scene.
// select modulate to mix texture with color for shading glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
Next, we have four texture parameters we need to setup. Here is where we can setup such wonderful effects like bilinear and trilinear texture filtering, and mipmapping. We also can setup whether the texture wraps over at the edges or is clamped at the ends. The most common feature used is 'repeating'.
// when texture area is small, bilinear filter the closest mipmap
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
GL_LINEAR_MIPMAP_NEAREST );
// when texture area is large, bilinear filter the original
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
// the texture wraps over at the edges (repeat)
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT );
|
|
| void glTexImage2D(GLenum target, GLint level, GLint internalFormat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid *pixels); |
| Defines a two-dimensional texture. The target parameter is set to either the constant GL_TEXTURE_2D or GL_PROXY_TEXTURE_2D. You use the level parameter if you're supplying multiple resolutions of the texture map; with only one resolution, level should be 0. |
| void glCopyTexImage2D(GLenum target, GLint level, GLint internalFormat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border); |
|
Creates a two-dimensional texture, using framebuffer data to define the texels.
The pixels are read from the current GL_READ_BUFFER and are processed exactly
as if glCopyPixels() had been called but stopped before final conversion.
The settings of glPixelTransfer*() are applied.
The target parameter must be set to the constant GL_TEXTURE_2D. The level, internalFormat, and border parameters have the same effects that they have for glTexImage2D(). The texture array is taken from a screen-aligned pixel rectangle with the lower-left corner at coordinates specified by the (x, y) parameters. The width and height parameters specify the size of this pixel rectangle. Both width and height must have the form 2m+2b, where m is a nonnegative integer (which can have a different value for width than for height) and b is the value of border. |