[Done] OpenWindowedScreen has no Autostretch

Post bugreports for the Mac OSX version here
User avatar
fsw
Addict
Addict
Posts: 1572
Joined: Tue Apr 29, 2003 9:18 pm
Location: North by Northwest

[Done] OpenWindowedScreen has no Autostretch

Post by fsw »

Using OpenWindowedScreen for the first time on MacOS.
Autostretch doesn't work.
The main window is smaller than an image displayed in the windowed screen.
(main window has desktop size 1366x768 and the screen has 1920x1080 HTPC size)
On the Windows OS the screen (and the image) shrink and can be seen 100% on MacOS not.

How to activate autostretch on MacOS?

Thanks

I am to provide the public with beneficial shocks.
Alfred Hitshock
User avatar
J. Baker
Addict
Addict
Posts: 2178
Joined: Sun Apr 27, 2003 8:12 am
Location: USA
Contact:

Re: OpenWindowedScreen has no Autostretch

Post by J. Baker »

Works here. You may want to post an example code of your issue. ;)
www.posemotion.com

PureBasic Tools for OS X: PureMonitor, plist Tool, Data Maker & App Chef

Mac: 10.13.6 / 1.4GHz Core 2 Duo / 2GB DDR3 / Nvidia 320M
PC: Win 7 / AMD 64 4000+ / 3GB DDR / Nvidia 720GT


Even the vine knows it surroundings but the man with eyes does not.
User avatar
fsw
Addict
Addict
Posts: 1572
Joined: Tue Apr 29, 2003 9:18 pm
Location: North by Northwest

Re: OpenWindowedScreen has no Autostretch

Post by fsw »

On MacOS the following code only shows a quarter of the image...

Code: Select all

If OpenWindow(0, 0, 0, 960, 540, "Gadget and sprites!", #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_ScreenCentered)
  InitSprite()
  InitKeyboard()
  UseJPEGImageDecoder() 
  ; open 1920 x 1080 screen 
  OpenWindowedScreen(WindowID(0), 0, 0, 1920, 1080, 1, 0, 0, #PB_Screen_SmartSynchronization)
  ; load 1920x1080 jpg image 
  ; macos
  LoadSprite(0, GetPathPart(ProgramFilename()) + "../../../" + "img/weather.jpg", #PB_Sprite_Texture | #PB_Sprite_Alpha | #PB_Sprite_Memory)
  ; windows
  ;LoadSprite(0, "img/weather.jpg", #PB_Sprite_Texture | #PB_Sprite_Alpha | #PB_Sprite_Memory)
  Repeat
    
    ; Inverse the buffers (the back become the front (visible)... And we can do the rendering on the back)
    event = WaitWindowEvent(10)
    
    FlipBuffers()
    
    ClearScreen(RGB(0,0,0))

    DisplaySprite(0, 0, 0)
    
    ExamineKeyboard()
  Until KeyboardPushed(#PB_Key_Escape) Or event = #PB_Event_CloseWindow
EndIf
On Windows the whole image is shown...

I am to provide the public with beneficial shocks.
Alfred Hitshock
User avatar
J. Baker
Addict
Addict
Posts: 2178
Joined: Sun Apr 27, 2003 8:12 am
Location: USA
Contact:

Re: OpenWindowedScreen has no Autostretch

Post by J. Baker »

I see what you are saying. Since your screen size is larger then your window size, you have to maximize then restore it back in order for it to fit the screen. Notice I change the window width and height by 1 pixel, to give a slightly maximized effect. Then it is returned to actual size with ResizeWindow(). This basically sets up the stretch feature on first launch. Here you go...

Code: Select all

If OpenWindow(0, 0, 0, 961, 541, "Gadget and sprites!", #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_ScreenCentered)
  InitSprite()
  InitKeyboard()
  UseJPEGImageDecoder() 
  ; open 1920 x 1080 screen 
  OpenWindowedScreen(WindowID(0), 0, 0, 1920, 1080, 1, 0, 0, #PB_Screen_SmartSynchronization)
  ; load 1920x1080 jpg image 
  ; macos
  LoadSprite(0, "/Users/jbaker/Desktop/paradise.jpg", #PB_Sprite_Texture | #PB_Sprite_Alpha | #PB_Sprite_Memory)
  ; windows
  ;LoadSprite(0, "img/weather.jpg", #PB_Sprite_Texture | #PB_Sprite_Alpha | #PB_Sprite_Memory)
  ResizeWindow(0, #PB_Ignore, #PB_Ignore, 960, 540)
  Repeat
    
    ; Inverse the buffers (the back become the front (visible)... And we can do the rendering on the back)
    event = WaitWindowEvent(10)
    
    FlipBuffers()
    
    ClearScreen(RGB(0,0,0))

    DisplaySprite(0, 0, 0)
    
    ExamineKeyboard()
  Until KeyboardPushed(#PB_Key_Escape) Or event = #PB_Event_CloseWindow
EndIf
www.posemotion.com

PureBasic Tools for OS X: PureMonitor, plist Tool, Data Maker & App Chef

Mac: 10.13.6 / 1.4GHz Core 2 Duo / 2GB DDR3 / Nvidia 320M
PC: Win 7 / AMD 64 4000+ / 3GB DDR / Nvidia 720GT


Even the vine knows it surroundings but the man with eyes does not.
User avatar
fsw
Addict
Addict
Posts: 1572
Joined: Tue Apr 29, 2003 9:18 pm
Location: North by Northwest

Re: OpenWindowedScreen has no Autostretch

Post by fsw »

Thank you for this workaround.

IMHO OpenWindowedScreen should work the same on all OS though.

I am to provide the public with beneficial shocks.
Alfred Hitshock
User avatar
J. Baker
Addict
Addict
Posts: 2178
Joined: Sun Apr 27, 2003 8:12 am
Location: USA
Contact:

Re: OpenWindowedScreen has no Autostretch

Post by J. Baker »

No problem. ;)

Fred just did recently get the stretch feature working on Mac. So it being new, it may not behave exactly like the Windows version. I'm just glad it works now. :D
www.posemotion.com

PureBasic Tools for OS X: PureMonitor, plist Tool, Data Maker & App Chef

Mac: 10.13.6 / 1.4GHz Core 2 Duo / 2GB DDR3 / Nvidia 320M
PC: Win 7 / AMD 64 4000+ / 3GB DDR / Nvidia 720GT


Even the vine knows it surroundings but the man with eyes does not.
Fred
Administrator
Administrator
Posts: 16617
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: OpenWindowedScreen has no Autostretch

Post by Fred »

Seems to work just fine in current version, can anybody else confirm ?

Code: Select all

If OpenWindow(0, 0, 0, 960, 540, "Gadget and sprites!", #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_ScreenCentered)
  InitSprite()
  InitKeyboard()
  UseJPEGImageDecoder()
  ; open 1920 x 1080 screen
  OpenWindowedScreen(WindowID(0), 0, 0, 1920, 1080, 1, 0, 0, #PB_Screen_SmartSynchronization)
  ; load 1920x1080 jpg image
  ; macos
  ;
  CreateSprite(0, 1920, 1080)
 ; LoadSprite(0, GetPathPart(ProgramFilename()) + "../../../" + "img/weather.jpg")
  ; windows
  ;LoadSprite(0, "img/weather.jpg", #PB_Sprite_Texture | #PB_Sprite_Alpha | #PB_Sprite_Memory)
  Repeat
   
    ; Inverse the buffers (the back become the front (visible)... And we can do the rendering on the back)
    event = WaitWindowEvent(10)
   
    FlipBuffers()
   
    ClearScreen(RGB(0,0,255))

    DisplaySprite(0, 0, 0)
   
    ExamineKeyboard()
  Until KeyboardPushed(#PB_Key_Escape) Or event = #PB_Event_CloseWindow
EndIf
Screen should be full black
skape
User
User
Posts: 17
Joined: Mon Nov 18, 2013 7:24 am

Re: OpenWindowedScreen has no Autostretch

Post by skape »

There are still issues with how OpenWindowedScreen works on MacOS (MacOS 10.15.5 and PB 5.72). Using the code posted at the end for testing:

1) On a "non-retina" screen connected to the Mac, everything works as expected, EXCEPT: mouse is captured, but is actually offset from the window so that when you click, you actually click on somewhere else on the desktop and your window loses focus. The mouse is "captured" off of the window, making Windowed Screens with captured mouse unusable.

2) On a "retina" screen (in-built laptop screen), a window of 500x500 is double the size of a screen of 500x500. This sort of makes sense, as the rendering surface is actually higher DPI, but the desktop DPI gets reported as 1.00, making it hard to adjust for.

3) On a "retina" screen, if you attempt to create the 2x resolution surface as above and then scale up the window to 2x size, the surface doesn't seem to scale with the window. The ClearScreen() still clears the entire window, but the mouse and ScreenOutput() drawing is clipped to the bottom-left quarter of the windowed screen?

I can attempt to explain better if needed.

Code: Select all

EnableExplicit

Structure Point
  x.f
  y.f
EndStructure

Structure Platform
  x1.f
  y1.f
  x2.f
  y2.f
EndStructure

Declare CreatePlatform(x1.f, y1.f, x2.f, y2.f)
Declare CreateMouse()

; General pre-setup stuff / initializations
If InitSprite() = 0 Or InitKeyboard() = 0 Or InitMouse() = 0
  MessageRequester("Startup error", "There was an error initializing the hardware. Exiting...")
  End
EndIf 

UsePNGImageDecoder()

; General constants
#SCREEN_WIDTH = 500
#SCREEN_HEIGHT = 500

ExamineDesktops()

If OpenWindow(0, 100, 100, #SCREEN_WIDTH/2, #SCREEN_HEIGHT/2, "PB DRAWING TEST", #PB_Window_ScreenCentered) = 0
  MessageRequester("Startup error", "There was an error opening the window. Exiting...")
  End
EndIf
  

; Open the screen for rendering...
If OpenWindowedScreen(WindowID(0),0,0, #SCREEN_WIDTH, #SCREEN_HEIGHT, 1, 0, 0, #PB_Screen_WaitSynchronization) = 0
  MessageRequester("Startup error", "There was an error initializing rendering. Exiting...")
  End
EndIf

CreateMouse();
ReleaseMouse(1)

Debug(Str(DesktopResolutionX()))
SetFrameRate(60)

Define e.i ; event handler
Define quit = #False

Define lastClick.Point
lastClick\x = 0
lastClick\y = 0

Global NewList platforms.Platform()

; initialize some test platforms
Define i.i
For i = 0 To 1000
  CreatePlatform(Random(#SCREEN_WIDTH), Random(#SCREEN_HEIGHT), Random(#SCREEN_WIDTH), Random(#SCREEN_HEIGHT))
Next

;ReleaseMouse(#True)

Define MouseClicked.a = #False
ReleaseMouse(0)

;- Start the main loop -----------------------
Repeat
  ;- Process events loop ---------------------
  Repeat
    e = WindowEvent()
    Select e
      Case #PB_Event_CloseWindow
        quit = #True
        
    EndSelect
  Until e = 0
  
  ;- Main game loop -------------------------
    
  ExamineKeyboard()
  ExamineMouse()
  
  If MouseButton(#PB_MouseButton_Left)
    If Not MouseClicked
      ; The mouse was clicked and we need to create another platform
      CreatePlatform(lastClick\x, lastClick\y, MouseX(), MouseY())
      lastClick\x = MouseX()
      lastClick\y = MouseY()
      MouseClicked = #True
    EndIf
  Else
    MouseClicked = #False
  EndIf
    
  If KeyboardPushed(#PB_Key_Escape)
    quit = #True
  EndIf
  
  If KeyboardPushed(#PB_Key_1 )
    ResizeWindow(0, #PB_Ignore, #PB_Ignore, #SCREEN_WIDTH*2, #SCREEN_HEIGHT*2)
  EndIf
  
  ;- Draw game
  ClearScreen(RGB(0,0,Random(200)))
  
  
  ; Draw mouse
  DisplayTransparentSprite(0,MouseX(),MouseY())
  
  StartDrawing(ScreenOutput())
  
  ForEach platforms()
    platforms()\x1 = platforms()\x1 + 1
    LineXY(platforms()\x1, platforms()\y1, platforms()\x2, platforms()\y2, $FFFFFF)  
  Next
  
  StopDrawing()
  
  FlipBuffers()
  
Until quit = #True

Procedure CreateMouse()
;   CreateImage(0, 32, 32, 24, $000000)
;   StartVectorDrawing(ImageVectorOutput(0))
;   VectorSourceColor($000000)
;   AddPathSegments("M 0 0 L 32 0 L 0 32 Z")
;   FillPath()
;   StopVectorDrawing()

;   StartDrawing(SpriteOutput(0))
;   DrawImage(0,0,0) 
;   StopDrawing()
;   FreeImage(0)       
  LoadSprite(0, "assets/cursor_t.png",#PB_Sprite_AlphaBlending)
EndProcedure

Procedure CreatePlatform(x1.f, y1.f, x2.f, y2.f)
  Define *p.Platform = AddElement(platforms())
  With *p
    \x1 = x1
    \y1 = y1
    \x2 = x2
    \y2 = y2
  EndWith
  
  ;Debug("Platform created.")
EndProcedure
skape
User
User
Posts: 17
Joined: Mon Nov 18, 2013 7:24 am

Re: OpenWindowedScreen has no Autostretch

Post by skape »

Playing around with it more: without an external display attached, sometimes the rendering surface appears to be the "correct" size (aka, actually takes up the whole window) and sometimes it appears as "true pixels" I guess, and therefore takes up only a quarter of the window. It varies from run to run which version you will get?

Every time you resize the window via ResizeWindow() though, it returns to being the quarter-window size. Every time you resize the window with the mouse, it corrects itself and stretches to the whole window. Extremely inconsistent.....

Windowed screens are completely unusable on MacOS at this time--at least for recent Macs with Hi-DPI screens.
ProphetOfDoom
User
User
Posts: 84
Joined: Mon Jun 30, 2008 4:36 pm
Location: UK

Re: OpenWindowedScreen has no Autostretch

Post by ProphetOfDoom »

I just came across a similar problem on macOS with a 12-inch Retina MacBook from 2016. I would display a sprite at y=0 and it would appear half way down the screen. This bug is from 2012!!! I’m really disappointed in PureBasic. It’s so incredibly buggy and I’m unlikely to use it for any new projects now it’s just a liability.
User avatar
idle
Always Here
Always Here
Posts: 5042
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: OpenWindowedScreen has no Autostretch

Post by idle »

This is still broken with the retina display, PB6.00 LTS on macOS Monterey 12.6.3
,
Fred
Administrator
Administrator
Posts: 16617
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: OpenWindowedScreen has no Autostretch

Post by Fred »

Fixed.
Post Reply