home *** CD-ROM | disk | FTP | other *** search
-
- #include "Display.h"
-
- #include "log.h"
-
- unsigned int Display::videoFlags = 0;
- SDL_Surface* Display::mainWindow = NULL;
-
- bool Display::initialized = false;
-
- bool Display::init(){
- if(initialized){
- error("(in Display::init()): Display is already initialized.\n\n");
- return false;
- }
-
- log("\n");
- log("****************************\n");
- log("*** Initializing Display ***\n");
- log("****************************\n");
- log("\n");
-
- // update cvars
- info.cvar.display_width->updateVar();
- info.cvar.display_height->updateVar();
- info.cvar.display_bpp->updateVar();
- info.cvar.display_depthBufferSize->updateVar();
- info.cvar.display_gamma->updateVar();
- info.cvar.display_fullscreen->updateVar();
-
-
- if(SDL_WasInit(SDL_INIT_VIDEO)==0){ // not initialized
- error("(in Display::init()): SDL video system not initialized.\n\n");
- return false;
- }
-
- const SDL_VideoInfo* VideoInfo = SDL_GetVideoInfo();
-
- if(VideoInfo == NULL){
- error("(in Display::init()): Failed getting Video Info: %s.\n\n",SDL_GetError());
- return false;
- }
-
- Display::videoFlags = 0;
- Display::videoFlags |= SDL_OPENGL;
- if(info.var.fullscreen)
- Display::videoFlags |= SDL_FULLSCREEN;
-
-
- SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 );
- SDL_GL_SetAttribute( SDL_GL_BUFFER_SIZE, info.var.bpp);
- // SDL_GL_SetAttribute( SDL_GL_RED_SIZE, 8);
- // SDL_GL_SetAttribute( SDL_GL_GREEN_SIZE, 8);
- // SDL_GL_SetAttribute( SDL_GL_BLUE_SIZE, 8);
- // SDL_GL_SetAttribute( SDL_GL_ALPHA_SIZE, 8);
- SDL_GL_SetAttribute( SDL_GL_DEPTH_SIZE, info.var.depthBufferSize);
- SDL_GL_SetAttribute( SDL_GL_STENCIL_SIZE, 0);
- SDL_GL_SetAttribute( SDL_GL_ACCUM_RED_SIZE, 0);
- SDL_GL_SetAttribute( SDL_GL_ACCUM_GREEN_SIZE, 0);
- SDL_GL_SetAttribute( SDL_GL_ACCUM_BLUE_SIZE, 0);
- SDL_GL_SetAttribute( SDL_GL_ACCUM_ALPHA_SIZE, 0);
-
- log("Probing for video modes...\n");
- Display::listAvailableModes(Display::videoFlags);
- log("\n");
-
- log("Setting video mode...\n");
- Display::mainWindow = SDL_SetVideoMode(info.var.width, info.var.height, info.var.bpp, Display::videoFlags);
-
- if( Display::mainWindow == NULL ){
- error("(in Display::init()): Failed to set video mode: %s.\n\n", SDL_GetError());
- return false;
- }
-
- SDL_WM_SetCaption("FWP", "FWP");
- log("VideoMode: width: %i, height: %i, bpp: %i.\n"
- , Display::mainWindow->w, Display::mainWindow->h, Display::mainWindow->format->BitsPerPixel);
- log("Flags: 0x%X.\n", mainWindow->flags);
-
- info.var.width = Display::mainWindow->w;
- info.var.height = Display::mainWindow->h;
- info.var.bpp = Display::mainWindow->format->BitsPerPixel;
- info.var.scaleX = info.var.width/(float)DISPLAY_VSCREEN_WIDTH;
- info.var.scaleY = info.var.height/(float)DISPLAY_VSCREEN_HEIGHT;
-
-
- Display::setGamma(info.var.gamma);
-
- initialized=true;
-
- return true;
- }
-
- bool Display::shutdown(){
- if(!initialized){
- error("(in Display::shutdown()): Display is not initialized.\n\n");
- return false;
- }
-
- log("\n");
- log("=============================\n");
- log("=== Shutting down Display ===\n");
- log("=============================\n");
- log("\n");
-
- Display::setGamma(1.0f);
-
- initialized=false;
-
- return true;
- }
-
- bool Display::wasInit(){
- return initialized;
- }
-
- bool Display::registerCVarsAndCCmds(){
- return info.registerCVarsAndCCmds();
- }
-
- bool Display::unregisterCVarsAndCCmds(){
- return info.unregisterCVarsAndCCmds();
- }
-
-
-
-
-
-
-
-
- // FIXME: funzt nett!
- void Display::takeScreenshot(){
- static int numScreenshots=0;
-
- char filename[128];
- sprintf(filename , "screenshot%i.bmp", numScreenshots);
- numScreenshots++;
-
- if(SDL_SaveBMP(mainWindow, filename) == -1){
- error("(in display::takeScreenshot()): Failed to save screenshot: %s.\n\n", SDL_GetError());
- }else{
- log("Wrote screenshot '%s'.\n", filename);
- }
- }
-
-
- void Display::setGamma(float gamma){
- if(SDL_SetGamma(gamma, gamma, gamma)==-1){
- error("(in display::setGamma()): Failed to set gamma values: %s.\n\n", SDL_GetError());
- }
- }
-
- void Display::listAvailableModes(unsigned int flags){
- SDL_Rect **modes;
- int i;
-
- modes=SDL_ListModes(NULL, flags);
-
- if(modes == (SDL_Rect **)0){
- log("No modes available!\n");
- return;
- }
-
- if(modes == (SDL_Rect **)-1){
- log("All resolutions available.\n");
- }else{
- log("Available modes:\n");
- for(i=0;modes[i];++i){
- log(" %d x %d\n", modes[i]->w, modes[i]->h);
- }
- }
- }
-