NeNe OpenGL Lesson41 - Volumetric Fog(体积雾) & IPicture Image Loading

lesson41_screenshot

     This samples shows us how to create some fog effect that does not fall off by the distance between the viewer and vertex position. With OpenGL command glFogCoordf, we could specify a fog density for each vertex.
    Of course, there are other ways to create the volumetric fog effect. To get better visual effect, we usually work with the render to texture & post-process.
1) method one, draw the back surface & front surface of a box separately to get two different depth map. These two depth map could be used to check whether some pixel in the fog or not. A volumetric fog post-process created to calculate how fog density will be for each pixel.
2) method two, we could create a volume texture to represent how the fog in the scene should be. In the post-process step, we could restore a 3D position by screen position, depth value and view matrix. We could sample the volume texture well with this 3D vertex position.

Volumetric fog with glFogCoordf

Set up fog with OpenGL commands, the code almost the same as usual fog set up process except the last line to switch on the fog coordinate feature:

glEnable(GL_FOG);    
glFogi(GL_FOG_MODE, GL_LINEAR);
glFogfv(GL_FOG_COLOR, fogColor);
glFogf(GL_FOG_START,  0.0f);
glFogf(GL_FOG_END,    1.0f);
glHint(GL_FOG_HINT, GL_NICEST);    
glFogi(GL_FOG_COORDINATE_SOURCE_EXT, GL_FOG_COORDINATE_EXT);

Fog extension on windows, because windows does not support OpenGL advanced feature natively.(Windows already has D3D, no need for them update OpenGL)

// check "EXT_fog_coord" extension first
...
// Enable glFogCoordEXT
glFogCoordfEXT = (PFNGLFOGCOORDFEXTPROC) wglGetProcAddress("glFogCoordfEXT");

Draw with glFogCoordfEXT, specify a fog density for each vertex, a bit similar as specify a texture coordinates with glTexCoord2f function.

glBegin(GL_QUADS);                                                    // Back Wall
    glFogCoordfEXT( 1.0f);    glTexCoord2f(0.0f, 0.0f);    glVertex3f(-2.5f,-2.5f,-15.0f);
    glFogCoordfEXT( 1.0f);    glTexCoord2f(1.0f, 0.0f);    glVertex3f( 2.5f,-2.5f,-15.0f);
    glFogCoordfEXT( 1.0f);    glTexCoord2f(1.0f, 1.0f);    glVertex3f( 2.5f, 2.5f,-15.0f);
    glFogCoordfEXT( 1.0f);    glTexCoord2f(0.0f, 1.0f);    glVertex3f(-2.5f, 2.5f,-15.0f);
glEnd();


IPicture Image Load

Create a texture from temporary bitmap (get after OleLoadPicturePath() load the image content ), no matter from local disc or network. Well, I think no matter you write a small graphic program ,engine or game, we should need to design how texture should be found and loaded. We may even need to design a texture assets pipeline.


The full source code could be found here.

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

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值