GPI wrote: Tue Mar 03, 2026 7:38 pmimportc
Code: Select all
; SDL 3 Test
Procedure.s UpperDir(path$, level = 1, setcurrdir = #False) ; get enclosing folder (multilevel)
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
PrototypeC.i _SDL_Init(flags.l)
PrototypeC _SDL_Quit()
PrototypeC _SDL_PumpEvents()
PrototypeC.i _SDL_CreateWindowAndRenderer(*title, 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)
; To make a standalone .app, copy SDL3.framework into your app.
; Put it into folder: your.app/Contents/Frameworks/ (needed only once!)
; Then you can use:
; If OpenLibrary(0, UpperDir(ProgramFilename())+"Frameworks/SDL3.framework/SDL3")
If OpenLibrary(0, "SDL3.framework/SDL3") ; Framework on source folder for debugging
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))
If (SDL_CreateWindowAndRenderer(UTF8("SDL3 Test"), 640, 480, 0, @*win, @*ren))
SDL_SetRenderDrawColor(*ren, 0, 255, 0, 255)
SDL_RenderClear(*ren)
SDL_RenderPresent(*ren)
For i=0 to 99
SDL_PumpEvents() ; fix for Mac
Next
Delay(2000)
SDL_DestroyRenderer(*ren)
SDL_DestroyWindow(*win)
EndIf
SDL_Quit()
EndIf
EndIf
PS:
