38 #if !defined(HAVE_DECL_SDL_WINDOW_ALLOW_HIGHDPI) || HAVE_DECL_SDL_WINDOW_ALLOW_HIGHDPI == 0 39 #define SDL_WINDOW_ALLOW_HIGHDPI 0 42 #ifndef HAVE_SDL_GETDISPLAYUSABLEBOUNDS 43 #define SDL_GetDisplayUsableBounds SDL_GetDisplayBounds 47 u_int8 screen::bytes_per_pixel_ = 0;
49 SDL_Window *screen::Window = NULL;
50 SDL_Renderer *screen::Renderer = NULL;
54 SDL_Rect screen::clip_rect_ = {};
56 void screen::cleanup()
58 if (Renderer) SDL_DestroyRenderer(Renderer);
59 if (Window) SDL_DestroyWindow(Window);
70 #if defined(SDL_VIDEO_DRIVER_X11) || defined(SDL_VIDEO_DRIVER_WAYLAND) 71 std::string wm_class =
"SDL_VIDEO_X11_WMCLASS=" + myconfig.
game_name;
72 putenv ((
char *) wm_class.c_str ());
75 if (SDL_Init (SDL_INIT_VIDEO | SDL_INIT_AUDIO) < 0)
77 std::cout <<
"Couldn't init SDL: " << SDL_GetError () << std::endl;
81 SDL_SetHint (SDL_HINT_RENDER_SCALE_QUALITY,
"nearest");
83 int availableDisplays = SDL_GetNumVideoDisplays();
84 if (availableDisplays < 1)
86 std::cout <<
"Couldn't init screen: " << SDL_GetError () << std::endl;
90 if (screen >= availableDisplays)
103 scale_ = get_scale_for_display(screen, nl, nh);
106 unsigned int flags = SDL_WINDOW_ALLOW_HIGHDPI;
111 flags |= SDL_WINDOW_FULLSCREEN_DESKTOP;
116 flags |= SDL_WINDOW_FULLSCREEN;
121 SDL_DisplayMode fullscreen_mode;
122 memset(&fullscreen_mode, 0,
sizeof(SDL_DisplayMode));
123 fullscreen_mode.format = SDL_PIXELFORMAT_RGB888;
128 SDL_ShowCursor(SDL_DISABLE);
130 Window = SDL_CreateWindow (
"Adonthell", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, nl, nh, flags);
133 std::cout <<
"Failed creating window: " << SDL_GetError() << std::endl;
138 if (!icon_name.empty())
140 SDL_Surface* icon = SDL_LoadBMP(icon_name.c_str());
143 SDL_SetWindowIcon(Window, icon);
144 SDL_FreeSurface(icon);
148 if (SDL_SetWindowDisplayMode(Window, &fullscreen_mode) < 0)
150 std::cout <<
"Failed setting display mode: " << SDL_GetError() << std::endl;
153 SDL_ShowWindow(Window);
155 Renderer = SDL_CreateRenderer(Window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
158 std::cout <<
"Failed creating accelerated renderer: " << SDL_GetError() << std::endl;
159 Renderer = SDL_CreateRenderer(Window, -1, SDL_RENDERER_SOFTWARE);
162 std::cout <<
"Failed creating renderer: " << SDL_GetError() << std::endl;
167 display.set_length(nl/scale_);
168 display.set_height(nh/scale_);
174 trans = display.map_color(255, 0, 255, SDL_ALPHA_OPAQUE);
181 SDL_version version_info;
182 SDL_RendererInfo render_info;
183 std::ostringstream temp;
185 SDL_GetVersion(&version_info);
189 SDL_GetRendererInfo(Renderer, &render_info);
193 render_info.name =
"not yet initialized";
194 render_info.flags = 0;
197 temp <<
"Video information: " << std::endl
198 <<
"Platform: " << SDL_GetPlatform() << std::endl
199 <<
"Version: " <<
"SDL " <<(int) version_info.major <<
"." << (
int) version_info.minor <<
"." << (int) version_info.patch <<
" " << SDL_GetRevision() << std::endl
200 <<
"Video driver used: " << SDL_GetCurrentVideoDriver() << std::endl
201 <<
"Renderer used: " << render_info.name << std::endl
202 <<
"HW Accelerated: " << ((render_info.flags & SDL_RENDERER_ACCELERATED) == SDL_RENDERER_ACCELERATED ?
"Yes" :
"No") << std::endl
203 <<
"Display Format: " << SDL_GetPixelFormatName (format()) << std::endl
204 <<
"Screen Size " << (int)length()*scale() <<
"x" << (int)height()*scale() << std::endl
205 <<
"Fullscreen: " << (mode() ?
"Yes" :
"No") << std::endl
217 std::cout <<
"Switching from " << (int)mode_ <<
" to " << (
int)m << std::endl;
221 r = SDL_SetWindowFullscreen(Window, SDL_FALSE) == 0;
232 u_int8 new_scale = get_scale_for_display(screen, length(), height());
233 if (new_scale != scale())
236 std::cout <<
"Scale changed from " << (int)scale_ <<
" to " << (
int)new_scale << std::endl;
238 SDL_SetWindowSize(Window, length()*new_scale, height()*new_scale);
245 SDL_SetWindowPosition(Window, SDL_WINDOWPOS_CENTERED_DISPLAY(screen), SDL_WINDOWPOS_CENTERED_DISPLAY(screen));
250 r = SDL_SetWindowFullscreen(Window, SDL_WINDOW_FULLSCREEN_DESKTOP) == 0;
256 SDL_GetDisplayBounds(screen, &bounds);
257 SDL_SetWindowPosition(Window, bounds.x, bounds.y);
258 r = SDL_SetWindowFullscreen(Window, SDL_WINDOW_FULLSCREEN) == 0;
282 SDL_GetDisplayUsableBounds(screen, &bounds);
288 SDL_GetDisplayBounds(screen, &bounds);
302 int scale_x = (bounds.w - bounds.x) / nl;
303 int scale_y = (bounds.h - bounds.y) / nh;
305 return scale_x > scale_y ? scale_y : scale_x;
308 void screen::update_scale()
312 SDL_GetRendererOutputSize(Renderer, &w, &h);
314 int scale_x = w / length();
315 int scale_y = h / height();
317 scale_ = scale_x > scale_y ? scale_y : scale_x;
322 clip_rect_.x = (w - length() * scale_) / 2;
323 clip_rect_.y = (h - height() * scale_) / 2;
324 clip_rect_.w = length() * scale_;
325 clip_rect_.h = height() * scale_;
327 SDL_RenderSetClipRect(Renderer, &clip_rect_);
334 clip_rect_.w = length() * scale_;
335 clip_rect_.h = height() * scale_;
337 SDL_RenderSetClipRect(Renderer, NULL);
341 std::cout <<
"Mode = " << (int) mode_ <<
", X = " << offset_x_ <<
", Y = " << offset_y_
342 <<
", Width = " << w <<
", Height = " << h <<
", Scale = " 343 << (
int) (scale_) << std::endl;
#define u_int16
16 bits long unsigned integer
Class where drawables can actually be drawn to.
Declares the screen class.
static u_int16 length()
Returns the length of the screen.
static string info()
Returns information about the current screen settings, suitable for being displayed to the user...
#define u_int32
32 bits long unsigned integer
#define u_int8
8 bits long unsigned integer
static bool init(u_int16 nl, u_int16 nh, u_int8 depth, const config &myconfig)
Initializes the video subsystem and creates the required resources.
static string find_file(const string &fname)
Finds a file in the directories hierarchy, starting searching from game_data_dir(), then global_data_dir() and finally user_data_dir().
static bool set_fullscreen(const u_int8 &m)
Sets fullscreen/windowed mode.
Screen access is made through this class.
u_int8 display
Index of the display to use for fullscreen mode.
string game_name
Name of the game that is running at present.
static void transition(u_int16 i)
Make a nice transition effect.
static surface display
The actual screen surface.
This class contains the engine's configuration read either from the config file or from the command l...
static u_int16 height()
Returns the height of the screen.
u_int8 screen_mode
Whether the engine shall run in window (0) or fullscreen (1) mode.