[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"
|
#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_Surface* screen = NULL;
|
||||||
SDL_Event event;
|
SDL_Event event;
|
||||||
|
|
||||||
|
@ -3,3 +3,5 @@
|
|||||||
|
|
||||||
extern SDL_Surface* screen;
|
extern SDL_Surface* screen;
|
||||||
extern SDL_Event event;
|
extern SDL_Event event;
|
||||||
|
|
||||||
|
static void ResizeWindow(int w, int h);
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
#include <GL/gl.h>
|
#include <GL/gl.h>
|
||||||
#include <GL/glu.h>
|
#include <GL/glu.h>
|
||||||
|
|
||||||
|
#include "../Global/Globals.h"
|
||||||
#include "../System/Debug.h"
|
#include "../System/Debug.h"
|
||||||
#include "../Sprite/Sprite.h"
|
#include "../Sprite/Sprite.h"
|
||||||
#include "../Texture/Texture.h"
|
#include "../Texture/Texture.h"
|
||||||
|
@ -22,6 +22,14 @@ void Destroy(void) {
|
|||||||
SDL_Quit();
|
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
|
#ifdef _WIN32
|
||||||
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR cmdLine, int cmdShow) {
|
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR cmdLine, int cmdShow) {
|
||||||
#else
|
#else
|
||||||
@ -72,20 +80,22 @@ int main(int argc, char** argv) {
|
|||||||
|
|
||||||
bool isRunning = true;
|
bool isRunning = true;
|
||||||
while(isRunning) {
|
while(isRunning) {
|
||||||
SDL_Event ev;
|
|
||||||
while(SDL_PollEvent(&ev)){
|
while(SDL_PollEvent(&event)){
|
||||||
if(ev.type == SDL_QUIT) {
|
if(event.type == SDL_QUIT) {
|
||||||
isRunning = false;
|
isRunning = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if(event.type == SDL_VIDEORESIZE) {
|
if(event.type == SDL_VIDEORESIZE) {
|
||||||
// Resize the window.
|
// // Resize the window.
|
||||||
screen = SDL_SetVideoMode(event.resize.w, event.resize.h, 32, flags);
|
// screen = SDL_SetVideoMode(event.resize.w, event.resize.h, 32, flags);
|
||||||
// Error?
|
// // Error?
|
||||||
if(!screen) {
|
// if(!screen) {
|
||||||
Debug::logger->message("Window resize is screwed");
|
// Debug::logger->message("Window resize is screwed");
|
||||||
Destroy();
|
// Destroy();
|
||||||
}
|
// }
|
||||||
|
ResizeWindow(event.resize.w, event.resize.h);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user