Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Screenshot for MacOS #7

Open
daar opened this issue Feb 24, 2019 · 4 comments
Open

Screenshot for MacOS #7

daar opened this issue Feb 24, 2019 · 4 comments
Labels
question Further information is requested

Comments

@daar
Copy link
Owner

daar commented Feb 24, 2019

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.

@daar daar added the question Further information is requested label Feb 24, 2019
@Seenkao
Copy link

Seenkao commented Nov 8, 2020

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;

@genericptr
Copy link
Collaborator

In FPC 3.2 boolean changed to "objcbool" for the Cocoa headers.

@michaliskambi
Copy link

In FPC 3.2 boolean changed to "objcbool" for the Cocoa headers.

I just submitted PR fixing it, #14 .

@michaliskambi
Copy link

I also submitted PR #15 .

After #14 and #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. :)

m

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

4 participants