2

I'm trying to make do water simulation. But I'm restricted to use 2D, So i started with just making the boundary of the sea by using sine wave, through Gl_Line_loop. but I'm just unable to fill it. I have tried changing it to the Gl_polygon mode but then i don't get the proper shape. here is the code:

here is the image of wave, i want to get filled

shahtaj khalid
  • 456
  • 6
  • 20

1 Answers1

3

To tessellate the above, specify a top then a bottom vertex right along the line, then draw a triangle strip. i.e. for each (x, y) position along the sin wave, emit two vertices, the same x but y = 0 (the bottom). Then render a triangle strip.

Something like this:

glBegin(GL_TRIANGLE_STRIP);
for(x=-50;x<=50;x+=inc){
    k = 2 * 3.14 / wavelength;
    y = amplitude * sin(k * x);
    glVertex3f(x, y-35, 0);
    glVertex3f(x, y, 0);
}
glEnd();
Robinson
  • 8,836
  • 13
  • 64
  • 108
  • Can you please also suggest me way to animate it in such a way that it looks like water is flowing ?? – shahtaj khalid Dec 23 '15 at 11:47
  • The wavelength angle for an x position is fixed from -50 to 50 as sin(k * x). You need k * x to be changing over time so perhaps sin(k * (x + t)), where t starts at 0 say, and increments by a small amount each frame. – Robinson Dec 23 '15 at 11:51
  • You sir are a genius :'D it's movingg.. thankss again :') – shahtaj khalid Dec 23 '15 at 12:07