ruby2d 0.9.4 → 0.11.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (156) hide show
  1. checksums.yaml +4 -4
  2. data/assets/include/SDL2/SDL.h +4 -1
  3. data/assets/include/SDL2/SDL_assert.h +3 -1
  4. data/assets/include/SDL2/SDL_atomic.h +1 -1
  5. data/assets/include/SDL2/SDL_audio.h +1 -1
  6. data/assets/include/SDL2/SDL_bits.h +1 -1
  7. data/assets/include/SDL2/SDL_blendmode.h +4 -1
  8. data/assets/include/SDL2/SDL_clipboard.h +1 -1
  9. data/assets/include/SDL2/SDL_config.h +1 -1
  10. data/assets/include/SDL2/SDL_config_android.h +7 -3
  11. data/assets/include/SDL2/SDL_config_iphoneos.h +16 -10
  12. data/assets/include/SDL2/SDL_config_macosx.h +40 -14
  13. data/assets/include/SDL2/SDL_config_minimal.h +1 -1
  14. data/assets/include/SDL2/SDL_config_os2.h +26 -8
  15. data/assets/include/SDL2/SDL_config_pandora.h +4 -2
  16. data/assets/include/SDL2/SDL_config_psp.h +2 -1
  17. data/assets/include/SDL2/SDL_config_windows.h +40 -9
  18. data/assets/include/SDL2/SDL_config_winrt.h +5 -2
  19. data/assets/include/SDL2/SDL_config_wiz.h +5 -2
  20. data/assets/include/SDL2/SDL_copying.h +1 -1
  21. data/assets/include/SDL2/SDL_cpuinfo.h +32 -3
  22. data/assets/include/SDL2/SDL_egl.h +4 -1
  23. data/assets/include/SDL2/SDL_endian.h +6 -3
  24. data/assets/include/SDL2/SDL_error.h +38 -2
  25. data/assets/include/SDL2/SDL_events.h +64 -28
  26. data/assets/include/SDL2/SDL_filesystem.h +1 -1
  27. data/assets/include/SDL2/SDL_gamecontroller.h +160 -9
  28. data/assets/include/SDL2/SDL_gesture.h +1 -1
  29. data/assets/include/SDL2/SDL_haptic.h +10 -1
  30. data/assets/include/SDL2/SDL_hints.h +316 -4
  31. data/assets/include/SDL2/SDL_joystick.h +115 -24
  32. data/assets/include/SDL2/SDL_keyboard.h +1 -1
  33. data/assets/include/SDL2/SDL_keycode.h +11 -9
  34. data/assets/include/SDL2/SDL_loadso.h +1 -1
  35. data/assets/include/SDL2/SDL_locale.h +101 -0
  36. data/assets/include/SDL2/SDL_log.h +3 -3
  37. data/assets/include/SDL2/SDL_main.h +1 -1
  38. data/assets/include/SDL2/SDL_messagebox.h +6 -4
  39. data/assets/include/SDL2/SDL_metal.h +117 -0
  40. data/assets/include/SDL2/SDL_misc.h +75 -0
  41. data/assets/include/SDL2/SDL_mouse.h +1 -1
  42. data/assets/include/SDL2/SDL_mutex.h +1 -1
  43. data/assets/include/SDL2/SDL_name.h +1 -1
  44. data/assets/include/SDL2/SDL_opengl.h +1 -1
  45. data/assets/include/SDL2/SDL_opengl_glext.h +3 -0
  46. data/assets/include/SDL2/SDL_opengles.h +1 -1
  47. data/assets/include/SDL2/SDL_opengles2.h +1 -1
  48. data/assets/include/SDL2/SDL_pixels.h +25 -16
  49. data/assets/include/SDL2/SDL_platform.h +1 -1
  50. data/assets/include/SDL2/SDL_power.h +1 -1
  51. data/assets/include/SDL2/SDL_quit.h +1 -1
  52. data/assets/include/SDL2/SDL_rect.h +1 -1
  53. data/assets/include/SDL2/SDL_render.h +63 -3
  54. data/assets/include/SDL2/SDL_revision.h +2 -2
  55. data/assets/include/SDL2/SDL_rwops.h +2 -10
  56. data/assets/include/SDL2/SDL_scancode.h +1 -1
  57. data/assets/include/SDL2/SDL_sensor.h +25 -9
  58. data/assets/include/SDL2/SDL_shape.h +1 -1
  59. data/assets/include/SDL2/SDL_stdinc.h +44 -4
  60. data/assets/include/SDL2/SDL_surface.h +11 -2
  61. data/assets/include/SDL2/SDL_system.h +50 -4
  62. data/assets/include/SDL2/SDL_syswm.h +29 -2
  63. data/assets/include/SDL2/SDL_test.h +1 -1
  64. data/assets/include/SDL2/SDL_test_assert.h +1 -1
  65. data/assets/include/SDL2/SDL_test_common.h +14 -1
  66. data/assets/include/SDL2/SDL_test_compare.h +1 -1
  67. data/assets/include/SDL2/SDL_test_crc32.h +1 -1
  68. data/assets/include/SDL2/SDL_test_font.h +1 -1
  69. data/assets/include/SDL2/SDL_test_fuzzer.h +1 -1
  70. data/assets/include/SDL2/SDL_test_harness.h +1 -1
  71. data/assets/include/SDL2/SDL_test_images.h +1 -1
  72. data/assets/include/SDL2/SDL_test_log.h +1 -1
  73. data/assets/include/SDL2/SDL_test_md5.h +1 -1
  74. data/assets/include/SDL2/SDL_test_memory.h +1 -1
  75. data/assets/include/SDL2/SDL_test_random.h +1 -1
  76. data/assets/include/SDL2/SDL_thread.h +34 -11
  77. data/assets/include/SDL2/SDL_timer.h +1 -1
  78. data/assets/include/SDL2/SDL_touch.h +1 -1
  79. data/assets/include/SDL2/SDL_types.h +1 -1
  80. data/assets/include/SDL2/SDL_version.h +2 -2
  81. data/assets/include/SDL2/SDL_video.h +11 -5
  82. data/assets/include/SDL2/SDL_vulkan.h +6 -8
  83. data/assets/include/SDL2/begin_code.h +5 -9
  84. data/assets/include/SDL2/close_code.h +1 -1
  85. data/assets/macos/lib/libFLAC.a +0 -0
  86. data/assets/macos/lib/libSDL2.a +0 -0
  87. data/assets/macos/lib/libSDL2_image.a +0 -0
  88. data/assets/macos/lib/libSDL2_mixer.a +0 -0
  89. data/assets/macos/lib/libSDL2_ttf.a +0 -0
  90. data/assets/macos/lib/libfreetype.a +0 -0
  91. data/assets/macos/lib/libjpeg.a +0 -0
  92. data/assets/macos/lib/libmodplug.a +0 -0
  93. data/assets/macos/lib/libmpg123.a +0 -0
  94. data/assets/macos/lib/libogg.a +0 -0
  95. data/assets/macos/lib/libpng16.a +0 -0
  96. data/assets/macos/lib/libtiff.a +0 -0
  97. data/assets/macos/lib/libvorbis.a +0 -0
  98. data/assets/macos/lib/libvorbisfile.a +0 -0
  99. data/assets/macos/lib/libwebp.a +0 -0
  100. data/assets/mingw/bin/SDL2.dll +0 -0
  101. data/assets/mingw/lib/libSDL2.a +0 -0
  102. data/assets/mingw/lib/libSDL2.dll.a +0 -0
  103. data/assets/mingw/lib/libSDL2_test.a +0 -0
  104. data/assets/mingw/lib/libSDL2main.a +0 -0
  105. data/bin/ruby2d +1 -0
  106. data/{assets/linux/simple2d/src/simple2d.c → ext/ruby2d/common.c} +32 -32
  107. data/{assets/linux/simple2d/src → ext/ruby2d}/controllers.c +17 -17
  108. data/ext/ruby2d/extconf.rb +37 -59
  109. data/ext/ruby2d/font.c +35 -0
  110. data/{assets/linux/simple2d/src → ext/ruby2d}/gl.c +66 -98
  111. data/ext/ruby2d/gl2.c +86 -0
  112. data/{assets/linux/simple2d/src → ext/ruby2d}/gl3.c +69 -112
  113. data/{assets/linux/simple2d/src → ext/ruby2d}/gles.c +22 -81
  114. data/ext/ruby2d/image.c +58 -0
  115. data/{assets/linux/simple2d/src → ext/ruby2d}/input.c +8 -8
  116. data/{assets/linux/simple2d/src → ext/ruby2d}/music.c +30 -17
  117. data/ext/ruby2d/ruby2d.c +449 -439
  118. data/ext/ruby2d/ruby2d.h +652 -0
  119. data/{assets/linux/simple2d/src → ext/ruby2d}/shapes.c +18 -18
  120. data/{assets/linux/simple2d/src → ext/ruby2d}/sound.c +39 -14
  121. data/ext/ruby2d/text.c +22 -0
  122. data/{assets/linux/simple2d/src → ext/ruby2d}/window.c +63 -63
  123. data/lib/ruby2d/circle.rb +21 -3
  124. data/lib/ruby2d/cli/build.rb +4 -7
  125. data/lib/ruby2d/dsl.rb +16 -9
  126. data/lib/ruby2d/entity.rb +17 -0
  127. data/lib/ruby2d/font.rb +23 -3
  128. data/lib/ruby2d/image.rb +35 -7
  129. data/lib/ruby2d/line.rb +23 -1
  130. data/lib/ruby2d/music.rb +5 -0
  131. data/lib/ruby2d/pixel.rb +17 -0
  132. data/lib/ruby2d/quad.rb +21 -1
  133. data/lib/ruby2d/rectangle.rb +12 -3
  134. data/lib/ruby2d/renderable.rb +4 -20
  135. data/lib/ruby2d/sound.rb +30 -0
  136. data/lib/ruby2d/sprite.rb +57 -75
  137. data/lib/ruby2d/square.rb +10 -1
  138. data/lib/ruby2d/text.rb +55 -12
  139. data/lib/ruby2d/texture.rb +28 -0
  140. data/lib/ruby2d/tileset.rb +87 -0
  141. data/lib/ruby2d/triangle.rb +19 -1
  142. data/lib/ruby2d/version.rb +1 -1
  143. data/lib/ruby2d/vertices.rb +84 -0
  144. data/lib/ruby2d/window.rb +259 -22
  145. data/lib/ruby2d.rb +6 -1
  146. metadata +30 -26
  147. data/assets/include/simple2d.h +0 -757
  148. data/assets/linux/simple2d/Makefile +0 -260
  149. data/assets/linux/simple2d/bin/simple2d.sh +0 -1318
  150. data/assets/linux/simple2d/include/simple2d.h +0 -757
  151. data/assets/linux/simple2d/src/gl2.c +0 -146
  152. data/assets/linux/simple2d/src/image.c +0 -138
  153. data/assets/linux/simple2d/src/sprite.c +0 -147
  154. data/assets/linux/simple2d/src/text.c +0 -129
  155. data/assets/macos/lib/libsimple2d.a +0 -0
  156. data/assets/mingw/lib/libsimple2d.a +0 -0
@@ -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(const 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,22 +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) {
49
+ void R2D_GL_StoreContextInfo(R2D_Window *window) {
50
50
 
51
- window->S2D_GL_VENDOR = glGetString(GL_VENDOR);
52
- window->S2D_GL_RENDERER = glGetString(GL_RENDERER);
53
- window->S2D_GL_VERSION = glGetString(GL_VERSION);
51
+ window->R2D_GL_VENDOR = glGetString(GL_VENDOR);
52
+ window->R2D_GL_RENDERER = glGetString(GL_RENDERER);
53
+ window->R2D_GL_VERSION = glGetString(GL_VERSION);
54
54
 
55
55
  // These are not defined in GLES
56
56
  #if GLES
57
- window->S2D_GL_MAJOR_VERSION = 0;
58
- window->S2D_GL_MINOR_VERSION = 0;
57
+ window->R2D_GL_MAJOR_VERSION = 0;
58
+ window->R2D_GL_MINOR_VERSION = 0;
59
59
  #else
60
- glGetIntegerv(GL_MAJOR_VERSION, &window->S2D_GL_MAJOR_VERSION);
61
- 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);
62
62
  #endif
63
63
 
64
- window->S2D_GL_SHADING_LANGUAGE_VERSION = glGetString(GL_SHADING_LANGUAGE_VERSION);
64
+ window->R2D_GL_SHADING_LANGUAGE_VERSION = glGetString(GL_SHADING_LANGUAGE_VERSION);
65
65
  };
66
66
 
67
67
 
@@ -69,13 +69,13 @@ void S2D_GL_StoreContextInfo(S2D_Window *window) {
69
69
  * Creates a shader object, loads shader string, and compiles.
70
70
  * Returns 0 if shader could not be compiled.
71
71
  */
72
- GLuint S2D_GL_LoadShader(GLenum type, const GLchar *shaderSrc, char *shaderName) {
72
+ GLuint R2D_GL_LoadShader(GLenum type, const GLchar *shaderSrc, const char *shaderName) {
73
73
 
74
74
  // Create the shader object
75
75
  GLuint shader = glCreateShader(type);
76
76
 
77
77
  if (shader == 0) {
78
- S2D_GL_PrintError("Failed to create shader program");
78
+ R2D_GL_PrintError("Failed to create shader program");
79
79
  return 0;
80
80
  }
81
81
 
@@ -111,7 +111,7 @@ GLuint S2D_GL_LoadShader(GLenum type, const GLchar *shaderSrc, char *shaderName)
111
111
  /*
112
112
  * Check if shader program was linked
113
113
  */
114
- int S2D_GL_CheckLinked(GLuint program, char *name) {
114
+ int R2D_GL_CheckLinked(GLuint program, const char *name) {
115
115
 
116
116
  GLint linked;
117
117
  glGetProgramiv(program, GL_LINK_STATUS, &linked);
@@ -138,7 +138,7 @@ int S2D_GL_CheckLinked(GLuint program, char *name) {
138
138
  /*
139
139
  * Calculate the viewport's scaled width and height
140
140
  */
141
- 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) {
142
142
 
143
143
  double s = fmin(
144
144
  window->width / (double)window->viewport.width,
@@ -155,7 +155,7 @@ void S2D_GL_GetViewportScale(S2D_Window *window, int *w, int *h, double *scale)
155
155
  /*
156
156
  * Sets the viewport and matrix projection
157
157
  */
158
- void S2D_GL_SetViewport(S2D_Window *window) {
158
+ void R2D_GL_SetViewport(R2D_Window *window) {
159
159
 
160
160
  int ortho_w = window->viewport.width;
161
161
  int ortho_h = window->viewport.height;
@@ -165,25 +165,25 @@ void S2D_GL_SetViewport(S2D_Window *window) {
165
165
 
166
166
  switch (window->viewport.mode) {
167
167
 
168
- case S2D_FIXED:
168
+ case R2D_FIXED:
169
169
  w = window->orig_width;
170
170
  h = window->orig_height;
171
171
  y = window->height - h;
172
172
  break;
173
173
 
174
- case S2D_EXPAND:
174
+ case R2D_EXPAND:
175
175
  ortho_w = w;
176
176
  ortho_h = h;
177
177
  break;
178
178
 
179
- case S2D_SCALE:
180
- S2D_GL_GetViewportScale(window, &w, &h, NULL);
179
+ case R2D_SCALE:
180
+ R2D_GL_GetViewportScale(window, &w, &h, NULL);
181
181
  // Center the viewport
182
182
  x = window->width / 2.0 - w/2.0;
183
183
  y = window->height / 2.0 - h/2.0;
184
184
  break;
185
185
 
186
- case S2D_STRETCH:
186
+ case R2D_STRETCH:
187
187
  break;
188
188
  }
189
189
 
@@ -194,12 +194,12 @@ void S2D_GL_SetViewport(S2D_Window *window) {
194
194
  orthoMatrix[5] = -2.0f / (GLfloat)ortho_h;
195
195
 
196
196
  #if GLES
197
- S2D_GLES_ApplyProjection(orthoMatrix);
197
+ R2D_GLES_ApplyProjection(orthoMatrix);
198
198
  #else
199
- if (S2D_GL2) {
200
- S2D_GL2_ApplyProjection(ortho_w, ortho_h);
199
+ if (R2D_GL2) {
200
+ R2D_GL2_ApplyProjection(ortho_w, ortho_h);
201
201
  } else {
202
- S2D_GL3_ApplyProjection(orthoMatrix);
202
+ R2D_GL3_ApplyProjection(orthoMatrix);
203
203
  }
204
204
  #endif
205
205
  }
@@ -208,7 +208,7 @@ void S2D_GL_SetViewport(S2D_Window *window) {
208
208
  /*
209
209
  * Initialize OpenGL
210
210
  */
211
- int S2D_GL_Init(S2D_Window *window) {
211
+ int R2D_GL_Init(R2D_Window *window) {
212
212
 
213
213
  // Specify OpenGL contexts and set attributes
214
214
  #if GLES
@@ -244,25 +244,25 @@ int S2D_GL_Init(S2D_Window *window) {
244
244
 
245
245
  // Initialize OpenGL ES 2.0
246
246
  #if GLES
247
- S2D_GLES_Init();
248
- S2D_GL_SetViewport(window);
247
+ R2D_GLES_Init();
248
+ R2D_GL_SetViewport(window);
249
249
 
250
250
  // Initialize OpenGL 3.3+
251
251
  #else
252
252
  // Initialize GLEW on Windows
253
253
  #if WINDOWS
254
254
  GLenum err = glewInit();
255
- if (GLEW_OK != err) S2D_Error("GLEW", glewGetErrorString(err));
255
+ if (GLEW_OK != err) R2D_Error("GLEW", glewGetErrorString(err));
256
256
  #endif
257
- S2D_GL3_Init();
258
- S2D_GL_SetViewport(window);
257
+ R2D_GL3_Init();
258
+ R2D_GL_SetViewport(window);
259
259
  #endif
260
260
 
261
261
  // Context could not be created
262
262
  } else {
263
263
 
264
264
  #if GLES
265
- S2D_Error("GLES / SDL_GL_CreateContext", SDL_GetError());
265
+ R2D_Error("GLES / SDL_GL_CreateContext", SDL_GetError());
266
266
 
267
267
  #else
268
268
  // Try to fallback using an OpenGL 2.1 context
@@ -275,22 +275,22 @@ int S2D_GL_Init(S2D_Window *window) {
275
275
  // Check if this context was created
276
276
  if (window->glcontext) {
277
277
  // Valid context found
278
- S2D_GL2 = true;
279
- S2D_GL2_Init();
280
- S2D_GL_SetViewport(window);
278
+ R2D_GL2 = true;
279
+ R2D_GL2_Init();
280
+ R2D_GL_SetViewport(window);
281
281
 
282
282
  // Could not create any OpenGL contexts, hard failure
283
283
  } else {
284
- S2D_Error("GL2 / SDL_GL_CreateContext", SDL_GetError());
285
- 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");
286
286
  return -1;
287
287
  }
288
288
  #endif
289
289
  }
290
290
 
291
291
  // Store the context and print it if diagnostics is enabled
292
- S2D_GL_StoreContextInfo(window);
293
- if (S2D_diagnostics) S2D_GL_PrintContextInfo(window);
292
+ R2D_GL_StoreContextInfo(window);
293
+ if (R2D_diagnostics) R2D_GL_PrintContextInfo(window);
294
294
 
295
295
  return 0;
296
296
  }
@@ -299,7 +299,7 @@ int S2D_GL_Init(S2D_Window *window) {
299
299
  /*
300
300
  * Creates a texture for rendering
301
301
  */
302
- void S2D_GL_CreateTexture(GLuint *id, GLint format,
302
+ void R2D_GL_CreateTexture(GLuint *id, GLint format,
303
303
  int w, int h,
304
304
  const GLvoid *data, GLint filter) {
305
305
 
@@ -324,7 +324,7 @@ void S2D_GL_CreateTexture(GLuint *id, GLint format,
324
324
  /*
325
325
  * Free a texture
326
326
  */
327
- void S2D_GL_FreeTexture(GLuint *id) {
327
+ void R2D_GL_FreeTexture(GLuint *id) {
328
328
  if (*id != 0) {
329
329
  glDeleteTextures(1, id);
330
330
  *id = 0;
@@ -335,7 +335,7 @@ void S2D_GL_FreeTexture(GLuint *id) {
335
335
  /*
336
336
  * Draw a triangle
337
337
  */
338
- void S2D_GL_DrawTriangle(GLfloat x1, GLfloat y1,
338
+ void R2D_GL_DrawTriangle(GLfloat x1, GLfloat y1,
339
339
  GLfloat r1, GLfloat g1, GLfloat b1, GLfloat a1,
340
340
  GLfloat x2, GLfloat y2,
341
341
  GLfloat r2, GLfloat g2, GLfloat b2, GLfloat a2,
@@ -343,16 +343,16 @@ void S2D_GL_DrawTriangle(GLfloat x1, GLfloat y1,
343
343
  GLfloat r3, GLfloat g3, GLfloat b3, GLfloat a3) {
344
344
 
345
345
  #if GLES
346
- S2D_GLES_DrawTriangle(x1, y1, r1, g1, b1, a1,
346
+ R2D_GLES_DrawTriangle(x1, y1, r1, g1, b1, a1,
347
347
  x2, y2, r2, g2, b2, a2,
348
348
  x3, y3, r3, g3, b3, a3);
349
349
  #else
350
- if (S2D_GL2) {
351
- S2D_GL2_DrawTriangle(x1, y1, r1, g1, b1, a1,
350
+ if (R2D_GL2) {
351
+ R2D_GL2_DrawTriangle(x1, y1, r1, g1, b1, a1,
352
352
  x2, y2, r2, g2, b2, a2,
353
353
  x3, y3, r3, g3, b3, a3);
354
354
  } else {
355
- S2D_GL3_DrawTriangle(x1, y1, r1, g1, b1, a1,
355
+ R2D_GL3_DrawTriangle(x1, y1, r1, g1, b1, a1,
356
356
  x2, y2, r2, g2, b2, a2,
357
357
  x3, y3, r3, g3, b3, a3);
358
358
  }
@@ -361,48 +361,16 @@ void S2D_GL_DrawTriangle(GLfloat x1, GLfloat y1,
361
361
 
362
362
 
363
363
  /*
364
- * Draw an image
364
+ * Draw a texture
365
365
  */
366
- void S2D_GL_DrawImage(S2D_Image *img) {
366
+ void R2D_GL_DrawTexture(GLfloat coordinates[], GLfloat texture_coordinates[], GLfloat color[], int texture_id) {
367
367
  #if GLES
368
- S2D_GLES_DrawImage(img);
368
+ R2D_GLES_DrawTexture(coordinates, texture_coordinates, color, texture_id);
369
369
  #else
370
- if (S2D_GL2) {
371
- S2D_GL2_DrawImage(img);
370
+ if (R2D_GL2) {
371
+ R2D_GL2_DrawTexture(coordinates, texture_coordinates, color, texture_id);
372
372
  } else {
373
- S2D_GL3_DrawImage(img);
374
- }
375
- #endif
376
- }
377
-
378
-
379
- /*
380
- * Draw sprite
381
- */
382
- void S2D_GL_DrawSprite(S2D_Sprite *spr) {
383
- #if GLES
384
- S2D_GLES_DrawSprite(spr);
385
- #else
386
- if (S2D_GL2) {
387
- S2D_GL2_DrawSprite(spr);
388
- } else {
389
- S2D_GL3_DrawSprite(spr);
390
- }
391
- #endif
392
- }
393
-
394
-
395
- /*
396
- * Draw text
397
- */
398
- void S2D_GL_DrawText(S2D_Text *txt) {
399
- #if GLES
400
- S2D_GLES_DrawText(txt);
401
- #else
402
- if (S2D_GL2) {
403
- S2D_GL2_DrawText(txt);
404
- } else {
405
- S2D_GL3_DrawText(txt);
373
+ R2D_GL3_DrawTexture(coordinates, texture_coordinates, color, texture_id);
406
374
  }
407
375
  #endif
408
376
  }
@@ -411,12 +379,12 @@ void S2D_GL_DrawText(S2D_Text *txt) {
411
379
  /*
412
380
  * Render and flush OpenGL buffers
413
381
  */
414
- void S2D_GL_FlushBuffers() {
382
+ void R2D_GL_FlushBuffers() {
415
383
  // Only implemented in our OpenGL 3.3+ and ES 2.0 renderers
416
384
  #if GLES
417
- // TODO: S2D_GLES_FlushBuffers();
385
+ // TODO: R2D_GLES_FlushBuffers();
418
386
  #else
419
- if (!S2D_GL2) S2D_GL3_FlushBuffers();
387
+ if (!R2D_GL2) R2D_GL3_FlushBuffers();
420
388
  #endif
421
389
  }
422
390
 
@@ -424,7 +392,7 @@ void S2D_GL_FlushBuffers() {
424
392
  /*
425
393
  * Clear buffers to given color values
426
394
  */
427
- void S2D_GL_Clear(S2D_Color clr) {
395
+ void R2D_GL_Clear(R2D_Color clr) {
428
396
  glClearColor(clr.r, clr.g, clr.b, clr.a);
429
397
  glClear(GL_COLOR_BUFFER_BIT);
430
398
  }
data/ext/ruby2d/gl2.c ADDED
@@ -0,0 +1,86 @@
1
+ // OpenGL 2.1
2
+
3
+ #include "ruby2d.h"
4
+
5
+ #if !GLES
6
+
7
+
8
+ /*
9
+ * Applies the projection matrix
10
+ */
11
+ void R2D_GL2_ApplyProjection(int w, int h) {
12
+
13
+ // Initialize the projection matrix
14
+ glMatrixMode(GL_PROJECTION);
15
+ glLoadIdentity();
16
+
17
+ // Multiply the current matrix with the orthographic matrix
18
+ glOrtho(0.f, w, h, 0.f, -1.f, 1.f);
19
+
20
+ // Initialize the model-view matrix
21
+ glMatrixMode(GL_MODELVIEW);
22
+ glLoadIdentity();
23
+ }
24
+
25
+
26
+ /*
27
+ * Initalize OpenGL
28
+ */
29
+ int R2D_GL2_Init() {
30
+
31
+ GLenum error = GL_NO_ERROR;
32
+
33
+ // Enable transparency
34
+ glEnable(GL_BLEND);
35
+ glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
36
+
37
+ // Check for errors
38
+ error = glGetError();
39
+ if (error != GL_NO_ERROR) {
40
+ R2D_GL_PrintError("OpenGL initialization failed");
41
+ return 1;
42
+ } else {
43
+ return 0;
44
+ }
45
+ }
46
+
47
+
48
+ /*
49
+ * Draw triangle
50
+ */
51
+ void R2D_GL2_DrawTriangle(GLfloat x1, GLfloat y1,
52
+ GLfloat r1, GLfloat g1, GLfloat b1, GLfloat a1,
53
+ GLfloat x2, GLfloat y2,
54
+ GLfloat r2, GLfloat g2, GLfloat b2, GLfloat a2,
55
+ GLfloat x3, GLfloat y3,
56
+ GLfloat r3, GLfloat g3, GLfloat b3, GLfloat a3) {
57
+
58
+ glBegin(GL_TRIANGLES);
59
+ glColor4f(r1, g1, b1, a1); glVertex2f(x1, y1);
60
+ glColor4f(r2, g2, b2, a2); glVertex2f(x2, y2);
61
+ glColor4f(r3, g3, b3, a3); glVertex2f(x3, y3);
62
+ glEnd();
63
+ }
64
+
65
+
66
+ /*
67
+ * Draw a texture (New method with vertices pre-calculated)
68
+ */
69
+ void R2D_GL2_DrawTexture(GLfloat coordinates[], GLfloat texture_coordinates[], GLfloat color[], int texture_id) {
70
+ glEnable(GL_TEXTURE_2D);
71
+
72
+ glBindTexture(GL_TEXTURE_2D, texture_id);
73
+
74
+ glBegin(GL_QUADS);
75
+ glColor4f(color[0], color[1], color[2], color[3]);
76
+ glTexCoord2f(texture_coordinates[0], texture_coordinates[1]); glVertex2f(coordinates[0], coordinates[1]);
77
+ glTexCoord2f(texture_coordinates[2], texture_coordinates[3]); glVertex2f(coordinates[2], coordinates[3]);
78
+ glTexCoord2f(texture_coordinates[4], texture_coordinates[5]); glVertex2f(coordinates[4], coordinates[5]);
79
+ glTexCoord2f(texture_coordinates[6], texture_coordinates[7]); glVertex2f(coordinates[6], coordinates[7]);
80
+ glEnd();
81
+
82
+ glDisable(GL_TEXTURE_2D);
83
+ };
84
+
85
+
86
+ #endif