ruby2d 0.9.3 → 0.11.0

Sign up to get free protection for your applications and to get access to all the features.
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/gl3.c ADDED
@@ -0,0 +1,305 @@
1
+ // OpenGL 3.3+
2
+
3
+ #include "ruby2d.h"
4
+
5
+ // Skip this file if OpenGL ES
6
+ #if !GLES
7
+
8
+ static GLuint vbo; // our primary vertex buffer object (VBO)
9
+ static GLuint vboSize; // size of the VBO in bytes
10
+ static GLfloat *vboData; // pointer to the VBO data
11
+ static GLfloat *vboDataCurrent; // pointer to the data for the current vertices
12
+ static GLuint vboDataIndex = 0; // index of the current object being rendered
13
+ static GLuint vboObjCapacity = 7500; // number of objects the VBO can store
14
+ static GLuint verticesTextureIds[7500]; // store the texture_id of each vertices
15
+ static GLuint shaderProgram; // triangle shader program
16
+ static GLuint texShaderProgram; // texture shader program
17
+
18
+
19
+ /*
20
+ * Applies the projection matrix
21
+ */
22
+ void R2D_GL3_ApplyProjection(GLfloat orthoMatrix[16]) {
23
+
24
+ // Use the program object
25
+ glUseProgram(shaderProgram);
26
+
27
+ // Apply the projection matrix to the triangle shader
28
+ glUniformMatrix4fv(
29
+ glGetUniformLocation(shaderProgram, "u_mvpMatrix"),
30
+ 1, GL_FALSE, orthoMatrix
31
+ );
32
+
33
+ // Use the texture program object
34
+ glUseProgram(texShaderProgram);
35
+
36
+ // Apply the projection matrix to the texture shader
37
+ glUniformMatrix4fv(
38
+ glGetUniformLocation(texShaderProgram, "u_mvpMatrix"),
39
+ 1, GL_FALSE, orthoMatrix
40
+ );
41
+ }
42
+
43
+
44
+ /*
45
+ * Initalize OpenGL
46
+ */
47
+ int R2D_GL3_Init() {
48
+
49
+ // Enable transparency
50
+ glEnable(GL_BLEND);
51
+ glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
52
+
53
+ // Vertex shader source string
54
+ GLchar vertexSource[] =
55
+ "#version 150 core\n" // shader version
56
+
57
+ "uniform mat4 u_mvpMatrix;" // projection matrix
58
+
59
+ // Input attributes to the vertex shader
60
+ "in vec4 position;" // position value
61
+ "in vec4 color;" // vertex color
62
+ "in vec2 texcoord;" // texture coordinates
63
+
64
+ // Outputs to the fragment shader
65
+ "out vec4 Color;" // vertex color
66
+ "out vec2 Texcoord;" // texture coordinates
67
+
68
+ "void main() {"
69
+ // Send the color and texture coordinates right through to the fragment shader
70
+ " Color = color;"
71
+ " Texcoord = texcoord;"
72
+ // Transform the vertex position using the projection matrix
73
+ " gl_Position = u_mvpMatrix * position;"
74
+ "}";
75
+
76
+ // Fragment shader source string
77
+ GLchar fragmentSource[] =
78
+ "#version 150 core\n" // shader version
79
+ "in vec4 Color;" // input color from vertex shader
80
+ "out vec4 outColor;" // output fragment color
81
+
82
+ "void main() {"
83
+ " outColor = Color;" // pass the color right through
84
+ "}";
85
+
86
+ // Fragment shader source string for textures
87
+ GLchar texFragmentSource[] =
88
+ "#version 150 core\n" // shader version
89
+ "in vec4 Color;" // input color from vertex shader
90
+ "in vec2 Texcoord;" // input texture coordinates
91
+ "out vec4 outColor;" // output fragment color
92
+ "uniform sampler2D tex;" // 2D texture unit
93
+
94
+ "void main() {"
95
+ // Apply the texture unit, texture coordinates, and color
96
+ " outColor = texture(tex, Texcoord) * Color;"
97
+ "}";
98
+
99
+ // Create a vertex array object
100
+ GLuint vao;
101
+ glGenVertexArrays(1, &vao);
102
+ glBindVertexArray(vao);
103
+
104
+ // Create a vertex buffer object and allocate data
105
+ glGenBuffers(1, &vbo);
106
+ glBindBuffer(GL_ARRAY_BUFFER, vbo);
107
+ vboSize = vboObjCapacity * sizeof(GLfloat) * 8;
108
+ vboData = (GLfloat *) malloc(vboSize);
109
+ vboDataCurrent = vboData;
110
+
111
+ // Create an element buffer object
112
+ GLuint ebo;
113
+ glGenBuffers(1, &ebo);
114
+ glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ebo);
115
+
116
+ // Load the vertex and fragment shaders
117
+ GLuint vertexShader = R2D_GL_LoadShader( GL_VERTEX_SHADER, vertexSource, "GL3 Vertex");
118
+ GLuint fragmentShader = R2D_GL_LoadShader(GL_FRAGMENT_SHADER, fragmentSource, "GL3 Fragment");
119
+ GLuint texFragmentShader = R2D_GL_LoadShader(GL_FRAGMENT_SHADER, texFragmentSource, "GL3 Texture Fragment");
120
+
121
+ // Triangle Shader //
122
+
123
+ // Create the shader program object
124
+ shaderProgram = glCreateProgram();
125
+
126
+ // Check if program was created successfully
127
+ if (shaderProgram == 0) {
128
+ R2D_GL_PrintError("Failed to create shader program");
129
+ return GL_FALSE;
130
+ }
131
+
132
+ // Attach the shader objects to the program object
133
+ glAttachShader(shaderProgram, vertexShader);
134
+ glAttachShader(shaderProgram, fragmentShader);
135
+
136
+ // Bind the output color variable to the fragment shader color number
137
+ glBindFragDataLocation(shaderProgram, 0, "outColor");
138
+
139
+ // Link the shader program
140
+ glLinkProgram(shaderProgram);
141
+
142
+ // Check if linked
143
+ R2D_GL_CheckLinked(shaderProgram, "GL3 shader");
144
+
145
+ // Specify the layout of the position vertex data...
146
+ GLint posAttrib = glGetAttribLocation(shaderProgram, "position");
147
+ glEnableVertexAttribArray(posAttrib);
148
+ glVertexAttribPointer(posAttrib, 2, GL_FLOAT, GL_FALSE, 8 * sizeof(GLfloat), 0);
149
+
150
+ // ...and the color vertex data
151
+ GLint colAttrib = glGetAttribLocation(shaderProgram, "color");
152
+ glEnableVertexAttribArray(colAttrib);
153
+ glVertexAttribPointer(colAttrib, 4, GL_FLOAT, GL_FALSE, 8 * sizeof(GLfloat), (void*)(2 * sizeof(GLfloat)));
154
+
155
+ // Texture Shader //
156
+
157
+ // Create the texture shader program object
158
+ texShaderProgram = glCreateProgram();
159
+
160
+ // Check if program was created successfully
161
+ if (texShaderProgram == 0) {
162
+ R2D_GL_PrintError("Failed to create shader program");
163
+ return GL_FALSE;
164
+ }
165
+
166
+ // Attach the shader objects to the program object
167
+ glAttachShader(texShaderProgram, vertexShader);
168
+ glAttachShader(texShaderProgram, texFragmentShader);
169
+
170
+ // Bind the output color variable to the fragment shader color number
171
+ glBindFragDataLocation(texShaderProgram, 0, "outColor");
172
+
173
+ // Link the shader program
174
+ glLinkProgram(texShaderProgram);
175
+
176
+ // Check if linked
177
+ R2D_GL_CheckLinked(texShaderProgram, "GL3 texture shader");
178
+
179
+ // Specify the layout of the position vertex data...
180
+ posAttrib = glGetAttribLocation(texShaderProgram, "position");
181
+ glVertexAttribPointer(posAttrib, 2, GL_FLOAT, GL_FALSE, 8 * sizeof(GLfloat), 0);
182
+ glEnableVertexAttribArray(posAttrib);
183
+
184
+ // ...and the color vertex data...
185
+ colAttrib = glGetAttribLocation(texShaderProgram, "color");
186
+ glVertexAttribPointer(colAttrib, 4, GL_FLOAT, GL_FALSE, 8 * sizeof(GLfloat), (void*)(2 * sizeof(GLfloat)));
187
+ glEnableVertexAttribArray(colAttrib);
188
+
189
+ // ...and the texture coordinates
190
+ GLint texAttrib = glGetAttribLocation(texShaderProgram, "texcoord");
191
+ glVertexAttribPointer(texAttrib, 2, GL_FLOAT, GL_FALSE, 8 * sizeof(GLfloat), (void*)(6 * sizeof(GLfloat)));
192
+ glEnableVertexAttribArray(texAttrib);
193
+
194
+ // Clean up
195
+ glDeleteShader(vertexShader);
196
+ glDeleteShader(fragmentShader);
197
+ glDeleteShader(texFragmentShader);
198
+
199
+ // If successful, return true
200
+ return GL_TRUE;
201
+ }
202
+
203
+
204
+ /*
205
+ * Render the vertex buffer and reset it
206
+ */
207
+ void R2D_GL3_FlushBuffers() {
208
+ // Bind to the vertex buffer object and update its data
209
+ glBindBuffer(GL_ARRAY_BUFFER, vbo);
210
+
211
+ glBufferData(GL_ARRAY_BUFFER, vboSize, NULL, GL_DYNAMIC_DRAW);
212
+ glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(GLfloat) * vboDataIndex * 8, vboData);
213
+
214
+ GLuint verticesOffset = 0;
215
+ GLuint lastTextureId = verticesTextureIds[0];
216
+
217
+ for (GLuint i = 0; i <= vboDataIndex; i++) {
218
+ if(lastTextureId != verticesTextureIds[i] || i == vboDataIndex) {
219
+ // A texture ID of 0 represents no texture (render a triangle)
220
+ if(lastTextureId == 0) {
221
+
222
+ // Use the triangle shader program
223
+ glUseProgram(shaderProgram);
224
+
225
+ // A number other than 0 represents a texture_id
226
+ } else {
227
+
228
+ // Use the texture shader program
229
+ glUseProgram(texShaderProgram);
230
+
231
+ // Bind the texture using the provided ID
232
+ glBindTexture(GL_TEXTURE_2D, lastTextureId);
233
+ }
234
+
235
+ glDrawArrays(GL_TRIANGLES, verticesOffset, i - verticesOffset);
236
+
237
+ lastTextureId = verticesTextureIds[i];
238
+ verticesOffset = i;
239
+ }
240
+ }
241
+
242
+ // Reset the buffer object index and data pointer
243
+ vboDataIndex = 0;
244
+ vboDataCurrent = vboData;
245
+ }
246
+
247
+
248
+ /*
249
+ * Draw triangle
250
+ */
251
+ void R2D_GL3_DrawTriangle(GLfloat x1, GLfloat y1,
252
+ GLfloat r1, GLfloat g1, GLfloat b1, GLfloat a1,
253
+ GLfloat x2, GLfloat y2,
254
+ GLfloat r2, GLfloat g2, GLfloat b2, GLfloat a2,
255
+ GLfloat x3, GLfloat y3,
256
+ GLfloat r3, GLfloat g3, GLfloat b3, GLfloat a3) {
257
+
258
+ // If buffer is full, flush it
259
+ if (vboDataIndex + 3 >= vboObjCapacity) R2D_GL3_FlushBuffers();
260
+
261
+ // Set the triangle data into a formatted array
262
+ GLfloat vertices[24] =
263
+ { x1, y1, r1, g1, b1, a1, 0, 0,
264
+ x2, y2, r2, g2, b2, a2, 0, 0,
265
+ x3, y3, r3, g3, b3, a3, 0, 0 };
266
+
267
+ // Copy the vertex data into the current position of the buffer
268
+ memcpy(vboDataCurrent, vertices, sizeof(vertices));
269
+
270
+ // Increment the buffer object index and the vertex data pointer for next use
271
+ verticesTextureIds[vboDataIndex] = verticesTextureIds[vboDataIndex + 1] = verticesTextureIds[vboDataIndex + 2] = 0;
272
+ vboDataIndex += 3;
273
+ vboDataCurrent = (GLfloat *)((char *)vboDataCurrent + (sizeof(GLfloat) * 24));
274
+ }
275
+
276
+
277
+ /*
278
+ * Draw a texture (New method with vertices pre-calculated)
279
+ */
280
+ void R2D_GL3_DrawTexture(GLfloat coordinates[], GLfloat texture_coordinates[], GLfloat color[], int texture_id) {
281
+ // If buffer is full, flush it
282
+ if (vboDataIndex + 6 >= vboObjCapacity) R2D_GL3_FlushBuffers();
283
+
284
+ // There are 6 vertices for a square as we are rendering two Triangles to make up our square:
285
+ // Triangle one: Top left, Top right, Bottom right
286
+ // Triangle two: Bottom right, Bottom left, Top left
287
+ GLfloat vertices[48] = {
288
+ coordinates[0], coordinates[1], color[0], color[1], color[2], color[3], texture_coordinates[0], texture_coordinates[1],
289
+ coordinates[2], coordinates[3], color[0], color[1], color[2], color[3], texture_coordinates[2], texture_coordinates[3],
290
+ coordinates[4], coordinates[5], color[0], color[1], color[2], color[3], texture_coordinates[4], texture_coordinates[5],
291
+ coordinates[4], coordinates[5], color[0], color[1], color[2], color[3], texture_coordinates[4], texture_coordinates[5],
292
+ coordinates[6], coordinates[7], color[0], color[1], color[2], color[3], texture_coordinates[6], texture_coordinates[7],
293
+ coordinates[0], coordinates[1], color[0], color[1], color[2], color[3], texture_coordinates[0], texture_coordinates[1],
294
+ };
295
+
296
+ // Copy the vertex data into the current position of the buffer
297
+ memcpy(vboDataCurrent, vertices, sizeof(vertices));
298
+
299
+ verticesTextureIds[vboDataIndex] = verticesTextureIds[vboDataIndex + 1] = verticesTextureIds[vboDataIndex + 2] = verticesTextureIds[vboDataIndex + 3] = verticesTextureIds[vboDataIndex + 4] = verticesTextureIds[vboDataIndex + 5] = texture_id;
300
+ vboDataIndex += 6;
301
+ vboDataCurrent = (GLfloat *)((char *)vboDataCurrent + (sizeof(GLfloat) * 48));
302
+ }
303
+
304
+
305
+ #endif
@@ -1,6 +1,6 @@
1
1
  // OpenGL ES 2.0
2
2
 
3
- #include "../include/simple2d.h"
3
+ #include "ruby2d.h"
4
4
 
5
5
  #if GLES
6
6
 
@@ -24,7 +24,7 @@ static GLushort indices[] =
24
24
  /*
25
25
  * Applies the projection matrix
26
26
  */
27
- void S2D_GLES_ApplyProjection(GLfloat orthoMatrix[16]) {
27
+ void R2D_GLES_ApplyProjection(GLfloat orthoMatrix[16]) {
28
28
 
29
29
  // Use the program object
30
30
  glUseProgram(shaderProgram);
@@ -47,7 +47,7 @@ void S2D_GLES_ApplyProjection(GLfloat orthoMatrix[16]) {
47
47
  /*
48
48
  * Initalize OpenGL ES
49
49
  */
50
- int S2D_GLES_Init() {
50
+ int R2D_GLES_Init() {
51
51
 
52
52
  // Enable transparency
53
53
  glEnable(GL_BLEND);
@@ -99,9 +99,9 @@ int S2D_GLES_Init() {
99
99
  "}";
100
100
 
101
101
  // Load the vertex and fragment shaders
102
- GLuint vertexShader = S2D_GL_LoadShader( GL_VERTEX_SHADER, vertexSource, "GLES Vertex");
103
- GLuint fragmentShader = S2D_GL_LoadShader(GL_FRAGMENT_SHADER, fragmentSource, "GLES Fragment");
104
- GLuint texFragmentShader = S2D_GL_LoadShader(GL_FRAGMENT_SHADER, texFragmentSource, "GLES Texture Fragment");
102
+ GLuint vertexShader = R2D_GL_LoadShader( GL_VERTEX_SHADER, vertexSource, "GLES Vertex");
103
+ GLuint fragmentShader = R2D_GL_LoadShader(GL_FRAGMENT_SHADER, fragmentSource, "GLES Fragment");
104
+ GLuint texFragmentShader = R2D_GL_LoadShader(GL_FRAGMENT_SHADER, texFragmentSource, "GLES Texture Fragment");
105
105
 
106
106
  // Triangle Shader //
107
107
 
@@ -110,7 +110,7 @@ int S2D_GLES_Init() {
110
110
 
111
111
  // Check if program was created successfully
112
112
  if (shaderProgram == 0) {
113
- S2D_GL_PrintError("Failed to create shader program");
113
+ R2D_GL_PrintError("Failed to create shader program");
114
114
  return GL_FALSE;
115
115
  }
116
116
 
@@ -122,7 +122,7 @@ int S2D_GLES_Init() {
122
122
  glLinkProgram(shaderProgram);
123
123
 
124
124
  // Check if linked
125
- S2D_GL_CheckLinked(shaderProgram, "GLES shader");
125
+ R2D_GL_CheckLinked(shaderProgram, "GLES shader");
126
126
 
127
127
  // Get the attribute locations
128
128
  positionLocation = glGetAttribLocation(shaderProgram, "a_position");
@@ -135,7 +135,7 @@ int S2D_GLES_Init() {
135
135
 
136
136
  // Check if program was created successfully
137
137
  if (texShaderProgram == 0) {
138
- S2D_GL_PrintError("Failed to create shader program");
138
+ R2D_GL_PrintError("Failed to create shader program");
139
139
  return GL_FALSE;
140
140
  }
141
141
 
@@ -147,7 +147,7 @@ int S2D_GLES_Init() {
147
147
  glLinkProgram(texShaderProgram);
148
148
 
149
149
  // Check if linked
150
- S2D_GL_CheckLinked(texShaderProgram, "GLES texture shader");
150
+ R2D_GL_CheckLinked(texShaderProgram, "GLES texture shader");
151
151
 
152
152
  // Get the attribute locations
153
153
  texPositionLocation = glGetAttribLocation(texShaderProgram, "a_position");
@@ -169,7 +169,7 @@ int S2D_GLES_Init() {
169
169
  /*
170
170
  * Draw triangle
171
171
  */
172
- void S2D_GLES_DrawTriangle(GLfloat x1, GLfloat y1,
172
+ void R2D_GLES_DrawTriangle(GLfloat x1, GLfloat y1,
173
173
  GLfloat r1, GLfloat g1, GLfloat b1, GLfloat a1,
174
174
  GLfloat x2, GLfloat y2,
175
175
  GLfloat r2, GLfloat g2, GLfloat b2, GLfloat a2,
@@ -202,40 +202,22 @@ void S2D_GLES_DrawTriangle(GLfloat x1, GLfloat y1,
202
202
 
203
203
 
204
204
  /*
205
- * Draw a texture
205
+ * Draw a texture (New method with vertices pre-calculated)
206
206
  */
207
- static void S2D_GLES_DrawTexture(int x, int y, int w, int h,
208
- GLfloat angle, GLfloat rx, GLfloat ry,
209
- GLfloat r, GLfloat g, GLfloat b, GLfloat a,
210
- GLfloat tx1, GLfloat ty1, GLfloat tx2, GLfloat ty2,
211
- GLfloat tx3, GLfloat ty3, GLfloat tx4, GLfloat ty4,
212
- GLuint texture_id) {
213
-
214
- S2D_GL_Point v1 = { .x = x, .y = y };
215
- S2D_GL_Point v2 = { .x = x + w, .y = y };
216
- S2D_GL_Point v3 = { .x = x + w, .y = y + h };
217
- S2D_GL_Point v4 = { .x = x, .y = y + h };
218
-
219
- // Rotate vertices
220
- if (angle != 0) {
221
- v1 = S2D_RotatePoint(v1, angle, rx, ry);
222
- v2 = S2D_RotatePoint(v2, angle, rx, ry);
223
- v3 = S2D_RotatePoint(v3, angle, rx, ry);
224
- v4 = S2D_RotatePoint(v4, angle, rx, ry);
225
- }
226
-
207
+ void R2D_GLES_DrawTexture(GLfloat coordinates[], GLfloat texture_coordinates[], GLfloat color[], int texture_id);
227
208
  GLfloat vertices[] =
228
209
  // x, y coords | x, y texture coords
229
- { v1.x, v1.y, 0.f, tx1, ty1,
230
- v2.x, v2.y, 0.f, tx2, ty2,
231
- v3.x, v3.y, 0.f, tx3, ty3,
232
- v4.x, v4.y, 0.f, tx4, ty4 };
210
+ {
211
+ coordinates[0], coordinates[1], 0.f, texture_coordinates[0], texture_coordinates[1],
212
+ coordinates[2], coordinates[3], 0.f, texture_coordinates[2], texture_coordinates[3],
213
+ coordinates[4], coordinates[5], 0.f, texture_coordinates[4], texture_coordinates[5],
214
+ coordinates[6], coordinates[7], 0.f, texture_coordinates[6], texture_coordinates[7] };
233
215
 
234
216
  GLfloat colors[] =
235
- { r, g, b, a,
236
- r, g, b, a,
237
- r, g, b, a,
238
- r, g, b, a };
217
+ { color[0], color[1], color[2], color[3],
218
+ color[0], color[1], color[2], color[3],
219
+ color[0], color[1], color[2], color[3],
220
+ color[0], color[1], color[2], color[3] };
239
221
 
240
222
  glUseProgram(texShaderProgram);
241
223
 
@@ -264,45 +246,4 @@ static void S2D_GLES_DrawTexture(int x, int y, int w, int h,
264
246
  }
265
247
 
266
248
 
267
- /*
268
- * Draw image
269
- */
270
- void S2D_GLES_DrawImage(S2D_Image *img) {
271
- S2D_GLES_DrawTexture(
272
- img->x, img->y, img->width, img->height,
273
- img->rotate, img->rx, img->ry,
274
- img->color.r, img->color.g, img->color.b, img->color.a,
275
- 0.f, 0.f, 1.f, 0.f, 1.f, 1.f, 0.f, 1.f,
276
- img->texture_id
277
- );
278
- }
279
-
280
-
281
- /*
282
- * Draw sprite
283
- */
284
- void S2D_GLES_DrawSprite(S2D_Sprite *spr) {
285
- S2D_GLES_DrawTexture(
286
- spr->x, spr->y, spr->width, spr->height,
287
- spr->rotate, spr->rx, spr->ry,
288
- spr->color.r, spr->color.g, spr->color.b, spr->color.a,
289
- spr->tx1, spr->ty1, spr->tx2, spr->ty2, spr->tx3, spr->ty3, spr->tx4, spr->ty4,
290
- spr->img->texture_id
291
- );
292
- }
293
-
294
-
295
- /*
296
- * Draw text
297
- */
298
- void S2D_GLES_DrawText(S2D_Text *txt) {
299
- S2D_GLES_DrawTexture(
300
- txt->x, txt->y, txt->width, txt->height,
301
- txt->rotate, txt->rx, txt->ry,
302
- txt->color.r, txt->color.g, txt->color.b, txt->color.a,
303
- 0.f, 0.f, 1.f, 0.f, 1.f, 1.f, 0.f, 1.f,
304
- txt->texture_id
305
- );
306
- }
307
-
308
249
  #endif