comparison modules/sdl.tp @ 277:2b58eafa360b

Add SDL bindings for creating a renderer, clearing it, presenting it and destroying it
author Michael Pavone <pavone@retrodev.com>
date Sun, 20 Jul 2014 17:30:46 -0700
parents a923b5b7da3d
children 1205c7a43cb4
comparison
equal deleted inserted replaced
276:9f9cc73bf86d 277:2b58eafa360b
16 _constant: haptic SDL_INIT_HAPTIC 16 _constant: haptic SDL_INIT_HAPTIC
17 _constant: gameController SDL_INIT_GAMECONTROLLER 17 _constant: gameController SDL_INIT_GAMECONTROLLER
18 _constant: events SDL_INIT_EVENTS 18 _constant: events SDL_INIT_EVENTS
19 _constant: everything SDL_INIT_EVERYTHING 19 _constant: everything SDL_INIT_EVERYTHING
20 } 20 }
21 21
22 _windowOpts <- #{ 22 _windowOpts <- #{
23 _constant: fullscreen SDL_WINDOW_FULLSCREEN 23 _constant: fullscreen SDL_WINDOW_FULLSCREEN
24 _constant: fullscreenDesktop SDL_WINDOW_FULLSCREEN_DESKTOP 24 _constant: fullscreenDesktop SDL_WINDOW_FULLSCREEN_DESKTOP
25 _constant: opengl SDL_WINDOW_OPENGL 25 _constant: opengl SDL_WINDOW_OPENGL
26 _constant: hidden SDL_WINDOW_HIDDEN 26 _constant: hidden SDL_WINDOW_HIDDEN
28 _constant: minimized SDL_WINDOW_MINIMIZED 28 _constant: minimized SDL_WINDOW_MINIMIZED
29 _constant: maximized SDL_WINDOW_MAXIMIZED 29 _constant: maximized SDL_WINDOW_MAXIMIZED
30 _constant: inputGrabbed SDL_WINDOW_INPUT_GRABBED 30 _constant: inputGrabbed SDL_WINDOW_INPUT_GRABBED
31 _constant: allowHighDPI SDL_WINDOW_ALLOW_HIGHDPI 31 _constant: allowHighDPI SDL_WINDOW_ALLOW_HIGHDPI
32 } 32 }
33 33
34 _renderOpts <- #{
35 _constant: software SDL_RENDERER_SOFTWARE
36 _constant: accelerated SDL_RENDERER_ACCELERATED
37 _constant: presentVSYNC SDL_RENDERER_PRESENTVSYNC
38 _constant: targetTexture SDL_RENDERER_TARGETTEXTURE
39
40 }
41
34 _helper <- #{ 42 _helper <- #{
35 llMessage: createWindow withVars: { 43 llMessage: createWindow withVars: {
36 title <- string ptr 44 title <- string ptr
37 x <- obj_int32 ptr 45 x <- obj_int32 ptr
38 y <- obj_int32 ptr 46 y <- obj_int32 ptr
50 mcall: value 2 option win 58 mcall: value 2 option win
51 } else: { 59 } else: {
52 mcall: none 1 option 60 mcall: none 1 option
53 } 61 }
54 } 62 }
55 } 63
56 64 llMessage: createRenderer withVars: {
65 window <- cpointer ptr
66 index <- obj_int32 ptr
67 flags <- obj_uint32 ptr
68 rendOpaque <- cpointer ptr
69 rend <- object ptr
70 makeRender <- lambda ptr
71 } andCode: :window index flags makeRender {
72 rendOpaque <- make_object: (addr_of: cpointer_meta) NULL 0
73 rendOpaque val!: (SDL_CreateRenderer: (window val) (index num) (flags num))
74 if: (rendOpaque val) {
75 rend <- ccall: makeRender 1 (rendOpaque castTo: (object ptr))
76 mcall: value 2 option rend
77 } else: {
78 mcall: none 1 option
79 }
80 }
81 }
82
57 #{ 83 #{
58 includeSystemHeader: "SDL.h" 84 includeSystemHeader: "SDL.h"
59 includeSystemHeader: "stdlib.h" 85 includeSystemHeader: "stdlib.h"
60 86
61 llMessage: init withVars: { 87 llMessage: init withVars: {
62 flags <- obj_uint32 ptr 88 flags <- obj_uint32 ptr
63 intret <- obj_int32 ptr 89 intret <- obj_int32 ptr
64 } andCode: :flags { 90 } andCode: :flags {
65 intret <- make_object: (addr_of: obj_int32_meta) NULL 0 91 intret <- make_object: (addr_of: obj_int32_meta) NULL 0
67 if: (intret num) { 93 if: (intret num) {
68 atexit: SDL_Quit 94 atexit: SDL_Quit
69 } 95 }
70 intret 96 intret
71 } 97 }
72 98
73 llMessage: initSubSystem withVars: { 99 llMessage: initSubSystem withVars: {
74 flags <- obj_uint32 ptr 100 flags <- obj_uint32 ptr
75 intret <- obj_int32 ptr 101 intret <- obj_int32 ptr
76 } andCode: :flags { 102 } andCode: :flags {
77 intret <- make_object: (addr_of: obj_int32_meta) NULL 0 103 intret <- make_object: (addr_of: obj_int32_meta) NULL 0
78 intret num!: (SDL_InitSubSystem: (flags num)) 104 intret num!: (SDL_InitSubSystem: (flags num))
79 intret 105 intret
80 } 106 }
81 107
82 llMessage: quitSubSystem withVars: { 108 llMessage: quitSubSystem withVars: {
83 flags <- obj_uint32 ptr 109 flags <- obj_uint32 ptr
84 } andCode: :flags { 110 } andCode: :flags {
85 SDL_QuitSubSystem: (flags num) 111 SDL_QuitSubSystem: (flags num)
86 true 112 true
87 } 113 }
88 114
115 r:g:b:a <- :rc :gc :bc :ac {
116 #{
117 r <- rc
118 g <- gc
119 b <- bc
120 a <- ac
121 }
122 }
123
124 r:g:b <- :r :g :b {
125 r: r g: g b: b a: 255u8
126 }
127
89 createWindow:pos:size:flags <- :title :x y :w h :flags{ 128 createWindow:pos:size:flags <- :title :x y :w h :flags{
90 _helper createWindow: title x y w h flags :ptr { 129 _helper createWindow: title x y w h flags :ptr {
130 print: (string: ptr) . "\n"
91 #{ 131 #{
92 includeSystemHeader: "SDL.h" 132 includeSystemHeader: "SDL.h"
93 llProperty: window withType: (SDL_Window ptr) 133 llProperty: window withType: (SDL_Window ptr)
94 134 llMessage: opaque withVars: {
135 op <- cpointer ptr
136 } andCode: {
137 op <- make_object: (addr_of: cpointer_meta) NULL 0
138 op val!: window
139 op
140 }
141
95 llMessage: _ptr_init withVars: { 142 llMessage: _ptr_init withVars: {
96 ptr <- cpointer ptr 143 ptr <- cpointer ptr
97 } andCode: :ptr { 144 } andCode: :ptr {
98 window <- ptr val 145 window <- ptr val
99 self 146 self
100 } 147 }
101 148
149 renderOpts <- { _renderOpts }
150
151 createRenderer:flags <- :index :flags {
152 _helper createRenderer: (self opaque) index flags :ptr {
153 #{
154 includeSystemHeader: "SDL.h"
155 llProperty: renderer withType: (SDL_Renderer ptr)
156 llMessage: _ptr_init withVars: {
157 ptr <- cpointer ptr
158 } andCode: :ptr {
159 renderer <- ptr val
160 self
161 }
162
163 llMessage: drawColor! withVars: {
164 color <- object ptr
165 rc <- obj_uint8 ptr
166 gc <- obj_uint8 ptr
167 bc <- obj_uint8 ptr
168 ac <- obj_uint8 ptr
169 intret <- obj_int32 ptr
170 } andCode: :color {
171 intret <- make_object: (addr_of: obj_int32_meta) NULL 0
172 rc <- (mcall: r 1 color) castTo: (obj_uint8 ptr)
173 gc <- (mcall: g 1 color) castTo: (obj_uint8 ptr)
174 bc <- (mcall: b 1 color) castTo: (obj_uint8 ptr)
175 ac <- (mcall: a 1 color) castTo: (obj_uint8 ptr)
176 intret num!: (SDL_SetRenderDrawColor: renderer (rc num) (gc num) (bc num) (ac num))
177 intret
178 }
179
180 llMessage: clear withVars: {
181 intret <- obj_int32 ptr
182 } andCode: {
183 intret <- make_object: (addr_of: obj_int32_meta) NULL 0
184 intret num!: (SDL_RenderClear: renderer)
185 intret
186 }
187
188 llMessage: present withVars: {} andCode: {
189 SDL_RenderPresent: renderer
190 true
191 }
192
193 llMessage: destroy withVars: {} andCode: {
194 SDL_DestroyRenderer: renderer
195 true
196 }
197 } _ptr_init: ptr
198 }
199 }
200
102 llMessage: destroy withVars: { 201 llMessage: destroy withVars: {
103 } andCode: { 202 } andCode: {
104 SDL_DestroyWindow: window 203 SDL_DestroyWindow: window
105 true 204 true
106 } 205 }
107 } _ptr_init 206 } _ptr_init: ptr
108 } 207 }
109 } 208 }
110 209
111 llMessage: delay withVars: { 210 llMessage: delay withVars: {
112 ms <- obj_uint32 ptr 211 ms <- obj_uint32 ptr
113 } andCode: :ms { 212 } andCode: :ms {
114 SDL_Delay: (ms num) 213 SDL_Delay: (ms num)
115 true 214 true
116 } 215 }
117 216
118 subsystems <- { _subsystems } 217 subsystems <- { _subsystems }
119 windowOpts <- { _windowOpts } 218 windowOpts <- { _windowOpts }
120 } 219 }
121 } 220 }