title: Handling window resizing using OpenGL and SDL
body: <p>From the code I have of a program that draws and moves a square around an application window, I'm having trouble when resizing the application window. When I handle a resize and alter states accordingly, everything on the screen that should be drawn and was before the resize vanishes. I have no idea why because none of the objects internal coordinates are changed during the window resizing.</p>
  
  <p>My question is can anyone point me in the right direction to solve my problem.(The code compiles fine)</p>
  
  <pre><code>void ResizeWindow()
  {
      screen_width = event.resize.w;
      screen_height = event.resize.h;
  
      SDL_SetVideoMode(screen_width, screen_height, bpp, SDL_OPENGL | SDL_RESIZABLE | SDL_DOUBLEBUF);
  
      glViewport(0, 0, screen_width, screen_height);
      glMatrixMode(GL_PROJECTION);
      glOrtho(0, screen_width, 0, screen_height, -1, 1);
      glLoadIdentity();
      glMatrixMode(GL_MODELVIEW);
      glLoadIdentity();
      glClear(GL_COLOR_BUFFER_BIT);
      glLoadIdentity();
  }
  </code></pre>
  
  <p>Main loop:</p>
  
  <pre><code>while (running == true)
  
  {
  
      while(SDL_PollEvent(&amp;event))
  
      {
  
          switch(event.type)
  
          {
  
              case SDL_VIDEORESIZE: ResizeWindow(); break; // resizing called here
              case SDL_QUIT: running = false; break;
              case SDL_KEYDOWN: square.Handle_Input(down); break;
              case SDL_KEYUP: square.Handle_Input(up); break;
  
          }
  
      }
  
      square.Move();
      square.Check_Collision();
  
      glClear(GL_COLOR_BUFFER_BIT);
  
      square.Draw();
  
      SDL_GL_SwapBuffers();
  
  }
  </code></pre>
  
  <p>It all runs perfectly until the window is resized.</p>