Screenshot for MacOS
Can anyone with MacOS supply a screenshot of one of the example files, or of it's own project? Just make a pull request and add the image to the image folder and update the README.md file. We are now working on the GL-version branch at the moment.
Hello! я протестировал ваш код на MacOS . Я использовал Lazarus.
В модуле GLPT_Cocoa.inc Мне пришлось заккоментировать в TBorderlessWindow = objcclass (NSWindow) :
// function initWithContentRect_styleMask_backing_defer (contentRect: NSRect; aStyle: NSUInteger; bufferingType: NSBackingStoreType; flag: boolean): id; override; // function canBecomeKeyWindow: boolean; override; // function canBecomeMainWindow: boolean; override;
и в TOpenGLView = objcclass (NSView) :
// function isOpaque: Boolean; override;
и соответственно код ниже.
Так же в модуле GLPT_Cocoa.inc есть ошибка (недоработка) при инициализации окна: function Cocoa_CreateWindow(win: pGLPTwindow; posx, posy, sizex, sizey: integer; title: PChar): boolean;
if flags <> (flags or GLPT_WINDOW_FULLSCREEN) then begin screen := NSScreen.mainScreen; if posx = GLPT_WINDOW_POS_CENTER then posx := trunc(NSWidth(screen.frame)/2 - sizex/2); if posy = GLPT_WINDOW_POS_CENTER then posy := trunc(NSHeight(screen.frame)/2 - sizey/2); window := TCocoaWindow.alloc.initWithContentRect_styleMask_backing_defer(NSMakeRect(posx, posy, sizex, sizey), windowFlags, NSBackingStoreBuffered, false); window.setTitle(NSSTR(title)); end
для исправления пришлось изменить этот код на :
if flags <> (flags or GLPT_WINDOW_FULLSCREEN) then begin screen := NSScreen.mainScreen; if (flags and GLPT_WINDOW_POS_CENTER) <> 0 then begin posx := trunc(NSWidth(screen.frame)/2 - sizex/2); posy := trunc(NSHeight(screen.frame)/2 - sizey/2); end; window := TCocoaWindow.alloc.initWithContentRect_styleMask_backing_defer(NSMakeRect(posx, posy, sizex, sizey), windowFlags, NSBackingStoreBuffered, false); window.setTitle(NSSTR(title)); end
но для этого надо опять менять флаг: GLPT_WINDOW_POS_CENTER - на другое значение
так же предлагаю для исправления (но это заденет основной файл, надо это или нет?) в той же функции :
if (flags and GLPT_WINDOW_DEFAULT) <> 0 then begin windowFlags := NSTitledWindowMask + NSClosableWindowMask + NSMiniaturizableWindowMask + NSResizableWindowMask; end else begin if (flags and GLPT_WINDOW_TITLED) <> 0 then windowFlags += NSTitledWindowMask; if (flags and GLPT_WINDOW_CLOSABLE) <> 0 then windowFlags += NSClosableWindowMask; if (flags and GLPT_WINDOW_MINIATURIZABLE) <> 0 then windowFlags += NSMiniaturizableWindowMask; if (flags and GLPT_WINDOW_RESIZABLE) <> 0 then windowFlags += NSResizableWindowMask; if (flags and GLPT_WINDOW_BORDERLESS) <> 0 then windowFlags := NSBorderlessWindowMask; end;`
и флаги в GLPT.pas :
// window style flags GLPT_WINDOW_BORDERLESS = $00000001; GLPT_WINDOW_TITLED = $00000002; GLPT_WINDOW_CLOSABLE = $00000004; GLPT_WINDOW_MINIATURIZABLE = $00000008; GLPT_WINDOW_RESIZABLE = $000000010; GLPT_WINDOW_FULLSCREEN = $000000020; GLPT_WINDOW_POS_CENTER = $000000040; GLPT_WINDOW_DEFAULT = GLPT_WINDOW_TITLED or GLPT_WINDOW_CLOSABLE or GLPT_WINDOW_MINIATURIZABLE or GLPT_WINDOW_RESIZABLE or GLPT_WINDOW_POS_CENTER;
google translate: i tested your code on macOS. I have used Lazarus.
In the GLPT_Cocoa.inc module I had to comment out in TBorderlessWindow = objcclass (NSWindow):
// function initWithContentRect_styleMask_backing_defer (contentRect: NSRect; aStyle: NSUInteger; bufferingType: NSBackingStoreType; flag: boolean): id; override; // function canBecomeKeyWindow: boolean; override; // function canBecomeMainWindow: boolean; override;
and in TOpenGLView = objcclass (NSView):
// function isOpaque: Boolean; override;
and accordingly the code below.
Also in the GLPT_Cocoa.inc module there is an error (flaw) during window initialization: function Cocoa_CreateWindow (win: pGLPTwindow; posx, posy, sizex, sizey: integer; title: PChar): boolean;
if flags <> (flags or GLPT_WINDOW_FULLSCREEN) then begin screen: = NSScreen.mainScreen; if posx = GLPT_WINDOW_POS_CENTER then posx: = trunc (NSWidth (screen.frame) / 2 - sizex / 2); if posy = GLPT_WINDOW_POS_CENTER then posy: = trunc (NSHeight (screen.frame) / 2 - sizey / 2); window: = TCocoaWindow.alloc.initWithContentRect_styleMask_backing_defer (NSMakeRect (posx, posy, sizex, sizey), windowFlags, NSBackingStoreBuffered, false); window.setTitle (NSSTR (title)); end
to fix it I had to change this code to:
if flags <> (flags or GLPT_WINDOW_FULLSCREEN) then begin screen: = NSScreen.mainScreen; if (flags and GLPT_WINDOW_POS_CENTER) <> 0 then begin posx: = trunc (NSWidth (screen.frame) / 2 - sizex / 2); posy: = trunc (NSHeight (screen.frame) / 2 - sizey / 2); end; window: = TCocoaWindow.alloc.initWithContentRect_styleMask_backing_defer (NSMakeRect (posx, posy, sizex, sizey), windowFlags, NSBackingStoreBuffered, false); window.setTitle (NSSTR (title)); end
but for this you need to change the flag again: GLPT_WINDOW_POS_CENTER - to another value
I also propose to fix it (but it will affect the main file, is it necessary or not?) in the same function:
if (flags and GLPT_WINDOW_DEFAULT) <> 0 then begin windowFlags: = NSTitledWindowMask + NSClosableWindowMask + NSMiniaturizableWindowMask + NSResizableWindowMask; end else begin if (flags and GLPT_WINDOW_TITLED) <> 0 then windowFlags + = NSTitledWindowMask; if (flags and GLPT_WINDOW_CLOSABLE) <> 0 then windowFlags + = NSClosableWindowMask; if (flags and GLPT_WINDOW_MINIATURIZABLE) <> 0 then windowFlags + = NSMiniaturizableWindowMask; if (flags and GLPT_WINDOW_RESIZABLE) <> 0 then windowFlags + = NSResizableWindowMask; if (flags and GLPT_WINDOW_BORDERLESS) <> 0 then windowFlags: = NSBorderlessWindowMask; end;
and flags in GLPT.pas:
// window style flags GLPT_WINDOW_BORDERLESS = $ 00000001; GLPT_WINDOW_TITLED = $ 00000002; GLPT_WINDOW_CLOSABLE = $ 00000004; GLPT_WINDOW_MINIATURIZABLE = $ 00000008; GLPT_WINDOW_RESIZABLE = $ 000000010; GLPT_WINDOW_FULLSCREEN = $ 000000020; GLPT_WINDOW_POS_CENTER = $ 000000040; GLPT_WINDOW_DEFAULT = GLPT_WINDOW_TITLED or GLPT_WINDOW_CLOSABLE or GLPT_WINDOW_MINIATURIZABLE or GLPT_WINDOW_RESIZABLE or GLPT_WINDOW_POS_CENTER;
In FPC 3.2 boolean changed to "objcbool" for the Cocoa headers.
In FPC 3.2 boolean changed to "objcbool" for the Cocoa headers.
I just submitted PR fixing it, https://github.com/daar/GLPT/pull/14 .
I also submitted PR https://github.com/daar/GLPT/pull/15 .
After https://github.com/daar/GLPT/pull/14 and https://github.com/daar/GLPT/pull/15 GLPT works now cool on macOS for me.
( I am specifically testing GLPT to adapt GLPT Cocoa code to have Cocoa support in Castle Game Engine in TCastleWindow, see TODO on https://castle-engine.io/macos - """The plan is to implement CastleWindow backend based directly on Cocoa (without using LCL in the middle).""" )
I'm attaching a screenshot. Feel free to add this to GLPT README etc. :)
