-
Notifications
You must be signed in to change notification settings - Fork 0
/
f.pl
210 lines (179 loc) · 4.96 KB
/
f.pl
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
mixertest :-
sdl_Init([audio]),
mix_Linked_Version(Maj, Min, Patch),
format("SDL_Mixer: ~w.~w.~w~n", [Maj, Min, Patch]),
sdl_Init([audio]),
mix_OpenAudio(22050, [default_format], 2, 4096),
mix_LoadMUS("./assets/test-music.mp3", Music),
format("Fading in the music now over 5 seconds: ~w~n....", [Music]),
mix_VolumeMusic(128, _),
mix_FadeInMusic(Music, 1, 5000),
sdl_Delay(5000),
format("Reduce volume to 50%% for two seconds~n", []),
mix_VolumeMusic(64, _),
sdl_Delay(2000),
format("Reduce volume to 25%% for two seconds~n", []),
mix_VolumeMusic(32, _),
sdl_Delay(2000),
format("Reduce volume to 6.25%% for two seconds~n", []),
mix_VolumeMusic(8, _),
sdl_Delay(2000),
format("Max volume to 100%%, play three seconds then pause~n", []),
mix_VolumeMusic(128, _),
sdl_Delay(3000),
mix_PauseMusic,
sdl_Delay(3000),
format("Resume playback~n", []),
mix_ResumeMusic.
check_sdl :-
sdl_Init([video]),
WndW=640,
WndH=480,
sdl_CreateWindow("in the middle of the screen", centered, centered, WndW, WndH, [], W),
evloop,
sdl_DestroyWindow(W),
sdl_Quit.
drawtest :-
sdl_Init([video]),
WndW=640,
WndH=480,
sdl_CreateWindow("fred", 0, 0, WndW, WndH, [], W),
sdl_CreateRenderer(W, -1, [presentvsync], R),
sdl_SetRenderDrawColor(R, 0, 0, 0, 255),
sdl_RenderClear(R),
evloop(drawstuff(R, WndW, WndH)),
sdl_DestroyRenderer(R),
sdl_DestroyWindow(W),
sdl_Quit.
drawstuff(R, WndW, WndH) :-
draw_a_box(R, WndW, WndH),
sdl_RenderPresent(R).
circletest :-
sdl_Init([video]),
WndW=640,
WndH=480,
sdl_CreateWindow("fred", 0, 0, WndW, WndH, [], W),
sdl_CreateRenderer(W, -1, [], R),
sdl_SetRenderDrawColor(R, 0, 0, 0, 255),
sdl_RenderClear(R),
sdl_SetRenderDrawColor(R, 255, 0, 0, 255),
sdl_RenderDrawCircle(R, 320, 240, 200),
sdl_SetRenderDrawColor(R, 255, 0, 255, 255),
sdl_RenderDrawCircle(R, 320, 240, 150),
sdl_SetRenderDrawColor(R, 0, 255, 255, 255),
sdl_RenderFillCircle(R, 320, 240, 100),
sdl_SetRenderDrawColor(R, 0, 0, 255, 255),
sdl_RenderFillCircle(R, 320, 240, 50),
sdl_RenderPresent(R),
sdl_Delay(60000),
sdl_DestroyRenderer(R),
sdl_DestroyWindow(W),
sdl_Quit.
draw_a_box(R, WndW, WndH) :-
random(0, WndW, X),
random(0, WndH, Y),
random(50, 300, W),
random(50, 200, H),
random(0, 255, Red),
random(0, 255, Grn),
random(0, 255, Blu),
sdl_SetRenderDrawColor(R, Red, Grn, Blu, 255),
sdl_RenderFillRect(R, X, Y, W, H).
draw_a_circle(R, WndW, WndH) :-
random(0, WndW, X),
random(0, WndH, Y),
random(50, 300, Radius),
random(0, 255, Red),
random(0, 255, Grn),
random(0, 255, Blu),
sdl_SetRenderDrawColor(R, Red, Grn, Blu, 255),
sdl_RenderDrawCircle(R, X, Y, Radius).
draw_a_dot(_, 0) :-
!.
draw_a_dot(R, N) :-
N2 is N-1,
random(0, 640, X),
random(0, 480, Y),
random(0, 255, Red),
random(0, 255, Grn),
random(0, 255, Blu),
sdl_SetRenderDrawColor(R, Red, Grn, Blu, 255),
sdl_RenderDrawPoint(R, X, Y),
draw_a_dot(R, N2).
textest(F) :-
format_to_codes(Filename, "/Users/seancharles/Pictures/~s", [F]),
sdl_Init([video]),
img_Init,
sdl_CreateWindow("Texture Test", undefined, undefined, 0, 0, [], W),
sdl_CreateRenderer(W, -1, [accelerated, presentvsync], R),
img_Load(Filename, Img),
sdl_CreateTextureFromSurface(R, Img, Tex),
sdl_QueryTexture(Tex, _, _, TW, TH),
sdl_FreeSurface(Img),
sdl_SetWindowSize(W, TW, TH),
sdl_RenderCopyDefaults(R, Tex),
sdl_RenderPresent(R),
evloop,
sdl_DestroyTexture(Tex),
sdl_DestroyRenderer(R),
sdl_DestroyWindow(W),
img_Quit,
sdl_Quit.
%%--------------------------------------------------------------------
%%
%% Event Handling
%%
%%--------------------------------------------------------------------
evtest :-
sdl_Init([video]),
evloop,
sdl_Quit.
evloop :-
sdl_PollEvent(E),
handle_event(E),
!,
evloop.
evloop. %% keep going on poll fail i.e. no event!
evloop(Callback) :-
call(Callback),
sdl_PollEvent(E),
handle_event(E),
!,
evloop(Callback).
evloop(_).
%%--------------------------------------------------------------------
%%
%% Event handlers...
%%
%%--------------------------------------------------------------------
handle_event(quit(_)) :-
format("QUIT selected~n", []), !, fail.
handle_event(keyup(_,_,released,_,_,27,_)) :-
format("ESC pressed~n", []), !, fail.
handle_event(_).
tt :-
sdl_CreateThread(doit(42), "test-thread", X),
write(X).
doit(N) :-
write("in the thread"),
write(N).
fonttest :-
sdl_Init([video]),
ttf_Init,
sdl_CreateWindow("Font Tests", centered, centered, 640, 480, [], W),
sdl_CreateRenderer(W, -1, [accelerated, presentvsync], R),
%% clear to black
sdl_SetRenderDrawColor(R, 0, 0, 0, 255),
sdl_RenderClear(R),
ttf_OpenFont("/Library/Fonts/OsakaMono.ttf",80, F),
ttf_OpenFont("/Library/Fonts/Impact.ttf",40, F2),
ttf_SizeUTF8(F, "Osaka Mono", RW, RH),
format("Font texture: ~w x ~w pixels~n", [RW, RH]),
sdl_SetRenderDrawColor(R, 255, 128, 128, 255),
ttf_RenderUTF8_Solid(R, F, 100, 0, "Osaka Mono"),
sdl_SetRenderDrawColor(R, 0, 128, 128, 255),
ttf_RenderUTF8_Solid(R, F2, 100, RH, "Some other font"),
sdl_RenderPresent(R),
evloop,
ttf_Quit,
sdl_Quit.