370 likes | 613 Views
OpenGL Programming Guide : Texture Mapping. 2004. 02. 10. Yoo jin wook Korea Univ. Computer Graphics Lab. Texture Mapping ( 1/3 ). Texture Simply rectangular arrays of data ex) Color data, luminance data, color & alpha data Texel Individual values in a texture array
E N D
OpenGL Programming Guide : Texture Mapping 2004. 02. 10. Yoo jin wook Korea Univ. Computer Graphics Lab
Texture Mapping ( 1/3 ) • Texture Simply rectangular arrays of data ex) Color data, luminance data, color & alpha data • Texel Individual values in a texture array cf) texel ≠Pixel requires filtering
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 ( 1/2 ) • Steps in Texture Mapping 1. Create object & Specify a texture 2. Indicate how the texture is to be applied to each pixel 3. Enable Texture mapping 4. Draw the scene
Example 9-1 An Overview & an Example ( 2/2 )
Specifying the Texture ( 1/3 ) target : GL_TEXTURE_2D, GL_PROXY_TEXTURE_2D internalFormat : 1~4 (R,G,B,A) Format : GL_RGB, GL_RGBA, GL_RED ….
Specifying the Texture ( 3/3 ) : Create a two-dimensional texture using framebuffer
Texture Proxy ( 1/3 ) • Texture Proxy : answers the question of whether a texture is capable of being loaded into texture memory • Steps in Texture Proxy 1. Create texture proxy with glTexImage2D( ) 2. Query the texture state variables withglGetTexLevelParameter*( )
Texture Proxy ( 2/3 ) pname : GL_TEXTURE_WIDTH, GL_TEXTURE_DEPTH GL_TEXTURE_HEIGHT…..
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 ( 1/2 ) xoffset, yoffset : texel offset in the x-,y- direction with (0,0) at the lower left corner of the texture
Example 9-3 Replacing a Texture Image ( 2/2 )
Multiple Levels of Detail ( 1/4 ) • Mipmap : series of prefiltered texture maps of decreasing resolutions ->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 map ex) 64×32 : 32×8, 16×4, 8×2, 4×1, 2×1, 1×1
Example 9-5 Multiple Levels of Detail ( 2/4 )
Multiple Levels of Detail ( 3/4 ) • Automated Mipmap Generation : define the pyramid of mipmaps down to a resolution 1×1
Multiple Levels of Detail ( 4/4 ) • Advanced Mipmap Details glTexParameter*( ) ** : openGL 1.2
Filtering ( 2/2 ) glTexParameter*( )
Texture Objects ( 1/4 ) • Steps 1. Generate texture names 2. Initially bind texture objects to texture data 3. See if you have enough space for all your texture object 4. Bind and rebind texture objects
Texture Objects ( 2/4 ) • Naming A texture Object
Texture Objects ( 3/4 ) • Creating and Using Texture Objects
Texture Objects ( 4/4 ) • A Working Set of Resident Textures : queries the texture residence status of the n texture object
Texture Functions ( 1/3 ) target : GL_TEXTURE_ENV_MODE, GL_TEXTURE_ENV_COLOR
Texture Functions ( 2/3 ) ** : used only if the GL_BLEND texture function has been specified
Texture Functions ( 3/3 ) < GL_DECAL ≈ GL_REPLACE> < GL_MODULATE >
Assigning Texture Coordinates ( 3/3 ) • Repeat & Clamp glTexImage2D(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-CoordinateGeneration ( 1/2 ) coord : GL_S, GL_T, GL_R, GL_Q pname : GL_TEXTURE_GEN_MODE, GL_OBJECT_PLANE, GL_EYE_PLANE param : GL_OBJECT_LINEAR, GL_EYE_LINEAR, GL_SHPERE_MAP or an array of texture generation parameters
<eye coordinate> <object coordinate> <slanted coordinate> Automatic Texture-CoordinateGeneration ( 2/2 )
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 ) • 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 ) • 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();