title: Creating a 2D grid using openGL and vertex and fragment shaders
body: <p>OK so i have a really big square (grid) that I have made up using triangles, then applied a heightmap to bump it. What im trying to do now is get grid lines on it. I have figured out a way to do this but this results in 33 if statements in the fragment shader just for x and then another 33 for y. I have been told I can use what im doing now and implement it slightly differently (using some GLSL function) to only need 1 or 2 if statements. This is my current code (not all finished but gives you the idea of what im doing.)</p>
  
  <pre><code>#version 330
  
  uniform sampler2D texture;
  
  in vec2 texCoord;
  
  layout (location=0) out vec4 fragColour;
  
  
  
  void main(void) {
  
  vec4 newColor;
  vec2 line = texCoord * 32; // makes texCoords easier to number (as divided by 32 in the C++array)
  
  
  if(line.x &gt; 0 &amp;&amp; line.x &lt; 0.9)
  {
      newColor = vec4(1.0,1.0,1.0,1.0);
  }
  else if(line.x &gt; 1 &amp;&amp; line.x &lt; 1.9)
  {
       newColor = vec4(1.0,1.0,1.0,1.0);
  }
      else if(line.x &gt; 2 &amp;&amp; line.x &lt; 2.9)
  {
       newColor = vec4(1.0,1.0,1.0,1.0);
  }
      else if(line.x &gt; 3 &amp;&amp; line.x &lt; 3.9)
  {
       newColor = vec4(1.0,1.0,1.0,1.0);
  }
      else if(line.x &gt; 4 &amp;&amp; line.x &lt; 4.9)
  {
       newColor = vec4(1.0,1.0,1.0,1.0);
  }
      else if(line.x &gt; 5 &amp;&amp; line.x &lt; 5.9)
  {
       newColor = vec4(1.0,1.0,1.0,1.0);
  }
      else if(line.x &gt; 6 &amp;&amp; line.x &lt; 6.9)
  {
       newColor = vec4(1.0,1.0,1.0,1.0);
  }
      else if(line.x &gt; 7 &amp;&amp; line.x &lt; 7.9)
  {
       newColor = vec4(1.0,1.0,1.0,1.0);
  }
      else if(line.x &gt; 8 &amp;&amp; line.x &lt; 8.9)
  {
       newColor = vec4(1.0,1.0,1.0,1.0);
  }
      else if(line.x &gt; 9 &amp;&amp; line.x &lt; 9.9)
  {
       newColor = vec4(1.0,1.0,1.0,1.0);
  }
      else if(line.x &gt; 10 &amp;&amp; line.x &lt; 10.9)
  {
       newColor = vec4(1.0,1.0,1.0,1.0);
  }
      else if(line.x &gt; 11 &amp;&amp; line.x &lt; 11.9)
  {
       newColor = vec4(1.0,1.0,1.0,1.0);
  }
      else if(line.x &gt; 12 &amp;&amp; line.x &lt; 12.9)
  {
       newColor = vec4(1.0,1.0,1.0,1.0);
  }
      else if(line.x &gt; 13 &amp;&amp; line.x &lt; 13.9)
  {
       newColor = vec4(1.0,1.0,1.0,1.0);
  }
      else if(line.x &gt; 14 &amp;&amp; line.x &lt; 14.9)
  {
       newColor = vec4(1.0,1.0,1.0,1.0);
  }
      else if(line.x &gt; 15 &amp;&amp; line.x &lt; 15.9)
  {
       newColor = vec4(1.0,1.0,1.0,1.0);
  }
      else if(line.x &gt; 16 &amp;&amp; line.x &lt; 16.9)
  {
       newColor = vec4(1.0,1.0,1.0,1.0);
  }
      else if(line.x &gt; 17 &amp;&amp; line.x &lt; 17.9)
  {
       newColor = vec4(1.0,1.0,1.0,1.0);
  }
      else if(line.x &gt; 18 &amp;&amp; line.x &lt; 18.9)
  {
       newColor = vec4(1.0,1.0,1.0,1.0);
  }
      else if(line.x &gt; 19 &amp;&amp; line.x &lt; 19.9)
  {
       newColor = vec4(1.0,1.0,1.0,1.0);
  }
      else if(line.x &gt; 20 &amp;&amp; line.x &lt; 20.9)
  {
       newColor = vec4(1.0,1.0,1.0,1.0);
  }
      else if(line.x &gt; 21 &amp;&amp; line.x &lt; 21.9)
  {
       newColor = vec4(1.0,1.0,1.0,1.0);
  }
      else if(line.x &gt; 22 &amp;&amp; line.x &lt; 22.9)
  {
       newColor = vec4(1.0,1.0,1.0,1.0);
  }
      else if(line.x &gt; 23 &amp;&amp; line.x &lt; 23.9)
  {
       newColor = vec4(1.0,1.0,1.0,1.0);
  }
      else if(line.x &gt; 24 &amp;&amp; line.x &lt; 24.9)
  {
       newColor = vec4(1.0,1.0,1.0,1.0);
  }
  
  else
  {
      newColor = vec4(0.0,0.0,0.0,1.0);
  }
  
  fragColour = newColor;
  }
  </code></pre>