NeNe OpenGL Lesson41 - Volumetric Fog(体积雾) & IPicture Image Loading
2012-08-17 08:23
211 查看
![](http://images.cnblogs.com/cnblogs_com/open-coder/201208/201208170823253209.png)
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 afterOleLoadPicturePath() 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.
相关文章推荐
- 3D人体姿态估计--Coarse-to-Fine Volumetric Prediction for Single-Image 3D Human Pose
- 3D【4】人脸重建:Large Pose 3D Face Reconstruction from a Single Image via Direct Volumetric
- openstack HA 环境中批量创建虚拟机(boot from image & create a new volume) 的bug (2)
- Clipboard()->Assign(Image1->Picture);
- Large Pose 3D Face Reconstruction from a Single Image via Direct Volumetric CNN Regression
- (vtk——The Visualization Toolkit)Visulizing Image & Volume Data(图像及三维体数据的可视化)
- openstack HA 环境中批量创建虚拟机(boot from image & create a new volume) 的bug (1)
- internet explorer cannot display image picture from google group?我的问题就这么解决了View > Encoding >
- error while loading shared libraries: xxx.so.x"错误的原因和解决办法
- Image loading with Imaging API
- 第37章、图片切换ImageSwitcher&Gallery(从零开始学Android)
- 转)x264重要结构体详细说明(2): x264_image_t、x264_picture_t、x264_nal_t
- error while loading shared libraries: xxx.so.x"错误的原因和解决办法
- AFN&SDWebImage配置HTTPS
- 论文阅读ImageNet Classification with Deep Convolutional Neural Networks &Going Deeper with Convolutions
- Response.ContentType="image/jpeg"
- HDU 1828 Picture(线段树扫描线·周长并)
- 【Loading Image】Loading Image Resource
- Loading Cineon DPX Image Into OpenGL
- error while loading shared libraries: xxx.so.x"错误的原因和解决办法