title: How to draw a simple grid using opengl?
body: <p>I am trying to draw a grid that should look something like this:</p>
  
  <p><a href="https://i.stack.imgur.com/Y32wR.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Y32wR.jpg" alt="enter image description here"></a></p>
  
  <p>but what I get instead:</p>
  
  <p><a href="https://i.stack.imgur.com/5JNgX.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/5JNgX.jpg" alt="enter image description here"></a></p>
  
  <p><em>A black screen with two orange lines on the left and bottom borders</em></p>
  
  <p>This is my code:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;GL/glut.h&gt;
  
  #define WIDTH 1000
  #define HEIGHT 400
  #define OFFSET 200
  
  using namespace std;
  
  float x = 0;
  float y = 0;
  
  void init (void)
  {
      //glClearColor (1.0, 1.0, 1.0, 0.0);
      glClear (GL_COLOR_BUFFER_BIT);
      glMatrixMode (GL_PROJECTION);
      glLoadIdentity();
      glOrtho (0.0, 5.0, 0.0, 5.0, -2.0, 2.0);
  
      glMatrixMode (GL_MODELVIEW);
      glLoadIdentity();
  }
  
  void drawline (float x1, float y1, float x2, float y2)
  {
      glBegin (GL_LINES);
      glVertex2f (x1, y1);
      glVertex2f (x2, y2);
      glEnd();
  }
  
  void drawgrid()
  {
      glClearColor (1.0, 1.0, 1.0, 1.0);
      glColor3ub (240, 57, 53);
  
      for (float i = 0; i &lt; HEIGHT; i += 10)
      {
          if ((int) i % 100 == 0) glLineWidth (3.0);
          else if ((int) i % 50 == 0) glLineWidth (2.0);
          else glLineWidth (1.0);
          drawline (0, i, (float) WIDTH, i);
      }
  
      for (float i = 0; i &lt; WIDTH; i += 10)
      {
          if ((int) i % 100 == 0) glLineWidth (3.0);
          else if ((int) i % 50 == 0) glLineWidth (2.0);
          else glLineWidth (1.0);
          drawline (i, 0, i, (float) HEIGHT);
      }
  }
  
  void display()
  {
      drawgrid();
  
      glFlush();
      glutSwapBuffers();
  }
  
  int main (int argc, char **argv)
  {
      glutInit (&amp;argc, argv);
      glutInitDisplayMode (GLUT_SINGLE | GLUT_RGBA);
      glutInitWindowSize (WIDTH, HEIGHT);
      glutCreateWindow ("ECG");
  
      init();
  
      glutDisplayFunc (display);
      glDisable (GL_TEXTURE_2D);
  
      glutMainLoop();
  
      return 0;
  }
  </code></pre>
  
  <p>What am I doing wrong? How to make the background white and draw the grid properly?</p>