ASW Lib
A.D.S. Games SDL Wrapper Library. A library targeted at Allegro4 users who want to switch to SDL3 and use modern c++.
Loading...
Searching...
No Matches
asw::display Namespace Reference

Functions

void _init (int width, int height, int scale)
 Initialize the display module. Called by asw::core::init().
 
void _init_opengl (int width, int height, int scale)
 Initialize the display module with OpenGL support. Called by asw::core::init().
 
void _shutdown ()
 Shut down the display module. Called by asw::core::shutdown(). Nulls the renderer and window pointers before destroying them, so any outstanding shared_ptr asset deleters see a null renderer and become no-ops.
 
asw::Renderer * get_renderer ()
 Get the SDL renderer.
 
asw::Window * get_window ()
 Get the SDL window.
 
void set_title (const std::string &title)
 Set the title of the window.
 
void set_icon (const std::string &path)
 Set the icon to display on the window. If it does not exist, this will silently fail.
 
void set_fullscreen (bool fullscreen)
 Set the window to fullscreen or windowed.
 
bool is_fullscreen ()
 Check if the window is fullscreen.
 
void set_resolution (int w, int h)
 Set the resolution of the window.
 
void set_resizable (bool resizable)
 Set resizable flag of the window.
 
asw::Vec2< int > get_size ()
 Get the size of the window.
 
asw::Vec2< int > get_logical_size ()
 Get the logical size of the window. This may differ from the actual size if scaling is enabled.
 
asw::Vec2< float > get_scale ()
 Get how many output pixels one logical pixel covers, after letterboxing. 2.0 means the game is drawn at twice its logical size.
 
void set_render_target (const asw::Texture &texture)
 Set the render target to the window.
 
void reset_render_target ()
 Reset the render target to the default.
 
void clear ()
 Clear the window to black.
 
void clear (const asw::Color &color)
 Clear to colour.
 
void present ()
 Present the window.
 
void set_blend_mode (asw::BlendMode mode)
 Set the blend mode used to draw primitives such as rectangles, lines and circles. Defaults to Blend, so colours with alpha are see through.
 
bool screenshot (const std::string &path)
 Save what has been drawn this frame to a PNG file. Call after drawing and before the frame is presented, for example at the end of a scene's draw(). Works with the dummy video driver (SDL_VIDEO_DRIVER=dummy), so scripted runs can capture frames without a window on screen.
 
void warp_mouse (float x, float y)
 Warp mouse in window.
 
void swap_window ()
 Swap window (gl)
 

Function Documentation

◆ _init()

void asw::display::_init ( int width,
int height,
int scale )

Initialize the display module. Called by asw::core::init().

Parameters
widthThe logical width of the display.
heightThe logical height of the display.
scaleThe initial window scale factor.

Definition at line 59 of file display.cpp.

◆ _init_opengl()

void asw::display::_init_opengl ( int width,
int height,
int scale )

Initialize the display module with OpenGL support. Called by asw::core::init().

Parameters
widthThe logical width of the display.
heightThe logical height of the display.
scaleThe initial window scale factor.

Definition at line 91 of file display.cpp.

◆ _shutdown()

void asw::display::_shutdown ( )

Shut down the display module. Called by asw::core::shutdown(). Nulls the renderer and window pointers before destroying them, so any outstanding shared_ptr asset deleters see a null renderer and become no-ops.

Definition at line 116 of file display.cpp.

◆ clear() [1/2]

void asw::display::clear ( )

Clear the window to black.

Definition at line 242 of file display.cpp.

◆ clear() [2/2]

void asw::display::clear ( const asw::Color & color)

Clear to colour.

Parameters
colorThe color to clear to.

Definition at line 254 of file display.cpp.

◆ get_logical_size()

asw::Vec2< int > asw::display::get_logical_size ( )

Get the logical size of the window. This may differ from the actual size if scaling is enabled.

Returns
The logical size of the window.

Definition at line 198 of file display.cpp.

◆ get_renderer()

asw::Renderer * asw::display::get_renderer ( )

Get the SDL renderer.

Returns
Pointer to the SDL_Renderer, or nullptr if not initialized.

Definition at line 139 of file display.cpp.

◆ get_scale()

asw::Vec2< float > asw::display::get_scale ( )

Get how many output pixels one logical pixel covers, after letterboxing. 2.0 means the game is drawn at twice its logical size.

Returns
The scale of the window.

Definition at line 207 of file display.cpp.

◆ get_size()

asw::Vec2< int > asw::display::get_size ( )

Get the size of the window.

Returns
The size of the window.

Definition at line 191 of file display.cpp.

◆ get_window()

asw::Window * asw::display::get_window ( )

Get the SDL window.

Returns
Pointer to the SDL_Window, or nullptr if not initialized.

Definition at line 144 of file display.cpp.

◆ is_fullscreen()

bool asw::display::is_fullscreen ( )

Check if the window is fullscreen.

Reads the window itself, so it is right when the config sets display.fullscreen. Useful for showing the real state in a settings menu.

Returns
true if the window is fullscreen.

Definition at line 172 of file display.cpp.

◆ present()

void asw::display::present ( )

Present the window.

Definition at line 264 of file display.cpp.

◆ reset_render_target()

void asw::display::reset_render_target ( )

Reset the render target to the default.

Definition at line 233 of file display.cpp.

◆ screenshot()

bool asw::display::screenshot ( const std::string & path)

Save what has been drawn this frame to a PNG file. Call after drawing and before the frame is presented, for example at the end of a scene's draw(). Works with the dummy video driver (SDL_VIDEO_DRIVER=dummy), so scripted runs can capture frames without a window on screen.

Parameters
pathWhere to write the PNG.
Returns
true - If the file was written.
false - If reading the frame or writing the file failed.

Definition at line 288 of file display.cpp.

◆ set_blend_mode()

void asw::display::set_blend_mode ( asw::BlendMode mode)

Set the blend mode used to draw primitives such as rectangles, lines and circles. Defaults to Blend, so colours with alpha are see through.

Parameters
modeThe blend mode to set.

Definition at line 273 of file display.cpp.

◆ set_fullscreen()

void asw::display::set_fullscreen ( bool fullscreen)

Set the window to fullscreen or windowed.

When the config sets display.fullscreen, it wins and fullscreen is ignored.

Parameters
fullscreenWhether or not to set the window to fullscreen.

Definition at line 166 of file display.cpp.

◆ set_icon()

void asw::display::set_icon ( const std::string & path)

Set the icon to display on the window. If it does not exist, this will silently fail.

Parameters
pathA path to the icon to display.

Definition at line 154 of file display.cpp.

◆ set_render_target()

void asw::display::set_render_target ( const asw::Texture & texture)

Set the render target to the window.

Definition at line 224 of file display.cpp.

◆ set_resizable()

void asw::display::set_resizable ( bool resizable)

Set resizable flag of the window.

Parameters
resizableWhether or not the window is resizable.

Definition at line 186 of file display.cpp.

◆ set_resolution()

void asw::display::set_resolution ( int w,
int h )

Set the resolution of the window.

Parameters
wThe width of the window.
hThe height of the window.

Definition at line 181 of file display.cpp.

◆ set_title()

void asw::display::set_title ( const std::string & title)

Set the title of the window.

Parameters
titleThe title to display at the top of the window.

Definition at line 149 of file display.cpp.

◆ swap_window()

void asw::display::swap_window ( )

Swap window (gl)

Definition at line 283 of file display.cpp.

◆ warp_mouse()

void asw::display::warp_mouse ( float x,
float y )

Warp mouse in window.

Parameters
xThe x coordinate to warp to.
yThe y coordinate to warp to.

Definition at line 278 of file display.cpp.