mirror of
https://github.com/raysan5/raylib.git
synced 2026-01-10 21:48:46 +01:00
Compare commits
15 Commits
05f5143603
...
eb3cc183cc
| Author | SHA1 | Date | |
|---|---|---|---|
| eb3cc183cc | |||
| a334a54eac | |||
| 890ca8d687 | |||
| 6450a48c75 | |||
| 8a75439c25 | |||
| 8871d7648d | |||
| 4176c518c7 | |||
| c0c8ee9dc8 | |||
| 11c248aa82 | |||
| 2cf8983e18 | |||
| 297dcc07b8 | |||
| 8cfb99f275 | |||
| 1d8e011eee | |||
| 37bc3f5012 | |||
| da1a76604f |
@ -33,6 +33,7 @@ int main(void)
|
||||
Vector2 scaleDpi = GetWindowScaleDPI();
|
||||
Vector2 mousePos = GetMousePosition();
|
||||
int currentMonitor = GetCurrentMonitor();
|
||||
Vector2 windowPos = GetWindowPosition();
|
||||
|
||||
int gridSpacing = 40; // Grid spacing in pixels
|
||||
|
||||
@ -47,8 +48,10 @@ int main(void)
|
||||
mousePos = GetMousePosition();
|
||||
currentMonitor = GetCurrentMonitor();
|
||||
scaleDpi = GetWindowScaleDPI();
|
||||
windowPos = GetWindowPosition();
|
||||
|
||||
if (IsKeyPressed(KEY_SPACE)) ToggleBorderlessWindowed();
|
||||
if (IsKeyPressed(KEY_F)) ToggleFullscreen();
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
// Draw
|
||||
@ -58,12 +61,12 @@ int main(void)
|
||||
ClearBackground(RAYWHITE);
|
||||
|
||||
// Draw grid
|
||||
for (int h = 0; h < 20; h++)
|
||||
for (int h = 0; h < GetScreenHeight()/gridSpacing + 1; h++)
|
||||
{
|
||||
DrawText(TextFormat("%02i", h*gridSpacing), 4, h*gridSpacing - 4, 10, GRAY);
|
||||
DrawLine(24, h*gridSpacing, GetScreenWidth(), h*gridSpacing, LIGHTGRAY);
|
||||
}
|
||||
for (int v = 0; v < 40; v++)
|
||||
for (int v = 0; v < GetScreenWidth()/gridSpacing + 1; v++)
|
||||
{
|
||||
DrawText(TextFormat("%02i", v*gridSpacing), v*gridSpacing - 10, 4, 10, GRAY);
|
||||
DrawLine(v*gridSpacing, 20, v*gridSpacing, GetScreenHeight(), LIGHTGRAY);
|
||||
@ -72,9 +75,14 @@ int main(void)
|
||||
// Draw UI info
|
||||
DrawText(TextFormat("CURRENT MONITOR: %i/%i (%ix%i)", currentMonitor + 1, GetMonitorCount(),
|
||||
GetMonitorWidth(currentMonitor), GetMonitorHeight(currentMonitor)), 50, 50, 20, DARKGRAY);
|
||||
DrawText(TextFormat("SCREEN SIZE: %ix%i", GetScreenWidth(), GetScreenHeight()), 50, 90, 20, DARKGRAY);
|
||||
DrawText(TextFormat("RENDER SIZE: %ix%i", GetRenderWidth(), GetRenderHeight()), 50, 130, 20, DARKGRAY);
|
||||
DrawText(TextFormat("SCALE FACTOR: %.1fx%.1f", scaleDpi.x, scaleDpi.y), 50, 170, 20, GRAY);
|
||||
DrawText(TextFormat("WINDOW POSITION: %ix%i", (int)windowPos.x, (int)windowPos.y), 50, 90, 20, DARKGRAY);
|
||||
DrawText(TextFormat("SCREEN SIZE: %ix%i", GetScreenWidth(), GetScreenHeight()), 50, 130, 20, DARKGRAY);
|
||||
DrawText(TextFormat("RENDER SIZE: %ix%i", GetRenderWidth(), GetRenderHeight()), 50, 170, 20, DARKGRAY);
|
||||
DrawText(TextFormat("SCALE FACTOR: %.1fx%.1f", scaleDpi.x, scaleDpi.y), 50, 210, 20, GRAY);
|
||||
|
||||
// Draw reference rectangles, top-left and bottom-right corners
|
||||
DrawRectangle(0, 0, 30, 60, RED);
|
||||
DrawRectangle(GetScreenWidth() - 30, GetScreenHeight() - 60, 30, 60, BLUE);
|
||||
|
||||
// Draw mouse position
|
||||
DrawCircleV(GetMousePosition(), 20, MAROON);
|
||||
|
||||
@ -267,6 +267,8 @@ static void AndroidCommandCallback(struct android_app *app, int32_t cmd);
|
||||
static int32_t AndroidInputCallback(struct android_app *app, AInputEvent *event); // Process Android inputs
|
||||
static GamepadButton AndroidTranslateGamepadButton(int button); // Map Android gamepad button to raylib gamepad button
|
||||
|
||||
static void SetupFramebuffer(int width, int height); // Setup main framebuffer (required by InitPlatform())
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// Module Functions Declaration
|
||||
//----------------------------------------------------------------------------------
|
||||
@ -885,7 +887,6 @@ void ClosePlatform(void)
|
||||
// NOTE: returns false in case graphic device could not be created
|
||||
static int InitGraphicsDevice(void)
|
||||
{
|
||||
CORE.Window.fullscreen = true;
|
||||
FLAG_SET(CORE.Window.flags, FLAG_FULLSCREEN_MODE);
|
||||
|
||||
EGLint samples = 0;
|
||||
@ -1420,4 +1421,82 @@ static int32_t AndroidInputCallback(struct android_app *app, AInputEvent *event)
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Compute framebuffer size relative to screen size and display size
|
||||
// NOTE: Global variables CORE.Window.render.width/CORE.Window.render.height and CORE.Window.renderOffset.x/CORE.Window.renderOffset.y can be modified
|
||||
static void SetupFramebuffer(int width, int height)
|
||||
{
|
||||
// Calculate CORE.Window.render.width and CORE.Window.render.height, we have the display size (input params) and the desired screen size (global var)
|
||||
if ((CORE.Window.screen.width > CORE.Window.display.width) || (CORE.Window.screen.height > CORE.Window.display.height))
|
||||
{
|
||||
TRACELOG(LOG_WARNING, "DISPLAY: Downscaling required: Screen size (%ix%i) is bigger than display size (%ix%i)", CORE.Window.screen.width, CORE.Window.screen.height, CORE.Window.display.width, CORE.Window.display.height);
|
||||
|
||||
// Downscaling to fit display with border-bars
|
||||
float widthRatio = (float)CORE.Window.display.width/(float)CORE.Window.screen.width;
|
||||
float heightRatio = (float)CORE.Window.display.height/(float)CORE.Window.screen.height;
|
||||
|
||||
if (widthRatio <= heightRatio)
|
||||
{
|
||||
CORE.Window.render.width = CORE.Window.display.width;
|
||||
CORE.Window.render.height = (int)round((float)CORE.Window.screen.height*widthRatio);
|
||||
CORE.Window.renderOffset.x = 0;
|
||||
CORE.Window.renderOffset.y = (CORE.Window.display.height - CORE.Window.render.height);
|
||||
}
|
||||
else
|
||||
{
|
||||
CORE.Window.render.width = (int)round((float)CORE.Window.screen.width*heightRatio);
|
||||
CORE.Window.render.height = CORE.Window.display.height;
|
||||
CORE.Window.renderOffset.x = (CORE.Window.display.width - CORE.Window.render.width);
|
||||
CORE.Window.renderOffset.y = 0;
|
||||
}
|
||||
|
||||
// Screen scaling required
|
||||
float scaleRatio = (float)CORE.Window.render.width/(float)CORE.Window.screen.width;
|
||||
CORE.Window.screenScale = MatrixScale(scaleRatio, scaleRatio, 1.0f);
|
||||
|
||||
// NOTE: We render to full display resolution!
|
||||
// We just need to calculate above parameters for downscale matrix and offsets
|
||||
CORE.Window.render.width = CORE.Window.display.width;
|
||||
CORE.Window.render.height = CORE.Window.display.height;
|
||||
|
||||
TRACELOG(LOG_WARNING, "DISPLAY: Downscale matrix generated, content will be rendered at (%ix%i)", CORE.Window.render.width, CORE.Window.render.height);
|
||||
}
|
||||
else if ((CORE.Window.screen.width < CORE.Window.display.width) || (CORE.Window.screen.height < CORE.Window.display.height))
|
||||
{
|
||||
// Required screen size is smaller than display size
|
||||
TRACELOG(LOG_INFO, "DISPLAY: Upscaling required: Screen size (%ix%i) smaller than display size (%ix%i)", CORE.Window.screen.width, CORE.Window.screen.height, CORE.Window.display.width, CORE.Window.display.height);
|
||||
|
||||
if ((CORE.Window.screen.width == 0) || (CORE.Window.screen.height == 0))
|
||||
{
|
||||
CORE.Window.screen.width = CORE.Window.display.width;
|
||||
CORE.Window.screen.height = CORE.Window.display.height;
|
||||
}
|
||||
|
||||
// Upscaling to fit display with border-bars
|
||||
float displayRatio = (float)CORE.Window.display.width/(float)CORE.Window.display.height;
|
||||
float screenRatio = (float)CORE.Window.screen.width/(float)CORE.Window.screen.height;
|
||||
|
||||
if (displayRatio <= screenRatio)
|
||||
{
|
||||
CORE.Window.render.width = CORE.Window.screen.width;
|
||||
CORE.Window.render.height = (int)round((float)CORE.Window.screen.width/displayRatio);
|
||||
CORE.Window.renderOffset.x = 0;
|
||||
CORE.Window.renderOffset.y = (CORE.Window.render.height - CORE.Window.screen.height);
|
||||
}
|
||||
else
|
||||
{
|
||||
CORE.Window.render.width = (int)round((float)CORE.Window.screen.height*displayRatio);
|
||||
CORE.Window.render.height = CORE.Window.screen.height;
|
||||
CORE.Window.renderOffset.x = (CORE.Window.render.width - CORE.Window.screen.width);
|
||||
CORE.Window.renderOffset.y = 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
CORE.Window.render.width = CORE.Window.screen.width;
|
||||
CORE.Window.render.height = CORE.Window.screen.height;
|
||||
CORE.Window.renderOffset.x = 0;
|
||||
CORE.Window.renderOffset.y = 0;
|
||||
}
|
||||
}
|
||||
|
||||
// EOF
|
||||
|
||||
@ -176,45 +176,72 @@ bool WindowShouldClose(void)
|
||||
// Toggle fullscreen mode
|
||||
void ToggleFullscreen(void)
|
||||
{
|
||||
if (!CORE.Window.fullscreen)
|
||||
if (!FLAG_IS_SET(CORE.Window.flags, FLAG_FULLSCREEN_MODE))
|
||||
{
|
||||
// Store previous window position (in case we exit fullscreen)
|
||||
// Store previous screen data (in case exiting fullscreen)
|
||||
CORE.Window.previousPosition = CORE.Window.position;
|
||||
CORE.Window.previousScreen = CORE.Window.screen;
|
||||
|
||||
// Use current monitor the window is on to get fullscreen required size
|
||||
int monitorCount = 0;
|
||||
int monitorIndex = GetCurrentMonitor();
|
||||
GLFWmonitor **monitors = glfwGetMonitors(&monitorCount);
|
||||
|
||||
// Use current monitor, so we correctly get the display the window is on
|
||||
GLFWmonitor *monitor = (monitorIndex < monitorCount)? monitors[monitorIndex] : NULL;
|
||||
|
||||
if (monitor == NULL)
|
||||
if (monitor != NULL)
|
||||
{
|
||||
TRACELOG(LOG_WARNING, "GLFW: Failed to get monitor");
|
||||
// Get current monitor video mode
|
||||
const GLFWvidmode *mode = glfwGetVideoMode(monitors[monitorIndex]);
|
||||
CORE.Window.display.width = mode->width;
|
||||
CORE.Window.display.height = mode->height;
|
||||
|
||||
CORE.Window.fullscreen = false;
|
||||
FLAG_CLEAR(CORE.Window.flags, FLAG_FULLSCREEN_MODE);
|
||||
CORE.Window.position = (Point){ 0, 0 };
|
||||
CORE.Window.screen = CORE.Window.display;
|
||||
|
||||
glfwSetWindowMonitor(platform.handle, NULL, 0, 0, CORE.Window.screen.width, CORE.Window.screen.height, GLFW_DONT_CARE);
|
||||
}
|
||||
else
|
||||
{
|
||||
CORE.Window.fullscreen = true;
|
||||
// Set fullscreen flag to be processed on FramebufferSizeCallback() accordingly
|
||||
FLAG_SET(CORE.Window.flags, FLAG_FULLSCREEN_MODE);
|
||||
|
||||
#if defined(_GLFW_X11) || defined(_GLFW_WAYLAND)
|
||||
// NOTE: X11 requires undecorating the window before switching to
|
||||
// fullscreen to avoid issues with framebuffer scaling
|
||||
glfwSetWindowAttrib(platform.handle, GLFW_DECORATED, GLFW_FALSE);
|
||||
FLAG_SET(CORE.Window.flags, FLAG_WINDOW_UNDECORATED);
|
||||
#endif
|
||||
// WARNING: This function launches FramebufferSizeCallback()
|
||||
glfwSetWindowMonitor(platform.handle, monitor, 0, 0, CORE.Window.screen.width, CORE.Window.screen.height, GLFW_DONT_CARE);
|
||||
}
|
||||
else TRACELOG(LOG_WARNING, "GLFW: Failed to get monitor");
|
||||
}
|
||||
else
|
||||
{
|
||||
CORE.Window.fullscreen = false;
|
||||
// Restore previous window position and size
|
||||
CORE.Window.position = CORE.Window.previousPosition;
|
||||
CORE.Window.screen = CORE.Window.previousScreen;
|
||||
|
||||
// Set fullscreen flag to be processed on FramebufferSizeCallback() accordingly
|
||||
// and considered by GetWindowScaleDPI()
|
||||
FLAG_CLEAR(CORE.Window.flags, FLAG_FULLSCREEN_MODE);
|
||||
|
||||
glfwSetWindowMonitor(platform.handle, NULL, CORE.Window.previousPosition.x, CORE.Window.previousPosition.y, CORE.Window.screen.width, CORE.Window.screen.height, GLFW_DONT_CARE);
|
||||
#if !defined(__APPLE__)
|
||||
// Make sure to restore render size considering HighDPI scaling
|
||||
if (FLAG_IS_SET(CORE.Window.flags, FLAG_WINDOW_HIGHDPI))
|
||||
{
|
||||
Vector2 scaleDpi = GetWindowScaleDPI();
|
||||
CORE.Window.screen.width *= scaleDpi.x;
|
||||
CORE.Window.screen.height *= scaleDpi.y;
|
||||
}
|
||||
#endif
|
||||
|
||||
// we update the window position right away
|
||||
CORE.Window.position.x = CORE.Window.previousPosition.x;
|
||||
CORE.Window.position.y = CORE.Window.previousPosition.y;
|
||||
// WARNING: This function launches FramebufferSizeCallback()
|
||||
glfwSetWindowMonitor(platform.handle, NULL, CORE.Window.position.x, CORE.Window.position.y,
|
||||
CORE.Window.screen.width, CORE.Window.screen.height, GLFW_DONT_CARE);
|
||||
|
||||
#if defined(_GLFW_X11) || defined(_GLFW_WAYLAND)
|
||||
// NOTE: X11 requires restoring the decorated window after switching from
|
||||
// fullscreen to avoid issues with framebuffer scaling
|
||||
glfwSetWindowAttrib(platform.handle, GLFW_DECORATED, GLFW_TRUE);
|
||||
FLAG_CLEAR(CORE.Window.flags, FLAG_WINDOW_UNDECORATED);
|
||||
#endif
|
||||
}
|
||||
|
||||
// Try to enable GPU V-Sync, so frames are limited to screen refresh rate (60Hz -> 60 FPS)
|
||||
@ -226,13 +253,8 @@ void ToggleFullscreen(void)
|
||||
void ToggleBorderlessWindowed(void)
|
||||
{
|
||||
// Leave fullscreen before attempting to set borderless windowed mode
|
||||
bool wasOnFullscreen = false;
|
||||
if (CORE.Window.fullscreen)
|
||||
{
|
||||
// Fullscreen already saves the previous position so it does not need to be set here again
|
||||
ToggleFullscreen();
|
||||
wasOnFullscreen = true;
|
||||
}
|
||||
// NOTE: Fullscreen already saves the previous position so it does not need to be set again later
|
||||
if (FLAG_IS_SET(CORE.Window.flags, FLAG_FULLSCREEN_MODE)) ToggleFullscreen();
|
||||
|
||||
int monitorCount = 0;
|
||||
GLFWmonitor **monitors = glfwGetMonitors(&monitorCount);
|
||||
@ -248,7 +270,7 @@ void ToggleBorderlessWindowed(void)
|
||||
{
|
||||
// Store screen position and size
|
||||
// NOTE: If it was on fullscreen, screen position was already stored, so skip setting it here
|
||||
if (!wasOnFullscreen) CORE.Window.previousPosition = CORE.Window.position;
|
||||
CORE.Window.previousPosition = CORE.Window.position;
|
||||
CORE.Window.previousScreen = CORE.Window.screen;
|
||||
|
||||
// Set undecorated flag
|
||||
@ -256,22 +278,13 @@ void ToggleBorderlessWindowed(void)
|
||||
FLAG_SET(CORE.Window.flags, FLAG_WINDOW_UNDECORATED);
|
||||
|
||||
// Get monitor position and size
|
||||
int monitorPosX = 0;
|
||||
int monitorPosY = 0;
|
||||
glfwGetMonitorPos(monitors[monitor], &monitorPosX, &monitorPosY);
|
||||
const int monitorWidth = mode->width;
|
||||
const int monitorHeight = mode->height;
|
||||
glfwGetMonitorPos(monitors[monitor], &CORE.Window.position.x, &CORE.Window.position.y);
|
||||
CORE.Window.screen.width = mode->width;
|
||||
CORE.Window.screen.height = mode->height;
|
||||
|
||||
// Set screen position and size
|
||||
glfwSetWindowMonitor(
|
||||
platform.handle,
|
||||
monitors[monitor],
|
||||
monitorPosX,
|
||||
monitorPosY,
|
||||
monitorWidth,
|
||||
monitorHeight,
|
||||
mode->refreshRate
|
||||
);
|
||||
glfwSetWindowMonitor(platform.handle, monitors[monitor], CORE.Window.position.x, CORE.Window.position.y,
|
||||
CORE.Window.screen.width, CORE.Window.screen.height, mode->refreshRate);
|
||||
|
||||
// Refocus window
|
||||
glfwFocusWindow(platform.handle);
|
||||
@ -280,39 +293,32 @@ void ToggleBorderlessWindowed(void)
|
||||
}
|
||||
else
|
||||
{
|
||||
// Restore previous screen values
|
||||
CORE.Window.position = CORE.Window.previousPosition;
|
||||
CORE.Window.screen = CORE.Window.previousScreen;
|
||||
|
||||
// Remove undecorated flag
|
||||
glfwSetWindowAttrib(platform.handle, GLFW_DECORATED, GLFW_TRUE);
|
||||
FLAG_CLEAR(CORE.Window.flags, FLAG_WINDOW_UNDECORATED);
|
||||
|
||||
#if !defined(__APPLE__)
|
||||
// Make sure to restore size to HighDPI
|
||||
// Make sure to restore size considering HighDPI scaling
|
||||
if (FLAG_IS_SET(CORE.Window.flags, FLAG_WINDOW_HIGHDPI))
|
||||
{
|
||||
Vector2 scaleDpi = GetWindowScaleDPI();
|
||||
CORE.Window.previousScreen.width *= scaleDpi.x;
|
||||
CORE.Window.previousScreen.height *= scaleDpi.y;
|
||||
CORE.Window.screen.width *= scaleDpi.x;
|
||||
CORE.Window.screen.height *= scaleDpi.y;
|
||||
}
|
||||
#endif
|
||||
|
||||
// Return previous screen size and position
|
||||
// NOTE: The order matters here, it must set size first, then set position, otherwise the screen will be positioned incorrectly
|
||||
glfwSetWindowMonitor(
|
||||
platform.handle,
|
||||
NULL,
|
||||
CORE.Window.previousPosition.x,
|
||||
CORE.Window.previousPosition.y,
|
||||
CORE.Window.previousScreen.width,
|
||||
CORE.Window.previousScreen.height,
|
||||
mode->refreshRate
|
||||
);
|
||||
// Return to previous screen size and position
|
||||
glfwSetWindowMonitor(platform.handle, NULL, CORE.Window.position.x, CORE.Window.position.y,
|
||||
CORE.Window.screen.width, CORE.Window.screen.height, mode->refreshRate);
|
||||
|
||||
// Refocus window
|
||||
glfwFocusWindow(platform.handle);
|
||||
|
||||
FLAG_CLEAR(CORE.Window.flags, FLAG_BORDERLESS_WINDOWED_MODE);
|
||||
|
||||
CORE.Window.position.x = CORE.Window.previousPosition.x;
|
||||
CORE.Window.position.y = CORE.Window.previousPosition.y;
|
||||
}
|
||||
}
|
||||
else TRACELOG(LOG_WARNING, "GLFW: Failed to find video mode for selected monitor");
|
||||
@ -666,7 +672,7 @@ void SetWindowMonitor(int monitor)
|
||||
|
||||
if ((monitor >= 0) && (monitor < monitorCount))
|
||||
{
|
||||
if (CORE.Window.fullscreen)
|
||||
if (FLAG_IS_SET(CORE.Window.flags, FLAG_FULLSCREEN_MODE))
|
||||
{
|
||||
TRACELOG(LOG_INFO, "GLFW: Selected fullscreen monitor: [%i] %s", monitor, glfwGetMonitorName(monitors[monitor]));
|
||||
|
||||
@ -1013,19 +1019,15 @@ const char *GetMonitorName(int monitor)
|
||||
// Get window position XY on monitor
|
||||
Vector2 GetWindowPosition(void)
|
||||
{
|
||||
int x = 0;
|
||||
int y = 0;
|
||||
|
||||
glfwGetWindowPos(platform.handle, &x, &y);
|
||||
|
||||
return (Vector2){ (float)x, (float)y };
|
||||
return (Vector2){ (float)CORE.Window.position.x, (float)CORE.Window.position.y };
|
||||
}
|
||||
|
||||
// Get window scale DPI factor for current monitor
|
||||
Vector2 GetWindowScaleDPI(void)
|
||||
{
|
||||
Vector2 scale = { 1.0f, 1.0f };
|
||||
if (FLAG_IS_SET(CORE.Window.flags, FLAG_WINDOW_HIGHDPI)) glfwGetWindowContentScale(platform.handle, &scale.x, &scale.y);
|
||||
if (FLAG_IS_SET(CORE.Window.flags, FLAG_WINDOW_HIGHDPI) && !FLAG_IS_SET(CORE.Window.flags, FLAG_FULLSCREEN_MODE))
|
||||
glfwGetWindowContentScale(platform.handle, &scale.x, &scale.y);
|
||||
return scale;
|
||||
}
|
||||
|
||||
@ -1422,8 +1424,6 @@ int InitPlatform(void)
|
||||
unsigned int requestedWindowFlags = CORE.Window.flags;
|
||||
|
||||
// Check window creation flags
|
||||
if (FLAG_IS_SET(CORE.Window.flags, FLAG_FULLSCREEN_MODE)) CORE.Window.fullscreen = true;
|
||||
|
||||
if (FLAG_IS_SET(CORE.Window.flags, FLAG_WINDOW_HIDDEN)) glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE); // Visible window
|
||||
else glfwWindowHint(GLFW_VISIBLE, GLFW_TRUE); // Window initially hidden
|
||||
|
||||
@ -1536,11 +1536,14 @@ int InitPlatform(void)
|
||||
// REF: https://github.com/raysan5/raylib/issues/1554
|
||||
glfwSetJoystickCallback(NULL);
|
||||
|
||||
GLFWmonitor *monitor = NULL;
|
||||
if (CORE.Window.fullscreen)
|
||||
if ((CORE.Window.screen.width == 0) || (CORE.Window.screen.height == 0)) FLAG_SET(CORE.Window.flags, FLAG_FULLSCREEN_MODE);
|
||||
|
||||
// Init window in fullscreen mode if requested
|
||||
// NOTE: Keeping original screen size for toggle
|
||||
if (FLAG_IS_SET(CORE.Window.flags, FLAG_FULLSCREEN_MODE))
|
||||
{
|
||||
// NOTE: Fullscreen applications default to the primary monitor
|
||||
monitor = glfwGetPrimaryMonitor();
|
||||
GLFWmonitor *monitor = glfwGetPrimaryMonitor();
|
||||
if (!monitor)
|
||||
{
|
||||
TRACELOG(LOG_WARNING, "GLFW: Failed to get primary monitor");
|
||||
@ -1554,59 +1557,20 @@ int InitPlatform(void)
|
||||
CORE.Window.display.width = mode->width;
|
||||
CORE.Window.display.height = mode->height;
|
||||
|
||||
// Set screen width/height to the display width/height if they are 0
|
||||
// Check if user requested some screen size
|
||||
if ((CORE.Window.screen.width == 0) || (CORE.Window.screen.height == 0))
|
||||
{
|
||||
// Set some default screen size in case user decides to exit fullscreen mode
|
||||
CORE.Window.previousScreen.width = 800;
|
||||
CORE.Window.previousScreen.height = 450;
|
||||
CORE.Window.previousPosition.x = CORE.Window.display.width/2 - 800/2;
|
||||
CORE.Window.previousPosition.y = CORE.Window.display.height/2 - 450/2;
|
||||
}
|
||||
|
||||
// Set screen width/height to the display width/height
|
||||
if (CORE.Window.screen.width == 0) CORE.Window.screen.width = CORE.Window.display.width;
|
||||
if (CORE.Window.screen.height == 0) CORE.Window.screen.height = CORE.Window.display.height;
|
||||
|
||||
// Remember center for switching from fullscreen to window
|
||||
if ((CORE.Window.screen.height == CORE.Window.display.height) && (CORE.Window.screen.width == CORE.Window.display.width))
|
||||
{
|
||||
// If screen width/height equal to the display, we can't calculate the window pos for toggling full-screened/windowed
|
||||
// Toggling full-screened/windowed with pos(0, 0) can cause problems in some platforms, such as X11
|
||||
CORE.Window.position.x = CORE.Window.display.width/4;
|
||||
CORE.Window.position.y = CORE.Window.display.height/4;
|
||||
}
|
||||
else
|
||||
{
|
||||
CORE.Window.position.x = CORE.Window.display.width/2 - CORE.Window.screen.width/2;
|
||||
CORE.Window.position.y = CORE.Window.display.height/2 - CORE.Window.screen.height/2;
|
||||
}
|
||||
|
||||
if (CORE.Window.position.x < 0) CORE.Window.position.x = 0;
|
||||
if (CORE.Window.position.y < 0) CORE.Window.position.y = 0;
|
||||
|
||||
// Obtain recommended CORE.Window.display.width/CORE.Window.display.height from a valid videomode for the monitor
|
||||
int count = 0;
|
||||
const GLFWvidmode *modes = glfwGetVideoModes(monitor, &count);
|
||||
|
||||
// Get closest video mode to desired CORE.Window.screen.width/CORE.Window.screen.height
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
if ((unsigned int)modes[i].width >= CORE.Window.screen.width)
|
||||
{
|
||||
if ((unsigned int)modes[i].height >= CORE.Window.screen.height)
|
||||
{
|
||||
CORE.Window.display.width = modes[i].width;
|
||||
CORE.Window.display.height = modes[i].height;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TRACELOG(LOG_INFO, "SYSTEM: Closest fullscreen videomode: %i x %i", CORE.Window.display.width, CORE.Window.display.height);
|
||||
|
||||
// NOTE: ISSUE: Closest videomode could not match monitor aspect-ratio, for example,
|
||||
// for a desired screen size of 800x450 (16:9), closest supported videomode is 800x600 (4:3),
|
||||
// framebuffer is rendered correctly but once displayed on a 16:9 monitor, it gets stretched
|
||||
// by the sides to fit all monitor space...
|
||||
|
||||
// Try to setup the most appropriate fullscreen framebuffer for the requested screenWidth/screenHeight
|
||||
// It considers device display resolution mode and setups a framebuffer with black bars if required (render size/offset)
|
||||
// Modified global variables: CORE.Window.screen.width/CORE.Window.screen.height - CORE.Window.render.width/CORE.Window.render.height - CORE.Window.renderOffset.x/CORE.Window.renderOffset.y - CORE.Window.screenScale
|
||||
// TODO: It is a quite cumbersome solution to display size vs requested size, it should be reviewed or removed...
|
||||
// HighDPI monitors are properly considered in a following similar function: SetupViewport()
|
||||
SetupFramebuffer(CORE.Window.display.width, CORE.Window.display.height);
|
||||
|
||||
platform.handle = glfwCreateWindow(CORE.Window.display.width, CORE.Window.display.height, (CORE.Window.title != 0)? CORE.Window.title : " ", monitor, NULL);
|
||||
if (!platform.handle)
|
||||
{
|
||||
@ -1614,20 +1578,14 @@ int InitPlatform(void)
|
||||
TRACELOG(LOG_WARNING, "GLFW: Failed to initialize Window");
|
||||
return -1;
|
||||
}
|
||||
|
||||
// NOTE: Full-screen change, not working properly...
|
||||
//glfwSetWindowMonitor(platform.handle, glfwGetPrimaryMonitor(), 0, 0, CORE.Window.screen.width, CORE.Window.screen.height, GLFW_DONT_CARE);
|
||||
}
|
||||
else
|
||||
{
|
||||
// No-fullscreen window creation
|
||||
bool requestWindowedFullscreen = (CORE.Window.screen.height == 0) && (CORE.Window.screen.width == 0);
|
||||
|
||||
// Default to at least one pixel in size, as creation with a zero dimension is not allowed
|
||||
int creationWidth = (CORE.Window.screen.width != 0)? CORE.Window.screen.width : 1;
|
||||
int creationHeight = (CORE.Window.screen.height != 0)? CORE.Window.screen.height : 1;
|
||||
if (CORE.Window.screen.width == 0) CORE.Window.screen.width = 1;
|
||||
if (CORE.Window.screen.height == 0) CORE.Window.screen.height = 1;
|
||||
|
||||
platform.handle = glfwCreateWindow(creationWidth, creationHeight, (CORE.Window.title != 0)? CORE.Window.title : " ", NULL, NULL);
|
||||
platform.handle = glfwCreateWindow(CORE.Window.screen.width, CORE.Window.screen.height, (CORE.Window.title != 0)? CORE.Window.title : " ", NULL, NULL);
|
||||
if (!platform.handle)
|
||||
{
|
||||
glfwTerminate();
|
||||
@ -1636,7 +1594,7 @@ int InitPlatform(void)
|
||||
}
|
||||
|
||||
// After the window was created, determine the monitor that the window manager assigned
|
||||
// Derive display sizes, and, if possible, window size in case it was zero at beginning
|
||||
// Derive display sizes and, if possible, window size in case it was zero at beginning
|
||||
|
||||
int monitorCount = 0;
|
||||
int monitorIndex = GetCurrentMonitor();
|
||||
@ -1644,7 +1602,7 @@ int InitPlatform(void)
|
||||
|
||||
if (monitorIndex < monitorCount)
|
||||
{
|
||||
monitor = monitors[monitorIndex];
|
||||
GLFWmonitor *monitor = monitors[monitorIndex];
|
||||
const GLFWvidmode *mode = glfwGetVideoMode(monitor);
|
||||
|
||||
// Default display resolution to that of the current mode
|
||||
@ -1655,7 +1613,7 @@ int InitPlatform(void)
|
||||
if (CORE.Window.screen.width == 0) CORE.Window.screen.width = CORE.Window.display.width;
|
||||
if (CORE.Window.screen.height == 0) CORE.Window.screen.height = CORE.Window.display.height;
|
||||
|
||||
if (requestWindowedFullscreen) glfwSetWindowSize(platform.handle, CORE.Window.screen.width, CORE.Window.screen.height);
|
||||
glfwSetWindowSize(platform.handle, CORE.Window.screen.width, CORE.Window.screen.height);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -1697,6 +1655,8 @@ int InitPlatform(void)
|
||||
{
|
||||
// NOTE: On APPLE platforms system should manage window/input scaling and also framebuffer scaling
|
||||
// Framebuffer scaling is activated with: glfwWindowHint(GLFW_SCALE_FRAMEBUFFER, GLFW_TRUE);
|
||||
|
||||
// Get current framebuffer size, on high-dpi it could be bigger than screen size
|
||||
glfwGetFramebufferSize(platform.handle, &fbWidth, &fbHeight);
|
||||
|
||||
// Screen scaling matrix is required in case desired screen area is different from display area
|
||||
@ -1730,6 +1690,11 @@ int InitPlatform(void)
|
||||
if (!CORE.Window.ready) { TRACELOG(LOG_FATAL, "PLATFORM: Failed to initialize graphic device"); return -1; }
|
||||
else
|
||||
{
|
||||
int monitorCount = 0;
|
||||
int monitorIndex = GetCurrentMonitor();
|
||||
GLFWmonitor **monitors = glfwGetMonitors(&monitorCount);
|
||||
GLFWmonitor *monitor = monitors[monitorIndex];
|
||||
|
||||
// Try to center window on screen but avoiding window-bar outside of screen
|
||||
int monitorX = 0;
|
||||
int monitorY = 0;
|
||||
@ -1737,7 +1702,7 @@ int InitPlatform(void)
|
||||
int monitorHeight = 0;
|
||||
glfwGetMonitorWorkarea(monitor, &monitorX, &monitorY, &monitorWidth, &monitorHeight);
|
||||
|
||||
// Here CORE.Window.render.width/height should be used instead of
|
||||
// TODO: Here CORE.Window.render.width/height should be used instead of
|
||||
// CORE.Window.screen.width/height to center the window correctly when the high dpi flag is enabled
|
||||
int posX = monitorX + (monitorWidth - (int)CORE.Window.render.width)/2;
|
||||
int posY = monitorY + (monitorHeight - (int)CORE.Window.render.height)/2;
|
||||
@ -1874,19 +1839,38 @@ static void FramebufferSizeCallback(GLFWwindow *window, int width, int height)
|
||||
CORE.Window.currentFbo.height = height;
|
||||
CORE.Window.resizedLastFrame = true;
|
||||
|
||||
// Check if render size was actually scaled for high-dpi
|
||||
if (FLAG_IS_SET(CORE.Window.flags, FLAG_WINDOW_HIGHDPI))
|
||||
{
|
||||
// Set screen size to logical pixel size, considering content scaling
|
||||
Vector2 scaleDpi = GetWindowScaleDPI();
|
||||
CORE.Window.screen.width = (int)((float)width/scaleDpi.x);
|
||||
CORE.Window.screen.height = (int)((float)height/scaleDpi.y);
|
||||
}
|
||||
else
|
||||
if (FLAG_IS_SET(CORE.Window.flags, FLAG_FULLSCREEN_MODE))
|
||||
{
|
||||
// On fullscreen mode, strategy is ignoring high-dpi and
|
||||
// use the all available display size
|
||||
|
||||
// Set screen size to render size (physical pixel size)
|
||||
CORE.Window.screen.width = width;
|
||||
CORE.Window.screen.height = height;
|
||||
CORE.Window.screenScale = MatrixScale(1.0f, 1.0f, 1.0f);
|
||||
SetMouseScale(1.0f, 1.0f);
|
||||
}
|
||||
else // Window mode (including borderless window)
|
||||
{
|
||||
// Check if render size was actually scaled for high-dpi
|
||||
if (FLAG_IS_SET(CORE.Window.flags, FLAG_WINDOW_HIGHDPI))
|
||||
{
|
||||
// Set screen size to logical pixel size, considering content scaling
|
||||
Vector2 scaleDpi = GetWindowScaleDPI();
|
||||
CORE.Window.screen.width = (int)((float)width/scaleDpi.x);
|
||||
CORE.Window.screen.height = (int)((float)height/scaleDpi.y);
|
||||
CORE.Window.screenScale = MatrixScale(scaleDpi.x, scaleDpi.y, 1.0f);
|
||||
#if !defined(__APPLE__)
|
||||
// Mouse input scaling for the new screen size
|
||||
SetMouseScale(1.0f/scaleDpi.x, 1.0f/scaleDpi.y);
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
// Set screen size to render size (physical pixel size)
|
||||
CORE.Window.screen.width = width;
|
||||
CORE.Window.screen.height = height;
|
||||
}
|
||||
}
|
||||
|
||||
// WARNING: If using a render texture, it is not scaled to new size
|
||||
@ -1896,7 +1880,7 @@ static void FramebufferSizeCallback(GLFWwindow *window, int width, int height)
|
||||
// WARNING: If FLAG_WINDOW_HIGHDPI is not set, this function is not called
|
||||
static void WindowContentScaleCallback(GLFWwindow *window, float scalex, float scaley)
|
||||
{
|
||||
TRACELOG(LOG_INFO, "GLFW3: Window content scale changed, scale: [%.2f,%.2f]", scalex, scaley);
|
||||
//TRACELOG(LOG_INFO, "GLFW3: Window content scale changed, scale: [%.2f,%.2f]", scalex, scaley);
|
||||
|
||||
float fbWidth = (float)CORE.Window.screen.width*scalex;
|
||||
float fbHeight = (float)CORE.Window.screen.height*scaley;
|
||||
@ -1907,13 +1891,12 @@ static void WindowContentScaleCallback(GLFWwindow *window, float scalex, float s
|
||||
|
||||
#if !defined(__APPLE__)
|
||||
// Mouse input scaling for the new screen size
|
||||
SetMouseScale((float)CORE.Window.screen.width/fbWidth, (float)CORE.Window.screen.height/fbHeight);
|
||||
SetMouseScale(1.0f/scalex, 1.0f/scaley);
|
||||
#endif
|
||||
|
||||
CORE.Window.render.width = (int)fbWidth;
|
||||
CORE.Window.render.height = (int)fbHeight;
|
||||
CORE.Window.currentFbo.width = (int)fbWidth;
|
||||
CORE.Window.currentFbo.height = (int)fbHeight;
|
||||
CORE.Window.currentFbo = CORE.Window.render;
|
||||
}
|
||||
|
||||
// GLFW3: Window position callback, runs when window position changes
|
||||
|
||||
@ -290,14 +290,13 @@ bool WindowShouldClose(void)
|
||||
// Toggle fullscreen mode
|
||||
void ToggleFullscreen(void)
|
||||
{
|
||||
if (!CORE.Window.fullscreen)
|
||||
if (!FLAG_IS_SET(CORE.Window.flags, FLAG_FULLSCREEN_MODE))
|
||||
{
|
||||
// Store previous window position (in case we exit fullscreen)
|
||||
CORE.Window.previousPosition = CORE.Window.position;
|
||||
CORE.Window.previousScreen = CORE.Window.screen;
|
||||
|
||||
platform.mon = RGFW_window_getMonitor(platform.window);
|
||||
CORE.Window.fullscreen = true;
|
||||
FLAG_SET(CORE.Window.flags, FLAG_FULLSCREEN_MODE);
|
||||
|
||||
RGFW_monitor_scaleToWindow(platform.mon, platform.window);
|
||||
@ -305,7 +304,6 @@ void ToggleFullscreen(void)
|
||||
}
|
||||
else
|
||||
{
|
||||
CORE.Window.fullscreen = false;
|
||||
FLAG_CLEAR(CORE.Window.flags, FLAG_FULLSCREEN_MODE);
|
||||
|
||||
if (platform.mon.mode.area.w)
|
||||
@ -331,7 +329,9 @@ void ToggleFullscreen(void)
|
||||
// Toggle borderless windowed mode
|
||||
void ToggleBorderlessWindowed(void)
|
||||
{
|
||||
if (CORE.Window.fullscreen)
|
||||
if (FLAG_IS_SET(CORE.Window.flags, FLAG_FULLSCREEN_MODE)) ToggleFullscreen();
|
||||
|
||||
if (FLAG_IS_SET(CORE.Window.flags, FLAG_BORDERLESS_WINDOWED_MODE))
|
||||
{
|
||||
CORE.Window.previousPosition = CORE.Window.position;
|
||||
CORE.Window.previousScreen = CORE.Window.screen;
|
||||
@ -348,8 +348,6 @@ void ToggleBorderlessWindowed(void)
|
||||
CORE.Window.position = CORE.Window.previousPosition;
|
||||
RGFW_window_resize(platform.window, RGFW_AREA(CORE.Window.previousScreen.width, CORE.Window.previousScreen.height));
|
||||
}
|
||||
|
||||
CORE.Window.fullscreen = !CORE.Window.fullscreen;
|
||||
}
|
||||
|
||||
// Set window state: maximized, if resizable
|
||||
@ -385,7 +383,7 @@ void SetWindowState(unsigned int flags)
|
||||
}
|
||||
if (FLAG_IS_SET(flags, FLAG_FULLSCREEN_MODE))
|
||||
{
|
||||
if (!CORE.Window.fullscreen) ToggleFullscreen();
|
||||
ToggleFullscreen();
|
||||
}
|
||||
if (FLAG_IS_SET(flags, FLAG_WINDOW_RESIZABLE))
|
||||
{
|
||||
@ -459,7 +457,7 @@ void ClearWindowState(unsigned int flags)
|
||||
}
|
||||
if (FLAG_IS_SET(flags, FLAG_FULLSCREEN_MODE))
|
||||
{
|
||||
if (CORE.Window.fullscreen) ToggleFullscreen();
|
||||
ToggleFullscreen();
|
||||
}
|
||||
if (FLAG_IS_SET(flags, FLAG_WINDOW_RESIZABLE))
|
||||
{
|
||||
@ -510,7 +508,7 @@ void ClearWindowState(unsigned int flags)
|
||||
}
|
||||
if (FLAG_IS_SET(flags, FLAG_BORDERLESS_WINDOWED_MODE))
|
||||
{
|
||||
if (CORE.Window.fullscreen) ToggleBorderlessWindowed();
|
||||
ToggleBorderlessWindowed();
|
||||
}
|
||||
if (FLAG_IS_SET(flags, FLAG_MSAA_4X_HINT))
|
||||
{
|
||||
@ -1258,13 +1256,11 @@ int InitPlatform(void)
|
||||
// Check window creation flags
|
||||
if (FLAG_IS_SET(CORE.Window.flags, FLAG_FULLSCREEN_MODE))
|
||||
{
|
||||
CORE.Window.fullscreen = true;
|
||||
FLAG_SET(flags, RGFW_windowFullscreen);
|
||||
}
|
||||
|
||||
if (FLAG_IS_SET(CORE.Window.flags, FLAG_BORDERLESS_WINDOWED_MODE))
|
||||
{
|
||||
CORE.Window.fullscreen = true;
|
||||
FLAG_SET(flags, RGFW_windowedFullscreen);
|
||||
}
|
||||
|
||||
@ -1315,10 +1311,6 @@ int InitPlatform(void)
|
||||
CORE.Window.display.width = CORE.Window.screen.width;
|
||||
CORE.Window.display.height = CORE.Window.screen.height;
|
||||
#endif
|
||||
// TODO: Is this needed by raylib now?
|
||||
// If so, rcore_desktop_sdl should be updated too
|
||||
//SetupFramebuffer(CORE.Window.display.width, CORE.Window.display.height);
|
||||
|
||||
if (FLAG_IS_SET(CORE.Window.flags, FLAG_VSYNC_HINT)) RGFW_window_swapInterval(platform.window, 1);
|
||||
RGFW_window_makeCurrent(platform.window);
|
||||
|
||||
|
||||
@ -472,13 +472,11 @@ void ToggleFullscreen(void)
|
||||
{
|
||||
SDL_SetWindowFullscreen(platform.window, 0);
|
||||
FLAG_CLEAR(CORE.Window.flags, FLAG_FULLSCREEN_MODE);
|
||||
CORE.Window.fullscreen = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
SDL_SetWindowFullscreen(platform.window, SDL_WINDOW_FULLSCREEN);
|
||||
FLAG_SET(CORE.Window.flags, FLAG_FULLSCREEN_MODE);
|
||||
CORE.Window.fullscreen = true;
|
||||
}
|
||||
}
|
||||
else TRACELOG(LOG_WARNING, "SDL: Failed to find selected monitor");
|
||||
@ -554,7 +552,7 @@ void SetWindowState(unsigned int flags)
|
||||
#endif
|
||||
{
|
||||
SDL_SetWindowFullscreen(platform.window, SDL_WINDOW_FULLSCREEN);
|
||||
CORE.Window.fullscreen = true;
|
||||
FLAG_SET(CORE.Window.flags, FLAG_FULLSCREEN_MODE);
|
||||
}
|
||||
else TRACELOG(LOG_WARNING, "SDL: Failed to find selected monitor");
|
||||
}
|
||||
@ -644,7 +642,6 @@ void ClearWindowState(unsigned int flags)
|
||||
if (FLAG_IS_SET(flags, FLAG_FULLSCREEN_MODE))
|
||||
{
|
||||
SDL_SetWindowFullscreen(platform.window, 0);
|
||||
CORE.Window.fullscreen = false;
|
||||
}
|
||||
if (FLAG_IS_SET(flags, FLAG_WINDOW_RESIZABLE))
|
||||
{
|
||||
@ -1937,11 +1934,7 @@ int InitPlatform(void)
|
||||
FLAG_SET(flags, SDL_WINDOW_MOUSE_CAPTURE); // Window has mouse captured
|
||||
|
||||
// Check window creation flags
|
||||
if (FLAG_IS_SET(CORE.Window.flags, FLAG_FULLSCREEN_MODE))
|
||||
{
|
||||
CORE.Window.fullscreen = true;
|
||||
FLAG_SET(flags, SDL_WINDOW_FULLSCREEN);
|
||||
}
|
||||
if (FLAG_IS_SET(CORE.Window.flags, FLAG_FULLSCREEN_MODE)) FLAG_SET(flags, SDL_WINDOW_FULLSCREEN);
|
||||
|
||||
//if (!FLAG_IS_SET(CORE.Window.flags, FLAG_WINDOW_HIDDEN)) FLAG_SET(flags, SDL_WINDOW_HIDDEN);
|
||||
if (FLAG_IS_SET(CORE.Window.flags, FLAG_WINDOW_UNDECORATED)) FLAG_SET(flags, SDL_WINDOW_BORDERLESS);
|
||||
|
||||
@ -2049,8 +2049,7 @@ static void HandleWindowResize(HWND hwnd, int *width, int *height)
|
||||
// TODO: Update framebuffer on resize
|
||||
CORE.Window.currentFbo.width = (int)clientSize.cx;
|
||||
CORE.Window.currentFbo.height = (int)clientSize.cy;
|
||||
//glViewport(0, 0, clientSize.cx, clientSize.cy);
|
||||
//SetupFramebuffer(0, 0);
|
||||
//SetupViewport(0, 0, clientSize.cx, clientSize.cy);
|
||||
|
||||
SetupViewport(clientSize.cx, clientSize.cy);
|
||||
CORE.Window.resizedLastFrame = true;
|
||||
|
||||
@ -265,6 +265,8 @@ static int FindMatchingConnectorMode(const drmModeConnector *connector, const dr
|
||||
static int FindExactConnectorMode(const drmModeConnector *connector, uint width, uint height, uint fps, bool allowInterlaced); // Search exactly matching DRM connector mode in connector's list
|
||||
static int FindNearestConnectorMode(const drmModeConnector *connector, uint width, uint height, uint fps, bool allowInterlaced); // Search the nearest matching DRM connector mode in connector's list
|
||||
|
||||
static void SetupFramebuffer(int width, int height); // Setup main framebuffer (required by InitPlatform())
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// Module Functions Declaration
|
||||
//----------------------------------------------------------------------------------
|
||||
@ -1147,7 +1149,6 @@ int InitPlatform(void)
|
||||
|
||||
// Initialize graphic device: display/window and graphic context
|
||||
//----------------------------------------------------------------------------
|
||||
CORE.Window.fullscreen = true;
|
||||
FLAG_SET(CORE.Window.flags, FLAG_FULLSCREEN_MODE);
|
||||
|
||||
#if defined(DEFAULT_GRAPHIC_DEVICE_DRM)
|
||||
@ -2479,4 +2480,82 @@ static int FindNearestConnectorMode(const drmModeConnector *connector, uint widt
|
||||
return nearestIndex;
|
||||
}
|
||||
|
||||
// Compute framebuffer size relative to screen size and display size
|
||||
// NOTE: Global variables CORE.Window.render.width/CORE.Window.render.height and CORE.Window.renderOffset.x/CORE.Window.renderOffset.y can be modified
|
||||
static void SetupFramebuffer(int width, int height)
|
||||
{
|
||||
// Calculate CORE.Window.render.width and CORE.Window.render.height, we have the display size (input params) and the desired screen size (global var)
|
||||
if ((CORE.Window.screen.width > CORE.Window.display.width) || (CORE.Window.screen.height > CORE.Window.display.height))
|
||||
{
|
||||
TRACELOG(LOG_WARNING, "DISPLAY: Downscaling required: Screen size (%ix%i) is bigger than display size (%ix%i)", CORE.Window.screen.width, CORE.Window.screen.height, CORE.Window.display.width, CORE.Window.display.height);
|
||||
|
||||
// Downscaling to fit display with border-bars
|
||||
float widthRatio = (float)CORE.Window.display.width/(float)CORE.Window.screen.width;
|
||||
float heightRatio = (float)CORE.Window.display.height/(float)CORE.Window.screen.height;
|
||||
|
||||
if (widthRatio <= heightRatio)
|
||||
{
|
||||
CORE.Window.render.width = CORE.Window.display.width;
|
||||
CORE.Window.render.height = (int)round((float)CORE.Window.screen.height*widthRatio);
|
||||
CORE.Window.renderOffset.x = 0;
|
||||
CORE.Window.renderOffset.y = (CORE.Window.display.height - CORE.Window.render.height);
|
||||
}
|
||||
else
|
||||
{
|
||||
CORE.Window.render.width = (int)round((float)CORE.Window.screen.width*heightRatio);
|
||||
CORE.Window.render.height = CORE.Window.display.height;
|
||||
CORE.Window.renderOffset.x = (CORE.Window.display.width - CORE.Window.render.width);
|
||||
CORE.Window.renderOffset.y = 0;
|
||||
}
|
||||
|
||||
// Screen scaling required
|
||||
float scaleRatio = (float)CORE.Window.render.width/(float)CORE.Window.screen.width;
|
||||
CORE.Window.screenScale = MatrixScale(scaleRatio, scaleRatio, 1.0f);
|
||||
|
||||
// NOTE: We render to full display resolution!
|
||||
// We just need to calculate above parameters for downscale matrix and offsets
|
||||
CORE.Window.render.width = CORE.Window.display.width;
|
||||
CORE.Window.render.height = CORE.Window.display.height;
|
||||
|
||||
TRACELOG(LOG_WARNING, "DISPLAY: Downscale matrix generated, content will be rendered at (%ix%i)", CORE.Window.render.width, CORE.Window.render.height);
|
||||
}
|
||||
else if ((CORE.Window.screen.width < CORE.Window.display.width) || (CORE.Window.screen.height < CORE.Window.display.height))
|
||||
{
|
||||
// Required screen size is smaller than display size
|
||||
TRACELOG(LOG_INFO, "DISPLAY: Upscaling required: Screen size (%ix%i) smaller than display size (%ix%i)", CORE.Window.screen.width, CORE.Window.screen.height, CORE.Window.display.width, CORE.Window.display.height);
|
||||
|
||||
if ((CORE.Window.screen.width == 0) || (CORE.Window.screen.height == 0))
|
||||
{
|
||||
CORE.Window.screen.width = CORE.Window.display.width;
|
||||
CORE.Window.screen.height = CORE.Window.display.height;
|
||||
}
|
||||
|
||||
// Upscaling to fit display with border-bars
|
||||
float displayRatio = (float)CORE.Window.display.width/(float)CORE.Window.display.height;
|
||||
float screenRatio = (float)CORE.Window.screen.width/(float)CORE.Window.screen.height;
|
||||
|
||||
if (displayRatio <= screenRatio)
|
||||
{
|
||||
CORE.Window.render.width = CORE.Window.screen.width;
|
||||
CORE.Window.render.height = (int)round((float)CORE.Window.screen.width/displayRatio);
|
||||
CORE.Window.renderOffset.x = 0;
|
||||
CORE.Window.renderOffset.y = (CORE.Window.render.height - CORE.Window.screen.height);
|
||||
}
|
||||
else
|
||||
{
|
||||
CORE.Window.render.width = (int)round((float)CORE.Window.screen.height*displayRatio);
|
||||
CORE.Window.render.height = CORE.Window.screen.height;
|
||||
CORE.Window.renderOffset.x = (CORE.Window.render.width - CORE.Window.screen.width);
|
||||
CORE.Window.renderOffset.y = 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
CORE.Window.render.width = CORE.Window.screen.width;
|
||||
CORE.Window.render.height = CORE.Window.screen.height;
|
||||
CORE.Window.renderOffset.x = 0;
|
||||
CORE.Window.renderOffset.y = 0;
|
||||
}
|
||||
}
|
||||
|
||||
// EOF
|
||||
|
||||
@ -454,7 +454,6 @@ int InitPlatform(void)
|
||||
// raylib uses OpenGL so, platform should create that kind of connection
|
||||
// Below example illustrates that process using EGL library
|
||||
//----------------------------------------------------------------------------
|
||||
CORE.Window.fullscreen = true;
|
||||
FLAG_SET(CORE.Window.flags, FLAG_FULLSCREEN_MODE);
|
||||
|
||||
if (FLAG_IS_SET(CORE.Window.flags, FLAG_MSAA_4X_HINT))
|
||||
|
||||
@ -204,7 +204,6 @@ void ToggleFullscreen(void)
|
||||
|
||||
EM_ASM(document.exitFullscreen(););
|
||||
|
||||
CORE.Window.fullscreen = false;
|
||||
FLAG_CLEAR(CORE.Window.flags, FLAG_FULLSCREEN_MODE);
|
||||
FLAG_CLEAR(CORE.Window.flags, FLAG_BORDERLESS_WINDOWED_MODE);
|
||||
}
|
||||
@ -213,14 +212,12 @@ void ToggleFullscreen(void)
|
||||
if (enterFullscreen)
|
||||
{
|
||||
// NOTE: The setTimeouts handle the browser mode change delay
|
||||
EM_ASM
|
||||
(
|
||||
setTimeout(function()
|
||||
{
|
||||
EM_ASM(
|
||||
setTimeout(function(){
|
||||
Module.requestFullscreen(false, false);
|
||||
}, 100);
|
||||
);
|
||||
CORE.Window.fullscreen = true;
|
||||
|
||||
FLAG_SET(CORE.Window.flags, FLAG_FULLSCREEN_MODE);
|
||||
}
|
||||
|
||||
@ -238,7 +235,7 @@ void ToggleFullscreen(void)
|
||||
*/
|
||||
// EM_ASM(Module.requestFullscreen(false, false););
|
||||
/*
|
||||
if (!CORE.Window.fullscreen)
|
||||
if (!FLAG_IS_SET(CORE.Window.flags, FLAG_FULLSCREEN_MODE))
|
||||
{
|
||||
// Option 1: Request fullscreen for the canvas element
|
||||
// This option does not seem to work at all:
|
||||
@ -274,7 +271,6 @@ void ToggleFullscreen(void)
|
||||
emscripten_get_canvas_element_size(platform.canvasId, &width, &height);
|
||||
TRACELOG(LOG_WARNING, "Emscripten: Enter fullscreen: Canvas size: %i x %i", width, height);
|
||||
|
||||
CORE.Window.fullscreen = true; // Toggle fullscreen flag
|
||||
FLAG_SET(CORE.Window.flags, FLAG_FULLSCREEN_MODE);
|
||||
}
|
||||
else
|
||||
@ -286,7 +282,6 @@ void ToggleFullscreen(void)
|
||||
emscripten_get_canvas_element_size(platform.canvasId, &width, &height);
|
||||
TRACELOG(LOG_WARNING, "Emscripten: Exit fullscreen: Canvas size: %i x %i", width, height);
|
||||
|
||||
CORE.Window.fullscreen = false; // Toggle fullscreen flag
|
||||
FLAG_CLEAR(CORE.Window.flags, FLAG_FULLSCREEN_MODE);
|
||||
}
|
||||
*/
|
||||
@ -313,7 +308,6 @@ void ToggleBorderlessWindowed(void)
|
||||
|
||||
EM_ASM(document.exitFullscreen(););
|
||||
|
||||
CORE.Window.fullscreen = false;
|
||||
FLAG_CLEAR(CORE.Window.flags, FLAG_FULLSCREEN_MODE);
|
||||
FLAG_CLEAR(CORE.Window.flags, FLAG_BORDERLESS_WINDOWED_MODE);
|
||||
}
|
||||
@ -545,7 +539,6 @@ void ClearWindowState(unsigned int flags)
|
||||
if (FLAG_IS_SET(CORE.Window.flags, FLAG_FULLSCREEN_MODE) || (canvasStyleWidth > canvasWidth)) EM_ASM(document.exitFullscreen(););
|
||||
}
|
||||
|
||||
CORE.Window.fullscreen = false;
|
||||
FLAG_CLEAR(CORE.Window.flags, FLAG_FULLSCREEN_MODE);
|
||||
}
|
||||
|
||||
@ -1155,8 +1148,6 @@ int InitPlatform(void)
|
||||
// glfwWindowHint(GLFW_AUX_BUFFERS, 0); // Number of auxiliar buffers
|
||||
|
||||
// Check window creation flags
|
||||
if (FLAG_IS_SET(CORE.Window.flags, FLAG_FULLSCREEN_MODE)) CORE.Window.fullscreen = true;
|
||||
|
||||
if (FLAG_IS_SET(CORE.Window.flags, FLAG_WINDOW_HIDDEN)) glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE); // Visible window
|
||||
else glfwWindowHint(GLFW_VISIBLE, GLFW_TRUE); // Window initially hidden
|
||||
|
||||
@ -1260,7 +1251,7 @@ int InitPlatform(void)
|
||||
// TODO: Consider requesting another type of canvas, not a WebGL one --> Replace GLFW-web by Emscripten?
|
||||
platform.pixels = (unsigned int *)RL_CALLOC(CORE.Window.screen.width*CORE.Window.screen.height, sizeof(unsigned int));
|
||||
#else
|
||||
if (CORE.Window.fullscreen)
|
||||
if (FLAG_IS_SET(CORE.Window.flags, FLAG_FULLSCREEN_MODE))
|
||||
{
|
||||
// remember center for switchinging from fullscreen to window
|
||||
if ((CORE.Window.screen.height == CORE.Window.display.height) && (CORE.Window.screen.width == CORE.Window.display.width))
|
||||
@ -1299,18 +1290,6 @@ int InitPlatform(void)
|
||||
|
||||
TRACELOG(LOG_WARNING, "SYSTEM: Closest fullscreen videomode: %i x %i", CORE.Window.display.width, CORE.Window.display.height);
|
||||
|
||||
// NOTE: ISSUE: Closest videomode could not match monitor aspect-ratio, for example,
|
||||
// for a desired screen size of 800x450 (16:9), closest supported videomode is 800x600 (4:3),
|
||||
// framebuffer is rendered correctly but once displayed on a 16:9 monitor, it gets stretched
|
||||
// by the sides to fit all monitor space...
|
||||
|
||||
// Try to setup the most appropriate fullscreen framebuffer for the requested screenWidth/screenHeight
|
||||
// It considers device display resolution mode and setups a framebuffer with black bars if required (render size/offset)
|
||||
// Modified global variables: CORE.Window.screen.width/CORE.Window.screen.height - CORE.Window.render.width/CORE.Window.render.height - CORE.Window.renderOffset.x/CORE.Window.renderOffset.y - CORE.Window.screenScale
|
||||
// TODO: It is a quite cumbersome solution to display size vs requested size, it should be reviewed or removed...
|
||||
// HighDPI monitors are properly considered in a following similar function: SetupViewport()
|
||||
SetupFramebuffer(CORE.Window.display.width, CORE.Window.display.height);
|
||||
|
||||
platform.handle = glfwCreateWindow(CORE.Window.display.width, CORE.Window.display.height, (CORE.Window.title != 0)? CORE.Window.title : " ", glfwGetPrimaryMonitor(), NULL);
|
||||
|
||||
// NOTE: Full-screen change, not working properly...
|
||||
@ -1830,7 +1809,6 @@ static EM_BOOL EmscriptenFullscreenChangeCallback(int eventType, const Emscripte
|
||||
const bool wasFullscreen = EM_ASM_INT( { if (document.fullscreenElement) return 1; }, 0);
|
||||
if (!wasFullscreen)
|
||||
{
|
||||
CORE.Window.fullscreen = false;
|
||||
FLAG_CLEAR(CORE.Window.flags, FLAG_FULLSCREEN_MODE);
|
||||
FLAG_CLEAR(CORE.Window.flags, FLAG_BORDERLESS_WINDOWED_MODE);
|
||||
}
|
||||
|
||||
@ -167,7 +167,6 @@ void ToggleFullscreen(void)
|
||||
|
||||
EM_ASM(document.exitFullscreen(););
|
||||
|
||||
CORE.Window.fullscreen = false;
|
||||
FLAG_CLEAR(CORE.Window.flags, FLAG_FULLSCREEN_MODE);
|
||||
FLAG_CLEAR(CORE.Window.flags, FLAG_BORDERLESS_WINDOWED_MODE);
|
||||
}
|
||||
@ -183,7 +182,7 @@ void ToggleFullscreen(void)
|
||||
Module.requestFullscreen(false, false);
|
||||
}, 100);
|
||||
);
|
||||
CORE.Window.fullscreen = true;
|
||||
|
||||
FLAG_SET(CORE.Window.flags, FLAG_FULLSCREEN_MODE);
|
||||
}
|
||||
|
||||
@ -201,7 +200,7 @@ void ToggleFullscreen(void)
|
||||
*/
|
||||
// EM_ASM(Module.requestFullscreen(false, false););
|
||||
/*
|
||||
if (!CORE.Window.fullscreen)
|
||||
if (!FLAG_IS_SET(CORE.Window.flags, FLAG_FULLSCREEN_MODE))
|
||||
{
|
||||
// Option 1: Request fullscreen for the canvas element
|
||||
// This option does not seem to work at all:
|
||||
@ -237,7 +236,6 @@ void ToggleFullscreen(void)
|
||||
emscripten_get_canvas_element_size("#canvas", &width, &height);
|
||||
TRACELOG(LOG_WARNING, "Emscripten: Enter fullscreen: Canvas size: %i x %i", width, height);
|
||||
|
||||
CORE.Window.fullscreen = true; // Toggle fullscreen flag
|
||||
FLAG_SET(CORE.Window.flags, FLAG_FULLSCREEN_MODE);
|
||||
}
|
||||
else
|
||||
@ -249,7 +247,6 @@ void ToggleFullscreen(void)
|
||||
emscripten_get_canvas_element_size("#canvas", &width, &height);
|
||||
TRACELOG(LOG_WARNING, "Emscripten: Exit fullscreen: Canvas size: %i x %i", width, height);
|
||||
|
||||
CORE.Window.fullscreen = false; // Toggle fullscreen flag
|
||||
FLAG_CLEAR(CORE.Window.flags, FLAG_FULLSCREEN_MODE);
|
||||
}
|
||||
*/
|
||||
@ -275,7 +272,6 @@ void ToggleBorderlessWindowed(void)
|
||||
|
||||
EM_ASM(document.exitFullscreen(););
|
||||
|
||||
CORE.Window.fullscreen = false;
|
||||
FLAG_CLEAR(CORE.Window.flags, FLAG_FULLSCREEN_MODE);
|
||||
FLAG_CLEAR(CORE.Window.flags, FLAG_BORDERLESS_WINDOWED_MODE);
|
||||
}
|
||||
@ -494,7 +490,6 @@ void ClearWindowState(unsigned int flags)
|
||||
if (FLAG_IS_SET(CORE.Window.flags, FLAG_FULLSCREEN_MODE) || (canvasStyleWidth > canvasWidth)) EM_ASM(document.exitFullscreen(););
|
||||
}
|
||||
|
||||
CORE.Window.fullscreen = false;
|
||||
FLAG_CLEAR(CORE.Window.flags, FLAG_FULLSCREEN_MODE);
|
||||
}
|
||||
|
||||
@ -1117,8 +1112,6 @@ int InitPlatform(void)
|
||||
attribs.antialias = EM_FALSE;
|
||||
|
||||
// Check window creation flags
|
||||
//if (FLAG_IS_SET(CORE.Window.flags, FLAG_FULLSCREEN_MODE)) CORE.Window.fullscreen = true;
|
||||
|
||||
// Disable FLAG_WINDOW_MINIMIZED, not supported
|
||||
if (FLAG_IS_SET(CORE.Window.flags, FLAG_WINDOW_MINIMIZED)) FLAG_CLEAR(CORE.Window.flags, FLAG_WINDOW_MINIMIZED);
|
||||
|
||||
@ -1354,7 +1347,6 @@ static EM_BOOL EmscriptenFullscreenChangeCallback(int eventType, const Emscripte
|
||||
const bool wasFullscreen = EM_ASM_INT( { if (document.fullscreenElement) return 1; }, 0);
|
||||
if (!wasFullscreen)
|
||||
{
|
||||
CORE.Window.fullscreen = false;
|
||||
FLAG_CLEAR(CORE.Window.flags, FLAG_FULLSCREEN_MODE);
|
||||
FLAG_CLEAR(CORE.Window.flags, FLAG_BORDERLESS_WINDOWED_MODE);
|
||||
}
|
||||
|
||||
122
src/rcore.c
122
src/rcore.c
@ -287,20 +287,19 @@ typedef struct CoreData {
|
||||
const char *title; // Window text title const pointer
|
||||
unsigned int flags; // Configuration flags (bit based), keeps window state
|
||||
bool ready; // Check if window has been initialized successfully
|
||||
bool fullscreen; // Check if fullscreen mode is enabled
|
||||
bool shouldClose; // Check if window set for closing
|
||||
bool resizedLastFrame; // Check if window has been resized last frame
|
||||
bool eventWaiting; // Wait for events before ending frame
|
||||
bool usingFbo; // Using FBO (RenderTexture) for rendering instead of default framebuffer
|
||||
|
||||
Point position; // Window position (required on fullscreen toggle)
|
||||
Point previousPosition; // Window previous position (required on borderless windowed toggle)
|
||||
Size display; // Display width and height (monitor, device-screen, LCD, ...)
|
||||
Size screen; // Screen width and height (used render area)
|
||||
Size previousScreen; // Screen previous width and height (required on borderless windowed toggle)
|
||||
Size currentFbo; // Current render width and height (depends on active fbo)
|
||||
Size render; // Framebuffer width and height (render area, including black bars if required)
|
||||
Point renderOffset; // Offset from render area (must be divided by 2)
|
||||
Size screen; // Screen current width and height
|
||||
Point position; // Window current position
|
||||
Size previousScreen; // Screen previous width and height (required on fullscreen/borderless-windowed toggle)
|
||||
Point previousPosition; // Window previous position (required on fullscreeen/borderless-windowed toggle)
|
||||
Size render; // Screen framebuffer width and height
|
||||
Point renderOffset; // Screen framebuffer render offset (Not required anymore?)
|
||||
Size currentFbo; // Current framebuffer render width and height (depends on active render texture)
|
||||
Size screenMin; // Screen minimum width and height (for resizable window)
|
||||
Size screenMax; // Screen maximum width and height (for resizable window)
|
||||
Matrix screenScale; // Matrix to scale screen (framebuffer rendering)
|
||||
@ -316,17 +315,17 @@ typedef struct CoreData {
|
||||
struct {
|
||||
struct {
|
||||
int exitKey; // Default exit key
|
||||
char currentKeyState[MAX_KEYBOARD_KEYS]; // Registers current frame key state
|
||||
char previousKeyState[MAX_KEYBOARD_KEYS]; // Registers previous frame key state
|
||||
char currentKeyState[MAX_KEYBOARD_KEYS]; // Registers current frame key state
|
||||
char previousKeyState[MAX_KEYBOARD_KEYS]; // Registers previous frame key state
|
||||
|
||||
// NOTE: Since key press logic involves comparing previous vs currrent key state,
|
||||
// key repeats needs to be handled specially
|
||||
char keyRepeatInFrame[MAX_KEYBOARD_KEYS]; // Registers key repeats for current frame
|
||||
char keyRepeatInFrame[MAX_KEYBOARD_KEYS]; // Registers key repeats for current frame
|
||||
|
||||
int keyPressedQueue[MAX_KEY_PRESSED_QUEUE]; // Input keys queue
|
||||
int keyPressedQueue[MAX_KEY_PRESSED_QUEUE]; // Input keys queue
|
||||
int keyPressedQueueCount; // Input keys queue count
|
||||
|
||||
int charPressedQueue[MAX_CHAR_PRESSED_QUEUE]; // Input characters queue (unicode)
|
||||
int charPressedQueue[MAX_CHAR_PRESSED_QUEUE]; // Input characters queue (unicode)
|
||||
int charPressedQueueCount; // Input characters queue count
|
||||
|
||||
} Keyboard;
|
||||
@ -342,8 +341,8 @@ typedef struct CoreData {
|
||||
bool cursorLocked; // Track if cursor is locked (disabled)
|
||||
bool cursorOnScreen; // Tracks if cursor is inside client area
|
||||
|
||||
char currentButtonState[MAX_MOUSE_BUTTONS]; // Registers current mouse button state
|
||||
char previousButtonState[MAX_MOUSE_BUTTONS]; // Registers previous mouse button state
|
||||
char currentButtonState[MAX_MOUSE_BUTTONS]; // Registers current mouse button state
|
||||
char previousButtonState[MAX_MOUSE_BUTTONS]; // Registers previous mouse button state
|
||||
Vector2 currentWheelMove; // Registers current mouse wheel variation
|
||||
Vector2 previousWheelMove; // Registers previous mouse wheel variation
|
||||
|
||||
@ -493,7 +492,6 @@ extern int InitPlatform(void); // Initialize platform (graphics, inputs
|
||||
extern void ClosePlatform(void); // Close platform
|
||||
|
||||
static void InitTimer(void); // Initialize timer, hi-resolution if available (required by InitPlatform())
|
||||
static void SetupFramebuffer(int width, int height); // Setup main framebuffer (required by InitPlatform())
|
||||
static void SetupViewport(int width, int height); // Set viewport for a provided width and height
|
||||
|
||||
static void ScanDirectoryFiles(const char *basePath, FilePathList *list, const char *filter); // Scan all files and directories in a base path
|
||||
@ -762,31 +760,31 @@ bool IsWindowReady(void)
|
||||
// Check if window is currently fullscreen
|
||||
bool IsWindowFullscreen(void)
|
||||
{
|
||||
return CORE.Window.fullscreen;
|
||||
return FLAG_IS_SET(CORE.Window.flags, FLAG_FULLSCREEN_MODE);
|
||||
}
|
||||
|
||||
// Check if window is currently hidden
|
||||
bool IsWindowHidden(void)
|
||||
{
|
||||
return (FLAG_IS_SET(CORE.Window.flags, FLAG_WINDOW_HIDDEN));
|
||||
return FLAG_IS_SET(CORE.Window.flags, FLAG_WINDOW_HIDDEN);
|
||||
}
|
||||
|
||||
// Check if window has been minimized
|
||||
bool IsWindowMinimized(void)
|
||||
{
|
||||
return (FLAG_IS_SET(CORE.Window.flags, FLAG_WINDOW_MINIMIZED));
|
||||
return FLAG_IS_SET(CORE.Window.flags, FLAG_WINDOW_MINIMIZED);
|
||||
}
|
||||
|
||||
// Check if window has been maximized
|
||||
bool IsWindowMaximized(void)
|
||||
{
|
||||
return (FLAG_IS_SET(CORE.Window.flags, FLAG_WINDOW_MAXIMIZED));
|
||||
return FLAG_IS_SET(CORE.Window.flags, FLAG_WINDOW_MAXIMIZED);
|
||||
}
|
||||
|
||||
// Check if window has the focus
|
||||
bool IsWindowFocused(void)
|
||||
{
|
||||
return (!FLAG_IS_SET(CORE.Window.flags, FLAG_WINDOW_UNFOCUSED));
|
||||
return !FLAG_IS_SET(CORE.Window.flags, FLAG_WINDOW_UNFOCUSED);
|
||||
}
|
||||
|
||||
// Check if window has been resizedLastFrame
|
||||
@ -798,7 +796,7 @@ bool IsWindowResized(void)
|
||||
// Check if one specific window flag is enabled
|
||||
bool IsWindowState(unsigned int flag)
|
||||
{
|
||||
return (FLAG_IS_SET(CORE.Window.flags, flag));
|
||||
return FLAG_IS_SET(CORE.Window.flags, flag);
|
||||
}
|
||||
|
||||
// Get current screen width
|
||||
@ -1100,7 +1098,7 @@ void BeginScissorMode(int x, int y, int width, int height)
|
||||
rlScissor((int)(x*scale.x), (int)(GetScreenHeight()*scale.y - (((y + height)*scale.y))), (int)(width*scale.x), (int)(height*scale.y));
|
||||
}
|
||||
#else
|
||||
if (!CORE.Window.usingFbo && (FLAG_IS_SET(CORE.Window.flags, FLAG_WINDOW_HIGHDPI)))
|
||||
if (!CORE.Window.usingFbo && FLAG_IS_SET(CORE.Window.flags, FLAG_WINDOW_HIGHDPI))
|
||||
{
|
||||
Vector2 scale = GetWindowScaleDPI();
|
||||
rlScissor((int)(x*scale.x), (int)(CORE.Window.currentFbo.height - (y + height)*scale.y), (int)(width*scale.x), (int)(height*scale.y));
|
||||
@ -3828,84 +3826,6 @@ void SetupViewport(int width, int height)
|
||||
rlLoadIdentity(); // Reset current matrix (modelview)
|
||||
}
|
||||
|
||||
// Compute framebuffer size relative to screen size and display size
|
||||
// NOTE: Global variables CORE.Window.render.width/CORE.Window.render.height and CORE.Window.renderOffset.x/CORE.Window.renderOffset.y can be modified
|
||||
void SetupFramebuffer(int width, int height)
|
||||
{
|
||||
// Calculate CORE.Window.render.width and CORE.Window.render.height, we have the display size (input params) and the desired screen size (global var)
|
||||
if ((CORE.Window.screen.width > CORE.Window.display.width) || (CORE.Window.screen.height > CORE.Window.display.height))
|
||||
{
|
||||
TRACELOG(LOG_WARNING, "DISPLAY: Downscaling required: Screen size (%ix%i) is bigger than display size (%ix%i)", CORE.Window.screen.width, CORE.Window.screen.height, CORE.Window.display.width, CORE.Window.display.height);
|
||||
|
||||
// Downscaling to fit display with border-bars
|
||||
float widthRatio = (float)CORE.Window.display.width/(float)CORE.Window.screen.width;
|
||||
float heightRatio = (float)CORE.Window.display.height/(float)CORE.Window.screen.height;
|
||||
|
||||
if (widthRatio <= heightRatio)
|
||||
{
|
||||
CORE.Window.render.width = CORE.Window.display.width;
|
||||
CORE.Window.render.height = (int)round((float)CORE.Window.screen.height*widthRatio);
|
||||
CORE.Window.renderOffset.x = 0;
|
||||
CORE.Window.renderOffset.y = (CORE.Window.display.height - CORE.Window.render.height);
|
||||
}
|
||||
else
|
||||
{
|
||||
CORE.Window.render.width = (int)round((float)CORE.Window.screen.width*heightRatio);
|
||||
CORE.Window.render.height = CORE.Window.display.height;
|
||||
CORE.Window.renderOffset.x = (CORE.Window.display.width - CORE.Window.render.width);
|
||||
CORE.Window.renderOffset.y = 0;
|
||||
}
|
||||
|
||||
// Screen scaling required
|
||||
float scaleRatio = (float)CORE.Window.render.width/(float)CORE.Window.screen.width;
|
||||
CORE.Window.screenScale = MatrixScale(scaleRatio, scaleRatio, 1.0f);
|
||||
|
||||
// NOTE: We render to full display resolution!
|
||||
// We just need to calculate above parameters for downscale matrix and offsets
|
||||
CORE.Window.render.width = CORE.Window.display.width;
|
||||
CORE.Window.render.height = CORE.Window.display.height;
|
||||
|
||||
TRACELOG(LOG_WARNING, "DISPLAY: Downscale matrix generated, content will be rendered at (%ix%i)", CORE.Window.render.width, CORE.Window.render.height);
|
||||
}
|
||||
else if ((CORE.Window.screen.width < CORE.Window.display.width) || (CORE.Window.screen.height < CORE.Window.display.height))
|
||||
{
|
||||
// Required screen size is smaller than display size
|
||||
TRACELOG(LOG_INFO, "DISPLAY: Upscaling required: Screen size (%ix%i) smaller than display size (%ix%i)", CORE.Window.screen.width, CORE.Window.screen.height, CORE.Window.display.width, CORE.Window.display.height);
|
||||
|
||||
if ((CORE.Window.screen.width == 0) || (CORE.Window.screen.height == 0))
|
||||
{
|
||||
CORE.Window.screen.width = CORE.Window.display.width;
|
||||
CORE.Window.screen.height = CORE.Window.display.height;
|
||||
}
|
||||
|
||||
// Upscaling to fit display with border-bars
|
||||
float displayRatio = (float)CORE.Window.display.width/(float)CORE.Window.display.height;
|
||||
float screenRatio = (float)CORE.Window.screen.width/(float)CORE.Window.screen.height;
|
||||
|
||||
if (displayRatio <= screenRatio)
|
||||
{
|
||||
CORE.Window.render.width = CORE.Window.screen.width;
|
||||
CORE.Window.render.height = (int)round((float)CORE.Window.screen.width/displayRatio);
|
||||
CORE.Window.renderOffset.x = 0;
|
||||
CORE.Window.renderOffset.y = (CORE.Window.render.height - CORE.Window.screen.height);
|
||||
}
|
||||
else
|
||||
{
|
||||
CORE.Window.render.width = (int)round((float)CORE.Window.screen.height*displayRatio);
|
||||
CORE.Window.render.height = CORE.Window.screen.height;
|
||||
CORE.Window.renderOffset.x = (CORE.Window.render.width - CORE.Window.screen.width);
|
||||
CORE.Window.renderOffset.y = 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
CORE.Window.render.width = CORE.Window.screen.width;
|
||||
CORE.Window.render.height = CORE.Window.screen.height;
|
||||
CORE.Window.renderOffset.x = 0;
|
||||
CORE.Window.renderOffset.y = 0;
|
||||
}
|
||||
}
|
||||
|
||||
// Scan all files and directories in a base path
|
||||
// WARNING: files.paths[] must be previously allocated and
|
||||
// contain enough space to store all required paths
|
||||
|
||||
Reference in New Issue
Block a user