ruby2d 0.9.2 → 0.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (162) hide show
  1. checksums.yaml +4 -4
  2. data/assets/README.md +7 -8
  3. data/assets/Rakefile +85 -0
  4. data/assets/include/SDL2/SDL.h +4 -1
  5. data/assets/include/SDL2/SDL_assert.h +3 -1
  6. data/assets/include/SDL2/SDL_atomic.h +20 -2
  7. data/assets/include/SDL2/SDL_audio.h +47 -14
  8. data/assets/include/SDL2/SDL_bits.h +10 -1
  9. data/assets/include/SDL2/SDL_blendmode.h +10 -7
  10. data/assets/include/SDL2/SDL_clipboard.h +1 -1
  11. data/assets/include/SDL2/SDL_config.h +24 -390
  12. data/assets/include/SDL2/SDL_config_android.h +182 -0
  13. data/assets/include/SDL2/SDL_config_iphoneos.h +207 -0
  14. data/assets/include/SDL2/SDL_config_macosx.h +266 -0
  15. data/assets/include/SDL2/SDL_config_minimal.h +85 -0
  16. data/assets/include/SDL2/SDL_config_os2.h +188 -0
  17. data/assets/include/SDL2/SDL_config_pandora.h +135 -0
  18. data/assets/include/SDL2/SDL_config_psp.h +165 -0
  19. data/assets/include/SDL2/SDL_config_windows.h +288 -0
  20. data/assets/include/SDL2/SDL_config_winrt.h +243 -0
  21. data/assets/include/SDL2/SDL_config_wiz.h +149 -0
  22. data/assets/include/SDL2/SDL_copying.h +20 -0
  23. data/assets/include/SDL2/SDL_cpuinfo.h +119 -8
  24. data/assets/include/SDL2/SDL_egl.h +4 -1
  25. data/assets/include/SDL2/SDL_endian.h +6 -3
  26. data/assets/include/SDL2/SDL_error.h +38 -2
  27. data/assets/include/SDL2/SDL_events.h +67 -28
  28. data/assets/include/SDL2/SDL_filesystem.h +1 -1
  29. data/assets/include/SDL2/SDL_gamecontroller.h +160 -9
  30. data/assets/include/SDL2/SDL_gesture.h +1 -1
  31. data/assets/include/SDL2/SDL_haptic.h +10 -1
  32. data/assets/include/SDL2/SDL_hints.h +460 -17
  33. data/assets/include/SDL2/SDL_image.h +2 -2
  34. data/assets/include/SDL2/SDL_joystick.h +115 -24
  35. data/assets/include/SDL2/SDL_keyboard.h +1 -1
  36. data/assets/include/SDL2/SDL_keycode.h +11 -9
  37. data/assets/include/SDL2/SDL_loadso.h +1 -1
  38. data/assets/include/SDL2/SDL_locale.h +101 -0
  39. data/assets/include/SDL2/SDL_log.h +3 -3
  40. data/assets/include/SDL2/SDL_main.h +28 -16
  41. data/assets/include/SDL2/SDL_messagebox.h +6 -4
  42. data/assets/include/SDL2/SDL_metal.h +117 -0
  43. data/assets/include/SDL2/SDL_misc.h +75 -0
  44. data/assets/include/SDL2/SDL_mouse.h +1 -1
  45. data/assets/include/SDL2/SDL_mutex.h +1 -1
  46. data/assets/include/SDL2/SDL_name.h +1 -1
  47. data/assets/include/SDL2/SDL_opengl.h +1 -1
  48. data/assets/include/SDL2/SDL_opengl_glext.h +3 -0
  49. data/assets/include/SDL2/SDL_opengles.h +1 -1
  50. data/assets/include/SDL2/SDL_opengles2.h +1 -1
  51. data/assets/include/SDL2/SDL_pixels.h +27 -18
  52. data/assets/include/SDL2/SDL_platform.h +1 -1
  53. data/assets/include/SDL2/SDL_power.h +1 -1
  54. data/assets/include/SDL2/SDL_quit.h +1 -1
  55. data/assets/include/SDL2/SDL_rect.h +29 -3
  56. data/assets/include/SDL2/SDL_render.h +230 -3
  57. data/assets/include/SDL2/SDL_revision.h +2 -2
  58. data/assets/include/SDL2/SDL_rwops.h +51 -22
  59. data/assets/include/SDL2/SDL_scancode.h +2 -2
  60. data/assets/include/SDL2/SDL_sensor.h +28 -12
  61. data/assets/include/SDL2/SDL_shape.h +1 -1
  62. data/assets/include/SDL2/SDL_stdinc.h +44 -4
  63. data/assets/include/SDL2/SDL_surface.h +12 -2
  64. data/assets/include/SDL2/SDL_system.h +50 -4
  65. data/assets/include/SDL2/SDL_syswm.h +39 -9
  66. data/assets/include/SDL2/SDL_test.h +1 -1
  67. data/assets/include/SDL2/SDL_test_assert.h +1 -1
  68. data/assets/include/SDL2/SDL_test_common.h +32 -2
  69. data/assets/include/SDL2/SDL_test_compare.h +1 -1
  70. data/assets/include/SDL2/SDL_test_crc32.h +1 -1
  71. data/assets/include/SDL2/SDL_test_font.h +1 -1
  72. data/assets/include/SDL2/SDL_test_fuzzer.h +1 -1
  73. data/assets/include/SDL2/SDL_test_harness.h +1 -1
  74. data/assets/include/SDL2/SDL_test_images.h +1 -1
  75. data/assets/include/SDL2/SDL_test_log.h +1 -1
  76. data/assets/include/SDL2/SDL_test_md5.h +1 -1
  77. data/assets/include/SDL2/SDL_test_memory.h +3 -3
  78. data/assets/include/SDL2/SDL_test_random.h +1 -1
  79. data/assets/include/SDL2/SDL_thread.h +34 -11
  80. data/assets/include/SDL2/SDL_timer.h +1 -1
  81. data/assets/include/SDL2/SDL_touch.h +17 -1
  82. data/assets/include/SDL2/SDL_types.h +1 -1
  83. data/assets/include/SDL2/SDL_version.h +2 -2
  84. data/assets/include/SDL2/SDL_video.h +11 -5
  85. data/assets/include/SDL2/SDL_vulkan.h +9 -11
  86. data/assets/include/SDL2/begin_code.h +8 -9
  87. data/assets/include/SDL2/close_code.h +4 -1
  88. data/assets/macos/lib/libFLAC.a +0 -0
  89. data/assets/macos/lib/libSDL2.a +0 -0
  90. data/assets/macos/lib/libSDL2_image.a +0 -0
  91. data/assets/macos/lib/libSDL2_mixer.a +0 -0
  92. data/assets/macos/lib/libSDL2_ttf.a +0 -0
  93. data/assets/macos/lib/libfreetype.a +0 -0
  94. data/assets/macos/lib/libjpeg.a +0 -0
  95. data/assets/macos/lib/libmpg123.a +0 -0
  96. data/assets/macos/lib/libogg.a +0 -0
  97. data/assets/macos/lib/libpng16.a +0 -0
  98. data/assets/macos/lib/libtiff.a +0 -0
  99. data/assets/macos/lib/libvorbis.a +0 -0
  100. data/assets/macos/lib/libvorbisfile.a +0 -0
  101. data/assets/macos/lib/libwebp.a +0 -0
  102. data/assets/mingw/bin/SDL2.dll +0 -0
  103. data/assets/mingw/bin/SDL2_image.dll +0 -0
  104. data/assets/mingw/bin/libpng16-16.dll +0 -0
  105. data/assets/mingw/bin/libtiff-5.dll +0 -0
  106. data/assets/mingw/bin/libwebp-7.dll +0 -0
  107. data/assets/mingw/lib/libSDL2.a +0 -0
  108. data/assets/mingw/lib/libSDL2.dll.a +0 -0
  109. data/assets/mingw/lib/libSDL2_image.a +0 -0
  110. data/assets/mingw/lib/libSDL2_image.dll.a +0 -0
  111. data/assets/mingw/lib/libSDL2_test.a +0 -0
  112. data/assets/mingw/lib/libSDL2main.a +0 -0
  113. data/bin/ruby2d +2 -1
  114. data/{assets/linux/simple2d/src/simple2d.c → ext/ruby2d/common.c} +32 -32
  115. data/{assets/linux/simple2d/src → ext/ruby2d}/controllers.c +17 -17
  116. data/ext/ruby2d/extconf.rb +6 -36
  117. data/{assets/linux/simple2d/src → ext/ruby2d}/gl.c +106 -85
  118. data/{assets/linux/simple2d/src → ext/ruby2d}/gl2.c +35 -20
  119. data/{assets/linux/simple2d/src → ext/ruby2d}/gl3.c +146 -58
  120. data/{assets/linux/simple2d/src → ext/ruby2d}/gles.c +41 -26
  121. data/{assets/linux/simple2d/src → ext/ruby2d}/image.c +16 -16
  122. data/{assets/linux/simple2d/src → ext/ruby2d}/input.c +8 -8
  123. data/{assets/linux/simple2d/src → ext/ruby2d}/music.c +30 -17
  124. data/ext/ruby2d/ruby2d.c +427 -290
  125. data/ext/ruby2d/ruby2d.h +789 -0
  126. data/{assets/linux/simple2d/src → ext/ruby2d}/shapes.c +18 -18
  127. data/ext/ruby2d/sound.c +118 -0
  128. data/{assets/linux/simple2d/src → ext/ruby2d}/sprite.c +16 -16
  129. data/{assets/linux/simple2d/src → ext/ruby2d}/text.c +22 -22
  130. data/ext/ruby2d/tileset.c +30 -0
  131. data/{assets/linux/simple2d/src → ext/ruby2d}/window.c +71 -60
  132. data/lib/ruby2d.rb +5 -2
  133. data/lib/ruby2d/circle.rb +18 -2
  134. data/lib/ruby2d/cli/build.rb +3 -8
  135. data/lib/ruby2d/cli/colorize.rb +10 -0
  136. data/lib/ruby2d/dsl.rb +16 -9
  137. data/lib/ruby2d/entity.rb +17 -0
  138. data/lib/ruby2d/font.rb +4 -3
  139. data/lib/ruby2d/image.rb +24 -1
  140. data/lib/ruby2d/line.rb +20 -0
  141. data/lib/ruby2d/music.rb +5 -0
  142. data/lib/ruby2d/pixel.rb +17 -0
  143. data/lib/ruby2d/quad.rb +18 -0
  144. data/lib/ruby2d/rectangle.rb +11 -2
  145. data/lib/ruby2d/renderable.rb +4 -8
  146. data/lib/ruby2d/sound.rb +5 -0
  147. data/lib/ruby2d/sprite.rb +35 -3
  148. data/lib/ruby2d/square.rb +9 -0
  149. data/lib/ruby2d/text.rb +22 -1
  150. data/lib/ruby2d/tileset.rb +69 -0
  151. data/lib/ruby2d/triangle.rb +16 -0
  152. data/lib/ruby2d/version.rb +1 -1
  153. data/lib/ruby2d/window.rb +249 -22
  154. metadata +41 -27
  155. data/assets/include/simple2d.h +0 -735
  156. data/assets/linux/simple2d/Makefile +0 -250
  157. data/assets/linux/simple2d/bin/simple2d.sh +0 -1249
  158. data/assets/linux/simple2d/include/simple2d.h +0 -735
  159. data/assets/linux/simple2d/src/sound.c +0 -56
  160. data/assets/macos/lib/libsimple2d.a +0 -0
  161. data/assets/mingw/lib/libsimple2d.a +0 -0
  162. data/lib/ruby2d/colorize.rb +0 -10
@@ -0,0 +1,789 @@
1
+ // ruby2d.h
2
+
3
+ #ifdef __cplusplus
4
+ extern "C" {
5
+ #endif
6
+
7
+ #include <stdbool.h>
8
+
9
+ // Set Platform Constants //////////////////////////////////////////////////////
10
+
11
+ // Apple
12
+ #ifdef __APPLE__
13
+ #ifndef __TARGETCONDITIONALS__
14
+ #include "TargetConditionals.h"
15
+ #endif
16
+ #if TARGET_OS_OSX
17
+ #define MACOS true
18
+ #elif TARGET_OS_IOS
19
+ #define IOS true
20
+ #elif TARGET_OS_TV
21
+ #define TVOS true
22
+ #endif
23
+ #endif
24
+
25
+ // Windows
26
+ #ifdef _WIN32
27
+ #define WINDOWS true
28
+ #endif
29
+
30
+ // Windows and MinGW
31
+ #ifdef __MINGW32__
32
+ #define MINGW true
33
+ #endif
34
+
35
+ // GLES
36
+ #if defined(__arm__) || IOS || TVOS
37
+ #define GLES true
38
+ #else
39
+ #define GLES false
40
+ #endif
41
+
42
+ // Includes ////////////////////////////////////////////////////////////////////
43
+
44
+ // Define to get GNU extension functions and types, like `vasprintf()` and M_PI
45
+ #ifndef _GNU_SOURCE
46
+ #define _GNU_SOURCE 1
47
+ #endif
48
+
49
+ #if WINDOWS && !MINGW
50
+ #include <io.h>
51
+ #define F_OK 0 // For testing file existence
52
+ #else
53
+ #include <unistd.h>
54
+ #endif
55
+
56
+ #if WINDOWS
57
+ #include <stdio.h>
58
+ #include <math.h>
59
+ #include <windows.h>
60
+ // For terminal colors
61
+ #ifndef ENABLE_VIRTUAL_TERMINAL_PROCESSING
62
+ #define ENABLE_VIRTUAL_TERMINAL_PROCESSING 0x0004
63
+ #endif
64
+ #endif
65
+
66
+ // SDL
67
+ #if IOS || TVOS
68
+ #include "SDL2/SDL.h"
69
+ #else
70
+ #include <SDL2/SDL.h>
71
+ #endif
72
+
73
+ // If MinGW, undefine `main()` from SDL_main.c
74
+ #if MINGW
75
+ #undef main
76
+ #endif
77
+
78
+ // OpenGL
79
+ #if GLES
80
+ #if IOS || TVOS
81
+ #include "SDL2/SDL_opengles2.h"
82
+ #else
83
+ #include <SDL2/SDL_opengles2.h>
84
+ #endif
85
+ #else
86
+ #define GL_GLEXT_PROTOTYPES 1
87
+ #if WINDOWS
88
+ #include <glew.h>
89
+ #endif
90
+ #include <SDL2/SDL_opengl.h>
91
+ #endif
92
+
93
+ // SDL libraries
94
+ #if IOS || TVOS
95
+ #include "SDL2/SDL_image.h"
96
+ #include "SDL2/SDL_mixer.h"
97
+ #include "SDL2/SDL_ttf.h"
98
+ #else
99
+ #include <SDL2/SDL_image.h>
100
+ #include <SDL2/SDL_mixer.h>
101
+ #include <SDL2/SDL_ttf.h>
102
+ #endif
103
+
104
+ // Ruby 2D Definitions /////////////////////////////////////////////////////////
105
+
106
+ // Messages
107
+ #define R2D_INFO 1
108
+ #define R2D_WARN 2
109
+ #define R2D_ERROR 3
110
+
111
+ // Window attributes
112
+ #define R2D_RESIZABLE SDL_WINDOW_RESIZABLE
113
+ #define R2D_BORDERLESS SDL_WINDOW_BORDERLESS
114
+ #define R2D_FULLSCREEN SDL_WINDOW_FULLSCREEN_DESKTOP
115
+ #define R2D_HIGHDPI SDL_WINDOW_ALLOW_HIGHDPI
116
+ #define R2D_DISPLAY_WIDTH 0
117
+ #define R2D_DISPLAY_HEIGHT 0
118
+
119
+ // Viewport scaling modes
120
+ #define R2D_FIXED 1
121
+ #define R2D_EXPAND 2
122
+ #define R2D_SCALE 3
123
+ #define R2D_STRETCH 4
124
+
125
+ // Positions
126
+ #define R2D_CENTER 1
127
+ #define R2D_TOP_LEFT 2
128
+ #define R2D_TOP_RIGHT 3
129
+ #define R2D_BOTTOM_LEFT 4
130
+ #define R2D_BOTTOM_RIGHT 5
131
+
132
+ // Keyboard events
133
+ #define R2D_KEY_DOWN 1 // key is pressed
134
+ #define R2D_KEY_HELD 2 // key is held down
135
+ #define R2D_KEY_UP 3 // key is released
136
+
137
+ // Mouse events
138
+ #define R2D_MOUSE_DOWN 1 // mouse button pressed
139
+ #define R2D_MOUSE_UP 2 // mouse button released
140
+ #define R2D_MOUSE_SCROLL 3 // mouse scrolling or wheel movement
141
+ #define R2D_MOUSE_MOVE 4 // mouse movement
142
+ #define R2D_MOUSE_LEFT SDL_BUTTON_LEFT
143
+ #define R2D_MOUSE_MIDDLE SDL_BUTTON_MIDDLE
144
+ #define R2D_MOUSE_RIGHT SDL_BUTTON_RIGHT
145
+ #define R2D_MOUSE_X1 SDL_BUTTON_X1
146
+ #define R2D_MOUSE_X2 SDL_BUTTON_X2
147
+ #define R2D_MOUSE_SCROLL_NORMAL SDL_MOUSEWHEEL_NORMAL
148
+ #define R2D_MOUSE_SCROLL_INVERTED SDL_MOUSEWHEEL_FLIPPED
149
+
150
+ // Controller events
151
+ #define R2D_AXIS 1
152
+ #define R2D_BUTTON_DOWN 2
153
+ #define R2D_BUTTON_UP 3
154
+
155
+ // Controller axis labels
156
+ #define R2D_AXIS_INVALID SDL_CONTROLLER_AXIS_INVALID
157
+ #define R2D_AXIS_LEFTX SDL_CONTROLLER_AXIS_LEFTX
158
+ #define R2D_AXIS_LEFTY SDL_CONTROLLER_AXIS_LEFTY
159
+ #define R2D_AXIS_RIGHTX SDL_CONTROLLER_AXIS_RIGHTX
160
+ #define R2D_AXIS_RIGHTY SDL_CONTROLLER_AXIS_RIGHTY
161
+ #define R2D_AXIS_TRIGGERLEFT SDL_CONTROLLER_AXIS_TRIGGERLEFT
162
+ #define R2D_AXIS_TRIGGERRIGHT SDL_CONTROLLER_AXIS_TRIGGERRIGHT
163
+ #define R2D_AXIS_MAX SDL_CONTROLLER_AXIS_MAX
164
+
165
+ // Controller button labels
166
+ #define R2D_BUTTON_INVALID SDL_CONTROLLER_BUTTON_INVALID
167
+ #define R2D_BUTTON_A SDL_CONTROLLER_BUTTON_A
168
+ #define R2D_BUTTON_B SDL_CONTROLLER_BUTTON_B
169
+ #define R2D_BUTTON_X SDL_CONTROLLER_BUTTON_X
170
+ #define R2D_BUTTON_Y SDL_CONTROLLER_BUTTON_Y
171
+ #define R2D_BUTTON_BACK SDL_CONTROLLER_BUTTON_BACK
172
+ #define R2D_BUTTON_GUIDE SDL_CONTROLLER_BUTTON_GUIDE
173
+ #define R2D_BUTTON_START SDL_CONTROLLER_BUTTON_START
174
+ #define R2D_BUTTON_LEFTSTICK SDL_CONTROLLER_BUTTON_LEFTSTICK
175
+ #define R2D_BUTTON_RIGHTSTICK SDL_CONTROLLER_BUTTON_RIGHTSTICK
176
+ #define R2D_BUTTON_LEFTSHOULDER SDL_CONTROLLER_BUTTON_LEFTSHOULDER
177
+ #define R2D_BUTTON_RIGHTSHOULDER SDL_CONTROLLER_BUTTON_RIGHTSHOULDER
178
+ #define R2D_BUTTON_DPAD_UP SDL_CONTROLLER_BUTTON_DPAD_UP
179
+ #define R2D_BUTTON_DPAD_DOWN SDL_CONTROLLER_BUTTON_DPAD_DOWN
180
+ #define R2D_BUTTON_DPAD_LEFT SDL_CONTROLLER_BUTTON_DPAD_LEFT
181
+ #define R2D_BUTTON_DPAD_RIGHT SDL_CONTROLLER_BUTTON_DPAD_RIGHT
182
+ #define R2D_BUTTON_MAX SDL_CONTROLLER_BUTTON_MAX
183
+
184
+ // Internal Shared Data ////////////////////////////////////////////////////////
185
+
186
+ extern bool R2D_diagnostics; // flag for whether to print diagnostics with R2D_Log
187
+
188
+ // Type Definitions ////////////////////////////////////////////////////////////
189
+
190
+ // R2D_Event
191
+ typedef struct {
192
+ int which;
193
+ int type;
194
+ int button;
195
+ bool dblclick;
196
+ const char *key;
197
+ int x;
198
+ int y;
199
+ int delta_x;
200
+ int delta_y;
201
+ int direction;
202
+ int axis;
203
+ int value;
204
+ } R2D_Event;
205
+
206
+ typedef void (*R2D_Update)();
207
+ typedef void (*R2D_Render)();
208
+ typedef void (*R2D_On_Key)(R2D_Event e);
209
+ typedef void (*R2D_On_Mouse)(R2D_Event e);
210
+ typedef void (*R2D_On_Controller)(R2D_Event e);
211
+
212
+ // R2D_GL_Point, for graphics calculations
213
+ typedef struct {
214
+ GLfloat x;
215
+ GLfloat y;
216
+ } R2D_GL_Point;
217
+
218
+ // R2D_Color
219
+ typedef struct {
220
+ GLfloat r;
221
+ GLfloat g;
222
+ GLfloat b;
223
+ GLfloat a;
224
+ } R2D_Color;
225
+
226
+ // R2D_Mouse
227
+ typedef struct {
228
+ int visible;
229
+ int x;
230
+ int y;
231
+ } R2D_Mouse;
232
+
233
+ // R2D_Viewport
234
+ typedef struct {
235
+ int width;
236
+ int height;
237
+ int mode;
238
+ } R2D_Viewport;
239
+
240
+ // R2D_Window
241
+ typedef struct {
242
+ SDL_Window *sdl;
243
+ SDL_GLContext glcontext;
244
+ const GLubyte *R2D_GL_VENDOR;
245
+ const GLubyte *R2D_GL_RENDERER;
246
+ const GLubyte *R2D_GL_VERSION;
247
+ GLint R2D_GL_MAJOR_VERSION;
248
+ GLint R2D_GL_MINOR_VERSION;
249
+ const GLubyte *R2D_GL_SHADING_LANGUAGE_VERSION;
250
+ const char *title;
251
+ int width;
252
+ int height;
253
+ int orig_width;
254
+ int orig_height;
255
+ R2D_Viewport viewport;
256
+ R2D_Update update;
257
+ R2D_Render render;
258
+ int flags;
259
+ R2D_Mouse mouse;
260
+ R2D_On_Key on_key;
261
+ R2D_On_Mouse on_mouse;
262
+ R2D_On_Controller on_controller;
263
+ bool vsync;
264
+ int fps_cap;
265
+ R2D_Color background;
266
+ const char *icon;
267
+ Uint32 frames;
268
+ Uint32 elapsed_ms;
269
+ Uint32 loop_ms;
270
+ Uint32 delay_ms;
271
+ double fps;
272
+ bool close;
273
+ } R2D_Window;
274
+
275
+ // R2D_Image
276
+ typedef struct {
277
+ const char *path;
278
+ SDL_Surface *surface;
279
+ int format;
280
+ GLuint texture_id;
281
+ R2D_Color color;
282
+ int x;
283
+ int y;
284
+ int width;
285
+ int height;
286
+ int orig_width;
287
+ int orig_height;
288
+ GLfloat rotate; // Rotation angle in degrees
289
+ GLfloat rx; // X coordinate to be rotated around
290
+ GLfloat ry; // Y coordinate to be rotated around
291
+ } R2D_Image;
292
+
293
+ // R2D_Sprite
294
+ typedef struct {
295
+ const char *path;
296
+ R2D_Image *img;
297
+ R2D_Color color;
298
+ int x;
299
+ int y;
300
+ int width;
301
+ int height;
302
+ int clip_width;
303
+ int clip_height;
304
+ GLfloat rotate; // Rotation angle in degrees
305
+ GLfloat rx; // X coordinate to be rotated around
306
+ GLfloat ry; // Y coordinate to be rotated around
307
+ GLfloat tx1;
308
+ GLfloat ty1;
309
+ GLfloat tx2;
310
+ GLfloat ty2;
311
+ GLfloat tx3;
312
+ GLfloat ty3;
313
+ GLfloat tx4;
314
+ GLfloat ty4;
315
+ } R2D_Sprite;
316
+
317
+ // R2D_Text
318
+ typedef struct {
319
+ const char *font;
320
+ SDL_Surface *surface;
321
+ GLuint texture_id;
322
+ TTF_Font *font_data;
323
+ R2D_Color color;
324
+ char *msg;
325
+ int x;
326
+ int y;
327
+ int width;
328
+ int height;
329
+ GLfloat rotate; // Rotation angle in degrees
330
+ GLfloat rx; // X coordinate to be rotated around
331
+ GLfloat ry; // Y coordinate to be rotated around
332
+ } R2D_Text;
333
+
334
+ // R2D_Sound
335
+ typedef struct {
336
+ const char *path;
337
+ Mix_Chunk *data;
338
+ } R2D_Sound;
339
+
340
+ // R2D_Music
341
+ typedef struct {
342
+ const char *path;
343
+ Mix_Music *data;
344
+ int length; // Length of music track
345
+ } R2D_Music;
346
+
347
+ // Ruby 2D Functions ///////////////////////////////////////////////////////////
348
+
349
+ /*
350
+ * Checks if a file exists and can be accessed
351
+ */
352
+ bool R2D_FileExists(const char *path);
353
+
354
+ /*
355
+ * Logs standard messages to the console
356
+ */
357
+ void R2D_Log(int type, const char *msg, ...);
358
+
359
+ /*
360
+ * Logs Ruby 2D errors to the console, with caller and message body
361
+ */
362
+ void R2D_Error(const char *caller, const char *msg, ...);
363
+
364
+ /*
365
+ * Enable/disable logging of diagnostics
366
+ */
367
+ void R2D_Diagnostics(bool status);
368
+
369
+ /*
370
+ * Enable terminal colors in Windows
371
+ */
372
+ void R2D_Windows_EnableTerminalColors();
373
+
374
+ /*
375
+ * Initialize Ruby 2D subsystems
376
+ */
377
+ bool R2D_Init();
378
+
379
+ /*
380
+ * Gets the primary display's dimensions
381
+ */
382
+ void R2D_GetDisplayDimensions(int *w, int *h);
383
+
384
+ /*
385
+ * Quits Ruby 2D subsystems
386
+ */
387
+ void R2D_Quit(void);
388
+
389
+ // Shapes //////////////////////////////////////////////////////////////////////
390
+
391
+ /*
392
+ * Rotate a point around a given point
393
+ * Params:
394
+ * p The point to rotate
395
+ * angle The angle in degrees
396
+ * rx The x coordinate to rotate around
397
+ * ry The y coordinate to rotate around
398
+ */
399
+ R2D_GL_Point R2D_RotatePoint(R2D_GL_Point p, GLfloat angle, GLfloat rx, GLfloat ry);
400
+
401
+ /*
402
+ * Get the point to be rotated around given a position in a rectangle
403
+ */
404
+ R2D_GL_Point R2D_GetRectRotationPoint(int x, int y, int w, int h, int position);
405
+
406
+ /*
407
+ * Draw a triangle
408
+ */
409
+ void R2D_DrawTriangle(
410
+ GLfloat x1, GLfloat y1,
411
+ GLfloat r1, GLfloat g1, GLfloat b1, GLfloat a1,
412
+ GLfloat x2, GLfloat y2,
413
+ GLfloat r2, GLfloat g2, GLfloat b2, GLfloat a2,
414
+ GLfloat x3, GLfloat y3,
415
+ GLfloat r3, GLfloat g3, GLfloat b3, GLfloat a3
416
+ );
417
+
418
+ /*
419
+ * Draw a quad, using two triangles
420
+ */
421
+ void R2D_DrawQuad(
422
+ GLfloat x1, GLfloat y1,
423
+ GLfloat r1, GLfloat g1, GLfloat b1, GLfloat a1,
424
+ GLfloat x2, GLfloat y2,
425
+ GLfloat r2, GLfloat g2, GLfloat b2, GLfloat a2,
426
+ GLfloat x3, GLfloat y3,
427
+ GLfloat r3, GLfloat g3, GLfloat b3, GLfloat a3,
428
+ GLfloat x4, GLfloat y4,
429
+ GLfloat r4, GLfloat g4, GLfloat b4, GLfloat a4
430
+ );
431
+
432
+ /*
433
+ * Draw a line from a quad
434
+ */
435
+ void R2D_DrawLine(
436
+ GLfloat x1, GLfloat y1, GLfloat x2, GLfloat y2,
437
+ GLfloat width,
438
+ GLfloat r1, GLfloat g1, GLfloat b1, GLfloat a1,
439
+ GLfloat r2, GLfloat g2, GLfloat b2, GLfloat a2,
440
+ GLfloat r3, GLfloat g3, GLfloat b3, GLfloat a3,
441
+ GLfloat r4, GLfloat g4, GLfloat b4, GLfloat a4
442
+ );
443
+
444
+ /*
445
+ * Draw a circle from triangles
446
+ */
447
+ void R2D_DrawCircle(
448
+ GLfloat x, GLfloat y, GLfloat radius, int sectors,
449
+ GLfloat r, GLfloat g, GLfloat b, GLfloat a
450
+ );
451
+
452
+ // Image ///////////////////////////////////////////////////////////////////////
453
+
454
+ /*
455
+ * Create an image, given a file path
456
+ */
457
+ R2D_Image *R2D_CreateImage(const char *path);
458
+
459
+ /*
460
+ * Rotate an image
461
+ */
462
+ void R2D_RotateImage(R2D_Image *img, GLfloat angle, int position);
463
+
464
+ /*
465
+ * Draw an image
466
+ */
467
+ void R2D_DrawImage(R2D_Image *img);
468
+
469
+ /*
470
+ * Free an image
471
+ */
472
+ void R2D_FreeImage(R2D_Image *img);
473
+
474
+ // Sprite //////////////////////////////////////////////////////////////////////
475
+
476
+ /*
477
+ * Create a sprite, given an image file path
478
+ */
479
+ R2D_Sprite *R2D_CreateSprite(const char *path);
480
+
481
+ /*
482
+ * Clip a sprite
483
+ */
484
+ void R2D_ClipSprite(R2D_Sprite *spr, int x, int y, int w, int h);
485
+
486
+ /*
487
+ * Rotate a sprite
488
+ */
489
+ void R2D_RotateSprite(R2D_Sprite *spr, GLfloat angle, int position);
490
+
491
+ /*
492
+ * Draw a sprite
493
+ */
494
+ void R2D_DrawSprite(R2D_Sprite *spr);
495
+
496
+ /*
497
+ * Free a sprite
498
+ */
499
+ void R2D_FreeSprite(R2D_Sprite *spr);
500
+
501
+ // Tile ////////////////////////////////////////////////////////////////////////
502
+
503
+ /*
504
+ * Draw a tile
505
+ */
506
+ void R2D_DrawTile(R2D_Image *img, int tw, int th, int padding, int spacing, int tx, int ty, int x, int y);
507
+
508
+ // Text ////////////////////////////////////////////////////////////////////////
509
+
510
+ /*
511
+ * Create text, given a font file path, the message, and size
512
+ */
513
+ R2D_Text *R2D_CreateText(const char *font, const char *msg, int size);
514
+
515
+ /*
516
+ * Set the text message
517
+ */
518
+ void R2D_SetText(R2D_Text *txt, const char *msg, ...);
519
+
520
+ /*
521
+ * Rotate text
522
+ */
523
+ void R2D_RotateText(R2D_Text *txt, GLfloat angle, int position);
524
+
525
+ /*
526
+ * Draw text
527
+ */
528
+ void R2D_DrawText(R2D_Text *txt);
529
+
530
+ /*
531
+ * Free the text
532
+ */
533
+ void R2D_FreeText(R2D_Text *txt);
534
+
535
+ // Sound ///////////////////////////////////////////////////////////////////////
536
+
537
+ /*
538
+ * Create a sound, given an audio file path
539
+ */
540
+ R2D_Sound *R2D_CreateSound(const char *path);
541
+
542
+ /*
543
+ * Play the sound
544
+ */
545
+ void R2D_PlaySound(R2D_Sound *snd);
546
+
547
+ /*
548
+ * Get the sound's length
549
+ */
550
+ int R2D_GetSoundLength(R2D_Sound *snd);
551
+
552
+ /*
553
+ * Get the sound's volume
554
+ */
555
+ int R2D_GetSoundVolume(R2D_Sound *snd);
556
+
557
+ /*
558
+ * Set the sound's volume a given percentage
559
+ */
560
+ void R2D_SetSoundVolume(R2D_Sound *snd, int volume);
561
+
562
+ /*
563
+ * Get the sound mixer volume
564
+ */
565
+ int R2D_GetSoundMixVolume();
566
+
567
+ /*
568
+ * Set the sound mixer volume a given percentage
569
+ */
570
+ void R2D_SetSoundMixVolume(int volume);
571
+
572
+ /*
573
+ * Free the sound
574
+ */
575
+ void R2D_FreeSound(R2D_Sound *snd);
576
+
577
+ // Music ///////////////////////////////////////////////////////////////////////
578
+
579
+ /*
580
+ * Create the music, given an audio file path
581
+ */
582
+ R2D_Music *R2D_CreateMusic(const char *path);
583
+
584
+ /*
585
+ * Play the music
586
+ */
587
+ void R2D_PlayMusic(R2D_Music *mus, bool loop);
588
+
589
+ /*
590
+ * Pause the playing music
591
+ */
592
+ void R2D_PauseMusic();
593
+
594
+ /*
595
+ * Resume the current music
596
+ */
597
+ void R2D_ResumeMusic();
598
+
599
+ /*
600
+ * Stop the playing music; interrupts fader effects
601
+ */
602
+ void R2D_StopMusic();
603
+
604
+ /*
605
+ * Get the music volume
606
+ */
607
+ int R2D_GetMusicVolume();
608
+
609
+ /*
610
+ * Set the music volume a given percentage
611
+ */
612
+ void R2D_SetMusicVolume(int volume);
613
+
614
+ /*
615
+ * Fade out the playing music
616
+ */
617
+ void R2D_FadeOutMusic(int ms);
618
+
619
+ /*
620
+ * Get the length of the music in seconds
621
+ */
622
+ int R2D_GetMusicLength(R2D_Music *mus);
623
+
624
+ /*
625
+ * Free the music
626
+ */
627
+ void R2D_FreeMusic(R2D_Music *mus);
628
+
629
+ // Input ///////////////////////////////////////////////////////////////////////
630
+
631
+ /*
632
+ * Get the mouse coordinates relative to the viewport
633
+ */
634
+ void R2D_GetMouseOnViewport(R2D_Window *window, int wx, int wy, int *x, int *y);
635
+
636
+ /*
637
+ * Show the cursor over the window
638
+ */
639
+ void R2D_ShowCursor();
640
+
641
+ /*
642
+ * Hide the cursor over the window
643
+ */
644
+ void R2D_HideCursor();
645
+
646
+ // Controllers /////////////////////////////////////////////////////////////////
647
+
648
+ /*
649
+ * Add controller mapping from string
650
+ */
651
+ void R2D_AddControllerMapping(const char *map);
652
+
653
+ /*
654
+ * Load controller mappings from the specified file
655
+ */
656
+ void R2D_AddControllerMappingsFromFile(const char *path);
657
+
658
+ /*
659
+ * Check if joystick is a controller
660
+ */
661
+ bool R2D_IsController(SDL_JoystickID id);
662
+
663
+ /*
664
+ * Open controllers and joysticks
665
+ */
666
+ void R2D_OpenControllers();
667
+
668
+ // Window //////////////////////////////////////////////////////////////////////
669
+
670
+ /*
671
+ * Create a window
672
+ */
673
+ R2D_Window *R2D_CreateWindow(
674
+ const char *title, int width, int height, R2D_Update, R2D_Render, int flags
675
+ );
676
+
677
+ /*
678
+ * Show the window
679
+ */
680
+ int R2D_Show(R2D_Window *window);
681
+
682
+ /*
683
+ * Set the icon for the window
684
+ */
685
+ void R2D_SetIcon(R2D_Window *window, const char *icon);
686
+
687
+ /*
688
+ * Take a screenshot of the window
689
+ */
690
+ void R2D_Screenshot(R2D_Window *window, const char *path);
691
+
692
+ /*
693
+ * Close the window
694
+ */
695
+ int R2D_Close(R2D_Window *window);
696
+
697
+ /*
698
+ * Free all resources
699
+ */
700
+ int R2D_FreeWindow(R2D_Window *window);
701
+
702
+ // Ruby 2D OpenGL Functions ////////////////////////////////////////////////////
703
+
704
+ int R2D_GL_Init(R2D_Window *window);
705
+ void R2D_GL_PrintError(char *error);
706
+ void R2D_GL_PrintContextInfo(R2D_Window *window);
707
+ void R2D_GL_StoreContextInfo(R2D_Window *window);
708
+ GLuint R2D_GL_LoadShader(GLenum type, const GLchar *shaderSrc, char *shaderName);
709
+ int R2D_GL_CheckLinked(GLuint program, char *name);
710
+ void R2D_GL_GetViewportScale(R2D_Window *window, int *w, int *h, double *scale);
711
+ void R2D_GL_SetViewport(R2D_Window *window);
712
+ void R2D_GL_CreateTexture(
713
+ GLuint *id, GLint format,
714
+ int w, int h,
715
+ const GLvoid *data, GLint filter);
716
+ void R2D_GL_DrawTriangle(
717
+ GLfloat x1, GLfloat y1,
718
+ GLfloat r1, GLfloat g1, GLfloat b1, GLfloat a1,
719
+ GLfloat x2, GLfloat y2,
720
+ GLfloat r2, GLfloat g2, GLfloat b2, GLfloat a2,
721
+ GLfloat x3, GLfloat y3,
722
+ GLfloat r3, GLfloat g3, GLfloat b3, GLfloat a3);
723
+ void R2D_GL_DrawImage(R2D_Image *img);
724
+ void R2D_GL_DrawSprite(R2D_Sprite *spr);
725
+ void R2D_GL_DrawTile(R2D_Image *img, int x, int y, int tw, int th, GLfloat tx1, GLfloat ty1, GLfloat tx2,
726
+ GLfloat ty2, GLfloat tx3, GLfloat ty3, GLfloat tx4, GLfloat ty4);
727
+ void R2D_GL_DrawText(R2D_Text *txt);
728
+ void R2D_GL_FreeTexture(GLuint *id);
729
+ void R2D_GL_Clear(R2D_Color clr);
730
+ void R2D_GL_FlushBuffers();
731
+
732
+ // OpenGL & GLES Internal Functions ////////////////////////////////////////////
733
+
734
+ #if GLES
735
+ int R2D_GLES_Init();
736
+ void R2D_GLES_ApplyProjection(GLfloat orthoMatrix[16]);
737
+ void R2D_GLES_DrawTriangle(
738
+ GLfloat x1, GLfloat y1,
739
+ GLfloat r1, GLfloat g1, GLfloat b1, GLfloat a1,
740
+ GLfloat x2, GLfloat y2,
741
+ GLfloat r2, GLfloat g2, GLfloat b2, GLfloat a2,
742
+ GLfloat x3, GLfloat y3,
743
+ GLfloat r3, GLfloat g3, GLfloat b3, GLfloat a3);
744
+ void R2D_GLES_DrawImage(R2D_Image *img);
745
+ void R2D_GLES_DrawSprite(R2D_Sprite *spr);
746
+ void R2D_GLES_DrawTile(R2D_Image *img, int x, int y,
747
+ int tw, int th,
748
+ GLfloat tx1, GLfloat ty1, GLfloat tx2, GLfloat ty2,
749
+ GLfloat tx3, GLfloat ty3, GLfloat tx4, GLfloat ty4);
750
+ void R2D_GLES_DrawText(R2D_Text *txt);
751
+ #else
752
+ int R2D_GL2_Init();
753
+ int R2D_GL3_Init();
754
+ void R2D_GL2_ApplyProjection(int w, int h);
755
+ void R2D_GL3_ApplyProjection(GLfloat orthoMatrix[16]);
756
+ void R2D_GL2_DrawTriangle(
757
+ GLfloat x1, GLfloat y1,
758
+ GLfloat r1, GLfloat g1, GLfloat b1, GLfloat a1,
759
+ GLfloat x2, GLfloat y2,
760
+ GLfloat r2, GLfloat g2, GLfloat b2, GLfloat a2,
761
+ GLfloat x3, GLfloat y3,
762
+ GLfloat r3, GLfloat g3, GLfloat b3, GLfloat a3);
763
+ void R2D_GL3_DrawTriangle(
764
+ GLfloat x1, GLfloat y1,
765
+ GLfloat r1, GLfloat g1, GLfloat b1, GLfloat a1,
766
+ GLfloat x2, GLfloat y2,
767
+ GLfloat r2, GLfloat g2, GLfloat b2, GLfloat a2,
768
+ GLfloat x3, GLfloat y3,
769
+ GLfloat r3, GLfloat g3, GLfloat b3, GLfloat a3);
770
+ void R2D_GL2_DrawImage(R2D_Image *img);
771
+ void R2D_GL3_DrawImage(R2D_Image *img);
772
+ void R2D_GL2_DrawSprite(R2D_Sprite *spr);
773
+ void R2D_GL3_DrawSprite(R2D_Sprite *spr);
774
+ void R2D_GL2_DrawTile(R2D_Image *img, int x, int y,
775
+ int tw, int th,
776
+ GLfloat tx1, GLfloat ty1, GLfloat tx2, GLfloat ty2,
777
+ GLfloat tx3, GLfloat ty3, GLfloat tx4, GLfloat ty4);
778
+ void R2D_GL3_DrawTile(R2D_Image *img, int x, int y,
779
+ int tw, int th,
780
+ GLfloat tx1, GLfloat ty1, GLfloat tx2, GLfloat ty2,
781
+ GLfloat tx3, GLfloat ty3, GLfloat tx4, GLfloat ty4);
782
+ void R2D_GL2_DrawText(R2D_Text *txt);
783
+ void R2D_GL3_DrawText(R2D_Text *txt);
784
+ void R2D_GL3_FlushBuffers();
785
+ #endif
786
+
787
+ #ifdef __cplusplus
788
+ }
789
+ #endif