Presentation is loading. Please wait.

Presentation is loading. Please wait.

OpenGL Programming Guide : Texture Mapping 2004. 02. 10. Yoo jin wook Korea Univ. Computer Graphics Lab.

Similar presentations


Presentation on theme: "OpenGL Programming Guide : Texture Mapping 2004. 02. 10. Yoo jin wook Korea Univ. Computer Graphics Lab."— Presentation transcript:

1 OpenGL Programming Guide : Texture Mapping 2004. 02. 10. Yoo jin wook Korea Univ. Computer Graphics Lab

2 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

3 Texture Mapping ( 2/3 )

4 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)

5 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

6 An Overview & an Example ( 2/2 ) Example 9-1

7 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 …. void glTexImage2D (GLenum target, GLint level, GLint internalFormat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid *texels)

8 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)

9 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)

10 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 with glGetTexLevelParameter*( )

11 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)

12 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);

13 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 void glTexSubImage2D (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *texels)

14 Replacing a Texture Image ( 2/2 ) Example 9-3

15 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

16 Multiple Levels of Detail ( 2/4 ) Example 9-5

17 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)

18 Multiple Levels of Detail ( 4/4 )  Advanced Mipmap Details parameterDescriptionValues GL_TEXTURE_BASE_LEVE L level for highest-resolution texture in use non-negative integer GL_TEXTURE_MAX_LEVEL level 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

19 Filtering ( 1/2 )

20 Filtering ( 2/2 ) parameterValues GL_TEXTURE_MAG_FILTERGL_NEAREST or GL_LINEAR GL_TEXTURE_MIN_FILTERGL_NEAREST, GL_LINEAR GL_NEAREST_MIPMAP_NEAREST GL_NEAREST_MIPMAP_LINEAR GL_LINEAR_MIPMAP_NEAREST GL_LINEAR_MIPMAP_LINEAR glTexParameter*( )

21 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

22 Texture Objects ( 2/4 )  Naming A texture Object void glGenTextures (GLsizei n, GLuint *textureNames) Glboolean glIsTexture (GLuint textureName)

23 Texture Objects ( 3/4 )  Creating and Using Texture Objects void glBindTexture (GLenum target, Gluint textureNames) void glDeleteTexture (GLsizei n, const Gluint *textureNames)

24 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 *residences)

25 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)

26 Texture Functions ( 2/3 ) pnameparam GL_TEXTURE_ENV_MODE GL_DECAL GL_REPLACE GL_MODULATE GL_BLEND GL_TEXTURE_ENV_COLOR ** Four floating value (R,G,B,A) ** : used only if the GL_BLEND texture function has been specified

27 Texture Functions ( 3/3 )

28 Assigning Texture Coordinates ( 1/3 )

29 Assigning Texture Coordinates ( 2/3 )

30 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);

31 Automatic Texture-Coordinate Generation ( 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 void glTexGen* (GLenum coord, GLenum pname, TYPE param)

32 Automatic Texture-Coordinate Generation ( 2/2 )

33 Multitexturing ( 1/4 )

34 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()

35 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]); ……………………………..

36 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();


Download ppt "OpenGL Programming Guide : Texture Mapping 2004. 02. 10. Yoo jin wook Korea Univ. Computer Graphics Lab."

Similar presentations


Ads by Google