title: 2D Water ripple effect in SFML not working, produces a black screen
body: <p>I'm trying to implement the algorithm detailed over here: <a href="https://web.archive.org/web/20160418004149/http://freespace.virgin.net/hugo.elias/graphics/x_water.htm" rel="nofollow noreferrer">https://web.archive.org/web/20160418004149/http://freespace.virgin.net/hugo.elias/graphics/x_water.htm</a> in c++ with SFML but so far I've only been getting a completely black screen. In the game loop, I've hard coded some of the values to be 255, at the center of the screen, so you can constantly see ripples originating from the center but it isn't working. I'm also using a vertex array to draw pixels onto the screen because I feel it would be faster that drawing 1 by 1 rectangles instead and the code uses gray scale so you can see the ripples turn from white to black and gradually disappear. I've been stuck on this for quite some time, any help is greatly appreciated.</p>
  
  <pre><code>#include &lt;SFML/Graphics.hpp&gt;
  #include &lt;vector&gt;
  
  constexpr int row = 640, col = 400;
  
  std::vector&lt; std::vector&lt;int&gt; &gt; buffer1(row, std::vector&lt;int&gt;(col));
  
  std::vector&lt; std::vector&lt;int&gt; &gt; buffer2(row, std::vector&lt;int&gt;(col));
  
  int damping = 0.9;
  
  int main()
  {
      sf::RenderWindow window(sf::VideoMode(row, col), "Ripples");
      while (window.isOpen())
      {
          sf::Event event;
          while (window.pollEvent(event))
          {
              if (event.type == sf::Event::Closed)
                  window.close();
          }
          //main loop
          while (true)
          {
              //hard coded this part to constantly see a ripple originate from the center
              buffer1[row / 2][col / 2] = 255;
              buffer1[row / 2 - 1][col / 2] = 255;
              buffer1[row / 2 + 1][col / 2] = 255;
              buffer1[row / 2][col / 2 - 1] = 255;
              buffer1[row / 2][col / 2 + 1] = 255;
              //
              for (int x = 1; x &lt; row - 1; x++)
              {
                  for (int y = 1; y &lt; col - 1; y++)
                  {
                      buffer2[x][y] = (buffer1[x - 1][y] +
                                        buffer1[x + 1][y] +
                                        buffer1[x][y + 1] +
                                        buffer1[x][y - 1]) / 2 - buffer2[x][y];
                      buffer2[x][y] = buffer2[x][y] * damping;
                  }
              }
              window.clear();
              //draw buffer
              for (int i = 1; i &lt; row - 1; i++)
              {
                  for (int j = 1; j &lt; col - 1; j++)
                  {
                      sf::Vertex vertex1;
                      vertex1.position = sf::Vector2f(i, j);
                      vertex1.color = sf::Color(buffer2[i][j], buffer2[i][j], buffer2[i][j]);//grayscale
                      sf::VertexArray pixel;
                      pixel.append(vertex1);
                      window.draw(pixel);
                  }
              }
              window.display();
              //swap buffers
              std::vector&lt; std::vector&lt;int&gt; &gt; temp(row, std::vector&lt;int&gt;(col));
              temp = buffer1;
              buffer1 = buffer2;
              buffer2 = temp;
          }
      }
      return 0;
  }
  </code></pre>
  
  <p>update: it works now but it's incredibly, incredibly, slow. I've tried using openmp(by adding #pragma omp parallel for shared(buffer1, buffer2) right before the start of the first for loop in the main loop)but it doesn't help. Any advice?</p>
  
  <p>new code(i had to use float instead of int)</p>
  
  <pre><code>#include &lt;SFML/Graphics.hpp&gt;
  #include &lt;omp.h&gt;
  #include &lt;vector&gt;
  
  int main()
  {
      constexpr int row = 640, col = 400;
  
      std::vector&lt; std::vector&lt;float&gt; &gt; buffer1(row, std::vector&lt;float&gt;(col));
  
      std::vector&lt; std::vector&lt;float&gt; &gt; buffer2(row, std::vector&lt;float&gt;(col));
  
      float damping = 0.9;
  
      //added this part to constantly see a ripple originate from the center
      buffer1[row / 2][col / 2] = 255;
      buffer1[row / 2 - 1][col / 2] = 255;
      buffer1[row / 2 + 1][col / 2] = 255;
      buffer1[row / 2][col / 2 - 1] = 255;
      buffer1[row / 2][col / 2 + 1] = 255;
      //
  
      sf::RenderWindow window(sf::VideoMode(row, col), "Ripples");
  
      while (window.isOpen())
      {
          sf::Event event;
  
          while (window.pollEvent(event))
          {
              if (event.type == sf::Event::Closed)
                  window.close();
          }
          //main loop
          while (true)
          {
  #pragma omp parallel for shared(buffer1, buffer2)
              for (int x = 1; x &lt; row - 1; x++)
              {
                  for (int y = 1; y &lt; col - 1; y++)
                  {
                      buffer2[x][y] = ( 
                                        buffer1[x - 1][y] +
                                        buffer1[x + 1][y] +
                                        buffer1[x][y + 1] +
                                        buffer1[x][y - 1]) / 2 - buffer2[x][y];
  
                      buffer2[x][y] = buffer2[x][y] * damping;
  
                      if (buffer2[x][y] &lt; 0)
                          buffer2[x][y] = 0;
  
                      if (buffer2[x][y] &gt; 255)
                          buffer2[x][y] = 255;
                  }
              }
              window.clear();
              //draw buffer
              for (int i = 0; i &lt; row; i++)
              {
                  for (int j = 0; j &lt; col; j++)
                  {
                      sf::Vertex vertex1;
                      vertex1.position = sf::Vector2f(i, j);
                      vertex1.color = sf::Color(buffer2[i][j], buffer2[i][j], buffer2[i][j]);//grayscale
                      sf::VertexArray pixel;
                      pixel.append(vertex1);
                      window.draw(pixel);
                  }
              }
              window.display();
              //swap buffers
              buffer1.swap(buffer2);
          }
      }
      return 0;
  }
  
  </code></pre>