[Add] Added a method to resize the GL window, so the canvas resizes too!

This commit is contained in:
Rtch90 2012-04-09 21:23:16 +01:00
parent 616ed1bca5
commit c4789fd077
4 changed files with 32 additions and 10 deletions

View File

@ -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;

View File

@ -3,3 +3,5 @@
extern SDL_Surface* screen;
extern SDL_Event event;
static void ResizeWindow(int w, int h);

View File

@ -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"

View File

@ -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;
}
}