00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
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
00051 int doubleBuffer = OptionsDisplay::instance()->getDoubleBuffer()?1:0;
00052 SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, doubleBuffer);
00053
00054
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
00064 SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 1);
00065 SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES,
00066 OptionsDisplay::instance()->getAntiAlias());
00067 }
00068
00069
00070 int depthBufferBits = OptionsDisplay::instance()->getDepthBufferBits();
00071 SDL_GL_SetAttribute( SDL_GL_DEPTH_SIZE, depthBufferBits );
00072
00073
00074 int videoFlags = SDL_OPENGL | SDL_ANYFORMAT;
00075 int flags = ( full ? videoFlags|SDL_FULLSCREEN : videoFlags);
00076 int bpp = OptionsDisplay::instance()->getBitsPerPixel();
00077
00078
00079 surface = SDL_SetVideoMode( width, height, bpp, flags);
00080
00081
00082
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
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