Initial commit, includes Lua with broken Luabind as a backup for branching purposes
[terrastrategy.git] / src / core / client / display.cpp
blobd09a783c60c5381dfebbaaa4279349fe0002be69
1 //
2 // Copyright (C) 2008 by Martin Moracek
3 //
4 // This program is free software; you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation; either version 2 of the License, or
7 // (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with this program; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 /**
20 * @file display.cpp
22 * blahblah
25 #include <SDL/SDL.h>
27 #include "assertion.h"
28 #include "exception.h"
30 #include "vfs/logfile.h"
32 #include "core/client/display.h"
34 namespace tre {
36 Display::Display() : fullscreen_(false), stereo_(false)
38 vLog << info("SDL") << "Initializing display..." << std::endl;
40 // init SDL video
41 if(SDL_InitSubSystem(SDL_INIT_VIDEO) != 0) {
42 vLog << err("SDL") << "Unable to initialize SDL.\nReason: "
43 << SDL_GetError() << std::endl;
44 throw(Exception("Error intializing display"));
47 vLog << ok("SDL") << "Success. Using driver: "
48 << GetDriverName() << std::endl;
51 void Display::Init(void)
53 SetDisplayMode(GetDisplayInfo());
56 void Display::SetDisplayMode(const DisplayInfo & nfo)
58 SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER,1);
60 // let's try to create a big depth buffer possible
61 SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);
63 // disable the default SDL cursor
64 SDL_ShowCursor(0);
66 Uint32 flags = SDL_OPENGL | SDL_HWSURFACE;
67 if(nfo.fullscreen)
68 flags |= SDL_FULLSCREEN;
69 if(nfo.stereo)
70 flags |= SDL_GL_STEREO;
72 stereo_ = nfo.stereo;
73 fullscreen_ = nfo.fullscreen;
75 vLog << info("SDL") << "New video mode: " << nfo.width << "x"
76 << nfo.height << "x" << nfo.bpp;
77 if(fullscreen_)
78 vLog << " [fullscreen]";
79 if(stereo_)
80 vLog << " [stereo]";
81 vLog << std::endl;
83 if(!SDL_SetVideoMode(nfo.width, nfo.height, nfo.bpp, flags)) {
84 vLog << err("SDL") << "Unable to set requested video mode.\nReason: "
85 << SDL_GetError() << std::endl;
86 throw(Exception("Error intializing display"));
90 const std::string Display::GetDriverName(void) const
92 char tmpstr[40];
94 DEBUG_ASSERT(SDL_VideoDriverName(tmpstr, 40));
96 return std::string(tmpstr);
99 const DisplayInfo Display::GetDisplayInfo(void) const
101 const SDL_VideoInfo * info = SDL_GetVideoInfo();
103 DisplayInfo res;
104 res.width = info->current_w;
105 res.height = info->current_h;
106 res.bpp = info->vfmt->BitsPerPixel;
107 res.fullscreen = fullscreen_;
108 res.stereo = stereo_;
109 return res;
112 const DInfoVector Display::ListModes(void) const
114 SDL_Rect ** modes = SDL_ListModes(NULL, SDL_FULLSCREEN | SDL_HWSURFACE);
116 if(!modes)
117 return DInfoVector();
119 DisplayInfo info;
120 DInfoVector res;
122 uint bits = GetDisplayInfo().bpp;
124 for(uint i = 0; modes[i]; ++i) {
125 info.width = modes[i]->w;
126 info.height = modes[i]->h;
127 info.bpp = bits;
128 info.fullscreen = true;
129 info.stereo = false;
130 res.push_back(info);
132 return res;