21 #include <SDL2/SDL_hints.h>
22 #include <SDL2/SDL_render.h>
32 const uint32_t window_flags,
33 const uint32_t render_flags)
34 : window_(SDL_CreateWindow(
35 title.c_str(), x, y,
w,
h, window_flags | SDL_WINDOW_HIDDEN))
36 , pixel_format_(SDL_PIXELFORMAT_UNKNOWN)
39 throw exception(
"Failed to create a SDL_Window object.",
true);
51 SDL_SetHint(SDL_HINT_RENDER_DRIVER,
"direct3d11");
54 if(!SDL_CreateRenderer(
window_, -1, render_flags)) {
55 throw exception(
"Failed to create a SDL_Renderer object.",
true);
58 SDL_RendererInfo
info;
59 if(SDL_GetRendererInfo(*
this, &
info) != 0) {
60 throw exception(
"Failed to retrieve the information of the renderer.",
64 if(
info.num_texture_formats == 0) {
65 throw exception(
"The renderer has no texture information available.\n",
69 if((
info.flags & SDL_RENDERER_TARGETTEXTURE) == 0) {
70 throw exception(
"Render-to-texture not supported or enabled!",
false);
74 SDL_SetRenderDrawBlendMode(*
this, SDL_BLENDMODE_BLEND);
78 SDL_SetHint(SDL_HINT_VIDEO_MINIMIZE_ON_FOCUS_LOSS,
"0");
87 if(!(window_flags & SDL_WINDOW_HIDDEN)) {
107 SDL_GetWindowSize(*
this, &res.x, &res.y);
115 SDL_GetRendererOutputSize(*
this, &res.x, &res.y);
122 SDL_SetWindowPosition(
window_, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED);
132 SDL_SetWindowFullscreen(
window_, 0);
142 SDL_SetWindowFullscreen(
window_, SDL_WINDOW_FULLSCREEN_DESKTOP);
147 SDL_SetRenderDrawColor(*
this, r,
g,
b, a);
148 if(SDL_RenderClear(*
this) != 0) {
149 throw exception(
"Failed to clear the SDL_Renderer object.",
156 SDL_RenderPresent(*
this);
161 SDL_SetWindowTitle(
window_, title.c_str());
166 SDL_SetWindowIcon(
window_, icon);
171 return SDL_GetWindowFlags(
window_);
176 SDL_SetWindowMinimumSize(
window_, min_w, min_h);
181 return SDL_GetWindowDisplayIndex(
window_);
186 SDL_Renderer* r = SDL_GetRenderer(
window_);
187 SDL_RenderSetLogicalSize(r,
w,
h);
197 SDL_Renderer* r = SDL_GetRenderer(
window_);
199 SDL_RenderGetLogicalSize(r, &
w, &
h);
205 SDL_Renderer* r = SDL_GetRenderer(
window_);
206 SDL_RenderGetLogicalSize(r, &
w, &
h);
214 window::operator SDL_Window*()
219 window::operator SDL_Renderer*()
221 return SDL_GetRenderer(window_);
SDL_Point get_output_size()
Gets the window's renderer output size, in pixels.
void set_size(const int w, const int h)
Wrapper for SDL_SetWindowSize.
void to_window()
Dummy function for returning the window to windowed mode.
uint32_t pixel_format()
The current pixel format of the renderer.
window(const window &)=delete
void fill(uint8_t r, uint8_t g, uint8_t b, uint8_t a=0)
Clears the contents of the window with a given color.
point get_logical_size() const
void center()
Dummy function for centering the window.
void render()
Renders the contents of the window.
void restore()
Dummy function for restoring the window.
void set_minimum_size(int min_w, int min_h)
Set minimum size of the window.
SDL_Window * window_
The SDL_Window we own.
void full_screen()
Dummy function for setting the window to fullscreen mode.
SDL_Point get_size()
Gets the window's size, in screen coordinates.
void set_icon(const surface &icon)
Sets the icon of the window.
void set_logical_size(int w, int h)
Sets the desired size of the rendering surface.
void maximize()
Dummy function for maximizing the window.
uint32_t pixel_format_
The preferred pixel format for the renderer.
void set_title(const std::string &title)
Sets the title of the window.
Contains a basic exception class for SDL operations.
Contains a wrapper class for the SDL_Window class.