graphics

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

commit 7511c235b33067fc3f9ed8b0f62e88268a8a98ff
parent ae85086e3056c67c14883e325211a1e0e4cb6618
Author: Brian Swetland <swetland@frotz.net>
Date:   Mon,  9 Sep 2013 03:50:52 -0700

app: add fullscreen() isFullscreen() and onResize()

Diffstat:
Mcommon/app.h | 4+++-
Mcommon/glapp.cc | 20++++++++++++++++++++
2 files changed, 23 insertions(+), 1 deletion(-)

diff --git a/common/app.h b/common/app.h @@ -22,16 +22,18 @@ class App { public: App(); virtual ~App(); + void fullscreen(int yes); virtual int init(void) = 0; virtual void render(void) = 0; virtual void release(void) {}; virtual void onKeyDown(unsigned code) {}; virtual void onKeyUp(unsigned code) {}; + virtual void onResize(void) {}; int getWidth(void) { return width; } int getHeight(void) { return height; } - + int isFullscreen(void) { return _fullscreen; } int keydown(unsigned code) { return keystate[code >> 5] & (1 << (code & 0x1f)); } diff --git a/common/glapp.cc b/common/glapp.cc @@ -43,6 +43,15 @@ void App::handleEvents(void) { while (SDL_PollEvent(&ev)) { switch (ev.type) { + case SDL_WINDOWEVENT: + switch (ev.window.event) { + case SDL_WINDOWEVENT_RESIZED: + width = ev.window.data1; + height = ev.window.data2; + glViewport(0, 0, width, height); + onResize(); + } + break; case SDL_KEYDOWN: code = ev.key.keysym.scancode; keystate[code >> 5] |= (1 << (code & 0x1F)); @@ -168,6 +177,16 @@ static void APIENTRY dbg_callback(GLenum source, GLenum type, GLuint id, GLenum #endif } +void App::fullscreen(int yes) { + if (yes) { + SDL_SetWindowFullscreen(win, SDL_WINDOW_FULLSCREEN); + _fullscreen = 1; + } else { + SDL_SetWindowFullscreen(win, 0); + _fullscreen = 0; + } +} + int App::start(void) { memset(keystate, 0, sizeof(keystate)); @@ -189,6 +208,7 @@ int App::start(void) { unsigned flags = SDL_WINDOW_OPENGL; if (_fullscreen) flags |= SDL_WINDOW_FULLSCREEN; + //flags |= SDL_WINDOW_RESIZABLE; win = SDL_CreateWindow("Application", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,