ruby2d 0.9.2 → 0.10.0

Sign up to get free protection for your applications and to get access to all the features.
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
@@ -1,15 +1,15 @@
1
- // Simple 2D OpenGL Functions
1
+ // Ruby 2D OpenGL Functions
2
2
 
3
- #include "../include/simple2d.h"
3
+ #include "ruby2d.h"
4
4
 
5
5
  // Set to `true` to force OpenGL 2.1 (for testing)
6
6
  static bool FORCE_GL2 = false;
7
7
 
8
8
  // Flag set if using OpenGL 2.1
9
- static bool S2D_GL2 = false;
9
+ static bool R2D_GL2 = false;
10
10
 
11
11
  // The orthographic projection matrix for 2D rendering.
12
- // Elements 0 and 5 are set in S2D_GL_SetViewport.
12
+ // Elements 0 and 5 are set in R2D_GL_SetViewport.
13
13
  static GLfloat orthoMatrix[16] =
14
14
  { 0, 0, 0, 0,
15
15
  0, 0, 0, 0,
@@ -20,25 +20,25 @@ static GLfloat orthoMatrix[16] =
20
20
  /*
21
21
  * Prints current GL error
22
22
  */
23
- void S2D_GL_PrintError(char *error) {
24
- S2D_Log(S2D_ERROR, "%s (%d)", error, glGetError());
23
+ void R2D_GL_PrintError(char *error) {
24
+ R2D_Log(R2D_ERROR, "%s (%d)", error, glGetError());
25
25
  }
26
26
 
27
27
 
28
28
  /*
29
29
  * Print info about the current OpenGL context
30
30
  */
31
- void S2D_GL_PrintContextInfo(S2D_Window *window) {
32
- S2D_Log(S2D_INFO,
31
+ void R2D_GL_PrintContextInfo(R2D_Window *window) {
32
+ R2D_Log(R2D_INFO,
33
33
  "OpenGL Context\n"
34
34
  " GL_VENDOR: %s\n"
35
35
  " GL_RENDERER: %s\n"
36
36
  " GL_VERSION: %s\n"
37
37
  " GL_SHADING_LANGUAGE_VERSION: %s",
38
- window->S2D_GL_VENDOR,
39
- window->S2D_GL_RENDERER,
40
- window->S2D_GL_VERSION,
41
- window->S2D_GL_SHADING_LANGUAGE_VERSION
38
+ window->R2D_GL_VENDOR,
39
+ window->R2D_GL_RENDERER,
40
+ window->R2D_GL_VERSION,
41
+ window->R2D_GL_SHADING_LANGUAGE_VERSION
42
42
  );
43
43
  }
44
44
 
@@ -46,21 +46,22 @@ void S2D_GL_PrintContextInfo(S2D_Window *window) {
46
46
  /*
47
47
  * Store info about the current OpenGL context
48
48
  */
49
- void S2D_GL_StoreContextInfo(S2D_Window *window) {
50
- window->S2D_GL_VENDOR = glGetString(GL_VENDOR);
51
- window->S2D_GL_RENDERER = glGetString(GL_RENDERER);
52
- window->S2D_GL_VERSION = glGetString(GL_VERSION);
49
+ void R2D_GL_StoreContextInfo(R2D_Window *window) {
50
+
51
+ window->R2D_GL_VENDOR = glGetString(GL_VENDOR);
52
+ window->R2D_GL_RENDERER = glGetString(GL_RENDERER);
53
+ window->R2D_GL_VERSION = glGetString(GL_VERSION);
53
54
 
54
55
  // These are not defined in GLES
55
56
  #if GLES
56
- window->S2D_GL_MAJOR_VERSION = 0;
57
- window->S2D_GL_MINOR_VERSION = 0;
57
+ window->R2D_GL_MAJOR_VERSION = 0;
58
+ window->R2D_GL_MINOR_VERSION = 0;
58
59
  #else
59
- glGetIntegerv(GL_MAJOR_VERSION, &window->S2D_GL_MAJOR_VERSION);
60
- glGetIntegerv(GL_MINOR_VERSION, &window->S2D_GL_MINOR_VERSION);
60
+ glGetIntegerv(GL_MAJOR_VERSION, &window->R2D_GL_MAJOR_VERSION);
61
+ glGetIntegerv(GL_MINOR_VERSION, &window->R2D_GL_MINOR_VERSION);
61
62
  #endif
62
63
 
63
- window->S2D_GL_SHADING_LANGUAGE_VERSION = glGetString(GL_SHADING_LANGUAGE_VERSION);
64
+ window->R2D_GL_SHADING_LANGUAGE_VERSION = glGetString(GL_SHADING_LANGUAGE_VERSION);
64
65
  };
65
66
 
66
67
 
@@ -68,16 +69,13 @@ void S2D_GL_StoreContextInfo(S2D_Window *window) {
68
69
  * Creates a shader object, loads shader string, and compiles.
69
70
  * Returns 0 if shader could not be compiled.
70
71
  */
71
- GLuint S2D_GL_LoadShader(GLenum type, const GLchar *shaderSrc, char *shaderName) {
72
-
73
- GLuint shader;
74
- GLint compiled;
72
+ GLuint R2D_GL_LoadShader(GLenum type, const GLchar *shaderSrc, char *shaderName) {
75
73
 
76
74
  // Create the shader object
77
- shader = glCreateShader(type);
75
+ GLuint shader = glCreateShader(type);
78
76
 
79
77
  if (shader == 0) {
80
- S2D_GL_PrintError("Failed to create shader program");
78
+ R2D_GL_PrintError("Failed to create shader program");
81
79
  return 0;
82
80
  }
83
81
 
@@ -88,21 +86,17 @@ GLuint S2D_GL_LoadShader(GLenum type, const GLchar *shaderSrc, char *shaderName)
88
86
  glCompileShader(shader);
89
87
 
90
88
  // Check the compile status
89
+ GLint compiled;
91
90
  glGetShaderiv(shader, GL_COMPILE_STATUS, &compiled);
92
91
 
93
92
  if (!compiled) {
94
-
95
93
  GLint infoLen = 0;
96
-
97
94
  glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &infoLen);
98
95
 
99
96
  if (infoLen > 1) {
100
-
101
97
  char *infoLog = malloc(sizeof(char) * infoLen);
102
-
103
98
  glGetShaderInfoLog(shader, infoLen, NULL, infoLog);
104
99
  printf("Error compiling shader \"%s\":\n%s\n", shaderName, infoLog);
105
-
106
100
  free(infoLog);
107
101
  }
108
102
 
@@ -117,23 +111,19 @@ GLuint S2D_GL_LoadShader(GLenum type, const GLchar *shaderSrc, char *shaderName)
117
111
  /*
118
112
  * Check if shader program was linked
119
113
  */
120
- int S2D_GL_CheckLinked(GLuint program, char *name) {
114
+ int R2D_GL_CheckLinked(GLuint program, char *name) {
121
115
 
122
116
  GLint linked;
123
117
  glGetProgramiv(program, GL_LINK_STATUS, &linked);
124
118
 
125
119
  if (!linked) {
126
-
127
120
  GLint infoLen = 0;
128
121
  glGetProgramiv(program, GL_INFO_LOG_LENGTH, &infoLen);
129
122
 
130
123
  if (infoLen > 1) {
131
-
132
124
  char *infoLog = malloc(sizeof(char) * infoLen);
133
-
134
125
  glGetProgramInfoLog(program, infoLen, NULL, infoLog);
135
126
  printf("Error linking program `%s`: %s\n", name, infoLog);
136
-
137
127
  free(infoLog);
138
128
  }
139
129
 
@@ -148,7 +138,7 @@ int S2D_GL_CheckLinked(GLuint program, char *name) {
148
138
  /*
149
139
  * Calculate the viewport's scaled width and height
150
140
  */
151
- void S2D_GL_GetViewportScale(S2D_Window *window, int *w, int *h, double *scale) {
141
+ void R2D_GL_GetViewportScale(R2D_Window *window, int *w, int *h, double *scale) {
152
142
 
153
143
  double s = fmin(
154
144
  window->width / (double)window->viewport.width,
@@ -165,7 +155,7 @@ void S2D_GL_GetViewportScale(S2D_Window *window, int *w, int *h, double *scale)
165
155
  /*
166
156
  * Sets the viewport and matrix projection
167
157
  */
168
- void S2D_GL_SetViewport(S2D_Window *window) {
158
+ void R2D_GL_SetViewport(R2D_Window *window) {
169
159
 
170
160
  int ortho_w = window->viewport.width;
171
161
  int ortho_h = window->viewport.height;
@@ -175,25 +165,25 @@ void S2D_GL_SetViewport(S2D_Window *window) {
175
165
 
176
166
  switch (window->viewport.mode) {
177
167
 
178
- case S2D_FIXED:
168
+ case R2D_FIXED:
179
169
  w = window->orig_width;
180
170
  h = window->orig_height;
181
171
  y = window->height - h;
182
172
  break;
183
173
 
184
- case S2D_EXPAND:
174
+ case R2D_EXPAND:
185
175
  ortho_w = w;
186
176
  ortho_h = h;
187
177
  break;
188
178
 
189
- case S2D_SCALE:
190
- S2D_GL_GetViewportScale(window, &w, &h, NULL);
179
+ case R2D_SCALE:
180
+ R2D_GL_GetViewportScale(window, &w, &h, NULL);
191
181
  // Center the viewport
192
182
  x = window->width / 2.0 - w/2.0;
193
183
  y = window->height / 2.0 - h/2.0;
194
184
  break;
195
185
 
196
- case S2D_STRETCH:
186
+ case R2D_STRETCH:
197
187
  break;
198
188
  }
199
189
 
@@ -204,12 +194,12 @@ void S2D_GL_SetViewport(S2D_Window *window) {
204
194
  orthoMatrix[5] = -2.0f / (GLfloat)ortho_h;
205
195
 
206
196
  #if GLES
207
- S2D_GLES_ApplyProjection(orthoMatrix);
197
+ R2D_GLES_ApplyProjection(orthoMatrix);
208
198
  #else
209
- if (S2D_GL2) {
210
- S2D_GL2_ApplyProjection(ortho_w, ortho_h);
199
+ if (R2D_GL2) {
200
+ R2D_GL2_ApplyProjection(ortho_w, ortho_h);
211
201
  } else {
212
- S2D_GL3_ApplyProjection(orthoMatrix);
202
+ R2D_GL3_ApplyProjection(orthoMatrix);
213
203
  }
214
204
  #endif
215
205
  }
@@ -218,7 +208,7 @@ void S2D_GL_SetViewport(S2D_Window *window) {
218
208
  /*
219
209
  * Initialize OpenGL
220
210
  */
221
- int S2D_GL_Init(S2D_Window *window) {
211
+ int R2D_GL_Init(R2D_Window *window) {
222
212
 
223
213
  // Specify OpenGL contexts and set attributes
224
214
  #if GLES
@@ -231,6 +221,7 @@ int S2D_GL_Init(S2D_Window *window) {
231
221
  if (FORCE_GL2) {
232
222
  SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2);
233
223
  SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1);
224
+
234
225
  // Request an OpenGL 3.3 forward-compatible core profile
235
226
  } else {
236
227
  SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
@@ -253,25 +244,25 @@ int S2D_GL_Init(S2D_Window *window) {
253
244
 
254
245
  // Initialize OpenGL ES 2.0
255
246
  #if GLES
256
- S2D_GLES_Init();
257
- S2D_GL_SetViewport(window);
247
+ R2D_GLES_Init();
248
+ R2D_GL_SetViewport(window);
258
249
 
259
250
  // Initialize OpenGL 3.3+
260
251
  #else
261
252
  // Initialize GLEW on Windows
262
253
  #if WINDOWS
263
254
  GLenum err = glewInit();
264
- if (GLEW_OK != err) S2D_Error("GLEW", glewGetErrorString(err));
255
+ if (GLEW_OK != err) R2D_Error("GLEW", glewGetErrorString(err));
265
256
  #endif
266
- S2D_GL3_Init();
267
- S2D_GL_SetViewport(window);
257
+ R2D_GL3_Init();
258
+ R2D_GL_SetViewport(window);
268
259
  #endif
269
260
 
270
261
  // Context could not be created
271
262
  } else {
272
263
 
273
264
  #if GLES
274
- S2D_Error("GLES / SDL_GL_CreateContext", SDL_GetError());
265
+ R2D_Error("GLES / SDL_GL_CreateContext", SDL_GetError());
275
266
 
276
267
  #else
277
268
  // Try to fallback using an OpenGL 2.1 context
@@ -284,22 +275,22 @@ int S2D_GL_Init(S2D_Window *window) {
284
275
  // Check if this context was created
285
276
  if (window->glcontext) {
286
277
  // Valid context found
287
- S2D_GL2 = true;
288
- S2D_GL2_Init();
289
- S2D_GL_SetViewport(window);
278
+ R2D_GL2 = true;
279
+ R2D_GL2_Init();
280
+ R2D_GL_SetViewport(window);
290
281
 
291
282
  // Could not create any OpenGL contexts, hard failure
292
283
  } else {
293
- S2D_Error("GL2 / SDL_GL_CreateContext", SDL_GetError());
294
- S2D_Log(S2D_ERROR, "An OpenGL context could not be created");
284
+ R2D_Error("GL2 / SDL_GL_CreateContext", SDL_GetError());
285
+ R2D_Log(R2D_ERROR, "An OpenGL context could not be created");
295
286
  return -1;
296
287
  }
297
288
  #endif
298
289
  }
299
290
 
300
291
  // Store the context and print it if diagnostics is enabled
301
- S2D_GL_StoreContextInfo(window);
302
- if (S2D_diagnostics) S2D_GL_PrintContextInfo(window);
292
+ R2D_GL_StoreContextInfo(window);
293
+ if (R2D_diagnostics) R2D_GL_PrintContextInfo(window);
303
294
 
304
295
  return 0;
305
296
  }
@@ -308,7 +299,7 @@ int S2D_GL_Init(S2D_Window *window) {
308
299
  /*
309
300
  * Creates a texture for rendering
310
301
  */
311
- void S2D_GL_CreateTexture(GLuint *id, GLint format,
302
+ void R2D_GL_CreateTexture(GLuint *id, GLint format,
312
303
  int w, int h,
313
304
  const GLvoid *data, GLint filter) {
314
305
 
@@ -333,7 +324,7 @@ void S2D_GL_CreateTexture(GLuint *id, GLint format,
333
324
  /*
334
325
  * Free a texture
335
326
  */
336
- void S2D_GL_FreeTexture(GLuint *id) {
327
+ void R2D_GL_FreeTexture(GLuint *id) {
337
328
  if (*id != 0) {
338
329
  glDeleteTextures(1, id);
339
330
  *id = 0;
@@ -344,7 +335,7 @@ void S2D_GL_FreeTexture(GLuint *id) {
344
335
  /*
345
336
  * Draw a triangle
346
337
  */
347
- void S2D_GL_DrawTriangle(GLfloat x1, GLfloat y1,
338
+ void R2D_GL_DrawTriangle(GLfloat x1, GLfloat y1,
348
339
  GLfloat r1, GLfloat g1, GLfloat b1, GLfloat a1,
349
340
  GLfloat x2, GLfloat y2,
350
341
  GLfloat r2, GLfloat g2, GLfloat b2, GLfloat a2,
@@ -352,16 +343,16 @@ void S2D_GL_DrawTriangle(GLfloat x1, GLfloat y1,
352
343
  GLfloat r3, GLfloat g3, GLfloat b3, GLfloat a3) {
353
344
 
354
345
  #if GLES
355
- S2D_GLES_DrawTriangle(x1, y1, r1, g1, b1, a1,
346
+ R2D_GLES_DrawTriangle(x1, y1, r1, g1, b1, a1,
356
347
  x2, y2, r2, g2, b2, a2,
357
348
  x3, y3, r3, g3, b3, a3);
358
349
  #else
359
- if (S2D_GL2) {
360
- S2D_GL2_DrawTriangle(x1, y1, r1, g1, b1, a1,
350
+ if (R2D_GL2) {
351
+ R2D_GL2_DrawTriangle(x1, y1, r1, g1, b1, a1,
361
352
  x2, y2, r2, g2, b2, a2,
362
353
  x3, y3, r3, g3, b3, a3);
363
354
  } else {
364
- S2D_GL3_DrawTriangle(x1, y1, r1, g1, b1, a1,
355
+ R2D_GL3_DrawTriangle(x1, y1, r1, g1, b1, a1,
365
356
  x2, y2, r2, g2, b2, a2,
366
357
  x3, y3, r3, g3, b3, a3);
367
358
  }
@@ -372,14 +363,14 @@ void S2D_GL_DrawTriangle(GLfloat x1, GLfloat y1,
372
363
  /*
373
364
  * Draw an image
374
365
  */
375
- void S2D_GL_DrawImage(S2D_Image *img) {
366
+ void R2D_GL_DrawImage(R2D_Image *img) {
376
367
  #if GLES
377
- S2D_GLES_DrawImage(img);
368
+ R2D_GLES_DrawImage(img);
378
369
  #else
379
- if (S2D_GL2) {
380
- S2D_GL2_DrawImage(img);
370
+ if (R2D_GL2) {
371
+ R2D_GL2_DrawImage(img);
381
372
  } else {
382
- S2D_GL3_DrawImage(img);
373
+ R2D_GL3_DrawImage(img);
383
374
  }
384
375
  #endif
385
376
  }
@@ -388,14 +379,31 @@ void S2D_GL_DrawImage(S2D_Image *img) {
388
379
  /*
389
380
  * Draw sprite
390
381
  */
391
- void S2D_GL_DrawSprite(S2D_Sprite *spr) {
382
+ void R2D_GL_DrawSprite(R2D_Sprite *spr) {
383
+ #if GLES
384
+ R2D_GLES_DrawSprite(spr);
385
+ #else
386
+ if (R2D_GL2) {
387
+ R2D_GL2_DrawSprite(spr);
388
+ } else {
389
+ R2D_GL3_DrawSprite(spr);
390
+ }
391
+ #endif
392
+ }
393
+
394
+
395
+ /*
396
+ * Draw a tile
397
+ */
398
+ void R2D_GL_DrawTile(R2D_Image *img, int x, int y, int tw, int th, GLfloat tx1, GLfloat ty1, GLfloat tx2,
399
+ GLfloat ty2, GLfloat tx3, GLfloat ty3, GLfloat tx4, GLfloat ty4) {
392
400
  #if GLES
393
- S2D_GLES_DrawSprite(spr);
401
+ R2D_GLES_DrawTile(img, x, y, tw, th, tx1, ty1, tx2, ty2, tx3, ty3, tx4, ty4);
394
402
  #else
395
- if (S2D_GL2) {
396
- S2D_GL2_DrawSprite(spr);
403
+ if (R2D_GL2) {
404
+ R2D_GL2_DrawTile(img, x, y, tw, th, tx1, ty1, tx2, ty2, tx3, ty3, tx4, ty4);
397
405
  } else {
398
- S2D_GL3_DrawSprite(spr);
406
+ R2D_GL3_DrawTile(img, x, y, tw, th, tx1, ty1, tx2, ty2, tx3, ty3, tx4, ty4);
399
407
  }
400
408
  #endif
401
409
  }
@@ -404,23 +412,36 @@ void S2D_GL_DrawSprite(S2D_Sprite *spr) {
404
412
  /*
405
413
  * Draw text
406
414
  */
407
- void S2D_GL_DrawText(S2D_Text *txt) {
415
+ void R2D_GL_DrawText(R2D_Text *txt) {
408
416
  #if GLES
409
- S2D_GLES_DrawText(txt);
417
+ R2D_GLES_DrawText(txt);
410
418
  #else
411
- if (S2D_GL2) {
412
- S2D_GL2_DrawText(txt);
419
+ if (R2D_GL2) {
420
+ R2D_GL2_DrawText(txt);
413
421
  } else {
414
- S2D_GL3_DrawText(txt);
422
+ R2D_GL3_DrawText(txt);
415
423
  }
416
424
  #endif
417
425
  }
418
426
 
419
427
 
428
+ /*
429
+ * Render and flush OpenGL buffers
430
+ */
431
+ void R2D_GL_FlushBuffers() {
432
+ // Only implemented in our OpenGL 3.3+ and ES 2.0 renderers
433
+ #if GLES
434
+ // TODO: R2D_GLES_FlushBuffers();
435
+ #else
436
+ if (!R2D_GL2) R2D_GL3_FlushBuffers();
437
+ #endif
438
+ }
439
+
440
+
420
441
  /*
421
442
  * Clear buffers to given color values
422
443
  */
423
- void S2D_GL_Clear(S2D_Color clr) {
444
+ void R2D_GL_Clear(R2D_Color clr) {
424
445
  glClearColor(clr.r, clr.g, clr.b, clr.a);
425
446
  glClear(GL_COLOR_BUFFER_BIT);
426
447
  }
@@ -1,6 +1,6 @@
1
1
  // OpenGL 2.1
2
2
 
3
- #include "../include/simple2d.h"
3
+ #include "ruby2d.h"
4
4
 
5
5
  #if !GLES
6
6
 
@@ -8,7 +8,7 @@
8
8
  /*
9
9
  * Applies the projection matrix
10
10
  */
11
- void S2D_GL2_ApplyProjection(int w, int h) {
11
+ void R2D_GL2_ApplyProjection(int w, int h) {
12
12
 
13
13
  // Initialize the projection matrix
14
14
  glMatrixMode(GL_PROJECTION);
@@ -26,7 +26,7 @@ void S2D_GL2_ApplyProjection(int w, int h) {
26
26
  /*
27
27
  * Initalize OpenGL
28
28
  */
29
- int S2D_GL2_Init() {
29
+ int R2D_GL2_Init() {
30
30
 
31
31
  GLenum error = GL_NO_ERROR;
32
32
 
@@ -37,7 +37,7 @@ int S2D_GL2_Init() {
37
37
  // Check for errors
38
38
  error = glGetError();
39
39
  if (error != GL_NO_ERROR) {
40
- S2D_GL_PrintError("OpenGL initialization failed");
40
+ R2D_GL_PrintError("OpenGL initialization failed");
41
41
  return 1;
42
42
  } else {
43
43
  return 0;
@@ -48,7 +48,7 @@ int S2D_GL2_Init() {
48
48
  /*
49
49
  * Draw triangle
50
50
  */
51
- void S2D_GL2_DrawTriangle(GLfloat x1, GLfloat y1,
51
+ void R2D_GL2_DrawTriangle(GLfloat x1, GLfloat y1,
52
52
  GLfloat r1, GLfloat g1, GLfloat b1, GLfloat a1,
53
53
  GLfloat x2, GLfloat y2,
54
54
  GLfloat r2, GLfloat g2, GLfloat b2, GLfloat a2,
@@ -66,24 +66,24 @@ void S2D_GL2_DrawTriangle(GLfloat x1, GLfloat y1,
66
66
  /*
67
67
  * Draw texture
68
68
  */
69
- static void S2D_GL2_DrawTexture(int x, int y, int w, int h,
69
+ static void R2D_GL2_DrawTexture(int x, int y, int w, int h,
70
70
  GLfloat angle, GLfloat rx, GLfloat ry,
71
71
  GLfloat r, GLfloat g, GLfloat b, GLfloat a,
72
72
  GLfloat tx1, GLfloat ty1, GLfloat tx2, GLfloat ty2,
73
73
  GLfloat tx3, GLfloat ty3, GLfloat tx4, GLfloat ty4,
74
74
  GLuint texture_id) {
75
75
 
76
- S2D_GL_Point v1 = { .x = x, .y = y };
77
- S2D_GL_Point v2 = { .x = x + w, .y = y };
78
- S2D_GL_Point v3 = { .x = x + w, .y = y + h };
79
- S2D_GL_Point v4 = { .x = x, .y = y + h };
76
+ R2D_GL_Point v1 = { .x = x, .y = y };
77
+ R2D_GL_Point v2 = { .x = x + w, .y = y };
78
+ R2D_GL_Point v3 = { .x = x + w, .y = y + h };
79
+ R2D_GL_Point v4 = { .x = x, .y = y + h };
80
80
 
81
81
  // Rotate vertices
82
82
  if (angle != 0) {
83
- v1 = S2D_RotatePoint(v1, angle, rx, ry);
84
- v2 = S2D_RotatePoint(v2, angle, rx, ry);
85
- v3 = S2D_RotatePoint(v3, angle, rx, ry);
86
- v4 = S2D_RotatePoint(v4, angle, rx, ry);
83
+ v1 = R2D_RotatePoint(v1, angle, rx, ry);
84
+ v2 = R2D_RotatePoint(v2, angle, rx, ry);
85
+ v3 = R2D_RotatePoint(v3, angle, rx, ry);
86
+ v4 = R2D_RotatePoint(v4, angle, rx, ry);
87
87
  }
88
88
 
89
89
  glEnable(GL_TEXTURE_2D);
@@ -105,8 +105,8 @@ static void S2D_GL2_DrawTexture(int x, int y, int w, int h,
105
105
  /*
106
106
  * Draw image
107
107
  */
108
- void S2D_GL2_DrawImage(S2D_Image *img) {
109
- S2D_GL2_DrawTexture(
108
+ void R2D_GL2_DrawImage(R2D_Image *img) {
109
+ R2D_GL2_DrawTexture(
110
110
  img->x, img->y, img->width, img->height,
111
111
  img->rotate, img->rx, img->ry,
112
112
  img->color.r, img->color.g, img->color.b, img->color.a,
@@ -119,8 +119,8 @@ void S2D_GL2_DrawImage(S2D_Image *img) {
119
119
  /*
120
120
  * Draw sprite
121
121
  */
122
- void S2D_GL2_DrawSprite(S2D_Sprite *spr) {
123
- S2D_GL2_DrawTexture(
122
+ void R2D_GL2_DrawSprite(R2D_Sprite *spr) {
123
+ R2D_GL2_DrawTexture(
124
124
  spr->x, spr->y, spr->width, spr->height,
125
125
  spr->rotate, spr->rx, spr->ry,
126
126
  spr->color.r, spr->color.g, spr->color.b, spr->color.a,
@@ -130,11 +130,26 @@ void S2D_GL2_DrawSprite(S2D_Sprite *spr) {
130
130
  }
131
131
 
132
132
 
133
+ /*
134
+ * Draw a tile
135
+ */
136
+ void R2D_GL2_DrawTile(R2D_Image *img, int x, int y, int tw, int th, GLfloat tx1, GLfloat ty1, GLfloat tx2,
137
+ GLfloat ty2, GLfloat tx3, GLfloat ty3, GLfloat tx4, GLfloat ty4) {
138
+ R2D_GL2_DrawTexture(
139
+ x, y, tw, th,
140
+ img->rotate, img->rx, img->ry,
141
+ img->color.r, img->color.g, img->color.b, img->color.a,
142
+ tx1, ty1, tx2, ty2, tx3, ty3, tx4, ty4,
143
+ img->texture_id
144
+ );
145
+ }
146
+
147
+
133
148
  /*
134
149
  * Draw text
135
150
  */
136
- void S2D_GL2_DrawText(S2D_Text *txt) {
137
- S2D_GL2_DrawTexture(
151
+ void R2D_GL2_DrawText(R2D_Text *txt) {
152
+ R2D_GL2_DrawTexture(
138
153
  txt->x, txt->y, txt->width, txt->height,
139
154
  txt->rotate, txt->rx, txt->ry,
140
155
  txt->color.r, txt->color.g, txt->color.b, txt->color.a,