Upload
jewel-mathews
View
218
Download
3
Embed Size (px)
Citation preview
OpenGL Programming Guide : Texture Mapping
2004. 02. 10. Yoo jin wook2004. 02. 10. Yoo jin wookKorea Univ. Computer Graphics LabKorea Univ. Computer Graphics Lab
Texture Mapping ( 1/3 )Texture Mapping ( 1/3 )
Texture Simply rectangular arrays of data
ex) Color data, luminance data, color & alpha data
Texel Individual values in a texture arraycf) texel ≠Pixel requires filtering
Texture Mapping ( 2/3 )Texture Mapping ( 2/3 )
Texture Mapping ( 3/3 )Texture Mapping ( 3/3 )
An Overview & an Example Specifying the Texture Filtering Texture Objects Texture Functions Assigning Texture Coordinates Automatic Texture-Coordinate Generation Advanced Feature (Multitexturing)
An Overview & an Example An Overview & an Example ( 1/2 )( 1/2 )
Steps in Texture Mapping1. Create object & Specify a texture2. Indicate how the texture is to be applied to each pixel3. Enable Texture mapping4. Draw the scene
An Overview & an Example An Overview & an Example ( 2/2 )( 2/2 )
Example 9-1
Specifying the Texture ( 1/3 )Specifying the Texture ( 1/3 )
target : GL_TEXTURE_2D, GL_PROXY_TEXTURE_2DinternalFormat : 1~4 (R,G,B,A)Format : GL_RGB, GL_RGBA, GL_RED ….
void glTexImage2D (GLenum target, GLint level, GLint internalFormat, GLsizei width,
GLsizei height, GLint border, GLenum format, GLenum type,
const GLvoid *texels)
Specifying the Texture ( 2/3 )Specifying the Texture ( 2/3 )
void gluScaleImage (GLenum format, GLint widthin, GLint heightin, GLenum typein,
const void *datain, GLint widthout, GLint heightout, GLenum typeout, void *dataout)
Specifying the Texture ( 3/3 )Specifying the Texture ( 3/3 )
: Create a two-dimensional texture using framebuffer
void glCopyTexImage2D (GLenum target, GLint level, GLint internalFormat, GLint x,
GLint y, GLsizei width, Glsizei height GLint border)
Texture Proxy ( 1/3 )Texture Proxy ( 1/3 )
Texture Proxy: answers the question of whether a texture is capable of being loaded into texture memory
Steps in Texture Proxy1. Create texture proxy with glTexImage2D( )2. Query the texture state variables with glGetTexLevelPar
ameter*( )
Texture Proxy ( 2/3 )Texture Proxy ( 2/3 )
pname : GL_TEXTURE_WIDTH, GL_TEXTURE_DEPTH GL_TEXTURE_HEIGHT…..
void glGetTexLevelParameter*v(GLenum target, GLint level, GLenum pname, TYPE*params)
Texture Proxy ( 3/3 )Texture Proxy ( 3/3 )
Ex) Glint width;
glTexImage2D(GL_PROXY_TEXTURE_2D, 0, GL_RGBA8, 64, 64, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
glGetTexLevelParameteriv(GL_PROXY_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, &width);
Replacing a Texture Image Replacing a Texture Image ( 1/2 )( 1/2 )
xoffset, yoffset : texel offset in the x-,y- direction with (0,0) at the lower left corner of the t
exture
void glTexSubImage2D (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width,
GLsizei height, GLenum format, GLenum type, const GLvoid *texels)
Replacing a Texture Image Replacing a Texture Image ( 2/2 )( 2/2 )
Example 9-3
Multiple Levels of Detail ( 1/4 )Multiple Levels of Detail ( 1/4 )
Mipmap: series of prefiltered texture maps of decreasing resolution
s
->openGL automatically determines which texture map to use based on the size(in pixels)
->must provide all sizes of your texture in powers of 2 between the largest size and 1×1 mapex) 64×32 : 32×8, 16×4, 8×2, 4×1, 2×1, 1×1
Multiple Levels of Detail ( 2/4 )Multiple Levels of Detail ( 2/4 )
Example 9-5
Multiple Levels of Detail ( 3/4 )Multiple Levels of Detail ( 3/4 )
Automated Mipmap Generation: define the pyramid of mipmaps down to a resolution 1×1
void gluBuild3DMipmaps(GLenum target, GLint internalFormat, GLint width, GLint height, GLint depth, GLenum format,Glenum type,void *texels)
Multiple Levels of Detail ( 4/4 )Multiple Levels of Detail ( 4/4 )
Advanced Mipmap Details
parameter Description Values
GL_TEXTURE_BASE_LEVEL
level for highest-resolution texture in use
non-negative integer
GL_TEXTURE_MAX_LEVELlevel for smallest-resolution texture in use
non-negative integer
GL_TEXTURE_MIN_LOD** minimum value for λ any value
GL_TEXTURE_MAX_LOD** maximum value for λ any value
glTexParameter*( )
** : openGL 1.2
Filtering ( 1/2 )Filtering ( 1/2 )
Filtering ( 2/2 )Filtering ( 2/2 )
parameter Values
GL_TEXTURE_MAG_FILTER GL_NEAREST or GL_LINEAR
GL_TEXTURE_MIN_FILTER GL_NEAREST, GL_LINEARGL_NEAREST_MIPMAP_NEARESTGL_NEAREST_MIPMAP_LINEARGL_LINEAR_MIPMAP_NEARESTGL_LINEAR_MIPMAP_LINEAR
glTexParameter*( )
Texture Objects ( 1/4 )Texture Objects ( 1/4 )
Steps1. Generate texture names2. Initially bind texture objects to texture data3. See if you have enough space for all your
texture object4. Bind and rebind texture objects
Texture Objects ( 2/4 )Texture Objects ( 2/4 )
Naming A texture Object
void glGenTextures (GLsizei n, GLuint *textureNames) Glboolean glIsTexture (GLuint textureName)
Texture Objects ( 3/4 )Texture Objects ( 3/4 )
Creating and Using Texture Objects
void glBindTexture (GLenum target, Gluint textureNames)void glDeleteTexture (GLsizei n,
const Gluint *textureNames)
Texture Objects ( 4/4 )Texture Objects ( 4/4 )
A Working Set of Resident Textures: queries the texture residence status of the n texture object
void glAreTexturesResident ( GLsizei n, const Gluint *textureNames, Glboolean *residen
ces)
Texture Functions ( 1/3 )Texture Functions ( 1/3 )
target : GL_TEXTURE_ENV_MODE, GL_TEXTURE_ENV_COLOR
void glTexEnv* (GLenum target, GLenum pname, TYPE param)
void glTexEnv*v (GLenum target, GLenum pname, TYPE *param)
Texture Functions ( 2/3 )Texture Functions ( 2/3 )
pname param
GL_TEXTURE_ENV_MODE GL_DECALGL_REPLACEGL_MODULATEGL_BLEND
GL_TEXTURE_ENV_COLOR** Four floating value (R,G,B,A)
** : used only if the GL_BLEND texture function has been specified
Texture Functions ( 3/3 )Texture Functions ( 3/3 )
< GL_DECAL ≈ GL_REPLACE>
< GL_MODULATE >
Assigning Texture Coordinates Assigning Texture Coordinates ( 1/3 )( 1/3 )
Assigning Texture Coordinates Assigning Texture Coordinates ( 2/3 )( 2/3 )
Assigning Texture Coordinates Assigning Texture Coordinates ( 3/3 )( 3/3 )
Repeat & ClampglTexImage2D(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S,
GL_REPEAT/GL_CLAMP); glTexImage2D(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T,
GL_REPEAT/GL_CLAMP);
Automatic Texture-CoordinateAutomatic Texture-CoordinateGeneration ( 1/2 )Generation ( 1/2 )
coord : GL_S, GL_T, GL_R, GL_Qpname : GL_TEXTURE_GEN_MODE, GL_OBJECT_PLANE, GL_EYE_PLANEparam : GL_OBJECT_LINEAR, GL_EYE_LINEAR, GL_SHPERE_MAP or an array of te
xture generation parameters
void glTexGen* (GLenum coord, GLenum pname, TYPE param)
Automatic Texture-CoordinateAutomatic Texture-CoordinateGeneration ( 2/2 )Generation ( 2/2 )
<eye coordinate> <object coordinate> <slanted coordinate>
Multitexturing ( 1/4 )Multitexturing ( 1/4 )
Multitexturing ( 2/4 )Multitexturing ( 2/4 ) Steps
1. Check to see if multitexturing is supported- glGetIntegerv(GL_MAX_TEXTURE_UNITS_ARB, ….)
2. For each texturing unit, establish the texture state- glActiveTextureARB()
3. During vertex specification, use glMultiTexCoord*ARB()
Multitexturing ( 3/4 )Multitexturing ( 3/4 ) Establishing Texture Unit
GLuint texNames[2]; …………………………….
glActiveTextureARB(GL_TEXTURE0_ARB);glEnable(GL_TEXTURE_2D);glBindTexture(GL_TEXTURE_2D, texNames[0]);…………………………….. glActiveTextureARB(GL_TEXTURE1_ARB);glEnable(GL_TEXTURE_2D);glBindTexture(GL_TEXTURE_2D, texNames[1]);……………………………..
Multitexturing ( 4/4 )Multitexturing ( 4/4 ) Specifying
glBegin(GL_TRIANGLES);glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 0.0, 0.0);glMultiTexCoord2fARB(GL_TEXTURE1_ARB, 1.0, 0.0);glVertex2f(0.0, 0.0);glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 0.5, 1.0);glMultiTexCoord2fARB(GL_TEXTURE1_ARB, 0.5, 0.0);glVertex2f(50.0, 100.0);glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 1.0, 0.0);glMultiTexCoord2fARB(GL_TEXTURE1_ARB, 1.0, 1.0);glVertex2f(100.0, 0.0)glEnd();