From c4789fd077df225196a6e70f4506f8c2c345d323 Mon Sep 17 00:00:00 2001
From: Rtch90 <ritchie.cunningham@protonmail.com>
Date: Mon, 9 Apr 2012 21:23:16 +0100
Subject: [PATCH] [Add] Added a method to resize the GL window, so the canvas
 resizes too!

---
 src/Global/Globals.cpp |  9 +++++++++
 src/Global/Globals.h   |  2 ++
 src/Main/Game.cpp      |  1 +
 src/Main/main.cpp      | 30 ++++++++++++++++++++----------
 4 files changed, 32 insertions(+), 10 deletions(-)

diff --git a/src/Global/Globals.cpp b/src/Global/Globals.cpp
index 5ddada9..055df14 100644
--- a/src/Global/Globals.cpp
+++ b/src/Global/Globals.cpp
@@ -1,5 +1,14 @@
+#include <GL/gl.h>
 #include "Globals.h"
 
+static void ResizeWindow(int w, int h) {
+  SDL_SetVideoMode(w, h, 32, SDL_OPENGL | SDL_RESIZABLE);
+  glViewport(0,0,w,h);
+  glLoadIdentity();
+  glOrtho(0.0, 800.0, 600.0, 0.0, 0.0, 1.0);
+  SDL_GL_SwapBuffers();
+}
+
 SDL_Surface* screen   = NULL;
 SDL_Event event;
 
diff --git a/src/Global/Globals.h b/src/Global/Globals.h
index b035443..8700c69 100644
--- a/src/Global/Globals.h
+++ b/src/Global/Globals.h
@@ -3,3 +3,5 @@
 
 extern SDL_Surface* screen;
 extern SDL_Event event;
+
+static void ResizeWindow(int w, int h);
diff --git a/src/Main/Game.cpp b/src/Main/Game.cpp
index 13547b7..1ac0336 100644
--- a/src/Main/Game.cpp
+++ b/src/Main/Game.cpp
@@ -5,6 +5,7 @@
 #include <GL/gl.h>
 #include <GL/glu.h>
 
+#include "../Global/Globals.h"
 #include "../System/Debug.h"
 #include "../Sprite/Sprite.h"
 #include "../Texture/Texture.h"
diff --git a/src/Main/main.cpp b/src/Main/main.cpp
index b3968f1..09a1e38 100644
--- a/src/Main/main.cpp
+++ b/src/Main/main.cpp
@@ -22,6 +22,14 @@ void Destroy(void) {
   SDL_Quit();
 }
 
+static void ResizeWindow(int w, int h) {
+  SDL_SetVideoMode(w, h, 32, SDL_OPENGL | SDL_RESIZABLE);
+  glViewport(0,0,w,h);
+  glLoadIdentity();
+  glOrtho(0.0, 800.0, 600.0, 0.0, 0.0, 1.0);
+  SDL_GL_SwapBuffers();
+}
+
 #ifdef _WIN32
 int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR cmdLine, int cmdShow) {
 #else
@@ -72,20 +80,22 @@ int main(int argc, char** argv) {
 
   bool isRunning = true;
   while(isRunning) {
-    SDL_Event ev;
-    while(SDL_PollEvent(&ev)){
-      if(ev.type == SDL_QUIT) {
+
+    while(SDL_PollEvent(&event)){
+      if(event.type == SDL_QUIT) {
         isRunning = false;
         break;
       }
       if(event.type == SDL_VIDEORESIZE) {
-        // Resize the window.
-        screen = SDL_SetVideoMode(event.resize.w, event.resize.h, 32, flags);
-        // Error?
-        if(!screen) {
-          Debug::logger->message("Window resize is screwed");
-          Destroy();
-        }
+//        // Resize the window.
+//        screen = SDL_SetVideoMode(event.resize.w, event.resize.h, 32, flags);
+//        // Error?
+//        if(!screen) {
+//          Debug::logger->message("Window resize is screwed");
+//          Destroy();
+//        }
+        ResizeWindow(event.resize.w, event.resize.h);
+        break;
       }
     }