高级 OpenGL 纹理贴图 Advanced OpenGL Texture Mapping
来源:互联网 发布:怎么看自己windows版本 编辑:程序博客网 时间:2024/04/29 04:41
转自:http://www.flipcode.com/archives/Advanced_OpenGL_Texture_Mapping.shtml
by Nate Miller (03 April 2000)
Return to The Archives
Generating And Using Mipmaps
Each mipmap level is generated by taking half the size of the previous mipmap and then applying some sort of filter to it. If we have a base image that is 64x64 in size, the lower levels of detail will be 32x32, 16x16, 8x8, 4x4, 2x2 and 1x1. There are two ways to calculate the mipmaps and use them in OpenGL, by hand or through the gluBuild2DMipmaps() function. If mipmaps are generated using your own algorithm, the glTexImage2D() function would be used with an increasing level parameter for each successive level of detail, with level 0 being the base texture level. More often than not, the gluBuild2DMipmaps()utility function will be used to generate a set of mipmaps for a given texture. gluBuild2DMipmaps() will take care of filtering and uploading the mipmaps to memory. The gluBuild2DMipmaps() utility function is the same as glTexImage2D(), except for the fact that it builds mipmaps.
Now that the different levels of detail have been generated how can they be used to improve the quality of a textured object? Once the mipmaps have been calculated for a texture and uploaded into memory no special code is needed to use them. OpenGL will automatically select the best level of detail to use for the texture without any intervention from the programmer. Which mipmap is selected can be defined with the glTexParameter() function, described in the next section. The tradeoff with mipmaps is that they will require additional texture memory and some extra computation must be made to generate them.
No mipmapping
Mipmapping
Notice how the texture is distorted in the distance without mipmaps, but with mipmaps the texture is smooth and does not become distorted in the distance.
TargetSpecifies the target textureGL_TEXTURE_1DOne dimensional texturing.GL_TEXTURE_2DTwo dimensional texturing.
Texture ParameterAccepted valuesDescription
The texture minification function is used when a single screen pixel maps to more than one texel, this means the texture must be shrunk in size.
Default setting is GL_NEAREST_MIPMAP_LINEAR.
The texture magnification function is used when the pixel being textured maps to an area less than or equal to one texel, this means the texture must be magnified.
Default setting is GL_LINEAR.
Sets the wrap parameter for the s texture coordinate. Can be set to either GL_CLAMP or GL_REPEAT.
Default setting is GL_REPEAT.
Sets the wrap parameter for the t texture coordinate. Can be set to either GL_CLAMP or GL_REPEAT.
Default setting is GL_REPEAT.
Sets the border color for the texture, if border is present.
Default setting is (0, 0, 0, 0).
ParameterDescription
Examples
Wrap T : GL_CLAMP
Wrap T : GL_REPEAT
Wrap T : GL_CLAMP
Wrap T : GL_REPEAT
Usage
The big question now is, how can this information be used in an application? If a texture is known to contain gray-scale or luminance values only then the GL_LUMINANCE format should be used rather than GL_RGB. If a small memory footprint and better performance is desired, then the GL_RGB4 format should be used. Using GL_RGB4 sacrifices texture quality for speed and low memory usage. If high visual quality is needed then the GL_RGB8 format could be used at the expense of speed and memory usage.
What is the catch for specifying the texture internal format? There is none. If the requested format is not supported by the implementation of OpenGL, the closest supported format will be selected for the texture. If a generic internal format is specified, GL_RGB for example, OpenGL will pick the most appropriate format to use for the particular implementation. Not all OpenGL implementations support all formats listed in the table. If GL_RGB8 is requested, there is no guarantee that the texture data will be stored in this manner. The internal texture format parameter is merely a hint for the implementation, if the requested format is supported it will be used, but if it is not supported the closest supported format will be used.
A final note is that the internalformat parameter is independent of the format parameter in the glTexImage2D() call. Even though an internal format can be selected that has a lower resolution than the source texture image, format must be set to the appropriate type for the source texture data regardless of whatinternalformat is set too.
Internal format : GL_RGB
Internal format : GL_RGB4
- 高级 OpenGL 纹理贴图 Advanced OpenGL Texture Mapping
- OpenGL之纹理贴图(2):Texture Objects
- OpenGl 第七章:纹理映射 (texture mapping)
- android ndk调用OpenGL 实现纹理贴图Texture
- OpenGl 编程指南笔记 第九章:纹理映射 (texture mapping)
- OpenGL Texture 纹理
- OpenGL ES纹理贴图
- OpenGL ES纹理贴图
- opengl 关于纹理贴图
- OpenGL 纹理贴图
- OpenGL--纹理贴图基础
- Qt OpenGL----纹理贴图
- OpenGL ES纹理贴图
- OpenGL纹理贴图
- [转] opengl ---- 纹理贴图
- OpenGL ES 纹理贴图
- opengl 纹理贴图
- OpenGL纹理贴图 JPEG纹理
- struts2笔记(二)action的配置
- UML精粹--use case
- c++ const关键字 总结
- 小学科学骨干教师课堂教学展示活动总结
- Android:Changes to the SecretKeyFactory API in Android 4.4
- 高级 OpenGL 纹理贴图 Advanced OpenGL Texture Mapping
- 黑马程序员-- 二、this、super、final和static关键字
- Hibernate : 配置文件具体属性
- PowerDesigner反向工程 mysql
- 课程设计总结
- linux下 mysql data目录迁移
- java笔记6
- linux如何上网
- 北邮某牛人找工作切身感受