From 1215decda179e2355136a21fa6c029f0c4e61d93 Mon Sep 17 00:00:00 2001 From: Caden Parker Date: Thu, 5 Nov 2026 23:23:27 -0600 Subject: [PATCH 1/2] [examples] Fix 2D camera offsets --- examples/core/core_2d_camera_mouse_zoom.c | 6 ++++-- examples/core/core_2d_camera_split_screen.c | 4 ++-- examples/textures/textures_magnifying_glass.c | 2 +- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/examples/core/core_2d_camera_mouse_zoom.c b/examples/core/core_2d_camera_mouse_zoom.c index 54bc60aa1e46..cd6a75585cd8 100644 --- a/examples/core/core_2d_camera_mouse_zoom.c +++ b/examples/core/core_2d_camera_mouse_zoom.c @@ -56,6 +56,8 @@ int main(void) camera.target = Vector2Add(camera.target, delta); } + Vector2 renderScale = { (float)GetRenderWidth()/GetScreenWidth(), (float)GetRenderHeight()/GetScreenHeight() }; + if (zoomMode == 0) { // Zoom based on mouse wheel @@ -66,7 +68,7 @@ int main(void) Vector2 mouseWorldPos = GetScreenToWorld2D(GetMousePosition(), camera); // Set the offset to where the mouse is, mouse is scaled to viewport space, but offset is in unscaled pixels - camera.offset = Vector2Multiply(GetMousePosition(), GetWindowScaleDPI()); + camera.offset = Vector2Multiply(GetMousePosition(), renderScale); // Set the target to match, so that the camera maps the world space point // under the cursor to the screen space point under the cursor at any zoom @@ -87,7 +89,7 @@ int main(void) Vector2 mouseWorldPos = GetScreenToWorld2D(GetMousePosition(), camera); // Set the offset to where the mouse is, mouse is scaled to viewport space, but offset is in unscaled pixels - camera.offset = Vector2Multiply(GetMousePosition(), GetWindowScaleDPI()); + camera.offset = Vector2Multiply(GetMousePosition(), renderScale); // Set the target to match, so that the camera maps the world space point // under the cursor to the screen space point under the cursor at any zoom diff --git a/examples/core/core_2d_camera_split_screen.c b/examples/core/core_2d_camera_split_screen.c index d32c71b1b8ca..4e65206fdc2d 100644 --- a/examples/core/core_2d_camera_split_screen.c +++ b/examples/core/core_2d_camera_split_screen.c @@ -40,13 +40,13 @@ int main(void) Camera2D camera1 = { 0 }; camera1.target = (Vector2){ player1.x, player1.y }; - camera1.offset = Vector2Multiply((Vector2){ 200.0f, 200.0f }, GetWindowScaleDPI()); + camera1.offset = (Vector2){ 200.0f, 200.0f }; camera1.rotation = 0.0f; camera1.zoom = 1.0f; Camera2D camera2 = { 0 }; camera2.target = (Vector2){ player2.x, player2.y }; - camera2.offset = Vector2Multiply((Vector2){ 200.0f, 200.0f }, GetWindowScaleDPI()); + camera2.offset = (Vector2){ 200.0f, 200.0f }; camera2.rotation = 0.0f; camera2.zoom = 1.0f; diff --git a/examples/textures/textures_magnifying_glass.c b/examples/textures/textures_magnifying_glass.c index 43827e39a136..f0d7347bc0e0 100644 --- a/examples/textures/textures_magnifying_glass.c +++ b/examples/textures/textures_magnifying_glass.c @@ -47,7 +47,7 @@ int main(void) // Set magnifying glass zoom camera.zoom = 2; // Offset by half the size of the magnifying glass to counteract drawing the texture centered on the mouse position - camera.offset = Vector2Multiply((Vector2){ 128, 128 }, GetWindowScaleDPI()); + camera.offset = (Vector2){ 128, 128 }; SetTargetFPS(60); //-------------------------------------------------------------------------------------- From 6a370fb63b071e9c1ee0d916e9d92ed3b3bfc7fd Mon Sep 17 00:00:00 2001 From: Caden Parker Date: Fri, 6 Nov 2026 00:21:55 -0600 Subject: [PATCH 2/2] Remove raymath.h includes --- examples/core/core_2d_camera_split_screen.c | 1 - examples/textures/textures_magnifying_glass.c | 1 - 2 files changed, 2 deletions(-) diff --git a/examples/core/core_2d_camera_split_screen.c b/examples/core/core_2d_camera_split_screen.c index 4e65206fdc2d..169465f9d361 100644 --- a/examples/core/core_2d_camera_split_screen.c +++ b/examples/core/core_2d_camera_split_screen.c @@ -19,7 +19,6 @@ ********************************************************************************************/ #include "raylib.h" -#include "raymath.h" #define PLAYER_SIZE 40 diff --git a/examples/textures/textures_magnifying_glass.c b/examples/textures/textures_magnifying_glass.c index f0d7347bc0e0..51ff9b2a793a 100644 --- a/examples/textures/textures_magnifying_glass.c +++ b/examples/textures/textures_magnifying_glass.c @@ -18,7 +18,6 @@ #include "raylib.h" #include "rlgl.h" // Required for: rlSetBlendFactorsSeparate() -#include "raymath.h" // Required for: Vector2Multiply() //------------------------------------------------------------------------------------ // Program main entry point