21 #include <SDL2/SDL_render.h>
31 const uint32_t window_flags,
32 const uint32_t render_flags)
33 : window_(SDL_CreateWindow(
34 title.c_str(), x, y,
w,
h, window_flags | SDL_WINDOW_HIDDEN))
35 , pixel_format_(SDL_PIXELFORMAT_UNKNOWN)
38 throw exception(
"Failed to create a SDL_Window object.",
true);
50 SDL_SetHint(SDL_HINT_RENDER_DRIVER,
"direct3d11");
53 if(!SDL_CreateRenderer(
window_, -1, render_flags)) {
54 throw exception(
"Failed to create a SDL_Renderer object.",
true);
57 SDL_RendererInfo
info;
58 if(SDL_GetRendererInfo(*
this, &
info) != 0) {
59 throw exception(
"Failed to retrieve the information of the renderer.",
63 if(
info.num_texture_formats == 0) {
64 throw exception(
"The renderer has no texture information available.\n",
68 if((
info.flags & SDL_RENDERER_TARGETTEXTURE) == 0) {
69 throw exception(
"Render-to-texture not supported or enabled!",
false);
73 SDL_SetRenderDrawBlendMode(*
this, SDL_BLENDMODE_BLEND);
77 SDL_SetHint(SDL_HINT_VIDEO_MINIMIZE_ON_FOCUS_LOSS,
"0");
86 if(!(window_flags & SDL_WINDOW_HIDDEN)) {
106 SDL_GetWindowSize(*
this, &res.x, &res.y);
114 SDL_GetRendererOutputSize(*
this, &res.x, &res.y);
121 SDL_SetWindowPosition(
window_, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED);
131 SDL_SetWindowFullscreen(
window_, 0);
141 SDL_SetWindowFullscreen(
window_, SDL_WINDOW_FULLSCREEN_DESKTOP);
146 SDL_SetRenderDrawColor(*
this, r,
g,
b, a);
147 if(SDL_RenderClear(*
this) != 0) {
148 throw exception(
"Failed to clear the SDL_Renderer object.",
155 SDL_RenderPresent(*
this);
160 SDL_SetWindowTitle(
window_, title.c_str());
165 SDL_SetWindowIcon(
window_, icon);
170 return SDL_GetWindowFlags(
window_);
175 SDL_SetWindowMinimumSize(
window_, min_w, min_h);
180 return SDL_GetWindowDisplayIndex(
window_);
185 SDL_Renderer* r = SDL_GetRenderer(
window_);
186 SDL_RenderSetLogicalSize(r,
w,
h);
196 SDL_Renderer* r = SDL_GetRenderer(
window_);
198 SDL_RenderGetLogicalSize(r, &
w, &
h);
204 SDL_Renderer* r = SDL_GetRenderer(
window_);
205 SDL_RenderGetLogicalSize(r, &
w, &
h);
213 window::operator SDL_Window*()
218 window::operator SDL_Renderer*()
220 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.