title: Can't draw lines in 2D space with GLFW and OpenGL
body: <p>I'm trying to draw a grid in 2D space using GLFW and OpenGL but for some reason I only get this on the screen:</p>
  
  <p><a href="https://i.stack.imgur.com/Fybr5.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Fybr5.jpg" alt="image"></a>
  Here's my code:</p>
  
  <pre><code>#include &lt;GLFW/glfw3.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;stdio.h&gt;
  #include &lt;iostream&gt;
  
  const int gridSize = 32;
  
  const int SCREEN_WIDTH = gridSize*32;
  const int SCREEN_HEIGHT = gridSize*16;
  
  static void inputK(GLFWwindow* window, int key, int scancode, int action, int mods){
      if (key == GLFW_KEY_ESCAPE &amp;&amp; action == GLFW_PRESS) glfwSetWindowShouldClose(window, GL_TRUE);
  }
  
  static void error_callback(int error, const char* description){
      fputs(description, stderr);
  }
  
  int main(void){
      GLFWwindow* window;
      glfwSetErrorCallback(error_callback);
      if (!glfwInit())
          exit(EXIT_FAILURE);
      window = glfwCreateWindow(SCREEN_WIDTH, SCREEN_HEIGHT, "MSSIN_no", NULL, NULL);
      if (!window){
          glfwTerminate();
          exit(EXIT_FAILURE);
      }
  
      glfwMakeContextCurrent(window);
      glfwSwapInterval(1);
      glfwSetKeyCallback(window, inputK);
  
      while (!glfwWindowShouldClose(window)){
          float ratio;
          int width, height;
          glfwGetFramebufferSize(window, &amp;width, &amp;height);
          ratio = width / (float) height;
          glViewport(0, 0, width, height);
          glClear(GL_COLOR_BUFFER_BIT);
          glMatrixMode(GL_PROJECTION);
          glLoadIdentity();
  
  
          glOrtho(-ratio, ratio, -1.f, 1.f, 1.f, -1.f);
          glMatrixMode(GL_MODELVIEW);
          glLoadIdentity();
  
      //attempt to draw lines
      glBegin(GL_LINES);
      //horizontal
      for (int i = 0; i &lt; SCREEN_HEIGHT; i+=gridSize){
          glVertex2f(0, i);
          glVertex2f(SCREEN_WIDTH,i);
      }
      //vertical
      for (int i = 0; i &lt; SCREEN_WIDTH; i += gridSize){
          glVertex2f(i,0);
          glVertex2f(i, SCREEN_HEIGHT);
      }
      glEnd();
  
  
      glfwSwapBuffers(window);
      glfwPollEvents();
  
      }
  
      glfwDestroyWindow(window);
      glfwTerminate();
      exit(EXIT_SUCCESS);
  }
  </code></pre>