Display.cpp

Go to the documentation of this file.
00001 ////////////////////////////////////////////////////////////////////////////////
00002 //    Scorched3D (c) 2000-2009
00003 //
00004 //    This file is part of Scorched3D.
00005 //
00006 //    Scorched3D is free software; you can redistribute it and/or modify
00007 //    it under the terms of the GNU General Public License as published by
00008 //    the Free Software Foundation; either version 2 of the License, or
00009 //    (at your option) any later version.
00010 //
00011 //    Scorched3D is distributed in the hope that it will be useful,
00012 //    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 //    GNU General Public License for more details.
00015 //
00016 //    You should have received a copy of the GNU General Public License
00017 //    along with Scorched3D; if not, write to the Free Software
00018 //    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019 ////////////////////////////////////////////////////////////////////////////////
00020 
00021 #include <stdio.h>
00022 #include <graph/Display.h>
00023 #include <graph/OptionsDisplay.h>
00024 #include <common/Defines.h>
00025 
00026 Display *Display::instance_ = 0;
00027 
00028 Display *Display::instance()
00029 {
00030         if (!instance_)
00031         {
00032                 instance_ = new Display;
00033         }
00034 
00035         return instance_;
00036 }
00037 
00038 Display::Display()
00039 {
00040 
00041 }
00042 
00043 Display::~Display()
00044 {
00045 }
00046 
00047 
00048 bool Display::changeSettings(int width, int height, bool full)
00049 {
00050         // set opengl double buffering 
00051         int doubleBuffer = OptionsDisplay::instance()->getDoubleBuffer()?1:0;
00052         SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, doubleBuffer);
00053 
00054         // set opengl component size 
00055         int componentSize = OptionsDisplay::instance()->getColorComponentSize();
00056         SDL_GL_SetAttribute( SDL_GL_ALPHA_SIZE, componentSize);
00057         SDL_GL_SetAttribute( SDL_GL_RED_SIZE, componentSize);
00058         SDL_GL_SetAttribute( SDL_GL_GREEN_SIZE, componentSize);
00059         SDL_GL_SetAttribute( SDL_GL_BLUE_SIZE, componentSize);
00060 
00061         if (OptionsDisplay::instance()->getAntiAlias() > 0)
00062         {
00063                 // Anti-aliased
00064                 SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 1);
00065                 SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, 
00066                         OptionsDisplay::instance()->getAntiAlias());
00067         }
00068         
00069         // At least 24 bits depth buffer
00070         int depthBufferBits = OptionsDisplay::instance()->getDepthBufferBits();
00071         SDL_GL_SetAttribute( SDL_GL_DEPTH_SIZE, depthBufferBits );
00072 
00073         // create display surface 
00074         int videoFlags = SDL_OPENGL | SDL_ANYFORMAT; // | SDL_RESIZABLE;  
00075         int flags = ( full ? videoFlags|SDL_FULLSCREEN : videoFlags);
00076         int bpp = OptionsDisplay::instance()->getBitsPerPixel();
00077 
00078         // Try to create suface
00079         surface = SDL_SetVideoMode( width, height, bpp, flags);
00080 
00081         // If this fails
00082         // Hack, to check if 16bit depth will work instead if 24 bits specified
00083         if (!surface &&
00084                 depthBufferBits == 24)
00085         {
00086                 SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16);
00087                 surface = SDL_SetVideoMode( width, height, bpp, flags);
00088         }
00089 
00090         // And if this fails
00091         if (!surface)
00092         {
00093                 char buffer[256];
00094                 SDL_VideoDriverName(buffer, 256);
00095                 S3D::dialogMessage("Display", S3D::formatStringBuffer(
00096                         "ERROR: Failed to set video mode.\n"
00097                         "Error Message: %s\n"
00098                         "----------------------------\n"
00099                         "Requested Display Mode:-\n"
00100                         "Driver=%s\n"
00101                         "Resolution=%ix%ix%i %s\n" 
00102                         "DepthBuffer=%i\n"
00103                         "DoubleBuffer=%s\n"
00104                         "ColorComponentSize=%i\n",
00105                         SDL_GetError(),
00106                         buffer, 
00107                         width, height, 
00108                         OptionsDisplay::instance()->getBitsPerPixel(),
00109                         (full?"(fullscreen)":"(windowed)"), 
00110                         OptionsDisplay::instance()->getDepthBufferBits(),
00111                         OptionsDisplay::instance()->getDoubleBuffer()?"On":"Off",
00112                         OptionsDisplay::instance()->getColorComponentSize()));
00113                 return false;
00114         }
00115         return true;
00116 }
00117 

Generated on Mon Feb 16 15:14:46 2009 for Scorched3D by  doxygen 1.5.3