-
Notifications
You must be signed in to change notification settings - Fork 0
/
sdl-binding.lisp
99 lines (71 loc) · 2.98 KB
/
sdl-binding.lisp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
;; (require :cffi)
;; (require :cffi-grovel)
;; (use-package :cffi)
;; (load (cffi-grovel:process-grovel-file "sdl-keyboard-grovel.lisp" "/dev/shm/_sdl_keyboard.o"))
;; (load (cffi-grovel:process-grovel-file "sdl-grovel.lisp" "/dev/shm/_sdl.o"))
(in-package :handy-sdl)
(defun load-sdl ()
(load-foreign-library "libSDL2-2.0.so")
(load-foreign-library "libSDL2_image-2.0.so.0"))
(defcfun ("SDL_Init" c-sdl-init) :int (flags :int))
(defcfun ("SDL_Quit" c-sdl-quit) :void)
(defcfun ("SDL_GetError" c-sdl-get-error) :string)
(defcfun ("SDL_CreateWindow" c-sdl-createwindow) :pointer
(title :string)
(x :int)
(y :int)
(w :int)
(h :int)
(flags :uint32))
;; (foreign-enum-keyword-list 'c-sdl-window-flags)
(defcfun ("SDL_DestroyWindow" c-sdl-DestroyWindow) :void (window :pointer))
;; ------------------------------------------------------
;; Stream IO
(defcfun ("SDL_RWFromFile" c-sdl-rw-from-file) (:pointer (:struct c-sdl-rwops))
(file :string) (mode :string))
(defcfun ("SDL_FreeRW" c-sdl-free-rw) :void
(area (:pointer (:struct c-sdl-rwops))))
(defcfun ("SDL_LoadBMP_RW" c-sdl-load-bmp-rw) (:pointer (:struct c-sdl-surface))
(src (:pointer (:struct c-sdl-rwops))) (freesrc :int))
;; ------------------------------------------------------
;; Renderer
(defcfun ("SDL_CreateRenderer" c-sdl-CreateRenderer) :pointer
(window-ptr :pointer)
(index :int)
(flags :uint32))
(defcfun ("SDL_DestroyRenderer" c-sdl-destroyrenderer) :void (renderer :pointer))
(defcfun ("SDL_RenderClear" c-sdl-RenderClear) :void (render :pointer))
(defcfun ("SDL_RenderCopy" c-sdl-RenderCopy) :void
(render :pointer)
(texture :pointer)
(srcrect (:pointer (:struct c-sdl-rect)))
(dstrect (:pointer (:struct c-sdl-rect))))
(defcfun ("SDL_RenderPresent" c-sdl-RenderPresent) :void (renderer :pointer))
;; --------------------------------------------------------
;; Surface & Texture
;;void SDL_FreeSurface(SDL_Surface* surface)
(defcfun ("SDL_FreeSurface" c-sdl-freesurface) :void (surface :pointer))
(defcfun ("SDL_CreateTexture" c-sdl-create-texture) :pointer
(renderer :pointer)
(format :uint32)
(w :int) (h :int))
(defcfun ("SDL_CreateTextureFromSurface" c-sdl-create-texture-from-surface) :pointer
(renderer :pointer)
(surface (:pointer (:struct c-sdl-surface))))
(defcfun ("SDL_DestroyTexture" c-sdl-DestroyTexture) :void (texture :pointer))
(defcfun ("SDL_BlitSurface" c-sdl-blit-surface) :int
(src (:pointer (:struct c-sdl-surface)))
(srcrect (:pointer (:struct c-sdl-rect)))
(dst (:pointer (:struct c-sdl-surface)))
(dstrect (:pointer (:struct c-sdl-rect))))
(defcfun ("SDL_RenderCopy" c-sdl-render-copy) :int
(renderer :pointer)
(texture :pointer)
(srcrect (:pointer (:struct c-sdl-rect)))
(dstrect (:pointer (:struct c-sdl-rect))))
;; --------------------------------------------------------
;; Event
(defcfun ("SDL_WaitEvent" c-sdl-wait-event) :int
(event (:pointer (:struct c-sdl-event))))
(defcfun ("SDL_PollEvent" c-sdl-poll-event) :int
(event (:pointer (:struct c-sdl-event))))