Graphic divide by 2 on Mac M1

Post bugreports for the Mac OSX version here
Bmld756
User
User
Posts: 30
Joined: Mon Sep 19, 2022 3:30 pm

Graphic divide by 2 on Mac M1

Post by Bmld756 »

Hello,

To learn to program on my first computer, a HP model 85, I create a little game 45 years ago. I want to write it with PB, but I found a difference between PB 6,20 on Imac Sequoia and PB 6.20 on MacBook M1 pb 6.20

On each case , it is the same code share via google drive.

The game compile on Imac, everything is correct
Image

The game compile on M1 , graphic is divided by 2
Image

The code
To control player 1 use arrows right and left, and player2 key "w" and key "x"

Code: Select all

EnableExplicit  ;n'accepte que les variables déclarées

Global LargBox = 10, HautBox = 10,X1,Y1,X2,Y2,largeur=400,hauteur=400,delta = 20
Global dir1, dir2, coul1, coul2, h1,h2, v1,v2, fin
Debug largeur/delta
Global Dim tab(largeur/delta,hauteur/delta)
Global max = (largeur/delta)-1
Debug "max" + max

Procedure serpent1Aff()
  ;Debug "1 "+x1+" "+y1
  If X1 > largeur/delta Or Y1 > hauteur/delta Or x1 < 0 Or y1 < 0
    SetGadgetColor(14, #PB_Gadget_FrontColor , coul2)
    SetGadgetText(14,"Joueur 2 gagné") 
    fin = #True
  ElseIf tab(x1,y1) > 0
    SetGadgetColor(14, #PB_Gadget_FrontColor , coul2)
    SetGadgetText(14,"Joueur 2 gagné")
    fin = #True
  Else
    tab(x1,y1) = 1
    StartDrawing(CanvasOutput(10))
    Box(X1*delta, Y1*delta,delta, delta , coul1)
    StopDrawing()  
  EndIf
  
  
EndProcedure

Procedure serpent1()
  ; direction 1>h, 2>b, 3>d, 4>g
  Debug "dir1 1 "+dir1
  
  Debug "S1 x1:"+x1+" y1:"+y1 +" h1:"+h1+" v1:"+v1
  
  Debug ">>>>>>>>>>>>>>>>>"+tab(x1,y1)
  
  
  Select dir1 ; changement de direction si case non libre
    Case 1    ;^
      If tab(X1,y1-1) > 0 And tab(x1+1,Y1) > 0; coin 
        dir1 = 4
      ElseIf tab(X1,y1-1) > 0 And tab(x1-1,Y1) > 0 ; coin 
        dir1 = 3
      ElseIf tab(x1,y1-1) > 0
        dir1=Random(4,3)
      EndIf
    Case 2 ;v      
      If tab(X1,y1+1) > 0 And tab(x1-1,Y1) > 0; coin 
        dir1 = 3
      ElseIf tab(X1+1,y1) > 0 And tab(x1,Y1+1) > 0 ; coin 
        dir1 = 4
      ElseIf tab(x1,y1+1) > 0
        dir1=Random(4,3)
      EndIf
    Case 3 ;>
      If tab(X1,y1-1) > 0 And tab(x1+1,Y1) > 0; coin 
        dir1 = 2
      ElseIf tab(X1+1,y1) > 0 And tab(x1,Y1+1) > 0 ; coin 
        dir1 = 1
      ElseIf tab(x1+1,y1) > 0
        dir1=Random(2,1)
      EndIf
    Case 4 ;<
      If tab(X1-1,y1) > 0 And tab(x1,Y1-1) > 0; coin 
        dir1 = 2
      ElseIf tab(X1-1,y1) > 0 And tab(x1,Y1+1) > 0 ; coin 
        dir1 = 1
      ElseIf tab(x1-1,y1) > 0
        dir1=Random(2,1)
      EndIf
  EndSelect   
  
  
  Select dir1
    Case 1 ;^
      Y1 = y1 - 1 ; haut
    Case 2        ;v
      y1 = y1 + 1
    Case 3 ;>
      x1 = x1 + 1
    Case 4 ;<
      X1 = X1 - 1
  EndSelect
  
  serpent1Aff()
  
EndProcedure


Procedure serpent2Aff()
  ;Debug "2 "+x2+" "+y2
  
  If X2 > largeur/delta Or Y2 > hauteur/delta Or x2 < 0 Or y2 < 0
    SetGadgetColor(14, #PB_Gadget_FrontColor , coul1)
    SetGadgetText(14,"Joueur 1 gagné") 
    fin = #True
  ElseIf tab(x2,y2) >0
    SetGadgetColor(14, #PB_Gadget_FrontColor , coul1)
    SetGadgetText(14,"Joueur 1 gagné")
    fin = #True
  Else
    tab(x2,y2) = 2
    StartDrawing(CanvasOutput(10))
    Box(X2*delta, Y2*delta,delta, delta , coul2)
    StopDrawing()  
  EndIf
  
EndProcedure

Procedure serpent2()
  ; direction 1>h, 2>b, 3>d, 4>g
  Debug "2-1 x2:"+x2+" y2:"+y2+" d2"+dir2
  Select dir2 ; changement de direction si case non libre
    Case 1    ;^
      If tab(X2,y2-1) > 0 And tab(x2+1,y2) > 0; coin 
        dir2 = 4
      ElseIf tab(x2,y2-1) > 0 And tab(x2-1,y2) > 0 ; coin 
        dir2 = 3
      ElseIf tab(x2,y2-1) > 0
        dir2=Random(4,3)
      EndIf
    Case 2 ;v      
      If tab(x2,y2+1) > 0 And tab(x2-1,y2) > 0; coin 
        dir2 = 3
      ElseIf tab(x2+1,y2) > 0 And tab(x2,y2+1) > 0 ; coin 
        dir2 = 4
      ElseIf tab(x2,y2+1) > 0
        dir2=Random(4,3)
      EndIf
    Case 3 ;>
      If tab(x2,y2-1) > 0 And tab(x2+1,y2) > 0; coin 
        dir2 = 2
      ElseIf tab(x2+1,y2) > 0 And tab(x2,y2+1) > 0 ; coin 
        dir2 = 1
      ElseIf tab(x2+1,y2) > 0
        dir2=Random(2,1)
      EndIf
    Case 4 ;<
      If tab(x2-1,y2) > 0 And tab(x2,y2-1) > 0; coin 
        dir2 = 2
      ElseIf tab(x2-1,y2) > 0 And tab(x2,y2+1) > 0 ; coin 
        dir2 = 1
      ElseIf tab(x2-1,y2) > 0
        dir2=Random(2,1)
      EndIf
  EndSelect   
  Debug "2-2 x:"+x2+" y"+y2+" d"+dir2
  
  
  Select dir2
    Case 1
      Y2 = y2 - 1
    Case 2
      y2 = y2 + 1
    Case 3
      x2 = x2 + 1
    Case 4    
      X2 = X2 - 1
  EndSelect
  
  
  serpent2Aff()
EndProcedure

Procedure EffaceTab()
  Define i,j
  For i = 1 To max-1
    For j = 1 To max-1
      tab (i,j) = 0      
    Next
    Next
    
  EndProcedure

  Procedure limite()
    Define i,j
  For i = 0 To max
    StartDrawing(CanvasOutput(10))
    tab (max,i) = 2
    Box(max*delta, i*delta,delta, delta , $BDBDBD)
    tab (0,i) = 2
    Box(0, i*delta,delta, delta , $BDBDBD)
    tab (i,max) = 2
    Box(i*delta, max*delta,delta, delta , $BDBDBD)
    tab (i,0) = 2
    Box(i*delta, 0*delta,delta, delta , $BDBDBD)
    StopDrawing() 
  Next
EndProcedure

Procedure PrepareCanvas()
   StartDrawing(CanvasOutput(10))
            Box(delta, delta,largeur-2*delta, hauteur-2*delta , $ffffff)
            StopDrawing()  
            coul1 = RGB(Random(255),Random(255),Random(255))
            dir1 = Random(4,1)
            X1 = Random(largeur/delta-5,5)
            Y1 = Random(hauteur/delta-5,5)
            Debug "1: "+x1+"/"+y1+" "+dir1+" "+coul1
            serpent1aff()
            coul2 = RGB(Random(255),Random(255),Random(255))
            dir2 = Random(4,1)
            X2 = Random(largeur/delta-5,5)
            Y2 = Random(hauteur/delta-5,5)
            Debug "2: "+x2+"/"+y2+ " "+dir2+" "+coul2
            serpent2aff()
  
  EndProcedure


Procedure bordure()
  
EndProcedure

If OpenWindow(0, 0, 0, largeur, hauteur+50, "Le mur", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  Define Event, gadget, type,D, EventMenu, i
  
  AddWindowTimer(0, 123, 200)
  AddKeyboardShortcut(0, #PB_Key_Right, 31)   
  AddKeyboardShortcut(0, #PB_Key_Left, 33)    
  AddKeyboardShortcut(0, #PB_Shortcut_Escape, 34)  
  AddKeyboardShortcut(0, #PB_Key_Up, 32)           
  
  AddKeyboardShortcut(0, #PB_Key_X, 35)        ;w sepent 2 gauche  
  AddKeyboardShortcut(0, #PB_Key_W, 36)        ;x sepent 2 droite
  AddKeyboardShortcut(0, #PB_Key_Space, 37)
  
  TextGadget(14, 10, hauteur+20,150,20,"XXXXXXXXXX")
  
  ButtonGadget(15, largeur - 110, hauteur+20 , 100, 20, "NOUVEAU")
  
  CanvasGadget(10, 0, 0, largeur, hauteur, #PB_Canvas_Container)
  
  ;limite
  For i = 0 To max
    StartDrawing(CanvasOutput(10))
    tab (max,i) = 2
    Box(max*delta, i*delta,delta, delta , $BDBDBD)
    tab (0,i) = 2
    Box(0, i*delta,delta, delta , $BDBDBD)
    tab (i,max) = 2
    Box(i*delta, max*delta,delta, delta , $BDBDBD)
    tab (i,0) = 2
    Box(i*delta, 0*delta,delta, delta , $BDBDBD)
    StopDrawing() 
  Next
  
  
  coul1 = RGB(Random(255),Random(255),Random(255))
  dir1 = Random(4,1)
  X1 = Random(largeur/delta-5,5)
  Y1 = Random(hauteur/delta-5,5)
  Debug "1: "+x1+"/"+y1+" "+dir1+" "+coul1
  serpent1aff()
  coul2 = RGB(Random(255),Random(255),Random(255))
  dir2 = Random(4,1)
  X2 = Random(largeur/delta-5,5)
  Y2 = Random(hauteur/delta-5,5)
  Debug "2: "+x2+"/"+y2+ " "+dir2+" "+coul2
  serpent2aff()
  CloseGadgetList()
  
  Repeat
    Event = WaitWindowEvent()
    gadget = EventGadget()
    type = EventType() 
    
    Select Event
      Case #PB_Event_Menu
        EventMenu = EventMenu()
        Select EventMenu 
          Case 31
            Debug "droite"
            Select dir1
              Case 1 ;^
                dir1 = 3
              Case 2 ;v
                dir1 = 4
              Case 3 ;>
                dir1 = 2
              Case 4 ;<
                dir1 = 1
            EndSelect 
            
            
          Case 33 ;gauche 
            Debug "gauche"
            
            Select dir1
              Case 1 ;^
                dir1 = 4
              Case 2 ;v
                dir1 = 3
              Case 3 ;>
                dir1 = 1
              Case 4 ;<
                dir1 = 2
            EndSelect
            
          Case 36 ;w <
            Debug "2 gauche"
            Select dir2
              Case 1 ;^
                dir2 = 4
              Case 2 ;v
                dir2 = 3
              Case 3 ;>
                dir2 = 1
              Case 4 ;<
                dir2 = 2
            EndSelect
            
          Case 35 ;x >
            Debug "2 droite"
            
            Select dir2
              Case 1 ;^
                dir2 = 3
              Case 2 ;v
                dir2 = 4
              Case 3 ;>
                dir2 = 2
              Case 4 ;<
                dir2 = 1
            EndSelect 
            
          Case 34
            Debug "fin"
            fin  = #True
            
          Case 37  
            serpent1()
            
        EndSelect        
      Case #PB_Event_Timer
        If EventTimer() = 123
          If fin = 0
            serpent1()
            serpent2()
          EndIf
          
        EndIf  
        
        
      Case #PB_Event_Gadget
        Select EventGadget()
          Case 15
            PrepareCanvas()
            EffaceTab()
            fin =#False
          Case 1 
            CloseWindow(0)
            End  
        EndSelect
        
    EndSelect
  Until Event = #PB_Event_CloseWindow
EndIf
Last edited by Bmld756 on Wed Apr 23, 2025 9:07 pm, edited 4 times in total.
IMAC 21.5 2012 Core I5 - 2.70 Ghz. 16 GB NVIDIA GeForce GT 640M 512 Mo. MacOs OCPL Sequoia 15.0
MacBook Air M1 - 8Go - Sonoma 14.1
mrbungle
Enthusiast
Enthusiast
Posts: 143
Joined: Wed Dec 30, 2020 3:18 am

Re: Graphic divide by 2 on Mac M1

Post by mrbungle »

I don't think this is a bug. By default, Retina-enabled Macs automatically enable "DPI-awareness", which will cause this effect. If you uncheck that option in compiler settings, the graphics will use the full size of the window.
Bmld756
User
User
Posts: 30
Joined: Mon Sep 19, 2022 3:30 pm

Re: Graphic divide by 2 on Mac M1

Post by Bmld756 »

Hello,

I don't find this option on Mac, just an option " facteur d'échelle DPI for windows".£I test it and the result is the same. Another thing, when I copy past the code in a new windows editor, the result is correct without modify any option.
IMAC 21.5 2012 Core I5 - 2.70 Ghz. 16 GB NVIDIA GeForce GT 640M 512 Mo. MacOs OCPL Sequoia 15.0
MacBook Air M1 - 8Go - Sonoma 14.1
Bmld756
User
User
Posts: 30
Joined: Mon Sep 19, 2022 3:30 pm

Re: Graphic divide by 2 on Mac M1

Post by Bmld756 »

Hello,

My photos have disappeared...

link to the graphic correct http://bmaillard.free.fr/PureBasic/jeu1.png

Link to the graphic M1 http://bmaillard.free.fr/PureBasic/jeu2.png
IMAC 21.5 2012 Core I5 - 2.70 Ghz. 16 GB NVIDIA GeForce GT 640M 512 Mo. MacOs OCPL Sequoia 15.0
MacBook Air M1 - 8Go - Sonoma 14.1
User avatar
mk-soft
Always Here
Always Here
Posts: 6205
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Graphic divide by 2 on Mac M1

Post by mk-soft »

Show to Compiler-Options.
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
Bmld756
User
User
Posts: 30
Joined: Mon Sep 19, 2022 3:30 pm

Re: Graphic divide by 2 on Mac M1

Post by Bmld756 »

Hello

The options, a little difference between the French and the English. I test with this option and no change.

Image

Image

Image
IMAC 21.5 2012 Core I5 - 2.70 Ghz. 16 GB NVIDIA GeForce GT 640M 512 Mo. MacOs OCPL Sequoia 15.0
MacBook Air M1 - 8Go - Sonoma 14.1
User avatar
Mindphazer
Enthusiast
Enthusiast
Posts: 456
Joined: Mon Sep 10, 2012 10:41 am
Location: Savoie

Re: Graphic divide by 2 on Mac M1

Post by Mindphazer »

I've tried on my MacBook (M4)
If the DPI settings in the compiler options (in French : activer le facteur d'échelle d'affichage) is not checked, it's ok
If i check this option, i have the same behaviour as yours (graphic divided by 2)
MacBook Pro 16" M4 Pro - 24 Gb - MacOS 15.4.1 - Iphone 15 Pro Max - iPad at home
...and unfortunately... Windows at work...
Bmld756
User
User
Posts: 30
Joined: Mon Sep 19, 2022 3:30 pm

Re: Graphic divide by 2 on Mac M1

Post by Bmld756 »

Hello,

Thank for the test, now it works but I had the result divide by 2 without modify this option. I have update PB .... so effectively it is not a bug.
IMAC 21.5 2012 Core I5 - 2.70 Ghz. 16 GB NVIDIA GeForce GT 640M 512 Mo. MacOs OCPL Sequoia 15.0
MacBook Air M1 - 8Go - Sonoma 14.1
User avatar
Piero
Addict
Addict
Posts: 865
Joined: Sat Apr 29, 2023 6:04 pm
Location: Italy

Re: Graphic divide by 2 on Mac M1

Post by Piero »

Here happens only when checking "dpi aware" and display is in HiDPI mode

(I used BetterDisplay to test)
Bmld756
User
User
Posts: 30
Joined: Mon Sep 19, 2022 3:30 pm

Re: Graphic divide by 2 on Mac M1

Post by Bmld756 »

I confirm a problem, when the source is create on Imac intel , the option change nothing on the MacBook Air.

Image

Image


I have to create a new file, copy past the code and then the option work fine.
IMAC 21.5 2012 Core I5 - 2.70 Ghz. 16 GB NVIDIA GeForce GT 640M 512 Mo. MacOs OCPL Sequoia 15.0
MacBook Air M1 - 8Go - Sonoma 14.1
User avatar
Piero
Addict
Addict
Posts: 865
Joined: Sat Apr 29, 2023 6:04 pm
Location: Italy

Re: Graphic divide by 2 on Mac M1

Post by Piero »

Bmld756 wrote: Thu Apr 24, 2025 5:38 pm I confirm a problem, when the source is create on Imac intel , the option change nothing on the MacBook Air.
I have to create a new file, copy past the code and then the option work fine.
I'm ALMOST sure it happened to me too (I remember that initially it didn't work, and display surely was on HiDPI)
I have prefs saved on the end of source
User avatar
Piero
Addict
Addict
Posts: 865
Joined: Sat Apr 29, 2023 6:04 pm
Location: Italy

Re: Graphic divide by 2 on Mac M1

Post by Piero »

It seems that for now, if you want the graphics (canvas) to be (eventually) shown in HiDPI, you need to size/position the rest (e.g., window and gadgets) using DesktopResolutionX()/Y… and check "dpi aware"
Even Form Designer has this problem…
Post Reply