Skip to content

Instantly share code, notes, and snippets.

@slouken
slouken / SDL3-accumulate-relative-motion.c
Created March 19, 2023 18:23
Accumulating relative mouse motion
while (SDL_PollEvent(&event) > 0) {
if (event.type == SDL_EVENT_MOUSE_MOTION) {
static float dx_frac, dy_frac;
float dx, dy;
/* Accumulate new motion with previous sub-pixel motion */
dx = event.motion.xrel + dx_frac;
dy = event.motion.yrel + dy_frac;
/* Split the integral and fractional motion, dx and dy will contain whole pixel deltas */
@slouken
slouken / SDL3-desktop-scale.c
Created March 19, 2023 18:15
SDL 3.0 - Get desktop UI scale
float scale = 1.0f;
SDL_DisplayID display = SDL_GetDisplayForWindow(window);
const SDL_DisplayMode *mode = SDL_GetDesktopDisplayMode(display);
if (mode) {
scale = mode->display_scale;
}
SDL_Log("Window content scale: %d%%\n", (int)(scale * 100.0f));
bool BSteamRemotePlayActive()
{
uint32 unSessionCount = SteamRemotePlay()->GetSessionCount();
for ( uint32 iIndex = 0; iIndex < unSessionCount; iIndex++ )
{
RemotePlaySessionID_t unSessionID = SteamRemotePlay()->GetSessionID( iIndex );
if ( !unSessionID )
{
continue;
}