[Add] Added a method to resize the GL window, so the canvas resizes too!
This commit is contained in:
parent
616ed1bca5
commit
c4789fd077
@ -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;
|
||||
|
||||
|
@ -3,3 +3,5 @@
|
||||
|
||||
extern SDL_Surface* screen;
|
||||
extern SDL_Event event;
|
||||
|
||||
static void ResizeWindow(int w, int h);
|
||||
|
@ -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"
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user