Water rendering - HELP!

Started by
7 comments, last by fazekaim 20 years, 1 month ago
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!
Advertisement
How can I post here a screenshot to visualize the effect?
upload it to your webhost and post the url
The effect screenshot''s link:
http://delfin.unideb.hu/~fazekaim/a.jpg

If anyone has idea to resolve this problem, please write it.
Thanks.
looks like a offset problem?
offset problem? How could I resolve it?
So you are drawing one large quad at a certain level to show water? To me it looks like there''s z-fighting, to solve that either bring your far plane closer or send your near plane futher away (probably the better option).
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.
Thanks a lot! It works.

This topic is closed to new replies.

Advertisement