ruby2d 0.9.3 → 0.11.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 (166) hide show
  1. checksums.yaml +4 -4
  2. data/assets/README.md +7 -9
  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 +1 -0
  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 +36 -58
  117. data/ext/ruby2d/font.c +35 -0
  118. data/{assets/linux/simple2d/src → ext/ruby2d}/gl.c +72 -100
  119. data/ext/ruby2d/gl2.c +86 -0
  120. data/ext/ruby2d/gl3.c +305 -0
  121. data/{assets/linux/simple2d/src → ext/ruby2d}/gles.c +22 -81
  122. data/ext/ruby2d/image.c +58 -0
  123. data/{assets/linux/simple2d/src → ext/ruby2d}/input.c +8 -8
  124. data/{assets/linux/simple2d/src → ext/ruby2d}/music.c +30 -17
  125. data/ext/ruby2d/ruby2d.c +449 -439
  126. data/ext/ruby2d/ruby2d.h +652 -0
  127. data/{assets/linux/simple2d/src → ext/ruby2d}/shapes.c +18 -18
  128. data/ext/ruby2d/sound.c +118 -0
  129. data/ext/ruby2d/text.c +22 -0
  130. data/{assets/linux/simple2d/src → ext/ruby2d}/window.c +73 -62
  131. data/lib/ruby2d/circle.rb +21 -3
  132. data/lib/ruby2d/cli/build.rb +4 -7
  133. data/lib/ruby2d/dsl.rb +16 -9
  134. data/lib/ruby2d/entity.rb +17 -0
  135. data/lib/ruby2d/font.rb +23 -3
  136. data/lib/ruby2d/image.rb +35 -7
  137. data/lib/ruby2d/line.rb +23 -1
  138. data/lib/ruby2d/music.rb +5 -0
  139. data/lib/ruby2d/pixel.rb +17 -0
  140. data/lib/ruby2d/quad.rb +21 -1
  141. data/lib/ruby2d/rectangle.rb +12 -3
  142. data/lib/ruby2d/renderable.rb +4 -20
  143. data/lib/ruby2d/sound.rb +30 -0
  144. data/lib/ruby2d/sprite.rb +57 -75
  145. data/lib/ruby2d/square.rb +10 -1
  146. data/lib/ruby2d/text.rb +55 -12
  147. data/lib/ruby2d/texture.rb +28 -0
  148. data/lib/ruby2d/tileset.rb +87 -0
  149. data/lib/ruby2d/triangle.rb +19 -1
  150. data/lib/ruby2d/version.rb +1 -1
  151. data/lib/ruby2d/vertices.rb +84 -0
  152. data/lib/ruby2d/window.rb +259 -22
  153. data/lib/ruby2d.rb +6 -1
  154. metadata +41 -26
  155. data/assets/include/simple2d.h +0 -735
  156. data/assets/linux/simple2d/Makefile +0 -257
  157. data/assets/linux/simple2d/bin/simple2d.sh +0 -1312
  158. data/assets/linux/simple2d/include/simple2d.h +0 -735
  159. data/assets/linux/simple2d/src/gl2.c +0 -146
  160. data/assets/linux/simple2d/src/gl3.c +0 -275
  161. data/assets/linux/simple2d/src/image.c +0 -138
  162. data/assets/linux/simple2d/src/sound.c +0 -56
  163. data/assets/linux/simple2d/src/sprite.c +0 -147
  164. data/assets/linux/simple2d/src/text.c +0 -129
  165. data/assets/macos/lib/libsimple2d.a +0 -0
  166. data/assets/mingw/lib/libsimple2d.a +0 -0
data/ext/ruby2d/font.c ADDED
@@ -0,0 +1,35 @@
1
+ // font.c
2
+
3
+ #include "ruby2d.h"
4
+
5
+
6
+ /*
7
+ * Create a TTF_Font object given a path to a font and a size
8
+ */
9
+ TTF_Font *R2D_FontCreateTTFFont(const char *path, int size, const char *style) {
10
+
11
+ // Check if font file exists
12
+ if (!R2D_FileExists(path)) {
13
+ R2D_Error("R2D_FontCreateTTFFont", "Font file `%s` not found", path);
14
+ return NULL;
15
+ }
16
+
17
+ TTF_Font *font = TTF_OpenFont(path, size);
18
+
19
+ if (!font) {
20
+ R2D_Error("TTF_OpenFont", TTF_GetError());
21
+ return NULL;
22
+ }
23
+
24
+ if(strncmp(style, "bold", 4) == 0) {
25
+ TTF_SetFontStyle(font, TTF_STYLE_BOLD);
26
+ } else if(strncmp(style, "italic", 6) == 0) {
27
+ TTF_SetFontStyle(font, TTF_STYLE_ITALIC);
28
+ } else if(strncmp(style, "underline", 9) == 0) {
29
+ TTF_SetFontStyle(font, TTF_STYLE_UNDERLINE);
30
+ } else if(strncmp(style, "strikethrough", 13) == 0) {
31
+ TTF_SetFontStyle(font, TTF_STYLE_STRIKETHROUGH);
32
+ }
33
+
34
+ return font;
35
+ }
@@ -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,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, const 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, const 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
  }
@@ -370,49 +361,30 @@ void S2D_GL_DrawTriangle(GLfloat x1, GLfloat y1,
370
361
 
371
362
 
372
363
  /*
373
- * Draw an image
364
+ * Draw a texture
374
365
  */
375
- void S2D_GL_DrawImage(S2D_Image *img) {
366
+ void R2D_GL_DrawTexture(GLfloat coordinates[], GLfloat texture_coordinates[], GLfloat color[], int texture_id) {
376
367
  #if GLES
377
- S2D_GLES_DrawImage(img);
368
+ R2D_GLES_DrawTexture(coordinates, texture_coordinates, color, texture_id);
378
369
  #else
379
- if (S2D_GL2) {
380
- S2D_GL2_DrawImage(img);
370
+ if (R2D_GL2) {
371
+ R2D_GL2_DrawTexture(coordinates, texture_coordinates, color, texture_id);
381
372
  } else {
382
- S2D_GL3_DrawImage(img);
373
+ R2D_GL3_DrawTexture(coordinates, texture_coordinates, color, texture_id);
383
374
  }
384
375
  #endif
385
376
  }
386
377
 
387
378
 
388
379
  /*
389
- * Draw sprite
380
+ * Render and flush OpenGL buffers
390
381
  */
391
- void S2D_GL_DrawSprite(S2D_Sprite *spr) {
382
+ void R2D_GL_FlushBuffers() {
383
+ // Only implemented in our OpenGL 3.3+ and ES 2.0 renderers
392
384
  #if GLES
393
- S2D_GLES_DrawSprite(spr);
385
+ // TODO: R2D_GLES_FlushBuffers();
394
386
  #else
395
- if (S2D_GL2) {
396
- S2D_GL2_DrawSprite(spr);
397
- } else {
398
- S2D_GL3_DrawSprite(spr);
399
- }
400
- #endif
401
- }
402
-
403
-
404
- /*
405
- * Draw text
406
- */
407
- void S2D_GL_DrawText(S2D_Text *txt) {
408
- #if GLES
409
- S2D_GLES_DrawText(txt);
410
- #else
411
- if (S2D_GL2) {
412
- S2D_GL2_DrawText(txt);
413
- } else {
414
- S2D_GL3_DrawText(txt);
415
- }
387
+ if (!R2D_GL2) R2D_GL3_FlushBuffers();
416
388
  #endif
417
389
  }
418
390
 
@@ -420,7 +392,7 @@ void S2D_GL_DrawText(S2D_Text *txt) {
420
392
  /*
421
393
  * Clear buffers to given color values
422
394
  */
423
- void S2D_GL_Clear(S2D_Color clr) {
395
+ void R2D_GL_Clear(R2D_Color clr) {
424
396
  glClearColor(clr.r, clr.g, clr.b, clr.a);
425
397
  glClear(GL_COLOR_BUFFER_BIT);
426
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