diff --git a/driver.h b/driver.h index c9044d90020..f6b92ca1177 100644 --- a/driver.h +++ b/driver.h @@ -32,7 +32,12 @@ class Bitmap; class Driver { public: Driver() { ; } - Driver(int screenW, int screenH, int screenBPP) { ; } + Driver(int screenW, int screenH, int screenBPP, bool fullscreen = false) { + _screenWidth = screenW; + _screenHeight = screenH; + _screenBPP = screenBPP; + _isFullscreen = fullscreen; + } struct TextObjectHandle { uint16 *bitmapData; @@ -43,6 +48,8 @@ public: int height; }; + virtual void toggleFullscreenMode() = 0; + virtual void setupCamera(float fov, float nclip, float fclip, float roll) = 0; virtual void positionCamera(Vector3d pos, Vector3d interest) = 0; @@ -78,6 +85,10 @@ public: virtual void prepareSmushFrame(int width, int height, byte *bitmap) = 0; virtual void drawSmushFrame(int offsetX, int offsetY) = 0; + +protected: + int _screenWidth, _screenHeight, _screenBPP; + bool _isFullscreen; }; extern Driver *g_driver; diff --git a/driver_gl.cpp b/driver_gl.cpp index 1ecb7588c41..b24831d5d98 100644 --- a/driver_gl.cpp +++ b/driver_gl.cpp @@ -20,7 +20,8 @@ #include "material.h" #include "driver_gl.h" -DriverGL::DriverGL(int screenW, int screenH, int screenBPP) { +// Constructor. Should create the driver and open screens, etc. +DriverGL::DriverGL(int screenW, int screenH, int screenBPP, bool fullscreen) { char GLDriver[1024]; SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5); @@ -29,8 +30,15 @@ DriverGL::DriverGL(int screenW, int screenH, int screenBPP) { SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16); SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); - if (SDL_SetVideoMode(screenW, screenH, screenBPP, SDL_OPENGL) == 0) + Uint32 flags = SDL_OPENGL; + if (fullscreen) + flags |= SDL_FULLSCREEN; + if (SDL_SetVideoMode(screenW, screenH, screenBPP, flags) == 0) error("Could not initialize video"); + _screenWidth = screenW; + _screenHeight = screenH; + _screenBPP = screenBPP; + _isFullscreen = fullscreen; sprintf(GLDriver, "Residual: %s/%s", glGetString(GL_VENDOR), glGetString(GL_RENDERER)); SDL_WM_SetCaption(GLDriver, "Residual"); @@ -41,6 +49,17 @@ DriverGL::DriverGL(int screenW, int screenH, int screenBPP) { _smushNumTex = 0; } +void DriverGL::toggleFullscreenMode() { + Uint32 flags = SDL_OPENGL; + + if (! _isFullscreen) + flags |= SDL_FULLSCREEN; + if (SDL_SetVideoMode(_screenWidth, _screenHeight, _screenBPP, flags) == 0) + warning("Could not change fullscreen mode"); + else + _isFullscreen = ! _isFullscreen; +} + void DriverGL::setupCamera(float fov, float nclip, float fclip, float roll) { glMatrixMode(GL_PROJECTION); glLoadIdentity(); @@ -289,7 +308,7 @@ void DriverGL::drawBitmap(const Bitmap *bitmap) { GLuint *textures; glMatrixMode(GL_PROJECTION); glLoadIdentity(); - glOrtho(0, 640, 480, 0, 0, 1); + glOrtho(0, _screenWidth, _screenHeight, 0, 0, 1); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glMatrixMode(GL_TEXTURE); @@ -307,7 +326,7 @@ void DriverGL::drawBitmap(const Bitmap *bitmap) { glDisable(GL_DEPTH_TEST); glDepthMask(GL_FALSE); glEnable(GL_SCISSOR_TEST); - glScissor(bitmap->_x, 480 - (bitmap->_y + bitmap->_height), bitmap->_width, bitmap->_height); + glScissor(bitmap->_x, _screenHeight - (bitmap->_y + bitmap->_height), bitmap->_width, bitmap->_height); int cur_tex_idx = bitmap->_numTex * (bitmap->_currImage - 1); for (int y = bitmap->_y; y < (bitmap->_y + bitmap->_height); y += BITMAP_TEXTURE_SIZE) { for (int x = bitmap->_x; x < (bitmap->_x + bitmap->_width); x += BITMAP_TEXTURE_SIZE) { @@ -403,7 +422,7 @@ void DriverGL::drawDepthBitmap(int x, int y, int w, int h, char *data) { // } if (y + h == 480) { - glRasterPos2i(x, 479); + glRasterPos2i(x, _screenHeight - 1); glBitmap(0, 0, 0, 0, 0, -1, NULL); } else glRasterPos2i(x, y + h); @@ -465,7 +484,7 @@ void DriverGL::drawSmushFrame(int offsetX, int offsetY) { // prepare view glMatrixMode(GL_PROJECTION); glLoadIdentity(); - glOrtho(0, 640, 480, 0, 0, 1); + glOrtho(0, _screenWidth, _screenHeight, 0, 0, 1); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glMatrixMode(GL_TEXTURE); @@ -481,7 +500,7 @@ void DriverGL::drawSmushFrame(int offsetX, int offsetY) { glDepthMask(GL_FALSE); glEnable(GL_SCISSOR_TEST); - glScissor(offsetX, 480 - (offsetY + _smushHeight), _smushWidth, _smushHeight); + glScissor(offsetX, _screenHeight - (offsetY + _smushHeight), _smushWidth, _smushHeight); int curTexIdx = 0; for (int y = 0; y < _smushHeight; y += BITMAP_TEXTURE_SIZE) { @@ -523,7 +542,7 @@ void DriverGL::drawEmergString(int x, int y, const char *text, const Color &fgCo glMatrixMode(GL_PROJECTION); glPushMatrix(); glLoadIdentity(); - glOrtho(0, 640, 480, 0, 0, 1); + glOrtho(0, _screenWidth, _screenHeight, 0, 0, 1); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); diff --git a/driver_gl.h b/driver_gl.h index 79e9213cc97..1695232053c 100644 --- a/driver_gl.h +++ b/driver_gl.h @@ -31,11 +31,13 @@ class DriverGL : public Driver { public: - DriverGL(int screenW, int screenH, int screenBPP); + DriverGL(int screenW, int screenH, int screenBPP, bool fullscreen = false); void setupCamera(float fov, float nclip, float fclip, float roll); void positionCamera(Vector3d pos, Vector3d interest); + void toggleFullscreenMode(); + void clearScreen(); void flipBuffer(); diff --git a/driver_tinygl.cpp b/driver_tinygl.cpp index b5f88dd5456..b4b5b3230ec 100644 --- a/driver_tinygl.cpp +++ b/driver_tinygl.cpp @@ -93,10 +93,17 @@ static void lookAt(TGLfloat eyex, TGLfloat eyey, TGLfloat eyez, TGLfloat centerx tglTranslatef(-eyex, -eyey, -eyez); } -DriverTinyGL::DriverTinyGL(int screenW, int screenH, int screenBPP) { - _screen = SDL_SetVideoMode(screenW, screenH, screenBPP, SDL_HWSURFACE); +DriverTinyGL::DriverTinyGL(int screenW, int screenH, int screenBPP, bool fullscreen) { + Uint32 flags = SDL_HWSURFACE; + if (fullscreen) + flags |= SDL_FULLSCREEN; + _screen = SDL_SetVideoMode(screenW, screenH, screenBPP, flags); if (_screen == NULL) error("Could not initialize video"); + _screenWidth = screenW; + _screenHeight = screenH; + _screenBPP = screenBPP; + _isFullscreen = fullscreen; SDL_WM_SetCaption("Residual: Modified TinyGL - Software Renderer", "Residual"); @@ -116,6 +123,17 @@ DriverTinyGL::~DriverTinyGL() { ZB_close(_zb); } +void DriverTinyGL::toggleFullscreenMode() { + Uint32 flags = SDL_HWSURFACE; + + if (! _isFullscreen) + flags |= SDL_FULLSCREEN; + if (SDL_SetVideoMode(_screenWidth, _screenHeight, _screenBPP, flags) == 0) + warning("Could not change fullscreen mode"); + else + _isFullscreen = ! _isFullscreen; +} + void DriverTinyGL::setupCamera(float fov, float nclip, float fclip, float roll) { tglMatrixMode(TGL_PROJECTION); tglLoadIdentity(); diff --git a/driver_tinygl.h b/driver_tinygl.h index 87db507122e..21047da9f51 100644 --- a/driver_tinygl.h +++ b/driver_tinygl.h @@ -33,12 +33,13 @@ class DriverTinyGL : public Driver { public: - DriverTinyGL(int screenW, int screenH, int screenBPP); + DriverTinyGL(int screenW, int screenH, int screenBPP, bool fullscreen = false); virtual ~DriverTinyGL(); void setupCamera(float fov, float nclip, float fclip, float roll); void positionCamera(Vector3d pos, Vector3d interest); + void toggleFullscreenMode(); void clearScreen(); void flipBuffer(); diff --git a/engine.cpp b/engine.cpp index 16fed90cb31..a2acfbcdf7f 100644 --- a/engine.cpp +++ b/engine.cpp @@ -131,6 +131,10 @@ void Engine::mainLoop() { lua_endblock(); } if (event.type == SDL_KEYDOWN) { + if ((event.key.keysym.sym == SDLK_RETURN || + event.key.keysym.sym == SDLK_KP_ENTER) && + (event.key.keysym.mod & KMOD_ALT)) + g_driver->toggleFullscreenMode(); if (event.key.keysym.sym == SDLK_q) return; } diff --git a/main.cpp b/main.cpp index b56954de5fa..9b7f107fe24 100644 --- a/main.cpp +++ b/main.cpp @@ -89,6 +89,7 @@ int main(int argc, char *argv[]) { ZBUFFER_GLOBAL = parseBoolStr(g_registry->get("zbuffer")); SHOWFPS_GLOBAL = parseBoolStr(g_registry->get("fps")); TINYGL_GLOBAL = parseBoolStr(g_registry->get("soft")); + bool fullscreen = parseBoolStr(g_registry->get("fullscreen")); for (i = 1; i < argc; i++) { if (strcmp(argv[i], "-zbuffer") == 0) ZBUFFER_GLOBAL = true; @@ -98,6 +99,10 @@ int main(int argc, char *argv[]) { SHOWFPS_GLOBAL = true; else if (strcmp(argv[i], "-nofps") == 0) SHOWFPS_GLOBAL = false; + else if (strcmp(argv[i], "-fullscreen") == 0) + fullscreen = true; + else if (strcmp(argv[i], "-nofullscreen") == 0) + fullscreen = false; else if (strcmp(argv[i], "-soft") == 0) TINYGL_GLOBAL = true; else if (strcmp(argv[i], "-nosoft") == 0) @@ -108,6 +113,7 @@ int main(int argc, char *argv[]) { printf("Recognised options:\n"); printf("\t-[no]zbuffer\t\tEnable/disable ZBuffers (Very slow on older cards)\n"); printf("\t-[no]fps\t\tEnable/disable fps display in upper right corner\n"); + printf("\t-[no]fullscreen\tEnable/disable fullscreen mode at startup\n"); printf("\t-[no]soft\t\tEnable/disable software renderer\n"); exit(-1); } @@ -126,9 +132,9 @@ int main(int argc, char *argv[]) { g_timer = new Timer(); g_smush = new Smush(); if (TINYGL_GLOBAL) - g_driver = new DriverTinyGL(640, 480, 16); + g_driver = new DriverTinyGL(640, 480, 16, fullscreen); else - g_driver = new DriverGL(640, 480, 24); + g_driver = new DriverGL(640, 480, 24, fullscreen); g_imuse = new Imuse(20); Bitmap *splash_bm = g_resourceloader->loadBitmap("splash.bm");