NeHe OpenGL Lesson06 - Texture Mapping

screen_shot4-300x238 This program shows us how to apply texture mapping with OpenGL. Well, texture mapping increase the visual effect significantly. And also until now, the texture mapping was vastly used. Those textures are not limited to diffuse texture, but for other kind of usage: diffuse texture, specular map, light map, normal map, emissive map,parallex map, cube map, reflection map, blend mask map, light mask map, shadow map and so on. I even found that some body used some HDR textures to store some polygons’ position information in one of the GPU ray tracer.  It seems any thing that time expensive could be pre-computed in the texture, and also use some texture to emulate some very complicated visual effect.


The following are the code that used to create texture object with OpenGL API on Ubuntu:

const char* filename = “./data/NeHe.bmp”;
QImage buf;
if ( !buf.load(filename) )
{
    qWarning(“Could not read image file, using single-color instead.”);
}

QImage texture = QGLWidget::convertToGLFormat( buf );

glGenTextures(1, &mDiffuse);
glBindTexture(GL_TEXTURE_2D, mDiffuse);
glTexImage2D(GL_TEXTURE_2D, 0, 3,
        texture.width(), texture.height(), 0, GL_RGBA,
        GL_UNSIGNED_BYTE, texture.bits() );

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

Here an OpenGL texture created with the raw bit map data, and the min and mag filter mode were set. Here there are several things to think about: 1) The bit map texture is not kind of compressed texture, that means some certain disk waste with the file size. May be we could compress it a DXT1(1 bit or no alpha) or DXT5(with full range alpha channel). 2) Actually, the compressed format that we need is the format that the display card will need. That means every time you create a texture object, the display card will accept those texture data without further process, compress those data that display card & GPU could support well. 3) There is no mip maps created here. No mip map will cause some texture waving effect as the viewer get close to the object from a far away distance. When you create a texture object with mip map, you need to set mip map filter mode properly. 4) About the texture filtering, there is one very advance filter mode named anisotropic. This filter mode will consider the angle between the polygon and the view plane, and then will give more realistic effect without make the texture mapping blurry(The linear filter always cause this issue).  Notice the max anisotropic parameter;  5) When you start use the mip map, that means you start use the LOD textures. You could do some tuning work on the LOD basis, and other parameters to get more visual comparison effect to find the correct result.

The whole program coded for the Ubuntu 10.4. You need to install gcc, cmake, opengl to compile and run it.

 

The full source code could be found here.

转载于:https://www.cnblogs.com/open-coder/archive/2012/08/23/2653410.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值