




版權(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. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 方案:辦公腳手架施工規(guī)范
- 現(xiàn)代化進程中的職業(yè)教育:路徑優(yōu)化與實證分析
- 小學語文教師專業(yè)發(fā)展:學科知識復習資料匯編
- 5G技術(shù)對農(nóng)業(yè)新質(zhì)生產(chǎn)力影響的研究與實踐探索
- 物理知識精粹
- 村級扶貧電站管理辦法
- 大型集團采購決策中的比價機制設(shè)計與風險控制
- 語文雙基教學中的多感官協(xié)同訓練模式研究
- 家庭安全自查表
- 起重機事故鑒定
- 2025中國系統(tǒng)性紅斑狼瘡診療指南解讀課件
- 成人重癥患者顱內(nèi)壓增高防控護理專家共識
- 2025至2030中國家用血壓計行業(yè)發(fā)展趨勢分析與未來投資戰(zhàn)略咨詢研究報告
- 吉林省長春市2023?2024學年高二下冊期末考試數(shù)學科試卷附解析
- 主管護師《相關(guān)專業(yè)知識》考試真題及答案(2025年)
- 綠化所倉庫管理制度
- 聘請美容學徒合同協(xié)議
- 2025年全國保密教育線上培訓考試試題庫(含答案)含答案詳解
- 2025年江蘇省南京市鼓樓區(qū)中考一模英語試卷(含答案)
- 機場旅客醫(yī)療救援應急預案
- 非計劃再次手術(shù)知識培訓
評論
0/150
提交評論