Skip to content

Class Engine::VirtualResolution

ClassList > Engine > VirtualResolution

Fixed-size game canvas, scaled and centered into the OS window. More...

  • #include <VirtualResolution.hpp>

Public Functions

Type Name
void ApplyMouseMapping ()
Makes Raylib mouse queries return virtual canvas coordinates.
void Begin ()
Starts drawing into the virtual canvas.
void ClearMouseMapping ()
Restores Raylib mouse queries to window coordinates.
void End ()
Stops drawing into the virtual canvas.
void EnsureSize (int width, int height)
Recreates the render texture only when the virtual size changes.
Rectangle GetDestRect () const
int GetHeight () const
float GetScale () const
RenderTexture2D & GetTexture ()
const RenderTexture2D & GetTexture () const
Vector2 GetVirtualMouse () const
Mouse position in virtual canvas pixels, clamped to the canvas.
int GetWidth () const
void Load ()
(Re)loads the render texture for the current virtual size.
void Present ()
Draws the canvas into the current frame, letterboxed.
void Unload ()
Releases the GPU render texture. Safe to call more than once.
void UpdateLetterbox (int screenWidth, int screenHeight)
Recomputes the uniform scale and the centered destination rectangle.
VirtualResolution (int width, int height)
Creates the canvas and loads its render texture.
VirtualResolution (const VirtualResolution &) = delete
VirtualResolution (VirtualResolution &&) = delete
VirtualResolution & operator= (const VirtualResolution &) = delete
VirtualResolution & operator= (VirtualResolution &&) = delete
~VirtualResolution ()

Public Static Functions

Type Name
int ResolveAxis (int virtualSize, int windowSize)
Uses virtualSize when it is positive, otherwisewindowSize .

Detailed Description

Draw calls go into an off-screen render texture. The texture is then scaled uniformly so the virtual aspect ratio is preserved (letterbox / pillarbox). Mouse input can be mapped back into that canvas.

Public Functions Documentation

function ApplyMouseMapping

Makes Raylib mouse queries return virtual canvas coordinates.

void Engine::VirtualResolution::ApplyMouseMapping () 

Do not use this while immediate-mode UI (ImGui / rlImGui) reads the mouse.


function Begin

Starts drawing into the virtual canvas.

void Engine::VirtualResolution::Begin () 


function ClearMouseMapping

Restores Raylib mouse queries to window coordinates.

void Engine::VirtualResolution::ClearMouseMapping () 


function End

Stops drawing into the virtual canvas.

void Engine::VirtualResolution::End () 


function EnsureSize

Recreates the render texture only when the virtual size changes.

void Engine::VirtualResolution::EnsureSize (
    int width,
    int height
) 

Parameters:

  • width New virtual width in pixels.
  • height New virtual height in pixels.

function GetDestRect

inline Rectangle Engine::VirtualResolution::GetDestRect () const

function GetHeight

inline int Engine::VirtualResolution::GetHeight () const

function GetScale

inline float Engine::VirtualResolution::GetScale () const

function GetTexture [½]

inline RenderTexture2D & Engine::VirtualResolution::GetTexture () 

function GetTexture [2/2]

inline const RenderTexture2D & Engine::VirtualResolution::GetTexture () const

function GetVirtualMouse

Mouse position in virtual canvas pixels, clamped to the canvas.

Vector2 Engine::VirtualResolution::GetVirtualMouse () const

When ApplyMouseMapping() is active, Raylib's cursor is already in canvas space. Otherwise the window cursor is remapped from the letterbox.


function GetWidth

inline int Engine::VirtualResolution::GetWidth () const

function Load

(Re)loads the render texture for the current virtual size.

void Engine::VirtualResolution::Load () 

Safe to call again: an existing texture is released first.


function Present

Draws the canvas into the current frame, letterboxed.

void Engine::VirtualResolution::Present () 

The caller clears the window first. Does not change the mouse mapping.


function Unload

Releases the GPU render texture. Safe to call more than once.

void Engine::VirtualResolution::Unload () 

Must run while the Raylib window (OpenGL context) is still open.


function UpdateLetterbox

Recomputes the uniform scale and the centered destination rectangle.

void Engine::VirtualResolution::UpdateLetterbox (
    int screenWidth,
    int screenHeight
) 

Parameters:

  • screenWidth Current OS window width in pixels.
  • screenHeight Current OS window height in pixels.

function VirtualResolution [⅓]

Creates the canvas and loads its render texture.

Engine::VirtualResolution::VirtualResolution (
    int width,
    int height
) 

Parameters:

  • width Virtual canvas width in pixels.
  • height Virtual canvas height in pixels.

function VirtualResolution [⅔]

Engine::VirtualResolution::VirtualResolution (
    const VirtualResolution &
) = delete

function VirtualResolution [3/3]

Engine::VirtualResolution::VirtualResolution (
    VirtualResolution &&
) = delete

function operator=

VirtualResolution & Engine::VirtualResolution::operator= (
    const VirtualResolution &
) = delete

function operator=

VirtualResolution & Engine::VirtualResolution::operator= (
    VirtualResolution &&
) = delete

function ~VirtualResolution

Engine::VirtualResolution::~VirtualResolution () 

Public Static Functions Documentation

function ResolveAxis

Uses virtualSize when it is positive, otherwisewindowSize .

static int Engine::VirtualResolution::ResolveAxis (
    int virtualSize,
    int windowSize
) 

A non-positive virtual axis means "match the window" so older projects stay 1:1 until they set a distinct canvas size.



The documentation for this class was generated from the following file /home/runner/work/r-type/r-type/Engine/include/Core/VirtualResolution.hpp