开发者

OpenGL fog is based on Z-axis instead of depth

I'm trying to add fog to my scene, but instead of the scene becoming more foggy further away from the camera, the fog seems to be entirely dependent on height. Below is a screenshot demonstrating the problem:

OpenGL fog is based on Z-axis instead of depth

(source: gyazo.com)

I initialize the fog using the following code:

gl.glFogx( GL10.GL_FOG_MODE, GL10.GL_LINEAR );
gl.glFogfv( GL10.GL_FOG_COLOR, new float[] { 1.0f, 1.0f, 1.0f, 1.0f }, 0 );
gl.glFogf( GL10.GL_FOG_DENSITY, 0.35f );
gl.glHint( GL10.GL_FOG_HINT, GL10.GL_DONT_CARE );
gl.glFogf( GL10.GL_FOG_START, 10.0f );
gl.glFogf( GL10.GL_FOG_END, 15.0f );
gl.glEnable( GL10.GL_FOG );

And this is how my projection is set up:

gl.glMatrixMode( GL10.GL_PROJECTION );
gl.glLoadIdentity();
GLU.gluPerspective( gl, 90.0f, _w / _h, 0.1f, 15.0f );
GLU.gluLookAt( gl, _player.position.x, _player.position.y, _player.position.z, centerX, centerY, centerZ, 0.0f, 0.0f, 1.0f );

Any ide开发者_JAVA技巧a what's wrong?


As you say, you need to use GL_MODELVIEW for your camera.

See http://www.sjbaker.org/steve/omniv/projection_abuse.html


Oh. You need to use gluLookAt for the GL_MODELVIEW matrix instead of GL_PROJECTION. What a d'oh moment.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜