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 #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 #include +#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; } }