Implement a fullscreen mode.
This commit is contained in:
parent
6413a7d9e5
commit
9abc55fcfd
7 changed files with 76 additions and 15 deletions
13
driver.h
13
driver.h
|
@ -32,7 +32,12 @@ class Bitmap;
|
||||||
class Driver {
|
class Driver {
|
||||||
public:
|
public:
|
||||||
Driver() { ; }
|
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 {
|
struct TextObjectHandle {
|
||||||
uint16 *bitmapData;
|
uint16 *bitmapData;
|
||||||
|
@ -43,6 +48,8 @@ public:
|
||||||
int height;
|
int height;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
virtual void toggleFullscreenMode() = 0;
|
||||||
|
|
||||||
virtual void setupCamera(float fov, float nclip, float fclip, float roll) = 0;
|
virtual void setupCamera(float fov, float nclip, float fclip, float roll) = 0;
|
||||||
virtual void positionCamera(Vector3d pos, Vector3d interest) = 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 prepareSmushFrame(int width, int height, byte *bitmap) = 0;
|
||||||
virtual void drawSmushFrame(int offsetX, int offsetY) = 0;
|
virtual void drawSmushFrame(int offsetX, int offsetY) = 0;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
int _screenWidth, _screenHeight, _screenBPP;
|
||||||
|
bool _isFullscreen;
|
||||||
};
|
};
|
||||||
|
|
||||||
extern Driver *g_driver;
|
extern Driver *g_driver;
|
||||||
|
|
|
@ -20,7 +20,8 @@
|
||||||
#include "material.h"
|
#include "material.h"
|
||||||
#include "driver_gl.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];
|
char GLDriver[1024];
|
||||||
|
|
||||||
SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5);
|
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_DEPTH_SIZE, 16);
|
||||||
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
|
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");
|
error("Could not initialize video");
|
||||||
|
_screenWidth = screenW;
|
||||||
|
_screenHeight = screenH;
|
||||||
|
_screenBPP = screenBPP;
|
||||||
|
_isFullscreen = fullscreen;
|
||||||
|
|
||||||
sprintf(GLDriver, "Residual: %s/%s", glGetString(GL_VENDOR), glGetString(GL_RENDERER));
|
sprintf(GLDriver, "Residual: %s/%s", glGetString(GL_VENDOR), glGetString(GL_RENDERER));
|
||||||
SDL_WM_SetCaption(GLDriver, "Residual");
|
SDL_WM_SetCaption(GLDriver, "Residual");
|
||||||
|
@ -41,6 +49,17 @@ DriverGL::DriverGL(int screenW, int screenH, int screenBPP) {
|
||||||
_smushNumTex = 0;
|
_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) {
|
void DriverGL::setupCamera(float fov, float nclip, float fclip, float roll) {
|
||||||
glMatrixMode(GL_PROJECTION);
|
glMatrixMode(GL_PROJECTION);
|
||||||
glLoadIdentity();
|
glLoadIdentity();
|
||||||
|
@ -289,7 +308,7 @@ void DriverGL::drawBitmap(const Bitmap *bitmap) {
|
||||||
GLuint *textures;
|
GLuint *textures;
|
||||||
glMatrixMode(GL_PROJECTION);
|
glMatrixMode(GL_PROJECTION);
|
||||||
glLoadIdentity();
|
glLoadIdentity();
|
||||||
glOrtho(0, 640, 480, 0, 0, 1);
|
glOrtho(0, _screenWidth, _screenHeight, 0, 0, 1);
|
||||||
glMatrixMode(GL_MODELVIEW);
|
glMatrixMode(GL_MODELVIEW);
|
||||||
glLoadIdentity();
|
glLoadIdentity();
|
||||||
glMatrixMode(GL_TEXTURE);
|
glMatrixMode(GL_TEXTURE);
|
||||||
|
@ -307,7 +326,7 @@ void DriverGL::drawBitmap(const Bitmap *bitmap) {
|
||||||
glDisable(GL_DEPTH_TEST);
|
glDisable(GL_DEPTH_TEST);
|
||||||
glDepthMask(GL_FALSE);
|
glDepthMask(GL_FALSE);
|
||||||
glEnable(GL_SCISSOR_TEST);
|
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);
|
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 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) {
|
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) {
|
if (y + h == 480) {
|
||||||
glRasterPos2i(x, 479);
|
glRasterPos2i(x, _screenHeight - 1);
|
||||||
glBitmap(0, 0, 0, 0, 0, -1, NULL);
|
glBitmap(0, 0, 0, 0, 0, -1, NULL);
|
||||||
} else
|
} else
|
||||||
glRasterPos2i(x, y + h);
|
glRasterPos2i(x, y + h);
|
||||||
|
@ -465,7 +484,7 @@ void DriverGL::drawSmushFrame(int offsetX, int offsetY) {
|
||||||
// prepare view
|
// prepare view
|
||||||
glMatrixMode(GL_PROJECTION);
|
glMatrixMode(GL_PROJECTION);
|
||||||
glLoadIdentity();
|
glLoadIdentity();
|
||||||
glOrtho(0, 640, 480, 0, 0, 1);
|
glOrtho(0, _screenWidth, _screenHeight, 0, 0, 1);
|
||||||
glMatrixMode(GL_MODELVIEW);
|
glMatrixMode(GL_MODELVIEW);
|
||||||
glLoadIdentity();
|
glLoadIdentity();
|
||||||
glMatrixMode(GL_TEXTURE);
|
glMatrixMode(GL_TEXTURE);
|
||||||
|
@ -481,7 +500,7 @@ void DriverGL::drawSmushFrame(int offsetX, int offsetY) {
|
||||||
glDepthMask(GL_FALSE);
|
glDepthMask(GL_FALSE);
|
||||||
glEnable(GL_SCISSOR_TEST);
|
glEnable(GL_SCISSOR_TEST);
|
||||||
|
|
||||||
glScissor(offsetX, 480 - (offsetY + _smushHeight), _smushWidth, _smushHeight);
|
glScissor(offsetX, _screenHeight - (offsetY + _smushHeight), _smushWidth, _smushHeight);
|
||||||
|
|
||||||
int curTexIdx = 0;
|
int curTexIdx = 0;
|
||||||
for (int y = 0; y < _smushHeight; y += BITMAP_TEXTURE_SIZE) {
|
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);
|
glMatrixMode(GL_PROJECTION);
|
||||||
glPushMatrix();
|
glPushMatrix();
|
||||||
glLoadIdentity();
|
glLoadIdentity();
|
||||||
glOrtho(0, 640, 480, 0, 0, 1);
|
glOrtho(0, _screenWidth, _screenHeight, 0, 0, 1);
|
||||||
|
|
||||||
glMatrixMode(GL_MODELVIEW);
|
glMatrixMode(GL_MODELVIEW);
|
||||||
glLoadIdentity();
|
glLoadIdentity();
|
||||||
|
|
|
@ -31,11 +31,13 @@
|
||||||
|
|
||||||
class DriverGL : public Driver {
|
class DriverGL : public Driver {
|
||||||
public:
|
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 setupCamera(float fov, float nclip, float fclip, float roll);
|
||||||
void positionCamera(Vector3d pos, Vector3d interest);
|
void positionCamera(Vector3d pos, Vector3d interest);
|
||||||
|
|
||||||
|
void toggleFullscreenMode();
|
||||||
|
|
||||||
void clearScreen();
|
void clearScreen();
|
||||||
void flipBuffer();
|
void flipBuffer();
|
||||||
|
|
||||||
|
|
|
@ -93,10 +93,17 @@ static void lookAt(TGLfloat eyex, TGLfloat eyey, TGLfloat eyez, TGLfloat centerx
|
||||||
tglTranslatef(-eyex, -eyey, -eyez);
|
tglTranslatef(-eyex, -eyey, -eyez);
|
||||||
}
|
}
|
||||||
|
|
||||||
DriverTinyGL::DriverTinyGL(int screenW, int screenH, int screenBPP) {
|
DriverTinyGL::DriverTinyGL(int screenW, int screenH, int screenBPP, bool fullscreen) {
|
||||||
_screen = SDL_SetVideoMode(screenW, screenH, screenBPP, SDL_HWSURFACE);
|
Uint32 flags = SDL_HWSURFACE;
|
||||||
|
if (fullscreen)
|
||||||
|
flags |= SDL_FULLSCREEN;
|
||||||
|
_screen = SDL_SetVideoMode(screenW, screenH, screenBPP, flags);
|
||||||
if (_screen == NULL)
|
if (_screen == NULL)
|
||||||
error("Could not initialize video");
|
error("Could not initialize video");
|
||||||
|
_screenWidth = screenW;
|
||||||
|
_screenHeight = screenH;
|
||||||
|
_screenBPP = screenBPP;
|
||||||
|
_isFullscreen = fullscreen;
|
||||||
|
|
||||||
SDL_WM_SetCaption("Residual: Modified TinyGL - Software Renderer", "Residual");
|
SDL_WM_SetCaption("Residual: Modified TinyGL - Software Renderer", "Residual");
|
||||||
|
|
||||||
|
@ -116,6 +123,17 @@ DriverTinyGL::~DriverTinyGL() {
|
||||||
ZB_close(_zb);
|
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) {
|
void DriverTinyGL::setupCamera(float fov, float nclip, float fclip, float roll) {
|
||||||
tglMatrixMode(TGL_PROJECTION);
|
tglMatrixMode(TGL_PROJECTION);
|
||||||
tglLoadIdentity();
|
tglLoadIdentity();
|
||||||
|
|
|
@ -33,12 +33,13 @@
|
||||||
|
|
||||||
class DriverTinyGL : public Driver {
|
class DriverTinyGL : public Driver {
|
||||||
public:
|
public:
|
||||||
DriverTinyGL(int screenW, int screenH, int screenBPP);
|
DriverTinyGL(int screenW, int screenH, int screenBPP, bool fullscreen = false);
|
||||||
virtual ~DriverTinyGL();
|
virtual ~DriverTinyGL();
|
||||||
|
|
||||||
void setupCamera(float fov, float nclip, float fclip, float roll);
|
void setupCamera(float fov, float nclip, float fclip, float roll);
|
||||||
void positionCamera(Vector3d pos, Vector3d interest);
|
void positionCamera(Vector3d pos, Vector3d interest);
|
||||||
|
|
||||||
|
void toggleFullscreenMode();
|
||||||
void clearScreen();
|
void clearScreen();
|
||||||
void flipBuffer();
|
void flipBuffer();
|
||||||
|
|
||||||
|
|
|
@ -131,6 +131,10 @@ void Engine::mainLoop() {
|
||||||
lua_endblock();
|
lua_endblock();
|
||||||
}
|
}
|
||||||
if (event.type == SDL_KEYDOWN) {
|
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)
|
if (event.key.keysym.sym == SDLK_q)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
10
main.cpp
10
main.cpp
|
@ -89,6 +89,7 @@ int main(int argc, char *argv[]) {
|
||||||
ZBUFFER_GLOBAL = parseBoolStr(g_registry->get("zbuffer"));
|
ZBUFFER_GLOBAL = parseBoolStr(g_registry->get("zbuffer"));
|
||||||
SHOWFPS_GLOBAL = parseBoolStr(g_registry->get("fps"));
|
SHOWFPS_GLOBAL = parseBoolStr(g_registry->get("fps"));
|
||||||
TINYGL_GLOBAL = parseBoolStr(g_registry->get("soft"));
|
TINYGL_GLOBAL = parseBoolStr(g_registry->get("soft"));
|
||||||
|
bool fullscreen = parseBoolStr(g_registry->get("fullscreen"));
|
||||||
for (i = 1; i < argc; i++) {
|
for (i = 1; i < argc; i++) {
|
||||||
if (strcmp(argv[i], "-zbuffer") == 0)
|
if (strcmp(argv[i], "-zbuffer") == 0)
|
||||||
ZBUFFER_GLOBAL = true;
|
ZBUFFER_GLOBAL = true;
|
||||||
|
@ -98,6 +99,10 @@ int main(int argc, char *argv[]) {
|
||||||
SHOWFPS_GLOBAL = true;
|
SHOWFPS_GLOBAL = true;
|
||||||
else if (strcmp(argv[i], "-nofps") == 0)
|
else if (strcmp(argv[i], "-nofps") == 0)
|
||||||
SHOWFPS_GLOBAL = false;
|
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)
|
else if (strcmp(argv[i], "-soft") == 0)
|
||||||
TINYGL_GLOBAL = true;
|
TINYGL_GLOBAL = true;
|
||||||
else if (strcmp(argv[i], "-nosoft") == 0)
|
else if (strcmp(argv[i], "-nosoft") == 0)
|
||||||
|
@ -108,6 +113,7 @@ int main(int argc, char *argv[]) {
|
||||||
printf("Recognised options:\n");
|
printf("Recognised options:\n");
|
||||||
printf("\t-[no]zbuffer\t\tEnable/disable ZBuffers (Very slow on older cards)\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]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");
|
printf("\t-[no]soft\t\tEnable/disable software renderer\n");
|
||||||
exit(-1);
|
exit(-1);
|
||||||
}
|
}
|
||||||
|
@ -126,9 +132,9 @@ int main(int argc, char *argv[]) {
|
||||||
g_timer = new Timer();
|
g_timer = new Timer();
|
||||||
g_smush = new Smush();
|
g_smush = new Smush();
|
||||||
if (TINYGL_GLOBAL)
|
if (TINYGL_GLOBAL)
|
||||||
g_driver = new DriverTinyGL(640, 480, 16);
|
g_driver = new DriverTinyGL(640, 480, 16, fullscreen);
|
||||||
else
|
else
|
||||||
g_driver = new DriverGL(640, 480, 24);
|
g_driver = new DriverGL(640, 480, 24, fullscreen);
|
||||||
g_imuse = new Imuse(20);
|
g_imuse = new Imuse(20);
|
||||||
|
|
||||||
Bitmap *splash_bm = g_resourceloader->loadBitmap("splash.bm");
|
Bitmap *splash_bm = g_resourceloader->loadBitmap("splash.bm");
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue