Archived

This topic is now archived and is closed to further replies.

Water rendering - HELP!

This topic is 5043 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello, I have a problem. I draw a terrain, and I want to add a water field, simulating an ocean. A draw a GL_QUAD with blending, and a water texture. When the camera is close to the terrain, it''s ok, but if the camera shove off (the distance increase), the image will be striped along the intersection points. I tried to set the deeptest, but nothing changed. Here is a piece of code: ... public void init(){ glShadeModel( GL_SMOOTH); glClearColor(0.0f, 0.0f, 0.0f,0.0f); glEnable( GL_DEPTH_TEST); glDepthFunc(GL_LEQUAL); glHint( GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); glEnable( GL_CULL_FACE); glCullFace( GL_FRONT); ... } ... public void drawWater() { glEnable( GL_TEXTURE_2D ); glEnable( GL_BLEND ); glBlendFunc( GL_SRC_ALPHA, GL_ONE); glDepthMask(false); glColor4f( 0.5f, 0.5f, 1.0f, 0.7f ); glBindTexture( GL_TEXTURE_2D, water[0] ); glBegin( GL_QUADS ); ... } Thanks!

Share this post


Link to post
Share on other sites
You have a problem called "z-fighting", which occurs when there are multiple pixels with the same depth value, and on the same plane. There are a couple of ways to solve this.

Firstly, I have noticed that when running in 16 bits per pixel mode or less, z-fighting is much more prominent. So, if you aren''t already, try running your application in 32 bit mode and see what happens. Also, you may need to change your depth buffer to 24 bit mode.

If that doesn''t solve your problem, then the next thing to do is check your near and far frustum clip planes. The near clip plane should be set to at least 1.0, any less and you will notice annoying artifacts. Otherwise, keep mucking around with the near and far clip plane values and you should notice differences.

Hope it helped, and good luck.

Share this post


Link to post
Share on other sites