Can some Guru here show me the best way to "include/call" it, after placing it INSIDE a PB app?
It should include
Code: Select all
ImportC "/inside/app/libSDL2-2.0.0.dylib"
Thanks in advance, and please forgive me if I wrote some PB/C blasphemy




Code: Select all
ImportC "/inside/app/libSDL2-2.0.0.dylib"
Code: Select all
Procedure.s UpperDir(path$, level = 1, setcurrdir = #False)
Protected i, oldcurrdir$ = GetCurrentDirectory()
path$ = GetPathPart(path$) ; in case of file
For i = 1 To level : path$ + ".." + #PS$ : Next
SetCurrentDirectory(path$)
path$ = GetCurrentDirectory()
If Not setcurrdir : SetCurrentDirectory(oldcurrdir$) : EndIf
ProcedureReturn path$
EndProcedure
sdl2.s=UpperDir(ProgramFilename())+"Resources/Libraries/libSDL2-2.0.0.dylib"
OpenLibrary(0, sdl2) ; no error if it doesn't exist (so you can test the app later after adding it…)
Debug sdl2
Code: Select all
; SDL_Test.app
;
; Download: https://github.com/libsdl-org/SDL/releases/tag/release-2.30.11
;
; To make a standalone .app, copy SDL2.framework into your app.
; Put it into folder: your.app/Contents/Frameworks/
;
; Now run the following command on the command line (from the same directory where your .app is):
; install_name_tool -add_rpath @executable_path/../Frameworks ./SDL_Test.app/Contents/MacOS/SDL_Test
; This adds the .app internal 'Frameworks' directory to the search path for frameworks.
; YOU NEED TO DO IT EACH TIME YOU COMPILE "SDL_Test.app"!
;
; Now test if it is working:
; ./SDL_Test.app/Contents/MacOS/SDL_Test (or run it from Finder)
PrototypeC.i _SDL_Init(flags.l)
PrototypeC _SDL_Quit()
PrototypeC _SDL_PumpEvents()
PrototypeC.i _SDL_CreateWindowAndRenderer(width.i, height.i, window_flags.l, *pWindow, *pRenderer)
PrototypeC _SDL_DestroyRenderer(*renderer)
PrototypeC _SDL_DestroyWindow(*window)
PrototypeC.i _SDL_SetRenderDrawColor(*renderer, r.a, g.a, b.a, a.a)
PrototypeC.i _SDL_RenderClear(*renderer)
PrototypeC _SDL_RenderPresent(*renderer)
If OpenLibrary(0, "SDL2.framework/SDL2")
Global SDL_Init._SDL_Init = GetFunction(0, "SDL_Init")
Global SDL_Quit._SDL_Quit = GetFunction(0, "SDL_Quit")
Global SDL_PumpEvents._SDL_PumpEvents = GetFunction(0, "SDL_PumpEvents")
Global SDL_CreateWindowAndRenderer._SDL_CreateWindowAndRenderer = GetFunction(0, "SDL_CreateWindowAndRenderer")
Global SDL_DestroyRenderer._SDL_DestroyRenderer = GetFunction(0, "SDL_DestroyRenderer")
Global SDL_DestroyWindow._SDL_DestroyWindow = GetFunction(0, "SDL_DestroyWindow")
Global SDL_SetRenderDrawColor._SDL_SetRenderDrawColor = GetFunction(0, "SDL_SetRenderDrawColor")
Global SDL_RenderClear._SDL_RenderClear = GetFunction(0, "SDL_RenderClear")
Global SDL_RenderPresent._SDL_RenderPresent = GetFunction(0, "SDL_RenderPresent")
If (SDL_Init($20) = 0)
If (SDL_CreateWindowAndRenderer(640, 480, 0, @*win, @*ren) = 0)
SDL_SetRenderDrawColor(*ren, 0, 255, 0, 255)
SDL_RenderClear(*ren)
SDL_RenderPresent(*ren)
For i=0 to 100
SDL_PumpEvents() ; fix for Mac
Next
Delay(2000)
SDL_DestroyRenderer(*ren)
SDL_DestroyWindow(*win)
EndIf
SDL_Quit()
EndIf
EndIf
Code: Select all
; SDL Test
;
; Download: https://github.com/libsdl-org/SDL/releases/tag/release-2.32.10
;
; To make a standalone .app, copy SDL2.framework into your app.
; Put it into folder: your.app/Contents/Frameworks/ (needed only once!)
PrototypeC.i _SDL_Init(flags.l)
PrototypeC _SDL_Quit()
PrototypeC _SDL_PumpEvents()
PrototypeC.i _SDL_CreateWindowAndRenderer(width.i, height.i, window_flags.l, *pWindow, *pRenderer)
PrototypeC _SDL_DestroyRenderer(*renderer)
PrototypeC _SDL_DestroyWindow(*window)
PrototypeC.i _SDL_SetRenderDrawColor(*renderer, r.a, g.a, b.a, a.a)
PrototypeC.i _SDL_RenderClear(*renderer)
PrototypeC _SDL_RenderPresent(*renderer)
Procedure.s UpperDir(path$, level = 1, setcurrdir = #False)
Protected i, oldcurrdir$ = GetCurrentDirectory()
path$ = GetPathPart(path$) ; in case of file
For i = 1 To level : path$ + ".." + #PS$ : Next
SetCurrentDirectory(path$)
path$ = GetCurrentDirectory()
If Not setcurrdir : SetCurrentDirectory(oldcurrdir$) : EndIf
ProcedureReturn path$
EndProcedure
Macro dq : "
EndMacro
Macro Fun(f,i=0)
Global f#._#f = GetFunction(i, dq#f#dq)
EndMacro
If OpenLibrary(0, UpperDir(ProgramFilename())+"Frameworks/SDL2.framework/SDL2")
Fun(SDL_Init)
Fun(SDL_Quit)
Fun(SDL_PumpEvents)
Fun(SDL_CreateWindowAndRenderer)
Fun(SDL_DestroyRenderer)
Fun(SDL_DestroyWindow)
Fun(SDL_SetRenderDrawColor)
Fun(SDL_RenderClear)
Fun(SDL_RenderPresent)
If (SDL_Init($20) = 0)
If (SDL_CreateWindowAndRenderer(640, 480, 0, @*win, @*ren) = 0)
SDL_SetRenderDrawColor(*ren, 0, 255, 0, 255)
SDL_RenderClear(*ren)
SDL_RenderPresent(*ren)
For i=0 to 100
SDL_PumpEvents() ; fix for Mac
Next
Delay(2000)
SDL_DestroyRenderer(*ren)
SDL_DestroyWindow(*win)
EndIf
SDL_Quit()
EndIf
EndIf
Well, from what I've seen the framework seems more convenient than the dylib (I'll eventually test with the incoming inline C…)