为了正常的体验网站,请在浏览器设置里面开启Javascript功能!

OpenGL 纹理贴图基础[指南]

2018-04-28 8页 doc 55KB 28阅读

用户头像

is_153723

暂无简介

举报
OpenGL 纹理贴图基础[指南]OpenGL 纹理贴图基础[指南] OpenGL: Texture Mpping: When we pply imge to geometric primitive, we cll this texture or texture mpping. Lod texture imge: glTexImge /glTexSubImge Mp textures to geometry: glTexCoord Chnge the texture environment: glTexEnv Set texture mpping p...
OpenGL 纹理贴图基础[指南]
OpenGL 纹理贴图基础[] OpenGL: Texture Mpping: When we pply imge to geometric primitive, we cll this texture or texture mpping. Lod texture imge: glTexImge /glTexSubImge Mp textures to geometry: glTexCoord Chnge the texture environment: glTexEnv Set texture mpping prmeters: glTexprmeter Generte mipmps: gluBuildMipmps Mnge multiple textures: glBindTexture drmtic differnece: 戏剧性的. richness: 丰富. strk contrst: 对比. texel: the individul elements in texture. pixel: the individul elements in pixmp. one-to-one correspondence seldom exists between texels nd pixels on the screen. shrink: 收缩. bis: 误差, 偏差. Step on pplying texture mp to geometry: First: Lod the texture into memory: void glTexImge2D(GLenum trget, GLint level, GLint internlformt, GLsizei width, GLsizei height, GLint border, GLenum formt, GLenum type, void *dt); trget: GL_TEXTURE_1D, GL_TEXTURE_2D, GL_TEXTURE_3D level: specifies the mipmp level being loded, for non-mipmped texutres lwys to set this to 0. internlformt: how mny color components you wnt to store per texel. formt: e.g. GL_RGB, GL_RGB type: e.g. GL_UNSIGNED_BYTE, GL_BYTE, GL_FLOT, dt: picture dt. You should lso be wre tht OpenGL copies the texture informtion from dt when you cll one of these functions(fter loding, delete the dt rry, the wnted dt is copied into the memory). Loded textures re not pplied to geometry unless the pproprite texture stte is enbled. Second: specify texture coordintes. glTexCoord2f(s, t); Texture mtrix: glMtrixMode(GL_TEXTURE) texture coordintes cn lso be trnsformted, rotted, nd even scled. coordinte wrpping, texture filters, nd the texture environment. glTexImge2D(GL_TEXTURE_2D, 0, iComponents, iWidth, iHeight, 0, eFormt, GL_UNSIGNED_BYTE, pBytes); free(pBytes); glTexPrmeteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINER); glTexPrmeteri(GL_TEXTURE_2D, GL_TEXTURE_MG_FILTER, GL_LINER); glTexPrmeteri(GL_TEXTURE_2D, GL_TEXTURE_WRP_S, GL_CLMP_TO_EDGE); glTexPrmeteri(GL_TEXTURE_2D, GL_TEXTURE_WRP_T, GL_CLMP_TO_EDGE); glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULTE); glEnble(GL_TEXTURE_2D); Texture environment: How OpenGL combines the colors from texels nd the color of the underlying geometry. glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULTE); GL_MODULTE: The modulte environment mode multiplies the texel color by the geometry color (fter lighting clcultions). GL_REPLCE: Simply replce the color of the underlying geometry. GL_BLEND: If the texture hs n lph chnnel, you cn enble blending. Otherwise GL_BLEND behvors the sme wy s GL_REPLCE. Textures cn lso be blended with constnt blending color using the GL_BLENDtexture environment. If you set this environment mode, you must lso set the texture environ- ment color: GLflot fColor[4] = { 1.0f, 0.0f, 0.0f, 0.0f }; glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_BLEND); glTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, fColor); GL_DD: Simply dd the texel color vlues to the color of the underlying frgment. Texture Prmeters: GL_TEXTURE_MG_FILTER, GL_TEXTURE_MIN_FILTER GL_NEREST, GL_LINE glTexPrmeteri(GL_TEXTURE_2D, GL_TEXTURE_MG_FILTER, GL_NEREST); glTexPrmeteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEREST); Texture Wrp(s, t): Normlly, you specify texture coordintes between 0.0 nd 1.0 to mp out the texels in texture mp. If texture coordintes fll out side this rnge, OpenGL hndles them ccording to the current texture wrpping mode. You cn set the wrp mode for ech coordinte individully by clling glTexPrmeteri with GL_TEXTURE_WRP_S, GL_TEXTURE_WRP_T, or GL_TEXTURE_WRP_R s the prmeter nme. The wrp mode cn then be set to one of the following vlues: GL_REPET, GL_CLMP, GL_CLMP_TO_EDGE, or GL_CLMP_TO_BORDER. The GL_REPET wrp mode simply cuses the texture to repet in the direction in which the texture coordinte hs exceeded 1.0. The texture repets gin for every integer texture coordinte. This mode is very useful for pplying smll tiled texture to lrge geometric surfces. Toon-shding, which is often refered to cell-shding, ide: The bsic ide is to use surfce norml from the geometry nd vector to the light source to find the intensity of the light striking the surfce of the model. The dot product of these two vectors gives vlue between 0.0 nd 1.0 nd is used s one dimensionl texture coordinte. Mipmpping(mny things in smll spce): Mipmppingis powerful texturing technique tht cn improve both the rendering performnce nd the visul qulity of scene. In essence, you lod not single imge into the texture stte, but whole series of imges from lgerest to smllest into single "mipmpped" texture stte. OpenGL use new set of filter modes to choose the best-fitting texture or textures for given geometry. Using squre set of mipmpps requires bout one-third more memory thn not using mipmpps. Ech one hlf the size of the previous imge. 自动生成的,质量比较差的Mipmps: gluBuild2DMipmps: it utomticlly cretes the scled imges for you nd lods them ppropritely with glTexImge. int gluBuild2DMipmps(GLenum trget, GLint internlFormt, GLint width, GLint height, GLenum formt, GLenum type, const void *dt); You should lso be wre tht using these functions my not produce mip level imges with the sme qulity you cn obtin with other tools such s Photoshop. 自动生成的,质量比较好的Mipmps: With newer versions of the GLU librry, you cn lso obtin finer-grined control over which mip levels re loded with these functions: int gluBuild2DMipmpLevels(GLenum trget, GLint internlFormt, GLint width, GLint height, GLenum formt, GLenum type, GLint level, GLint bse, GLint mx, const void *dt); With these functions, level is the mip level specified by the dt prmeter. This texture dt is used to build mip levels bse through mx. 使用硬件加速生成Mipmps(对于整个场境都使用mipmps): Hrdwre Genertion of Mipmps: If you know beforehnd tht you wnt ll mip levels loded, you cn lso use OpenGL hrdwre ccelertion to quickly generte ll the necessry mip levels. You do so by setting the texture prmeter GL_GENERTE_MIPMP to GL_TRUE: glTexPrmeteri(GL_TEXTURE_2D, GL_GENERTE_MIPMP, GL_TRUE); When this prmeter is set, ll clls to glTexImge or glTexSubImge tht updte the bse texture mp (mip level 0) utomticlly updte ll the lower mip levels. By mking use of the grphics hrdwre, this feture is substntilly fster thn using gluBuildMipmps. However, you should be wre tht this feture ws originlly n extension nd ws promoted to the OpenGL core PI only s of version 1.4. This is definitely the fstest nd esiest wy to build mipmps on-the-fly. Texture Objects: Loding nd mintining the texture stte occupies considerble portion of mny texture-hevy OpenGL pplictions (gmes in prticulr). Texture objects llow you to lod up more thn one texture stte t time. 为texture对象分配内存: You llocte number of texture objects with the following function: void glGenTextures(GLsizei n, GLuint *textures); With this function, you specify the number of texture objects nd pointer to n rry of unsigned integers tht will be populted with the texture object identifiers. 指定texture对象(用一个整数来标志一个纹理对象): void glBindTexture(GLenum trget, GLuint texture); The trget prmeter needs to specify GL_TEXTURE_1D, GL_TEXTURE_2D, or GL_TEXTURE_3D, nd textureis the specific texture object to bind to. Herefter, ll texture lods nd texture prmeter settings ffect only the currently bound texture object. 每一个texture都要设置自己的prmeter, 因为每个prmeter只对某个绑定的texture有效. 删除texture对象的内存空间,释放内存: To delete texture objects, you cll the following function: void glDeleteTextures(GLsizei n, GLuint *textures); Clling glDeleteTextures multiple times my incur some dely, but only becuse you re dellocting possibly lrge mounts of texture memory. 测试是否有效的texture,如被删除后: You cn test texture object nmes (or hndles) to see whether they re vlid by using the following function: GLboolen glIsTexture(GLuint texture); This function returns GL_TRUE if the integer is previously llocted texture object nme or GL_FLSE if not
/
本文档为【OpenGL 纹理贴图基础[指南]】,请使用软件OFFICE或WPS软件打开。作品中的文字与图均可以修改和编辑, 图片更改请在作品中右键图片并更换,文字修改请直接点击文字进行修改,也可以新增和删除文档中的内容。
[版权声明] 本站所有资料为用户分享产生,若发现您的权利被侵害,请联系客服邮件isharekefu@iask.cn,我们尽快处理。 本作品所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用。 网站提供的党政主题相关内容(国旗、国徽、党徽..)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。
热门搜索

历史搜索

    清空历史搜索