4#include <SDL3_image/SDL_image.h>
17 window = SDL_CreateWindow(
"", width * scale, height * scale, SDL_WINDOW_RESIZABLE);
22 SDL_SetHint(SDL_HINT_RENDER_VSYNC,
"1");
26 SDL_SetRenderLogicalPresentation(
renderer, width, height, SDL_LOGICAL_PRESENTATION_LETTERBOX);
32 "", width * scale, height * scale, SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE);
37 SDL_GLContext glcontext = SDL_GL_CreateContext(
window);
38 if (glcontext ==
nullptr) {
42 if (!SDL_GL_MakeCurrent(
window, glcontext)) {
52 SDL_DestroyRenderer(r);
74 SDL_SetWindowTitle(
window, title.c_str());
79 SDL_Surface* icon = IMG_Load(path.c_str());
81 if (icon ==
nullptr) {
85 SDL_SetWindowIcon(
window, icon);
86 SDL_DestroySurface(icon);
91 SDL_SetWindowFullscreen(
window, fullscreen);
97 SDL_SetWindowSize(
window, w, h);
102 SDL_SetWindowResizable(
window, resizable);
108 SDL_GetWindowSize(
window, &size.
x, &size.
y);
120 SDL_GetRenderLogicalPresentation(
renderer, &size.
x, &size.
y,
nullptr);
132 SDL_GetRenderScale(
renderer, &scale.
x, &scale.
y);
142 SDL_SetRenderTarget(
renderer, texture.get());
151 SDL_SetRenderTarget(
renderer,
nullptr);
165 SDL_SetRenderDrawColor(
renderer, color.
r, color.
g, color.
b, color.
a);
180 SDL_SetRenderDrawBlendMode(
renderer,
static_cast<SDL_BlendMode
>(mode));
185 SDL_WarpMouseInWindow(
window, x, y);
190 SDL_GL_SwapWindow(
window);
T y
The y component of the vector.
T x
The x component of the vector.
Display and window routines for the ASW library.
void set_icon(const std::string &path)
Set the icon to display on the window. If it does not exist, this will silently fail.
asw::Vec2< float > get_scale()
Get the scale of the window. This is equivalent to the logical size divided by the actual size.
void set_fullscreen(bool fullscreen)
Set the window to fullscreen or windowed.
asw::Vec2< int > get_logical_size()
Get the logical size of the window. This may differ from the actual size if scaling is enabled.
void _init_opengl(int width, int height, int scale)
Initialize the display module with OpenGL support. Called by asw::core::init().
void set_blend_mode(asw::BlendMode mode)
Set the blend mode of a texture.
void reset_render_target()
Reset the render target to the default.
asw::Vec2< int > get_size()
Get the size of the window.
void swap_window()
Swap window (gl)
void present()
Present the window.
void set_render_target(const asw::Texture &texture)
Set the render target to the window.
void clear()
Clear the window.
void _shutdown()
Shut down the display module. Called by asw::core::shutdown(). Nulls the renderer and window pointers...
void warp_mouse(float x, float y)
Warp mouse in window.
asw::Renderer * get_renderer()
Get the SDL renderer.
asw::Window * get_window()
Get the SDL window.
void _init(int width, int height, int scale)
Initialize the display module. Called by asw::core::init().
void set_title(const std::string &title)
Set the title of the window.
void set_resolution(int w, int h)
Set the resolution of the window.
void set_resizable(bool resizable)
Set resizable flag of the window.
void abort_on_error(const std::string &message)
Abort program and display error message.
std::shared_ptr< SDL_Texture > Texture
Alias for a shared pointer to an SDL_Texture.
BlendMode
Mappings from SDL_BLENDMODE to ASW BlendMode.
SDL_Window Window
Alias for a shared pointer to an SDL_Window.
SDL_Renderer Renderer
Alias for a shared pointer to an SDL_Renderer.
RGBA color struct with 8-bit channels.
Types used throughout the ASW library.
General utility functions.