ruby2d 0.10.0 → 0.11.2

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 (387) hide show
  1. checksums.yaml +4 -4
  2. data/assets/include/SDL2/SDL.h +108 -14
  3. data/assets/include/SDL2/SDL_assert.h +81 -50
  4. data/assets/include/SDL2/SDL_atomic.h +135 -35
  5. data/assets/include/SDL2/SDL_audio.h +960 -355
  6. data/assets/include/SDL2/SDL_bits.h +11 -6
  7. data/assets/include/SDL2/SDL_blendmode.h +91 -14
  8. data/assets/include/SDL2/SDL_clipboard.h +30 -7
  9. data/assets/include/SDL2/SDL_config.h +3 -1
  10. data/assets/include/SDL2/SDL_config_android.h +11 -1
  11. data/assets/include/SDL2/SDL_config_emscripten.h +216 -0
  12. data/assets/include/SDL2/SDL_config_iphoneos.h +9 -1
  13. data/assets/include/SDL2/SDL_config_macosx.h +16 -2
  14. data/assets/include/SDL2/SDL_config_minimal.h +4 -1
  15. data/assets/include/SDL2/SDL_config_os2.h +37 -20
  16. data/assets/include/SDL2/SDL_config_pandora.h +6 -1
  17. data/assets/include/SDL2/SDL_config_psp.h +8 -8
  18. data/assets/include/SDL2/SDL_config_windows.h +39 -22
  19. data/assets/include/SDL2/SDL_config_winrt.h +23 -8
  20. data/assets/include/SDL2/SDL_config_wiz.h +6 -1
  21. data/assets/include/SDL2/SDL_copying.h +1 -1
  22. data/assets/include/SDL2/SDL_cpuinfo.h +331 -71
  23. data/assets/include/SDL2/SDL_egl.h +906 -280
  24. data/assets/include/SDL2/SDL_endian.h +101 -47
  25. data/assets/include/SDL2/SDL_error.h +70 -19
  26. data/assets/include/SDL2/SDL_events.h +387 -79
  27. data/assets/include/SDL2/SDL_filesystem.h +73 -64
  28. data/assets/include/SDL2/SDL_gamecontroller.h +585 -125
  29. data/assets/include/SDL2/SDL_gesture.h +36 -6
  30. data/assets/include/SDL2/SDL_haptic.h +304 -210
  31. data/assets/include/SDL2/SDL_hidapi.h +451 -0
  32. data/assets/include/SDL2/SDL_hints.h +1286 -897
  33. data/assets/include/SDL2/SDL_joystick.h +577 -130
  34. data/assets/include/SDL2/SDL_keyboard.h +162 -63
  35. data/assets/include/SDL2/SDL_keycode.h +7 -5
  36. data/assets/include/SDL2/SDL_loadso.h +42 -8
  37. data/assets/include/SDL2/SDL_locale.h +34 -32
  38. data/assets/include/SDL2/SDL_log.h +212 -19
  39. data/assets/include/SDL2/SDL_main.h +72 -17
  40. data/assets/include/SDL2/SDL_messagebox.h +70 -23
  41. data/assets/include/SDL2/SDL_metal.h +27 -32
  42. data/assets/include/SDL2/SDL_misc.h +19 -15
  43. data/assets/include/SDL2/SDL_mouse.h +262 -110
  44. data/assets/include/SDL2/SDL_mutex.h +286 -66
  45. data/assets/include/SDL2/SDL_name.h +1 -1
  46. data/assets/include/SDL2/SDL_opengl.h +1 -1
  47. data/assets/include/SDL2/SDL_opengles.h +1 -1
  48. data/assets/include/SDL2/SDL_opengles2.h +2 -2
  49. data/assets/include/SDL2/SDL_pixels.h +199 -34
  50. data/assets/include/SDL2/SDL_platform.h +39 -2
  51. data/assets/include/SDL2/SDL_power.h +23 -10
  52. data/assets/include/SDL2/SDL_quit.h +1 -1
  53. data/assets/include/SDL2/SDL_rect.h +78 -28
  54. data/assets/include/SDL2/SDL_render.h +1204 -472
  55. data/assets/include/SDL2/SDL_revision.h +2 -2
  56. data/assets/include/SDL2/SDL_rwops.h +605 -33
  57. data/assets/include/SDL2/SDL_scancode.h +1 -1
  58. data/assets/include/SDL2/SDL_sensor.h +76 -42
  59. data/assets/include/SDL2/SDL_shape.h +38 -27
  60. data/assets/include/SDL2/SDL_stdinc.h +96 -24
  61. data/assets/include/SDL2/SDL_surface.h +571 -139
  62. data/assets/include/SDL2/SDL_system.h +339 -101
  63. data/assets/include/SDL2/SDL_syswm.h +50 -20
  64. data/assets/include/SDL2/SDL_test.h +1 -1
  65. data/assets/include/SDL2/SDL_test_assert.h +2 -2
  66. data/assets/include/SDL2/SDL_test_common.h +23 -6
  67. data/assets/include/SDL2/SDL_test_compare.h +1 -1
  68. data/assets/include/SDL2/SDL_test_crc32.h +1 -1
  69. data/assets/include/SDL2/SDL_test_font.h +3 -3
  70. data/assets/include/SDL2/SDL_test_fuzzer.h +28 -26
  71. data/assets/include/SDL2/SDL_test_harness.h +6 -6
  72. data/assets/include/SDL2/SDL_test_images.h +1 -1
  73. data/assets/include/SDL2/SDL_test_log.h +1 -1
  74. data/assets/include/SDL2/SDL_test_md5.h +1 -1
  75. data/assets/include/SDL2/SDL_test_memory.h +1 -1
  76. data/assets/include/SDL2/SDL_test_random.h +2 -2
  77. data/assets/include/SDL2/SDL_thread.h +226 -128
  78. data/assets/include/SDL2/SDL_timer.h +129 -22
  79. data/assets/include/SDL2/SDL_touch.h +48 -8
  80. data/assets/include/SDL2/SDL_ttf.h +102 -9
  81. data/assets/include/SDL2/SDL_types.h +1 -1
  82. data/assets/include/SDL2/SDL_version.h +72 -46
  83. data/assets/include/SDL2/SDL_video.h +1266 -460
  84. data/assets/include/SDL2/SDL_vulkan.h +100 -161
  85. data/assets/include/SDL2/begin_code.h +22 -1
  86. data/assets/include/SDL2/close_code.h +1 -1
  87. data/assets/include/mrbconf.h +234 -0
  88. data/assets/include/mruby/array.h +317 -0
  89. data/assets/include/mruby/boxing_nan.h +130 -0
  90. data/assets/include/mruby/boxing_no.h +58 -0
  91. data/assets/include/mruby/boxing_word.h +205 -0
  92. data/assets/include/mruby/class.h +108 -0
  93. data/assets/include/mruby/common.h +92 -0
  94. data/assets/include/mruby/compile.h +210 -0
  95. data/assets/include/mruby/data.h +76 -0
  96. data/assets/include/mruby/debug.h +66 -0
  97. data/assets/include/mruby/dump.h +158 -0
  98. data/assets/include/mruby/endian.h +44 -0
  99. data/assets/include/mruby/error.h +137 -0
  100. data/assets/include/mruby/gc.h +92 -0
  101. data/assets/include/mruby/hash.h +242 -0
  102. data/assets/include/mruby/irep.h +147 -0
  103. data/assets/include/mruby/istruct.h +50 -0
  104. data/assets/include/mruby/khash.h +284 -0
  105. data/assets/include/mruby/numeric.h +169 -0
  106. data/assets/include/mruby/object.h +43 -0
  107. data/assets/include/mruby/opcode.h +43 -0
  108. data/assets/include/mruby/ops.h +122 -0
  109. data/assets/include/mruby/presym/disable.h +70 -0
  110. data/assets/include/mruby/presym/enable.h +37 -0
  111. data/assets/include/mruby/presym/scanning.h +73 -0
  112. data/assets/include/mruby/presym.h +40 -0
  113. data/assets/include/mruby/proc.h +209 -0
  114. data/assets/include/mruby/range.h +79 -0
  115. data/assets/include/mruby/re.h +16 -0
  116. data/assets/include/mruby/string.h +469 -0
  117. data/assets/include/mruby/throw.h +66 -0
  118. data/assets/include/mruby/value.h +400 -0
  119. data/assets/include/mruby/variable.h +140 -0
  120. data/assets/include/mruby/version.h +143 -0
  121. data/assets/include/mruby.h +1444 -0
  122. data/assets/macos/universal/bin/mrbc +0 -0
  123. data/assets/macos/universal/lib/libFLAC.a +0 -0
  124. data/assets/macos/universal/lib/libSDL2.a +0 -0
  125. data/assets/macos/universal/lib/libSDL2_image.a +0 -0
  126. data/assets/macos/{lib → universal/lib}/libSDL2_mixer.a +0 -0
  127. data/assets/macos/universal/lib/libSDL2_ttf.a +0 -0
  128. data/assets/macos/universal/lib/libfreetype.a +0 -0
  129. data/assets/macos/universal/lib/libgraphite2.a +0 -0
  130. data/assets/macos/universal/lib/libharfbuzz.a +0 -0
  131. data/assets/macos/universal/lib/libjpeg.a +0 -0
  132. data/assets/macos/universal/lib/libmodplug.a +0 -0
  133. data/assets/macos/{lib → universal/lib}/libmpg123.a +0 -0
  134. data/assets/{mingw/lib/libSDL2.a → macos/universal/lib/libmruby.a} +0 -0
  135. data/assets/macos/{lib → universal/lib}/libogg.a +0 -0
  136. data/assets/macos/universal/lib/libpng16.a +0 -0
  137. data/assets/macos/universal/lib/libtiff.a +0 -0
  138. data/assets/macos/universal/lib/libvorbis.a +0 -0
  139. data/assets/macos/universal/lib/libvorbisfile.a +0 -0
  140. data/assets/macos/universal/lib/libwebp.a +0 -0
  141. data/assets/test_media/README.md +3 -0
  142. data/assets/test_media/bitstream_vera/COPYRIGHT.txt +124 -0
  143. data/assets/test_media/bitstream_vera/vera.ttf +0 -0
  144. data/assets/test_media/boom.png +0 -0
  145. data/assets/test_media/coin.png +0 -0
  146. data/assets/test_media/colors.png +0 -0
  147. data/assets/test_media/controller.png +0 -0
  148. data/assets/test_media/dial.wav +0 -0
  149. data/assets/test_media/hero.png +0 -0
  150. data/assets/test_media/image.bmp +0 -0
  151. data/assets/test_media/image.jpg +0 -0
  152. data/assets/test_media/image.png +0 -0
  153. data/assets/test_media/music.flac +0 -0
  154. data/assets/test_media/music.mp3 +0 -0
  155. data/assets/test_media/music.ogg +0 -0
  156. data/assets/test_media/music.wav +0 -0
  157. data/assets/test_media/originals/boom.pxm +0 -0
  158. data/assets/test_media/originals/coin.pxm +0 -0
  159. data/assets/test_media/originals/controller.sketch +0 -0
  160. data/assets/test_media/originals/hero.pxm +0 -0
  161. data/assets/test_media/originals/image.pxm +0 -0
  162. data/assets/test_media/originals/music.caf +0 -0
  163. data/assets/test_media/originals/texture_atlas.pxm +0 -0
  164. data/assets/test_media/rondo_alla_turka.ogg +0 -0
  165. data/assets/test_media/sound.flac +0 -0
  166. data/assets/test_media/sound.mp3 +0 -0
  167. data/assets/test_media/sound.ogg +0 -0
  168. data/assets/test_media/sound.wav +0 -0
  169. data/assets/test_media/sprite_sheet.png +0 -0
  170. data/assets/test_media/texture_atlas.png +0 -0
  171. data/assets/wasm/build_config.rb +13 -0
  172. data/assets/wasm/libmruby.a +0 -0
  173. data/assets/wasm/template.html +17 -0
  174. data/assets/windows/glew/README.md +10 -0
  175. data/assets/windows/glew/glew.h +23686 -0
  176. data/assets/{mingw/lib → windows/glew}/libglew32.a +0 -0
  177. data/assets/windows/mingw-w64-x86_64/bin/mrbc.exe +0 -0
  178. data/assets/windows/mingw-w64-x86_64/lib/libFLAC.a +0 -0
  179. data/assets/windows/mingw-w64-x86_64/lib/libLerc.a +0 -0
  180. data/assets/windows/mingw-w64-x86_64/lib/libSDL2.a +0 -0
  181. data/assets/windows/mingw-w64-x86_64/lib/libSDL2_image.a +0 -0
  182. data/assets/windows/mingw-w64-x86_64/lib/libSDL2_mixer.a +0 -0
  183. data/assets/windows/mingw-w64-x86_64/lib/libSDL2_ttf.a +0 -0
  184. data/assets/windows/mingw-w64-x86_64/lib/libbrotlicommon.a +0 -0
  185. data/assets/windows/mingw-w64-x86_64/lib/libbrotlidec.a +0 -0
  186. data/assets/windows/mingw-w64-x86_64/lib/libbz2.a +0 -0
  187. data/assets/windows/mingw-w64-x86_64/lib/libdeflate.a +0 -0
  188. data/assets/windows/mingw-w64-x86_64/lib/libfreetype.a +0 -0
  189. data/assets/windows/mingw-w64-x86_64/lib/libglew32.a +0 -0
  190. data/assets/windows/mingw-w64-x86_64/lib/libgraphite2.a +0 -0
  191. data/assets/windows/mingw-w64-x86_64/lib/libharfbuzz.a +0 -0
  192. data/assets/windows/mingw-w64-x86_64/lib/libjbig.a +0 -0
  193. data/assets/windows/mingw-w64-x86_64/lib/libjpeg.a +0 -0
  194. data/assets/windows/mingw-w64-x86_64/lib/liblzma.a +0 -0
  195. data/assets/windows/mingw-w64-x86_64/lib/libmodplug.a +0 -0
  196. data/assets/windows/mingw-w64-x86_64/lib/libmpg123.a +0 -0
  197. data/assets/windows/mingw-w64-x86_64/lib/libmruby.a +0 -0
  198. data/assets/windows/mingw-w64-x86_64/lib/libogg.a +0 -0
  199. data/assets/windows/mingw-w64-x86_64/lib/libopus.a +0 -0
  200. data/assets/windows/mingw-w64-x86_64/lib/libopusfile.a +0 -0
  201. data/assets/windows/mingw-w64-x86_64/lib/libpng16.a +0 -0
  202. data/assets/windows/mingw-w64-x86_64/lib/libsndfile.a +0 -0
  203. data/assets/windows/mingw-w64-x86_64/lib/libssp.a +0 -0
  204. data/assets/windows/mingw-w64-x86_64/lib/libstdc++.a +0 -0
  205. data/assets/windows/mingw-w64-x86_64/lib/libtiff.a +0 -0
  206. data/assets/windows/mingw-w64-x86_64/lib/libvorbis.a +0 -0
  207. data/assets/windows/mingw-w64-x86_64/lib/libvorbisfile.a +0 -0
  208. data/assets/windows/mingw-w64-x86_64/lib/libwebp.a +0 -0
  209. data/assets/windows/mingw-w64-x86_64/lib/libz.a +0 -0
  210. data/assets/windows/mingw-w64-x86_64/lib/libzstd.a +0 -0
  211. data/assets/{ios → xcode/ios}/Assets.xcassets/AppIcon.appiconset/Contents.json +0 -0
  212. data/assets/{ios → xcode/ios}/Assets.xcassets/Contents.json +0 -0
  213. data/assets/{ios → xcode/ios}/Base.lproj/LaunchScreen.storyboard +0 -0
  214. data/assets/{ios → xcode/ios}/Info.plist +0 -0
  215. data/assets/{ios → xcode/ios}/MRuby.framework/Headers/mrbconf.h +0 -0
  216. data/assets/{ios → xcode/ios}/MRuby.framework/Headers/mruby/array.h +0 -0
  217. data/assets/{ios → xcode/ios}/MRuby.framework/Headers/mruby/boxing_nan.h +0 -0
  218. data/assets/{ios → xcode/ios}/MRuby.framework/Headers/mruby/boxing_no.h +0 -0
  219. data/assets/{ios → xcode/ios}/MRuby.framework/Headers/mruby/boxing_word.h +0 -0
  220. data/assets/{ios → xcode/ios}/MRuby.framework/Headers/mruby/class.h +0 -0
  221. data/assets/{ios → xcode/ios}/MRuby.framework/Headers/mruby/common.h +0 -0
  222. data/assets/{ios → xcode/ios}/MRuby.framework/Headers/mruby/compile.h +0 -0
  223. data/assets/{ios → xcode/ios}/MRuby.framework/Headers/mruby/data.h +0 -0
  224. data/assets/{ios → xcode/ios}/MRuby.framework/Headers/mruby/debug.h +0 -0
  225. data/assets/{ios → xcode/ios}/MRuby.framework/Headers/mruby/dump.h +0 -0
  226. data/assets/{ios → xcode/ios}/MRuby.framework/Headers/mruby/error.h +0 -0
  227. data/assets/{ios → xcode/ios}/MRuby.framework/Headers/mruby/gc.h +0 -0
  228. data/assets/{ios → xcode/ios}/MRuby.framework/Headers/mruby/hash.h +0 -0
  229. data/assets/{ios → xcode/ios}/MRuby.framework/Headers/mruby/irep.h +0 -0
  230. data/assets/{ios → xcode/ios}/MRuby.framework/Headers/mruby/istruct.h +0 -0
  231. data/assets/{ios → xcode/ios}/MRuby.framework/Headers/mruby/khash.h +0 -0
  232. data/assets/{ios → xcode/ios}/MRuby.framework/Headers/mruby/numeric.h +0 -0
  233. data/assets/{ios → xcode/ios}/MRuby.framework/Headers/mruby/object.h +0 -0
  234. data/assets/{ios → xcode/ios}/MRuby.framework/Headers/mruby/opcode.h +0 -0
  235. data/assets/{ios → xcode/ios}/MRuby.framework/Headers/mruby/ops.h +0 -0
  236. data/assets/{ios → xcode/ios}/MRuby.framework/Headers/mruby/proc.h +0 -0
  237. data/assets/{ios → xcode/ios}/MRuby.framework/Headers/mruby/range.h +0 -0
  238. data/assets/{ios → xcode/ios}/MRuby.framework/Headers/mruby/re.h +0 -0
  239. data/assets/{ios → xcode/ios}/MRuby.framework/Headers/mruby/string.h +0 -0
  240. data/assets/{ios → xcode/ios}/MRuby.framework/Headers/mruby/throw.h +0 -0
  241. data/assets/{ios → xcode/ios}/MRuby.framework/Headers/mruby/value.h +0 -0
  242. data/assets/{ios → xcode/ios}/MRuby.framework/Headers/mruby/variable.h +0 -0
  243. data/assets/{ios → xcode/ios}/MRuby.framework/Headers/mruby/version.h +0 -0
  244. data/assets/{ios → xcode/ios}/MRuby.framework/Headers/mruby.h +0 -0
  245. data/assets/{ios → xcode/ios}/MRuby.framework/Info.plist +0 -0
  246. data/assets/{ios → xcode/ios}/MRuby.framework/MRuby +0 -0
  247. data/assets/{ios → xcode/ios}/MyApp.xcodeproj/project.pbxproj +0 -0
  248. data/assets/{ios → xcode/ios}/MyApp.xcodeproj/project.xcworkspace/contents.xcworkspacedata +0 -0
  249. data/assets/{ios → xcode/ios}/MyApp.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +0 -0
  250. data/assets/{ios → xcode/ios}/MyApp.xcodeproj/project.xcworkspace/xcshareddata/MyApp.xcscmblueprint +0 -0
  251. data/assets/{ios → xcode/ios}/main.c +0 -0
  252. data/assets/{tvos → xcode/tvos}/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Large.imagestack/Back.imagestacklayer/Content.imageset/Contents.json +0 -0
  253. data/assets/{tvos → xcode/tvos}/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Large.imagestack/Back.imagestacklayer/Contents.json +0 -0
  254. data/assets/{tvos → xcode/tvos}/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Large.imagestack/Contents.json +0 -0
  255. data/assets/{tvos → xcode/tvos}/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Large.imagestack/Front.imagestacklayer/Content.imageset/Contents.json +0 -0
  256. data/assets/{tvos → xcode/tvos}/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Large.imagestack/Front.imagestacklayer/Contents.json +0 -0
  257. data/assets/{tvos → xcode/tvos}/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Large.imagestack/Middle.imagestacklayer/Content.imageset/Contents.json +0 -0
  258. data/assets/{tvos → xcode/tvos}/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Large.imagestack/Middle.imagestacklayer/Contents.json +0 -0
  259. data/assets/{tvos → xcode/tvos}/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Small.imagestack/Back.imagestacklayer/Content.imageset/Contents.json +0 -0
  260. data/assets/{tvos → xcode/tvos}/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Small.imagestack/Back.imagestacklayer/Contents.json +0 -0
  261. data/assets/{tvos → xcode/tvos}/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Small.imagestack/Contents.json +0 -0
  262. data/assets/{tvos → xcode/tvos}/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Small.imagestack/Front.imagestacklayer/Content.imageset/Contents.json +0 -0
  263. data/assets/{tvos → xcode/tvos}/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Small.imagestack/Front.imagestacklayer/Contents.json +0 -0
  264. data/assets/{tvos → xcode/tvos}/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Small.imagestack/Middle.imagestacklayer/Content.imageset/Contents.json +0 -0
  265. data/assets/{tvos → xcode/tvos}/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Small.imagestack/Middle.imagestacklayer/Contents.json +0 -0
  266. data/assets/{tvos → xcode/tvos}/Assets.xcassets/App Icon & Top Shelf Image.brandassets/Contents.json +0 -0
  267. data/assets/{tvos → xcode/tvos}/Assets.xcassets/App Icon & Top Shelf Image.brandassets/Top Shelf Image Wide.imageset/Contents.json +0 -0
  268. data/assets/{tvos → xcode/tvos}/Assets.xcassets/App Icon & Top Shelf Image.brandassets/Top Shelf Image.imageset/Contents.json +0 -0
  269. data/assets/{tvos → xcode/tvos}/Assets.xcassets/Contents.json +0 -0
  270. data/assets/{tvos → xcode/tvos}/Assets.xcassets/LaunchImage.launchimage/Contents.json +0 -0
  271. data/assets/{tvos → xcode/tvos}/Info.plist +0 -0
  272. data/assets/{tvos → xcode/tvos}/MRuby.framework/Headers/mrbconf.h +0 -0
  273. data/assets/{tvos → xcode/tvos}/MRuby.framework/Headers/mruby/array.h +0 -0
  274. data/assets/{tvos → xcode/tvos}/MRuby.framework/Headers/mruby/boxing_nan.h +0 -0
  275. data/assets/{tvos → xcode/tvos}/MRuby.framework/Headers/mruby/boxing_no.h +0 -0
  276. data/assets/{tvos → xcode/tvos}/MRuby.framework/Headers/mruby/boxing_word.h +0 -0
  277. data/assets/{tvos → xcode/tvos}/MRuby.framework/Headers/mruby/class.h +0 -0
  278. data/assets/{tvos → xcode/tvos}/MRuby.framework/Headers/mruby/common.h +0 -0
  279. data/assets/{tvos → xcode/tvos}/MRuby.framework/Headers/mruby/compile.h +0 -0
  280. data/assets/{tvos → xcode/tvos}/MRuby.framework/Headers/mruby/data.h +0 -0
  281. data/assets/{tvos → xcode/tvos}/MRuby.framework/Headers/mruby/debug.h +0 -0
  282. data/assets/{tvos → xcode/tvos}/MRuby.framework/Headers/mruby/dump.h +0 -0
  283. data/assets/{tvos → xcode/tvos}/MRuby.framework/Headers/mruby/error.h +0 -0
  284. data/assets/{tvos → xcode/tvos}/MRuby.framework/Headers/mruby/gc.h +0 -0
  285. data/assets/{tvos → xcode/tvos}/MRuby.framework/Headers/mruby/hash.h +0 -0
  286. data/assets/{tvos → xcode/tvos}/MRuby.framework/Headers/mruby/irep.h +0 -0
  287. data/assets/{tvos → xcode/tvos}/MRuby.framework/Headers/mruby/istruct.h +0 -0
  288. data/assets/{tvos → xcode/tvos}/MRuby.framework/Headers/mruby/khash.h +0 -0
  289. data/assets/{tvos → xcode/tvos}/MRuby.framework/Headers/mruby/numeric.h +0 -0
  290. data/assets/{tvos → xcode/tvos}/MRuby.framework/Headers/mruby/object.h +0 -0
  291. data/assets/{tvos → xcode/tvos}/MRuby.framework/Headers/mruby/opcode.h +0 -0
  292. data/assets/{tvos → xcode/tvos}/MRuby.framework/Headers/mruby/ops.h +0 -0
  293. data/assets/{tvos → xcode/tvos}/MRuby.framework/Headers/mruby/proc.h +0 -0
  294. data/assets/{tvos → xcode/tvos}/MRuby.framework/Headers/mruby/range.h +0 -0
  295. data/assets/{tvos → xcode/tvos}/MRuby.framework/Headers/mruby/re.h +0 -0
  296. data/assets/{tvos → xcode/tvos}/MRuby.framework/Headers/mruby/string.h +0 -0
  297. data/assets/{tvos → xcode/tvos}/MRuby.framework/Headers/mruby/throw.h +0 -0
  298. data/assets/{tvos → xcode/tvos}/MRuby.framework/Headers/mruby/value.h +0 -0
  299. data/assets/{tvos → xcode/tvos}/MRuby.framework/Headers/mruby/variable.h +0 -0
  300. data/assets/{tvos → xcode/tvos}/MRuby.framework/Headers/mruby/version.h +0 -0
  301. data/assets/{tvos → xcode/tvos}/MRuby.framework/Headers/mruby.h +0 -0
  302. data/assets/{tvos → xcode/tvos}/MRuby.framework/Info.plist +0 -0
  303. data/assets/{tvos → xcode/tvos}/MRuby.framework/MRuby +0 -0
  304. data/assets/{tvos → xcode/tvos}/MyApp.xcodeproj/project.pbxproj +0 -0
  305. data/assets/{tvos → xcode/tvos}/MyApp.xcodeproj/project.xcworkspace/contents.xcworkspacedata +0 -0
  306. data/assets/{tvos → xcode/tvos}/MyApp.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +0 -0
  307. data/assets/{tvos → xcode/tvos}/MyApp.xcodeproj/project.xcworkspace/xcshareddata/MyApp.xcscmblueprint +0 -0
  308. data/assets/{tvos → xcode/tvos}/main.c +0 -0
  309. data/bin/ruby2d +3 -4
  310. data/ext/ruby2d/extconf.rb +68 -46
  311. data/ext/ruby2d/font.c +35 -0
  312. data/ext/ruby2d/gl.c +9 -58
  313. data/ext/ruby2d/gl2.c +8 -83
  314. data/ext/ruby2d/gl3.c +57 -116
  315. data/ext/ruby2d/gles.c +130 -151
  316. data/ext/ruby2d/image.c +16 -96
  317. data/ext/ruby2d/ruby2d.c +265 -298
  318. data/ext/ruby2d/ruby2d.h +69 -159
  319. data/ext/ruby2d/sound.c +1 -1
  320. data/ext/ruby2d/text.c +20 -114
  321. data/ext/ruby2d/window.c +257 -219
  322. data/lib/ruby2d/circle.rb +3 -1
  323. data/lib/ruby2d/cli/build.rb +239 -59
  324. data/lib/ruby2d/cli/colorize.rb +5 -4
  325. data/lib/ruby2d/cli/platform.rb +17 -0
  326. data/lib/ruby2d/font.rb +26 -1
  327. data/lib/ruby2d/image.rb +22 -17
  328. data/lib/ruby2d/line.rb +3 -1
  329. data/lib/ruby2d/quad.rb +3 -1
  330. data/lib/ruby2d/rectangle.rb +1 -1
  331. data/lib/ruby2d/renderable.rb +0 -12
  332. data/lib/ruby2d/sound.rb +25 -0
  333. data/lib/ruby2d/sprite.rb +44 -89
  334. data/lib/ruby2d/square.rb +1 -1
  335. data/lib/ruby2d/text.rb +40 -20
  336. data/lib/ruby2d/texture.rb +28 -0
  337. data/lib/ruby2d/tileset.rb +47 -28
  338. data/lib/ruby2d/triangle.rb +3 -1
  339. data/lib/ruby2d/version.rb +1 -1
  340. data/lib/ruby2d/vertices.rb +89 -0
  341. data/lib/ruby2d/window.rb +13 -3
  342. data/lib/ruby2d.rb +16 -20
  343. metadata +249 -153
  344. data/assets/README.md +0 -22
  345. data/assets/Rakefile +0 -85
  346. data/assets/macos/lib/libFLAC.a +0 -0
  347. data/assets/macos/lib/libSDL2.a +0 -0
  348. data/assets/macos/lib/libSDL2_image.a +0 -0
  349. data/assets/macos/lib/libSDL2_ttf.a +0 -0
  350. data/assets/macos/lib/libfreetype.a +0 -0
  351. data/assets/macos/lib/libjpeg.a +0 -0
  352. data/assets/macos/lib/libpng16.a +0 -0
  353. data/assets/macos/lib/libtiff.a +0 -0
  354. data/assets/macos/lib/libvorbis.a +0 -0
  355. data/assets/macos/lib/libvorbisfile.a +0 -0
  356. data/assets/macos/lib/libwebp.a +0 -0
  357. data/assets/mingw/bin/SDL2.dll +0 -0
  358. data/assets/mingw/bin/SDL2_image.dll +0 -0
  359. data/assets/mingw/bin/SDL2_mixer.dll +0 -0
  360. data/assets/mingw/bin/SDL2_ttf.dll +0 -0
  361. data/assets/mingw/bin/glew32.dll +0 -0
  362. data/assets/mingw/bin/libFLAC-8.dll +0 -0
  363. data/assets/mingw/bin/libfreetype-6.dll +0 -0
  364. data/assets/mingw/bin/libjpeg-9.dll +0 -0
  365. data/assets/mingw/bin/libmodplug-1.dll +0 -0
  366. data/assets/mingw/bin/libmpg123-0.dll +0 -0
  367. data/assets/mingw/bin/libogg-0.dll +0 -0
  368. data/assets/mingw/bin/libopus-0.dll +0 -0
  369. data/assets/mingw/bin/libopusfile-0.dll +0 -0
  370. data/assets/mingw/bin/libpng16-16.dll +0 -0
  371. data/assets/mingw/bin/libtiff-5.dll +0 -0
  372. data/assets/mingw/bin/libvorbis-0.dll +0 -0
  373. data/assets/mingw/bin/libvorbisfile-3.dll +0 -0
  374. data/assets/mingw/bin/libwebp-7.dll +0 -0
  375. data/assets/mingw/bin/zlib1.dll +0 -0
  376. data/assets/mingw/lib/libSDL2.dll.a +0 -0
  377. data/assets/mingw/lib/libSDL2_image.a +0 -0
  378. data/assets/mingw/lib/libSDL2_image.dll.a +0 -0
  379. data/assets/mingw/lib/libSDL2_mixer.a +0 -0
  380. data/assets/mingw/lib/libSDL2_mixer.dll.a +0 -0
  381. data/assets/mingw/lib/libSDL2_test.a +0 -0
  382. data/assets/mingw/lib/libSDL2_ttf.a +0 -0
  383. data/assets/mingw/lib/libSDL2_ttf.dll.a +0 -0
  384. data/assets/mingw/lib/libSDL2main.a +0 -0
  385. data/assets/mingw/lib/libglew32.dll.a +0 -0
  386. data/ext/ruby2d/sprite.c +0 -147
  387. data/ext/ruby2d/tileset.c +0 -30
data/ext/ruby2d/ruby2d.h CHANGED
@@ -1,5 +1,8 @@
1
1
  // ruby2d.h
2
2
 
3
+ #ifndef RUBY2D_H
4
+ #define RUBY2D_H
5
+
3
6
  #ifdef __cplusplus
4
7
  extern "C" {
5
8
  #endif
@@ -8,6 +11,10 @@ extern "C" {
8
11
 
9
12
  // Set Platform Constants //////////////////////////////////////////////////////
10
13
 
14
+ #ifndef MRUBY
15
+ #define MRUBY false
16
+ #endif
17
+
11
18
  // Apple
12
19
  #ifdef __APPLE__
13
20
  #ifndef __TARGETCONDITIONALS__
@@ -15,30 +22,54 @@ extern "C" {
15
22
  #endif
16
23
  #if TARGET_OS_OSX
17
24
  #define MACOS true
18
- #elif TARGET_OS_IOS
19
- #define IOS true
20
- #elif TARGET_OS_TV
21
- #define TVOS true
25
+ #else
26
+ #define MACOS false
27
+ #endif
28
+ #if TARGET_OS_IOS
29
+ #define IOS true
30
+ #else
31
+ #define IOS false
32
+ #endif
33
+ #if TARGET_OS_TV
34
+ #define TVOS true
35
+ #else
36
+ #define TVOS false
22
37
  #endif
23
38
  #endif
24
39
 
25
40
  // Windows
26
41
  #ifdef _WIN32
27
42
  #define WINDOWS true
43
+ #else
44
+ #define WINDOWS false
28
45
  #endif
29
46
 
30
47
  // Windows and MinGW
31
48
  #ifdef __MINGW32__
32
49
  #define MINGW true
50
+ #else
51
+ #define MINGW false
33
52
  #endif
34
53
 
35
- // GLES
36
- #if defined(__arm__) || IOS || TVOS
54
+ // WebAssembly
55
+ #ifdef __EMSCRIPTEN__
56
+ #define WASM true
57
+ #else
58
+ #define WASM false
59
+ #endif
60
+
61
+
62
+ // #define GLES true
63
+
64
+ // ARM and GLES
65
+ #if IOS || TVOS || WASM
37
66
  #define GLES true
38
67
  #else
39
68
  #define GLES false
40
69
  #endif
41
70
 
71
+
72
+
42
73
  // Includes ////////////////////////////////////////////////////////////////////
43
74
 
44
75
  // Define to get GNU extension functions and types, like `vasprintf()` and M_PI
@@ -56,6 +87,7 @@ extern "C" {
56
87
  #if WINDOWS
57
88
  #include <stdio.h>
58
89
  #include <math.h>
90
+ #include <winsock2.h>
59
91
  #include <windows.h>
60
92
  // For terminal colors
61
93
  #ifndef ENABLE_VIRTUAL_TERMINAL_PROCESSING
@@ -75,6 +107,17 @@ extern "C" {
75
107
  #undef main
76
108
  #endif
77
109
 
110
+ #if WASM
111
+ #include <stdlib.h>
112
+ #include <stdio.h>
113
+ #include <string.h>
114
+ #include <math.h>
115
+ #include <emscripten.h>
116
+ #include <SDL.h>
117
+ #define GL_GLEXT_PROTOTYPES 1
118
+ #include <SDL_opengles2.h>
119
+ #endif
120
+
78
121
  // OpenGL
79
122
  #if GLES
80
123
  #if IOS || TVOS
@@ -85,6 +128,7 @@ extern "C" {
85
128
  #else
86
129
  #define GL_GLEXT_PROTOTYPES 1
87
130
  #if WINDOWS
131
+ #define GLEW_STATIC
88
132
  #include <glew.h>
89
133
  #endif
90
134
  #include <SDL2/SDL_opengl.h>
@@ -272,64 +316,6 @@ typedef struct {
272
316
  bool close;
273
317
  } R2D_Window;
274
318
 
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
319
 
334
320
  // R2D_Sound
335
321
  typedef struct {
@@ -452,85 +438,28 @@ void R2D_DrawCircle(
452
438
  // Image ///////////////////////////////////////////////////////////////////////
453
439
 
454
440
  /*
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
441
+ * Create a surface with image pixel data, given a file path
483
442
  */
484
- void R2D_ClipSprite(R2D_Sprite *spr, int x, int y, int w, int h);
443
+ SDL_Surface *R2D_CreateImageSurface(const char *path);
485
444
 
486
445
  /*
487
- * Rotate a sprite
446
+ * Convert images to RGB format if they are in a different (BGR for example) format.
488
447
  */
489
- void R2D_RotateSprite(R2D_Sprite *spr, GLfloat angle, int position);
448
+ void R2D_ImageConvertToRGB(SDL_Surface *surface);
490
449
 
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 ////////////////////////////////////////////////////////////////////////
450
+ // Font ////////////////////////////////////////////////////////////////////////
502
451
 
503
452
  /*
504
- * Draw a tile
453
+ * Create a TTF_Font object given a path to a font and a size
505
454
  */
506
- void R2D_DrawTile(R2D_Image *img, int tw, int th, int padding, int spacing, int tx, int ty, int x, int y);
455
+ TTF_Font *R2D_FontCreateTTFFont(const char *path, int size, const char *style);
507
456
 
508
457
  // Text ////////////////////////////////////////////////////////////////////////
509
458
 
510
459
  /*
511
- * Create text, given a font file path, the message, and size
460
+ * Create a SDL_Surface that contains the pixel data to render text, given a font and message
512
461
  */
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);
462
+ SDL_Surface *R2D_TextCreateSurface(TTF_Font *font, const char *message);
534
463
 
535
464
  // Sound ///////////////////////////////////////////////////////////////////////
536
465
 
@@ -702,11 +631,11 @@ int R2D_FreeWindow(R2D_Window *window);
702
631
  // Ruby 2D OpenGL Functions ////////////////////////////////////////////////////
703
632
 
704
633
  int R2D_GL_Init(R2D_Window *window);
705
- void R2D_GL_PrintError(char *error);
634
+ void R2D_GL_PrintError(const char *error);
706
635
  void R2D_GL_PrintContextInfo(R2D_Window *window);
707
636
  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);
637
+ GLuint R2D_GL_LoadShader(GLenum type, const GLchar *shaderSrc, const char *shaderName);
638
+ int R2D_GL_CheckLinked(GLuint program, const char *name);
710
639
  void R2D_GL_GetViewportScale(R2D_Window *window, int *w, int *h, double *scale);
711
640
  void R2D_GL_SetViewport(R2D_Window *window);
712
641
  void R2D_GL_CreateTexture(
@@ -720,11 +649,7 @@ void R2D_GL_DrawTriangle(
720
649
  GLfloat r2, GLfloat g2, GLfloat b2, GLfloat a2,
721
650
  GLfloat x3, GLfloat y3,
722
651
  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);
652
+ void R2D_GL_DrawTexture(GLfloat coordinates[], GLfloat texture_coordinates[], GLfloat color[], int texture_id);
728
653
  void R2D_GL_FreeTexture(GLuint *id);
729
654
  void R2D_GL_Clear(R2D_Color clr);
730
655
  void R2D_GL_FlushBuffers();
@@ -741,13 +666,8 @@ void R2D_GL_FlushBuffers();
741
666
  GLfloat r2, GLfloat g2, GLfloat b2, GLfloat a2,
742
667
  GLfloat x3, GLfloat y3,
743
668
  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);
669
+ void R2D_GLES_DrawTexture(GLfloat coordinates[], GLfloat texture_coordinates[], GLfloat color[], int texture_id);
670
+ void R2D_GLES_FlushBuffers();
751
671
  #else
752
672
  int R2D_GL2_Init();
753
673
  int R2D_GL3_Init();
@@ -767,23 +687,13 @@ void R2D_GL_FlushBuffers();
767
687
  GLfloat r2, GLfloat g2, GLfloat b2, GLfloat a2,
768
688
  GLfloat x3, GLfloat y3,
769
689
  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);
690
+ void R2D_GL2_DrawTexture(GLfloat coordinates[], GLfloat texture_coordinates[], GLfloat color[], int texture_id);
691
+ void R2D_GL3_DrawTexture(GLfloat coordinates[], GLfloat texture_coordinates[], GLfloat color[], int texture_id);
784
692
  void R2D_GL3_FlushBuffers();
785
693
  #endif
786
694
 
787
695
  #ifdef __cplusplus
788
696
  }
789
697
  #endif
698
+
699
+ #endif /* RUBY2D_H */
data/ext/ruby2d/sound.c CHANGED
@@ -57,7 +57,7 @@ int R2D_GetSoundLength(R2D_Sound *snd) {
57
57
  int channels = 0;
58
58
 
59
59
  // Populate the frequency, format and channel variables
60
- if (!Mix_QuerySpec(&frequency, &format, &channels)) return -1; // Querying audio deails failed
60
+ if (!Mix_QuerySpec(&frequency, &format, &channels)) return -1; // Querying audio details failed
61
61
  if (!snd) return -1;
62
62
 
63
63
  // points = bytes / samplesize
data/ext/ruby2d/text.c CHANGED
@@ -4,126 +4,32 @@
4
4
 
5
5
 
6
6
  /*
7
- * Create text, given a font file path, the message, and size
7
+ * Create a SDL_Surface that contains the pixel data to render text, given a font and message
8
8
  */
9
- R2D_Text *R2D_CreateText(const char *font, const char *msg, int size) {
10
- R2D_Init();
11
-
12
- // Check if font file exists
13
- if (!R2D_FileExists(font)) {
14
- R2D_Error("R2D_CreateText", "Font file `%s` not found", font);
15
- return NULL;
16
- }
17
-
9
+ SDL_Surface *R2D_TextCreateSurface(TTF_Font *font, const char *message) {
18
10
  // `msg` cannot be an empty string or NULL for TTF_SizeText
19
- if (msg == NULL || strlen(msg) == 0) msg = " ";
11
+ if (message == NULL || strlen(message) == 0) message = " ";
20
12
 
21
- // Allocate the text structure
22
- R2D_Text *txt = (R2D_Text *) malloc(sizeof(R2D_Text));
23
- if (!txt) {
24
- R2D_Error("R2D_CreateText", "Out of memory!");
13
+ SDL_Color color = {255, 255, 255};
14
+ SDL_Surface *surface = TTF_RenderUTF8_Blended(font, message, color);
15
+ if (!surface)
16
+ {
17
+ R2D_Error("TTF_RenderUTF8_Blended", TTF_GetError());
25
18
  return NULL;
26
19
  }
27
20
 
28
- // Open the font
29
- txt->font_data = TTF_OpenFont(font, size);
30
- if (!txt->font_data) {
31
- R2D_Error("TTF_OpenFont", TTF_GetError());
32
- free(txt);
33
- return NULL;
34
- }
35
-
36
- // Initialize values
37
- txt->font = font;
38
- txt->msg = (char *) malloc(strlen(msg) + 1 * sizeof(char));
39
- strcpy(txt->msg, msg);
40
- txt->x = 0;
41
- txt->y = 0;
42
- txt->color.r = 1.f;
43
- txt->color.g = 1.f;
44
- txt->color.b = 1.f;
45
- txt->color.a = 1.f;
46
- txt->rotate = 0;
47
- txt->rx = 0;
48
- txt->ry = 0;
49
- txt->texture_id = 0;
50
-
51
- // Save the width and height of the text
52
- TTF_SizeUTF8(txt->font_data, txt->msg, &txt->width, &txt->height);
53
-
54
- return txt;
55
- }
56
-
57
-
58
- /*
59
- * Set the text message
60
- */
61
- void R2D_SetText(R2D_Text *txt, const char *msg, ...) {
62
- if (!txt) return;
63
-
64
- // `msg` cannot be an empty string or NULL for TTF_SizeUTF8
65
- if (msg == NULL || strlen(msg) == 0) msg = " ";
66
-
67
- // Format and store new text string
68
- va_list args;
69
- va_start(args, msg);
70
- free(txt->msg);
71
- vasprintf(&txt->msg, msg, args);
72
- va_end(args);
73
-
74
- // Save the width and height of the text
75
- TTF_SizeUTF8(txt->font_data, txt->msg, &txt->width, &txt->height);
76
-
77
- // Delete the current texture so a new one can be generated
78
- R2D_GL_FreeTexture(&txt->texture_id);
79
- }
80
-
81
-
82
- /*
83
- * Rotate text
84
- */
85
- void R2D_RotateText(R2D_Text *txt, GLfloat angle, int position) {
86
-
87
- R2D_GL_Point p = R2D_GetRectRotationPoint(
88
- txt->x, txt->y, txt->width, txt->height, position
89
- );
90
-
91
- txt->rotate = angle;
92
- txt->rx = p.x;
93
- txt->ry = p.y;
94
- }
95
-
96
-
97
- /*
98
- * Draw text
99
- */
100
- void R2D_DrawText(R2D_Text *txt) {
101
- if (!txt) return;
102
-
103
- if (txt->texture_id == 0) {
104
- SDL_Color color = { 255, 255, 255 };
105
- txt->surface = TTF_RenderUTF8_Blended(txt->font_data, txt->msg, color);
106
- if (!txt->surface) {
107
- R2D_Error("TTF_RenderUTF8_Blended", TTF_GetError());
108
- return;
109
- }
110
- R2D_GL_CreateTexture(&txt->texture_id, GL_RGBA,
111
- txt->width, txt->height,
112
- txt->surface->pixels, GL_NEAREST);
113
- SDL_FreeSurface(txt->surface);
21
+ // Re-pack surface for OpenGL
22
+ // See: https://discourse.libsdl.org/t/sdl-ttf-2-0-18-surface-to-opengl-texture-not-consistent-with-ttf-2-0-15
23
+ Sint32 i;
24
+ Uint32 len = surface->w * surface->format->BytesPerPixel;
25
+ Uint8 *src = surface->pixels;
26
+ Uint8 *dst = surface->pixels;
27
+ for (i = 0; i < surface->h; i++) {
28
+ SDL_memmove(dst, src, len);
29
+ dst += len;
30
+ src += surface->pitch;
114
31
  }
32
+ surface->pitch = len;
115
33
 
116
- R2D_GL_DrawText(txt);
117
- }
118
-
119
-
120
- /*
121
- * Free the text
122
- */
123
- void R2D_FreeText(R2D_Text *txt) {
124
- if (!txt) return;
125
- free(txt->msg);
126
- R2D_GL_FreeTexture(&txt->texture_id);
127
- TTF_CloseFont(txt->font_data);
128
- free(txt);
34
+ return surface;
129
35
  }