graphics

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

commit 55bddcb0b758b734330ea9d6b8ddca42f1ddaa4f
parent e0e6a47c4c7b6c0dd1ae9ab562ffb50dfc49f1be
Author: Brian Swetland <swetland@frotz.net>
Date:   Fri,  6 Sep 2013 22:57:20 -0700

app: re-enable commandline argument handling (-vsync, fullscreen, -fs, ###x###)

Diffstat:
Mcommon/app.h | 12++++++++----
Mcommon/glapp.cc | 31+++++++++++++++++++++----------
Mhello/hello.cc | 2--
3 files changed, 29 insertions(+), 16 deletions(-)

diff --git a/common/app.h b/common/app.h @@ -29,16 +29,15 @@ public: virtual void onKeyDown(unsigned code) {}; virtual void onKeyUp(unsigned code) {}; - /* glue - do not use */ - int start(void); - void handleEvents(void); - int getWidth(void) { return width; } int getHeight(void) { return height; } int keydown(unsigned code) { return keystate[code >> 5] & (1 << (code & 0x1f)); } + + static int __main(int argc, char **argv); + protected: int width; int height; @@ -55,7 +54,12 @@ protected: int fps; private: + int start(void); + void handleEvents(void); + void setOptions(int argc, char **argv); + int _vsync; + int _fullscreen; SDL_Window *win; SDL_GLContext glcontext; }; diff --git a/common/glapp.cc b/common/glapp.cc @@ -61,24 +61,26 @@ void App::handleEvents(void) { } } -#if 0 void App::setOptions(int argc, char **argv) { char *x; argc--; argv++; while (argc--) { - if (!strcmp("-nosync",argv[0])) { + if (!strcmp("-nosync", argv[0])) { _vsync = 0; + } else if (!strcmp("-fullscreen", argv[0])) { + _fullscreen = 1; + } else if (!strcmp("-fs", argv[0])) { + _fullscreen = 1; } else if (isdigit(argv[0][0]) && (x = strchr(argv[0],'x'))) { - _width = atoi(argv[0]); - _height = atoi(x + 1); + width = atoi(argv[0]); + height = atoi(x + 1); } else { fprintf(stderr,"unknown argument '%s'\n",argv[0]); } argv++; } } -#endif static void dump_gl_params(void) { #define GGI(name) { int n = -1; glGetIntegerv(GL_##name, &n); fprintf(stderr, #name ": %d\n", n); } @@ -184,12 +186,16 @@ int App::start(void) { //SDL_GL_SetAttribute(SDL_GL_SWAP_CONTROL, _vsync); SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, _vsync); + unsigned flags = SDL_WINDOW_OPENGL; + if (_fullscreen) + flags |= SDL_WINDOW_FULLSCREEN; + win = SDL_CreateWindow("Application", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, - width, height, SDL_WINDOW_OPENGL - // | SDL_WINDOW_RESIZABLE - // | SDL_WINDOW_FULLSCREEN - ); + width, height, flags); + + SDL_GetWindowSize(win, &width, &height); + printx("Window is %d x %d.\n", width, height); int minor = 3; while (minor > 0) { @@ -266,7 +272,7 @@ int App::start(void) { return -1; } -App::App() : width(800), height(600), _vsync(1) { +App::App() : width(800), height(600), _vsync(1), _fullscreen(0) { } App::~App() { @@ -276,7 +282,12 @@ void init_io(void); int main(int argc, char **argv) { init_io(); + return App::__main(argc, argv); +} + +int App::__main(int argc, char **argv) { App *app = createApp(); + app->setOptions(argc, argv); app->start(); app->release(); return 0; diff --git a/hello/hello.cc b/hello/hello.cc @@ -71,8 +71,6 @@ private: }; TestApp::TestApp() : App(), t(0.0f), zoom(0), rx(0), ry(0), nx(0), ny(0) { - width = 1280; - height = 1024; } void TestApp::release(void) {