大三05計算機圖形學texture mapping_第1頁
大三05計算機圖形學texture mapping_第2頁
大三05計算機圖形學texture mapping_第3頁
大三05計算機圖形學texture mapping_第4頁
大三05計算機圖形學texture mapping_第5頁
已閱讀5頁,還剩19頁未讀, 繼續(xù)免費閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)

文檔簡介

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由應用程序建立適當?shù)挠成浜瘮?shù)specify texture parameters指定紋理參數(shù)wrapping環(huán)繞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. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
  • 6. 下載文件中如有侵權(quán)或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論