Skip to content

Commit aa06baf

Browse files
committed
add SDL2 example
1 parent cea8c5a commit aa06baf

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

examples/sdl.cal

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# Compile with:
2+
# cac examples/sdl.cal -i std -bo use-libc -l SDL2
3+
4+
include "cores/select.cal"
5+
include "std/io.cal"
6+
7+
const SDL_INIT_VIDEO 32
8+
const SDL_RENDERER_ACCELERATED 2
9+
const SDL_RENDERER_PRESENTVSYNC 4
10+
const SDL_QUIT 0x100
11+
12+
extern C i32 SDL_Init u32 end
13+
extern C addr SDL_CreateWindow addr i32 i32 i32 i32 u32 end
14+
extern C addr SDL_CreateRenderer addr i32 u32 end
15+
extern C i32 SDL_PollEvent addr end
16+
extern C void SDL_DestroyWindow addr end
17+
extern C void SDL_DestroyRenderer addr end
18+
extern C void SDL_Quit end
19+
20+
struct SDL_Event
21+
array 56 u8 pad
22+
end
23+
24+
let addr window
25+
let addr renderer
26+
27+
"Init " printstr
28+
SDL_INIT_VIDEO SDL_Init printdec new_line
29+
30+
"Window " printstr
31+
"Callisto\0" Array.elements + @ 0 0 320 240 0 SDL_CreateWindow window !
32+
window @ printdec new_line
33+
34+
"Renderer " printstr
35+
window @ -1 SDL_RENDERER_PRESENTVSYNC SDL_RENDERER_ACCELERATED or SDL_CreateRenderer renderer !
36+
renderer @ printdec new_line
37+
38+
while true do
39+
let SDL_Event e
40+
while e SDL_PollEvent do
41+
if e d@ SDL_QUIT = then
42+
"Bye!\n" printstr
43+
renderer @ SDL_DestroyRenderer
44+
window @ SDL_DestroyWindow
45+
SDL_Quit
46+
0 exit
47+
end
48+
end
49+
end

0 commit comments

Comments
 (0)