BlitzmaxNG fullscreen virtual resolution issues macOS Catalina

Started by Ashmoor, July 05, 2020, 11:21:34

Previous topic - Next topic

Ashmoor

The code below works perfectly fine on windows but does not work on macOS Catalina. Switching to fullscreen triggers some issue that leads to drawing it as in the image linked below code. Any idea how to fix this?

Using SetViewport leads to even weirder issues, both in windowed mode and full screen. It either draws just a part of the bgImg in the bottom left corner of the screen or the top part of bgImg at the top of the screen.

However, if I set a different width and height for the graphics call and leave everything else as is (with or without viewport), it works. For example 1110x619 works fine but 800x450 does not. It is not a matter of aspect ratio (does not matter if it's 16/9 or 4/3 or whatever).

Code (blitzmax) Select


Framework SDL.gl2sdlmax2d
Import brl.jpgloader

Global fullscreen%=0


Graphics 800,600,fullscreen
SetBlend(ALPHABLEND)

Global bgImg:TImage=LoadImage("graphics/p1_wallpaper.jpg")
'Global bgImg:TImage=LoadImage("graphics/bgimg.jpg")
If Not bgImg Then RuntimeError("cant load bgImg")

'SetViewport(0,0,1920,1080)
SetVirtualResolution(1920,1080)



Repeat

Cls
DrawImage (bgImg,0,0)
DrawText(MouseX()+","+MouseY(),10,10)
Flip

If KeyHit (KEY_ESCAPE) Or AppTerminate() Then End
If KeyHit(KEY_1) Then PrintViewPort()
If KeyHit(KEY_2)Then printcoords()
If KeyHit (KEY_3) Then
fullscreen=Not(fullscreen)
EndGraphics()
ReInitGraphics()
EndIf

Forever

Function ReInitGraphics()
Graphics 800,600,fullscreen
SetVirtualResolution(1920,1080)
EndFunction


Function PrintViewPort()
Local xo%, yo%, vw%,vh%

GetViewport(xo,yo,vw,vh)
Print "viewport:"+xo+","+yo+","+vw+","+vh
Local x#,y#
GetOrigin( x,y )
Print "origin:"+x+","+y
EndFunction

Function PrintCoords()
Print ("x:"+MouseX()+"y:"+MouseY())
Print("vx:"+VirtualMouseX()+" vy:"+VirtualMouseY())
EndFunction



Image: https://drive.google.com/file/d/192Kur5i7nMhaIa8yTOcYBdyN0zmcGuBi/view?usp=sharing

Lavalamp

I've raised this several times now. :( Additionally if you enable HiDPI you cant create 64-32 bit binary only 32.

Ashmoor

What is HiDPI and how do you enable it?

I am still having issues with fullscreen mode. CMD+Tab does not work, do you guys have any idea how to fix that?


Derron

Did you raise an issue for it?

I at least mentioned this thread in the issues discord channel for now.


Bye
Ron

iWasAdam

Checking over the code on a mac I can confirm the errors both with fullscreen and the cmd+tab

It's not and issue with NG its an issue with the code itself. MacOS needs to be set up in a different way to windows. I can't elaborate more as I am having the same issues. but I will come up with a solution for you :)

Derron

It happen with SDL and non-SDL ?

Code (BlitzMax) Select

SuperStrict
Framework Brl.StandardIO
'old releases
'Import Brl.Random
'new modules
Import Brl.RandomDefault

'NON-SDL
'Import Brl.GLMax2D
'SDL
'Import SDL.GLSDLMax2D
'or SDL GL2
Import SDL.GL2SDLMax2D

Graphics(800, 600)
SetBlend AlphaBlend
SetColor 255,255,255
SetClsColor 40, 80, 160
While Not KeyDown(KEY_ESCAPE)   
    Cls
   
    SeedRnd(MilliSecs() / 1000)
    For Local i :Int = 0 To 100
        SetColor Rand(0,255), Rand(0,255), Rand(0,255)
        DrawText("Hey", Rand(0, GraphicsWidth()-50), Rand(0, GraphicsHeight()-20))
    Next
   
    Flip
Wend

End


?
(add your virtual resolution commands on your own)

iWasAdam

@derron- the issue is to do with native Commands and full screen. To do it properly, you have to call the correct commands and have the app core set up in a certain way. Using setgraphics is not the way to do it - especially when switching from windowed mode...

I'm looking into how get the correct result

Derron

SetGraphics should be working ...

SDL provides its own "set fullscreen" thing ...

TSDLWindow.SetFullScreen:

Rem
bbdoc: Sets the window's fullscreen state.
returns: 0 on success or a negative error code on failure.
about: @flags may be SDL_WINDOW_FULLSCREEN, for "real" fullscreen with a videomode change; SDL_WINDOW_FULLSCREEN_DESKTOP
for "fake" fullscreen that takes the size of the desktop; and 0 for windowed mode.
End Rem
Method SetFullScreen:Int(flags:UInt)
Return SDL_SetWindowFullscreen(windowPtr, flags)
End Method



I assume it needs a bit more to do "borderless windowed fullscreen" (app without decorations in the size of the "display" but not true full screen).


Code (Blitzmax) Select


Graphics(800, 600)
SetBlend AlphaBlend
SetColor 255,255,255
While Not KeyDown(KEY_ESCAPE)   
    Cls

If KeyHit(KEY_SPACE)
Local window:TSDLWindow = TSDLGLContext.GetCurrentWindow()
If Not window
Print "cannot find TSDLWindow - fullscreen switch not possible"
Else
If Not doFullScreen
doFullscreen = True

Local display:TSDLDisplay = window.GetDisplay()
Local displayMode:TSDLDisplayMode = display.GetCurrentDisplayMode()
Print "full active display size: " + displayMode.Width() + "x" + displayMode.Height()
window.SetBordered(0) 'disable borders
window.SetFullScreen(SDL_WINDOW_FULLSCREEN_DESKTOP)
Graphics(displayMode.Width(), displayMode.Height())
Else
doFullScreen = False

Print "back to windowed mode"

window.SetBordered(1) 'enable borders
window.SetFullScreen(0)
Graphics(800, 600)
EndIf
EndIf
EndIf
   
SeedRnd(MilliSecs() / 1000)
For Local i :Int = 0 To 100
SetColor Rand(0,255), Rand(0,255), Rand(0,255)
DrawText("Hey", Rand(0, GraphicsWidth()-50), Rand(0, GraphicsHeight()-20))
Next
   
    Flip
Wend

End


you might be able to remove the borders when appending the flag to the graphics command:
Graphics(800, 600, 0,0, SDL_WINDOW_BORDERLESS)

Here on linux it does not remove the borders - so I am not sure about it.


bye
Ron

Derron

Another thing to note:

When using "SDL" the window is created using "sdl.mod/sdlgraphics.mod/sdlgraphics.bmx"

In there is the method:

Method SDLGraphicsCreateGraphics:TGraphicsContext(width:Int,height:Int,depth:Int,hertz:Int,flags:Int,x:Int,y:Int)
...


Else

If depth Then
windowFlags :| SDL_WINDOW_FULLSCREEN
' mode = MODE_DISPLAY
Else
If flags & $80000000 Then
windowFlags :| SDL_WINDOW_FULLSCREEN_DESKTOP
End If
' mode = MODE_WINDOW
...


Have seen this $80000000 ?? This should correspond to the "SDL_FULLSCREEN" flag ... so when passing this but not providing a "depth" in the graphics command, you should get a desktop sized fullscreen window.

If you try to add this to the initial "graphics()" command in my code you will see an application which occupies your whole desktop - but only renders in the bottom left area in the size of 800x600.

this somehow looks similar to what the OP/Ashmoor experienced.



Edit: With Ashmoor's code get different results on my linux box:
- going into fullscreen and I only see a big big part of a number (so scaled up by some hundred percents)
- going out of fullscreen: works
- going again into fullscreen: works (it now properly scales the bg image for me)

Ok, so I copy pasted the stuff in "Key_3" ... so it automatically goes "into, out, into" ... and it is still borked up there. I added delays, added "cls; flip" lines over and over... but it was not "automatizable". Surely this is not just a bug for "OS X" but more a generic issue with Max2D ? (maybe not on windows though...)

hmmm .. played a bit more with it, and now "windowed -> fullscreen" works for me (linux, only brl.glmax2d, not sdl.glmax2d)

bye
Ron

Ashmoor

Code (blitzmax) Select
Import Brl.RandomDefault

I don't have this, was there a new version released? I used BRL.Random

Below are some screenshots gl2SdlMax2d looks exactly like non sdl.

"SDL provides its own "set fullscreen" thing ..."

This looks nice but dock covers the app both in SDL_WINDOW_FULLSCREEN_DESKTOP and SDL_WINDOW_FULLSCREEN

The following code switches to full screen but the resolution is wild: 3070x1438

Code (blitzmax) Select

Framework SDL.gl2sdlmax2d
Import brl.Random

Global doFullScreen

Graphics(800, 600)

Global vrWidth=1920
Global vrHeight=1080

SetVirtualResolution(vrWidth, vrHeight)
'SetViewport(0,0,vrWidth,vrHeight)
'SetViewport(0,0,vrWidth*2,vrHeight*2)

SetBlend AlphaBlend
SetColor 255,255,255
While Not KeyDown(KEY_ESCAPE)   
    Cls

        If KeyHit(KEY_SPACE)
                Local window:TSDLWindow = TSDLGLContext.GetCurrentWindow()
                If Not window
                        Print "cannot find TSDLWindow - fullscreen switch not possible"
                Else
                        If Not doFullScreen
                                doFullscreen = True

                                Local display:TSDLDisplay = window.GetDisplay()
                                Local displayMode:TSDLDisplayMode = display.GetCurrentDisplayMode()
                                Print "full active display size: " + displayMode.Width() + "x" + displayMode.Height()
                                'window.SetBordered(0) 'disable borders
                                window.SetFullScreen(SDL_WINDOW_FULLSCREEN_DESKTOP)
                                'Graphics(displayMode.Width(), displayMode.Height())
                        Else
                                doFullScreen = False
                               
                                Print "back to windowed mode"
                               
                                window.SetBordered(1) 'enable borders
                                window.SetFullScreen(0)
                                'Graphics(800, 600)
                        EndIf
                EndIf
        EndIf
   
        SeedRnd(MilliSecs() / 1000)
        For Local i :Int = 0 To 100
                SetColor Rand(0,255), Rand(0,255), Rand(0,255)
                DrawText("Hey", Rand(0, vrWidth-50), Rand(0, vrHeight-20))
        Next

SetScale(2.0,2.0)
DrawText(VirtualMouseX()+","+VirtualMouseY(),10,10)
SetScale(1.0,1.0)

    Flip
Wend

End


Thing is, I don't really care about using SDL and as long as the app can run, but with BRL the y coordinates are flipped in full screen. MacOS is wild.


iWasAdam

@Ashmoor
The macOS itself handles fullscreen and zoom and maximize. And they are all slightly different and they require menu system as well!

Proper fullscreen (which is what you want) can be seen by the third green traffic light and a window - if this is NOT there - then whatever fullscreen you think is right - it isn't <- read and read that again
There used to be a fullscreen option in the app menu under window. but this has been removed. BEWARE to use fullscreen, maximize, zoom, etc you WILL have to have a windows menu for your app!

Fullscreen (ON A MAC) from a window is done by pressing the green button or ctrl+cmd+f <- pressing ctrl+cmd+f again will restore the window. You will also see the window animate from being a window to fullscreen. Cmd+tab will be happy etc.

DO NOT ASSUME ANYTHING ON A MAC.
Do not think using sdl or other frameworks will work correctly - they might, they will more than likely need much more setup and OS specific code to work correct.

Although you can use internal language/sdl commands to force fullscreen on a mac - IT"S NOT PROPER FULLSCREEN. It's a kludge that will eventually give you HUGE headaches, as nothing will quite be right - your users will know instantly - BEWARE!!!!!!!!!!!

I am tracking down some for of code answer for you - but it's not a simple thing... It's a framework. Unfortunately you will HAVE to adopt something similar which will mean recoding your main program loops, etc.

Porting code from windows to mac is not as easy as clicking build - unless you are using something very highlevel like unity - it will take care of the nasty internal framework code for you!

I'm sorry this is not an easy answer...  :'(

Ashmoor

I have managed to get some code to work and fit my needs. Here it is:

Code (blitzmax) Select


Framework SDL.gl2sdlmax2d
Import brl.jpgloader
Import brl.Random
Import brl.StandardIO

Global isFullScreen

Global bgImg:TImage=LoadImage("graphics/screen_tester1.jpg")
If Not bgImg Then RuntimeError("cant load bgImg")


Global vrWidth=1920
Global vrHeight=1080

Global wWidth=960
Global wHeight=600

Global fsWidth=DesktopWidth()
Global fsHeight=DesktopHeight()

Graphics (wWidth,wHeight)
SetBlend AlphaBlend
SetVirtualResolution(vrWidth, vrHeight)


Repeat

Cls
If KeyHit (KEY_SPACE) Then
EndGraphics()

If Not isFullScreen Then
'switch to full screen
isFullScreen=True

Graphics (fsWidth, fsHeight)
SetVirtualResolution(1920,1080)

Local window:TSDLWindow = TSDLGLContext.GetCurrentWindow()
window.SetFullScreen(SDL_WINDOW_FULLSCREEN_DESKTOP)

Else
'switch to windowed
isFullScreen=False

Graphics (wWidth,wHeight)
SetVirtualResolution(1920,1080)
Local window:TSDLWindow = TSDLGLContext.GetCurrentWindow()
window.SetFullScreen(0)

EndIf


EndIf

'draw something so we can check
DrawImage(bgImg,0,0)

        SeedRnd(MilliSecs() / 1000)
        For Local i :Int = 0 To 100
                SetColor Rand(0,255), Rand(0,255), Rand(0,255)
                DrawText("Hey", Rand(0, vrWidth-50), Rand(0, vrHeight-20))
        Next
SetColor (255,255,255)

SetScale(2.0,2.0)
DrawText("rm:"+MouseX()+","+MouseY(),10,30)
DrawText(VirtualMouseX()+","+VirtualMouseY(),10,10)
SetScale(1.0,1.0)

Local x:Float, y:Float
x=VirtualMouseX(); y=VirtualMouseY()

DrawRect(x-5,y-5,10,10)

Flip()

'end condition
If KeyHit(KEY_ESCAPE) Or AppTerminate() Then End
Forever



For some reason if I switch to full screen using the code above, calling osascript no longer works. Does anyone have any idea why or how to fix it?



iWasAdam

sooo. You hacked a fullscreen - that's not proper fullscreen. \o/
And now you want to install some virus or do some other 'nasty' scriptkiddie stuff too? And MacOS wont let you...

Ashmoor

Why is this not "proper" full screen? Can you please explain what is expected of a proper full screen?

iWasAdam

first 2 questions for you:
1. do you use a mac?
2. did you compile the code on a mac?

ok. here's a detailed version to read:
https://www.techjunkie.com/leave-full-screen-os-x/

next
A mac is NOT windows. they use completely different commands and have different ways of doing things.

what is fullscreen on a mac?
- Is when a window covers the entire screen including the menu and taskbar.
- Putting the mouse at the top of the screen in this mode will show the menu and the title bar and allow you to switch mode back to window or OTHER screens - the mac can have multiple screens even on a mac with one monitor!
- a mac app which has TRUE fullscreen ability (see above) has a green top left button. this can be pressed to go into fullscreen
- ctrl+cmd+f will switch from window to fullscreen. the window will usually animate when it does this.
- cmd+tab will also function normally
- the app will  'window' as a menu item with sometimes minimise, zoom, fullscreen added.

anything else is NOT considered by apple or users as fullscreen - it MUST behave the way it should and use the correct icons, etc