-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[rcore] ToggleFullscreen()
not working as expected with HighDPI mode enabled
#3972
Comments
ToggleFullscreen()
not working as expected with HighDPI mode enabled
@fishbowlforever Thanks for reporting, could you reproduce this issue on Windows 10? It sounds like platform dependant... In any case, I'm afraid I don't have a HighDPI monitor at the moment for testing on my side... |
set display scaling to 125% enough |
If I multiply the monitor size by 2 before entering fullscreen another weird thing happens...
The monitor size should be 1920x1080 before entering fullscreen (my target resolution on a 4k monitor). If I multiply this by 2 I should get the 4k resolution and if I then set the window size to the 4k resolution and enter fullscreen (were the dpi value is suddenly 1) I expect those value:
Why is only width affect and height suddenly not? :) |
WindowsI have tested fullscreen & high dpi functionality on windows 11 with a 4k monitor as well. I have set the scaling to 200% in settings. I have also tested everything with the scaling set to 100%. If something is not clear or I did something wrong or missed a step, please feel free to correct me. Windowed
Maximized
Borderless Fullscreen
Fullscreen
I have tested everything with a 100% scaling on a 4k monitor as well. Everything works but it reported the exact same values as with a scaling of 200%.My findings:
Screen Size, Render Size, Monitor SizeThe following things are what I understand about screen size, monitor size, and render size. I do not know if I am correct at all. My main goal here is to figure out together what each of this numbers should represent independent of the the operating system.
To me personally only Example A makes sense. (on all operating systems. I do not know how scaling works on windows but on macOS it can only be 1, 1 or 2, 2. There are other combinations possible as well not just the ones from example A & B but I didn’t want to write them all down ;) Example A
Example B
|
@raysan5 If you need anything else just tell me. As mentioned above I can also put all my comments in a seperate issue. If needed I can also put a zip file here with the minimal project I used to test this (all raylib cs btw). |
@SoloByte : could you share a code example ?
Yes please, i'd like to test it too. |
@SuperUserNameMan Here you go :) I am very interested in your results :D Minimal Reproduction Example
minimal-reproduction-raylib-fullscreen.txt
|
OMG ! Yuck ! C# ! I feel like someone barfed into my eyes X-( I hope this is what you meant : #include "raylib.h"
void update();
void draw();
int main( int argc , char **argv )
{
SetWindowState( FLAG_MSAA_4X_HINT );
SetConfigFlags( FLAG_WINDOW_HIGHDPI ); // <===== ???
InitWindow( 800 , 800 , "Test" );
ClearWindowState( FLAG_VSYNC_HINT );
SetTargetFPS( 60 );
SetWindowState( FLAG_WINDOW_RESIZABLE );
while( ! WindowShouldClose() )
{
update();
BeginDrawing();
{
ClearBackground( RAYWHITE );
draw();
}
EndDrawing();
}
CloseWindow();
}
void update()
{
// He said he does not check if fullscreen is already active
// when pressing borderless fullscreen and vice versa.
static int prevFullscreenWidth = 0;
static int prevFullscreenHeight = 0;
static int prevFullscreenX = 0;
static int prevFullscreenY = 0;
// Fullscreen :
if ( IsKeyPressed( KEY_F ) )
{
if ( IsWindowFullscreen() )
{
ToggleFullscreen();
SetWindowSize( prevFullscreenWidth , prevFullscreenHeight );
SetWindowPosition( prevFullscreenX , prevFullscreenY );
}
else
{
prevFullscreenWidth = GetScreenWidth();
prevFullscreenHeight = GetScreenHeight();
prevFullscreenX = (int)GetWindowPosition().x;
prevFullscreenY = (int)GetWindowPosition().y;
int monitor = GetCurrentMonitor();
SetWindowSize( GetMonitorWidth(monitor) , GetMonitorHeight(monitor) );
ToggleFullscreen();
}
}
else // Borderless Fullscreen :
if ( IsKeyPressed( KEY_B ) )
{
ToggleBorderlessWindowed();
}
}
void draw()
{
int sw = GetScreenWidth();
int sh = GetScreenHeight();
int rw = GetRenderWidth();
int rh = GetRenderHeight();
Vector2 dpi = GetWindowScaleDPI();
int monitor = GetCurrentMonitor();
int mw = GetMonitorWidth( monitor );
int mh = GetMonitorHeight( monitor );
Rectangle infoRect = { 0.0 , 0.0 , sw , sh };
// Draw the border of the screen :
DrawRectangleLinesEx( infoRect , 4.0f , RED );
// Draw the text NOT in the center :
DrawText( TextFormat( "Screen : %d x %d" , sw , sh ) , 10 , 10 , 30 , BROWN );
DrawText( TextFormat( "Render : %d x %d" , rw , rh ) , 10 , 40 , 30 , DARKGREEN );
DrawText( TextFormat( "Monitor : %d x %d" , mw , mh ) , 10 , 70 , 30 , DARKBLUE );
DrawText( TextFormat( "DPI : %f x %f" , dpi.x , dpi.y ) , 10 , 100 , 30 , BLACK );
} |
Edit : ok, i'm currently proceeeding to various test on a more simplified example, because there seems to be many other issues related to both Maybe an separate issue should be opened for each different backends and OS ... On my Linux desktop, here are my observations :
#include "raylib.h"
void update();
void draw();
int main( int argc , char **argv )
{
//SetWindowState( FLAG_MSAA_4X_HINT );
SetConfigFlags(FLAG_WINDOW_HIGHDPI); // <======= ???
InitWindow( 1280 , 720 , "Test" );
//ClearWindowState( FLAG_VSYNC_HINT );
SetTargetFPS( 60 );
//SetWindowState( FLAG_WINDOW_RESIZABLE );
while( ! WindowShouldClose() )
{
update();
BeginDrawing();
{
ClearBackground( RAYWHITE );
draw();
}
EndDrawing();
}
CloseWindow();
}
void update()
{
if ( IsKeyPressed( KEY_F ) )
{
// SetWindowSize( 1280 , 720 );
ClearWindowState( FLAG_WINDOW_RESIZABLE );
ToggleFullscreen();
// SetWindowState( FLAG_WINDOW_RESIZABLE );
// SetWindowSize( 1280 , 720 );
}
else
if ( ! IsWindowFullscreen() && IsKeyPressed( KEY_B ) )
{
ToggleBorderlessWindowed();
}
}
void draw()
{
int sw = GetScreenWidth();
int sh = GetScreenHeight();
int rw = GetRenderWidth();
int rh = GetRenderHeight();
Vector2 dpi = GetWindowScaleDPI();
int monitor = GetCurrentMonitor();
int mw = GetMonitorWidth( monitor );
int mh = GetMonitorHeight( monitor );
Rectangle infoRect = { 0.0 , 0.0 , sw , sh };
// Draw the border of the screen :
DrawRectangleLinesEx( infoRect , 300.0f , RED );
// Draw the text NOT in the center :
DrawText( TextFormat( "Screen : %d x %d" , sw , sh ) , 10 , 10 , 30 , BROWN );
DrawText( TextFormat( "Render : %d x %d" , rw , rh ) , 10 , 40 , 30 , DARKGREEN );
DrawText( TextFormat( "Monitor : %d x %d" , mw , mh ) , 10 , 70 , 30 , DARKBLUE );
DrawText( TextFormat( "DPI : %f x %f" , dpi.x , dpi.y ) , 10 , 100 , 30 , BLACK );
DrawText( TextFormat( "infoRect : %f x %f" , infoRect.width , infoRect.height ) , 10 , 140 , 30 , RED ); // <===
} |
Ok so if I replicated @fishbowlforever issue correctly, and if @fishbowlforever uses the GLFW backend, i think the culprit is here : raylib/src/platforms/rcore_desktop_glfw.c Lines 1670 to 1682 in 9764fef
I think that it is not required to divide by raylib/src/platforms/rcore_desktop_glfw.c Lines 1300 to 1310 in 9764fef
@fishbowlforever , can you recompile Raylib to test this fix on your Windows OS ? In file // if ((CORE.Window.flags & FLAG_WINDOW_HIGHDPI) > 0)
if (0)
{
Vector2 windowScaleDPI = GetWindowScaleDPI();
CORE.Window.screen.width = (unsigned int)(width/windowScaleDPI.x);
CORE.Window.screen.height = (unsigned int)(height/windowScaleDPI.y);
}
else
{
CORE.Window.screen.width = width;
CORE.Window.screen.height = height;
} Or apply this patch : #4143 |
@SuperUserNameMan thanks a lot for your suggestion and research Fullscreen works like a charm now! The only issue left is that, when disabling Fullscreen, the window only displays the top left quarter of the screen. This does not increment to 4x, 8x, 16x, etc. like it previously did though. |
@fishbowlforever : Did you use the code example i provided ? |
@SuperUserNameMan can confirm that disabling resizable flag before entering fullscreen helps & can´t test it on macOS because I am not set up for raylib development. @raysan5 should I open new issues for the other problems I have found mention above? |
Edit oh i've just noticed i misinterpreted your answer. Yes, disabling resizable flag before toggling to fullscreen should help, and might have an effect on Macos too. |
@SoloByte @SuperUserNameMan Thank you very much for the extensive review of this issue, full-screen and high-dpi are big concerns on raylib that despite being reviewed many many times, still have issues, mostly platform and OS dependant...
@SoloByte Yes, please, I think it would be easier to track the issues separately (despite being highly dependant). If you want I can also reopen this issue for reference. |
@SuperUserNameMan @fishbowlforever What I have found is that fullscreen mode sets the window size to the current screen size before entering fullscreen instead of setting it to the monitor size. (Borderless fullscreen sets the window size to the monitor size) Setting the window size calls the window resized callback and before fix #4143 it would then scale the current window size further down each time fullscreen is exited. I think this loop may also causes the issue that is still there with the 1/4 of the screen in the topleft. @raysan5 I will open a new issue for fullscreen / borderless fullscreen mode & 1 issue for the screen/render/monitor size confusion with the dpi scale ? |
Adding @JeffM2501 to the loop, I remember he had some ideas about |
@SuperUserNameMan I have already tested it and it improves things. The screen size values are correct and no longer missing a few pixels. |
@SoloByte I'm reopening to continue the discussion but feel free to open separate issues for related problems. |
@SuperUserNameMan I have not tested it with the new patch |
ok then, let's start again from a fresh code base then. |
@SuperUserNameMan @fishbowlforever The window resize callback also calls SetupViewport which introdues dpi scale again. I don‘t know if that causes any problems though.
|
I agree but just for clarification, I have tested it on macOS with the same project as above. The patch you did should not have affected macOS anyway, correct? |
correct. because with the patch, all desktop platforms now use the same Now, i'm going to read the new issues and conversation you opened. |
If you use You have to choose one or another edit if you absolutely need to rescale your content accordingly to DPI, you better use the values of |
Could you please test this PR #4151 ? |
when enabling the highDPI flag in raylib (SetConfigFlags(FLAG_WINDOW_HIGHDPI);) and using ToggleFullscreen(); the fullscreen Window is twice the size it should be and you only see the top left quarter of your software. Toggling again will half the window size each time you toggle fullscreen until the window is gone.
steps to repdroduce:
SetConfigFlags(FLAG_WINDOW_HIGHDPI); on a high dpi monitor
call ToggleFullscreen();
I am using Windows 11
The text was updated successfully, but these errors were encountered: