chrisdill / raylib-cs

C# bindings for raylib, a simple and easy-to-use library to learn videogames programming
http://www.raylib.com/
zlib License
849 stars 74 forks source link

MacOS Fullscreen Problem #263

Open SoloByte opened 3 months ago

SoloByte commented 3 months ago

Issue description

When entering macOS fullscreen (clicking green button in the top left of the window or fn + F) only 1/ 4 of the screen is rendered. BeginTextureMode() and EndTextureMode() cause this problem. When you comment out the Begin/EndTextureMode() block in the code example the problem disappears. I have tested it with raylib master, raylib cs, and raylib cslo and only raylib cs has this problem.

This only happens in "macOS Fullscreen mode" and not with ToggleFullscreen() or ToggleBorderlessWindowed().

Environment

MacBook Pro M2 macOS Sonoma 14.5

Issue screenshot

Green Button

Screenshot 2024-08-16 at 08 11 30

Problem

Screenshot 2024-08-16 at 08 11 03

How it looks with Begin/EndTextureMode() commented out.

Screenshot 2024-08-16 at 08 12 41

Code example

using System.Numerics;
using Raylib_cs;

namespace RaylibCs;

public static class Program
{
    static void Main(string[] args)
    {
        const int width = 400;
        const int heigth = 400;

        Raylib.SetWindowState(ConfigFlags.Msaa4xHint);

        Raylib.InitWindow(width, heigth, "Raylib Cs");

        Raylib.SetWindowState(ConfigFlags.ResizableWindow);
        Raylib.ClearWindowState(ConfigFlags.VSyncHint);
        Raylib.SetTargetFPS(60);

        var renderTexture = Raylib.LoadRenderTexture(width, heigth);
        var sourceRect = new Rectangle(0, 0, width, -heigth);
        var origin = new Vector2(0, 0);
        var circleColor = Color.Red;

        while (!Raylib.WindowShouldClose())
        {
            float dt = Raylib.GetFrameTime();
            var mousePos = Raylib.GetMousePosition();

//Comment out -------
            Raylib.BeginTextureMode(renderTexture);
            Raylib.ClearBackground(new Color(0, 0, 0, 0));

            Raylib.DrawCircle(200, 200, 25, circleColor);

            Raylib.EndTextureMode();
//-------------------

            Raylib.BeginDrawing();
            Raylib.ClearBackground(Color.Black);
            var destRect = new Rectangle(0, 0, Raylib.GetScreenWidth(), Raylib.GetScreenHeight());

            Raylib.DrawRectangleLinesEx(destRect, 5f, circleColor);
            Raylib.DrawTexturePro(renderTexture.Texture, sourceRect, destRect, origin, 0f, Color.White);

            Raylib.DrawCircleV(mousePos, 5, circleColor);

            Raylib.EndDrawing();
        }

        Raylib.UnloadRenderTexture(renderTexture);
        Raylib.CloseWindow();
    }
}
chrisdill commented 2 months ago

Do you get the issue using raylib 5.0 instead of raylib master?

SoloByte commented 2 months ago

I have just tested the 5.0 release of raylib and it works fine as well, no issue with the fullscreen.

JudgeGroovyman commented 4 weeks ago

I have a clue: If you install the app 'display menu' it will change your screen to an exact resolution instead of a systemwide scaling and then when you go fullscreen it scales properly to fullscreen size.

Before:

Before

After: After

I have had this exact problem with games before and this was a workaround for that too.

Its like when any of these are selected in your display preferences then its doing some kind of scaling in macos that messes this code up

Screenshot 2024-10-29 at 8 03 59 AM

But when you use Display Menu it deselects these "convenience" options and forces the screen to an exact resolution Screenshot 2024-10-29 at 8 02 32 AM

I recognize that isn't a solution to the problem just a clue/workaround-in-some-cases. good luck

SoloByte commented 4 weeks ago

Thanks for the detailed information :)

I am curious why Begin/EndTextureMode cause this and why they only cause it in the raylib cs bindings? (and not raylib or raylib cslo)

JudgeGroovyman commented 3 weeks ago

Thanks for the detailed information :)

I am curious why Begin/EndTextureMode cause this and why they only cause it in the raylib cs bindings? (and not raylib or raylib cslo)

You are welcome. I am also curious about this. It doesn't add up. Perhaps theres some setting somewhere that is slightly different.

If you think of anything I could try to get it working let me know.