大三05计算机图形学texture mapping_第1页
大三05计算机图形学texture mapping_第2页
大三05计算机图形学texture mapping_第3页
大三05计算机图形学texture mapping_第4页
大三05计算机图形学texture mapping_第5页
已阅读5页,还剩19页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、OpenGL Texture MappingOpenGL中的纹理映射原著Ed AngelProfessor of Computer Science, Electrical and Computer Engineering, and Media ArtsUniversity of New Mexico编辑 武汉大学计算机学院图形学课程组2ObjectivesIntroduce the OpenGL texture functions and options3Basic Strategy基本策略Three steps to applying a texture应用纹理需要下面三个步骤specify

2、 the texture指定纹理read or generate image读入或生成图像assign to texture赋给纹理enable texturing激活纹理映射功能assign texture coordinates to vertices给每个顶点赋纹理坐标Proper mapping function is left to application由应用程序建立适当的映射函数specify texture parameters指定纹理参数wrapping环绕filtering滤波4Texture Mappingstxyzimagegeometrydisplay5Texture

3、 ExampleThe texture (below) is a 256 x 256 image that has been mapped to a rectangular polygon which is viewed in perspective6Texture Mapping and the OpenGL Pipelinegeometry pipelineverticespixel pipelineimagefragmentprocessorImages and geometry flow through separate pipelines that join during fragm

4、ent processing“complex” textures do not affect geometric complexity7Define a texture image from an array of texels (texture elements) in CPU memory Glubyte my_texels512512;Define as any other pixel mapScanned imageGenerate by application codeEnable texture mappingglEnable(GL_TEXTURE_2D)OpenGL suppor

5、ts 1-4 dimensional texture mapsSpecifying a Texture Image8Define Image as a TextureglTexImage2D( target, level, components, w, h, border, format, type, texels );target: type of texture, e.g. GL_TEXTURE_2Dlevel: used for mipmapping (discussed later)components: elements per texelw, h: width and height

6、 of texels in pixelsborder: used for smoothing (discussed later)format and type: describe texelstexels: pointer to texel arrayglTexImage2D(GL_TEXTURE_2D, 0, 3, 512, 512, 0, GL_RGB, GL_UNSIGNED_BYTE, my_texels);9Converting A Texture ImageOpenGL requires texture dimensions to be powers of 2If dimensio

7、ns of image are not powers of 2gluScaleImage( format, w_in, h_in, type_in, *data_in, w_out, h_out, type_out, *data_out );data_in is source imagedata_out is for destination imageImage interpolated and filtered during scaling10Based on parametric texture coordinatesglTexCoord*() specified at each vert

8、exst1, 10, 10, 01, 0(s, t) = (0.2, 0.8)(0.4, 0.2)(0.8, 0.4)ABCabcTexture SpaceObject SpaceMapping a Texture11Typical CodeglBegin(GL_POLYGON);glColor3f(r0, g0, b0); /if no shading usedglNormal3f(u0, v0, w0); / if shading usedglTexCoord2f(s0, t0);glVertex3f(x0, y0, z0);glColor3f(r1, g1, b1);glNormal3f

9、(u1, v1, w1);glTexCoord2f(s1, t1);glVertex3f(x1, y1, z1);.glEnd();Note that we can use vertex arrays to increase efficiency12InterpolationOpenGL uses interpolation to find proper texels from specified texture coordinatesCan be distortionsgood selectionof tex coordinatespoor selectionof tex coordinat

10、estexture stretchedover trapezoid showing effects of bilinear interpolation13Texture ParametersOpenGL has a variety of parameters that determine how texture is appliedWrapping parameters determine what happens if s and t are outside the (0,1) rangeFilter modes allow us to use area averaging instead

11、of point samplesMipmapping allows us to use textures at multiple resolutionsEnvironment parameters determine how texture mapping interacts with shading14Wrapping ModeClamping: if s,t 1 use 1, if s,t 0 use 0Wrapping: use s,t modulo 1glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP )glTexPa

12、rameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT )texturestGL_CLAMPwrappingGL_REPEATwrapping15Magnification and MinificationTexturePolygonMagnificationMinificationPolygonTextureMore than one texel can cover a pixel (minification) ormore than one pixel can cover a texel (magnification)Can use po

13、int sampling (nearest texel) or linear filtering( 2 x 2 filter) to obtain texture values16Filter ModesModes determined byglTexParameteri( target, type, mode ) glTexParameteri(GL_TEXTURE_2D, GL_TEXURE_MAG_FILTER, GL_NEAREST);glTexParameteri(GL_TEXTURE_2D, GL_TEXURE_MIN_FILTER, GL_LINEAR);Note that li

14、near filtering requires a border of an extra texel for filtering at edges (border = 1)17Mipmapped TexturesMipmapping allows for prefiltered texture maps of decreasing resolutionsLessens interpolation errors for smaller textured objectsDeclare mipmap level during texture definitionglTexImage2D( GL_TE

15、XTURE_*D, level, )GLU mipmap builder routines will build all the textures from a given imagegluBuild*DMipmaps( )18Example pointsamplingmipmapped pointsamplingmipmapped linear filtering linear filtering19Texture FunctionsControls how texture is appliedglTexEnvfiv( GL_TEXTURE_ENV, prop, param ) GL_TEX

16、TURE_ENV_MODE modesGL_MODULATE: modulates with computed shadeGL_BLEND: blends with an environmental colorGL_REPLACE: use only texture colorGL(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);Set blend color with GL_TEXTURE_ENV_COLOR20Perspective Correction HintTexture coordinate and color interpola

17、tioneither linearly in screen spaceor using depth/perspective values (slower)Noticeable for polygons “on edge”glHint( GL_PERSPECTIVE_CORRECTION_HINT, hint )where hint is one of GL_DONT_CAREGL_NICESTGL_FASTEST21Generating Texture CoordinatesOpenGL can generate texture coordinates automaticallyglTexGe

18、nifdv()specify a planegenerate texture coordinates based upon distance from the planegeneration modesGL_OBJECT_LINEARGL_EYE_LINEAR GL_SPHERE_MAP (used for environmental maps)22Angel: Interactive Computer Graphics 45E Addison-Wesley 2009Texture ObjectsTexture is part of the OpenGL state If we have different textures for different objects, OpenGL will be moving large amounts data from processor memory to texture memoryRecent versions of OpenGL have texture objectsone image per texture objectTexture memo

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论