2 // Copyright (C) 2008 by Martin Moracek
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.
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
27 #include "assertion.h"
28 #include "exception.h"
30 #include "vfs/logfile.h"
32 #include "core/client/display.h"
36 Display::Display() : fullscreen_(false), stereo_(false)
38 vLog
<< info("SDL") << "Initializing display..." << std::endl
;
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
66 Uint32 flags
= SDL_OPENGL
| SDL_HWSURFACE
;
68 flags
|= SDL_FULLSCREEN
;
70 flags
|= SDL_GL_STEREO
;
73 fullscreen_
= nfo
.fullscreen
;
75 vLog
<< info("SDL") << "New video mode: " << nfo
.width
<< "x"
76 << nfo
.height
<< "x" << nfo
.bpp
;
78 vLog
<< " [fullscreen]";
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
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();
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_
;
112 const DInfoVector
Display::ListModes(void) const
114 SDL_Rect
** modes
= SDL_ListModes(NULL
, SDL_FULLSCREEN
| SDL_HWSURFACE
);
117 return DInfoVector();
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
;
128 info
.fullscreen
= true;