ruby2d 0.10.0 → 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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: '0059bb28289e915843965295b765cb9538ee1fcb167ad7614232170afe755c59'
4
- data.tar.gz: 7b06dcf7936082f49778cd8652ed9e2475572e241031d6cd321547d8abab62c5
3
+ metadata.gz: 2a371c4ae782c20ba163d4267f55c06e65ab6893d8ced8dd99fc6fe1669a951e
4
+ data.tar.gz: f3d4715daec9b0b6e42c22ea6a58f8994773de62979981d994268f85af3d19a4
5
5
  SHA512:
6
- metadata.gz: 209a09d9d45bcdcb92c985f87a8f2696264790f5cc33e37120689af8768d8224e01811c3d093347b48899437731b48518fbac9c2f511982f7c884740503c54a6
7
- data.tar.gz: 6fcede24174d4e97f60cf338488970cedd6990be9e4755097442b62f7346b4a1df06f86cdf98a65757683f831afedb9bf222e456af9b949387cee7c48bd141e8
6
+ metadata.gz: d866419232f24bd69b8bcf99a5cb9eae1d003f9033cbb9abeae4561a7ef7bf92bed995fa2286daf314acd8eb6a9eb625cae44ecb63255ac3d0f51ef9fa561ca9
7
+ data.tar.gz: 3247b8f90722dfd8f156f6d724a311c925653896b764e740a0e15211918efc0b45dd1c4153a1e8abaafa5e469a399603f2380bf641cec10305ad3e55f1aed7fc
@@ -12,6 +12,8 @@ when /linux/
12
12
  if `cat /etc/os-release` =~ /raspbian/
13
13
  $platform = :linux_rpi
14
14
  end
15
+ when /bsd/
16
+ $platform = :bsd
15
17
  when /mingw/
16
18
  $platform = :windows
17
19
  else
@@ -41,32 +43,38 @@ def add_flags(type, flags)
41
43
  end
42
44
 
43
45
 
44
- # Check SDL libraries on Linux
45
- def check_sdl_linux
46
+ # Check for SDL libraries
47
+ def check_sdl
46
48
  unless have_library('SDL2') && have_library('SDL2_image') && have_library('SDL2_mixer') && have_library('SDL2_ttf')
47
49
 
48
50
  $errors << "Couldn't find packages needed by Ruby 2D."
49
51
 
50
- # Fedora and CentOS
51
- if system('which yum')
52
- $errors << "Install the following packages using `yum` (or `dnf`) and try again:\n" <<
53
- " SDL2-devel SDL2_image-devel SDL2_mixer-devel SDL2_ttf-devel".bold
54
-
55
- # Arch
56
- elsif system('which pacman')
57
- $errors << "Install the following packages using `pacman` and try again:\n" <<
52
+ case $platform
53
+ when :linux, :linux_rpi
54
+ # Fedora and CentOS
55
+ if system('which yum')
56
+ $errors << "Install the following packages using `yum` (or `dnf`) and try again:\n" <<
57
+ " SDL2-devel SDL2_image-devel SDL2_mixer-devel SDL2_ttf-devel".bold
58
+
59
+ # Arch
60
+ elsif system('which pacman')
61
+ $errors << "Install the following packages using `pacman` and try again:\n" <<
62
+ " sdl2 sdl2_image sdl2_mixer sdl2_ttf".bold
63
+
64
+ # openSUSE
65
+ elsif system('which zypper')
66
+ $errors << "Install the following packages using `zypper` and try again:\n" <<
67
+ " libSDL2-devel libSDL2_image-devel libSDL2_mixer-devel libSDL2_ttf-devel".bold
68
+
69
+ # Ubuntu, Debian, and Mint
70
+ # `apt` must be last because openSUSE has it aliased to `zypper`
71
+ elsif system('which apt')
72
+ $errors << "Install the following packages using `apt` and try again:\n" <<
73
+ " libsdl2-dev libsdl2-image-dev libsdl2-mixer-dev libsdl2-ttf-dev".bold
74
+ end
75
+ when :bsd
76
+ $errors << "Install the following packages using `pkg` and try again:\n" <<
58
77
  " sdl2 sdl2_image sdl2_mixer sdl2_ttf".bold
59
-
60
- # openSUSE
61
- elsif system('which zypper')
62
- $errors << "Install the following packages using `zypper` and try again:\n" <<
63
- " libSDL2-devel libSDL2_image-devel libSDL2_mixer-devel libSDL2_ttf-devel".bold
64
-
65
- # Ubuntu, Debian, and Mint
66
- # `apt` must be last because openSUSE has it aliased to `zypper`
67
- elsif system('which apt')
68
- $errors << "Install the following packages using `apt` and try again:\n" <<
69
- " libsdl2-dev libsdl2-image-dev libsdl2-mixer-dev libsdl2-ttf-dev".bold
70
78
  end
71
79
 
72
80
  $errors << "" << "See #{"ruby2d.com".bold} for additional help."
@@ -115,8 +123,8 @@ else
115
123
  add_flags(:ld, "#{ldir}/libfreetype.a")
116
124
  add_flags(:ld, "-Wl,-framework,Cocoa -Wl,-framework,GameController -Wl,-framework,ForceFeedback")
117
125
 
118
- when :linux, :linux_rpi
119
- check_sdl_linux
126
+ when :linux, :linux_rpi, :bsd
127
+ check_sdl
120
128
 
121
129
  set_rpi_flags
122
130
  add_flags(:ld, "-lSDL2 -lSDL2_image -lSDL2_mixer -lSDL2_ttf -lm")
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
+ }
data/ext/ruby2d/gl.c CHANGED
@@ -20,7 +20,7 @@ static GLfloat orthoMatrix[16] =
20
20
  /*
21
21
  * Prints current GL error
22
22
  */
23
- void R2D_GL_PrintError(char *error) {
23
+ void R2D_GL_PrintError(const char *error) {
24
24
  R2D_Log(R2D_ERROR, "%s (%d)", error, glGetError());
25
25
  }
26
26
 
@@ -69,7 +69,7 @@ void R2D_GL_StoreContextInfo(R2D_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 R2D_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);
@@ -111,7 +111,7 @@ GLuint R2D_GL_LoadShader(GLenum type, const GLchar *shaderSrc, char *shaderName)
111
111
  /*
112
112
  * Check if shader program was linked
113
113
  */
114
- int R2D_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);
@@ -361,65 +361,16 @@ void R2D_GL_DrawTriangle(GLfloat x1, GLfloat y1,
361
361
 
362
362
 
363
363
  /*
364
- * Draw an image
364
+ * Draw a texture
365
365
  */
366
- void R2D_GL_DrawImage(R2D_Image *img) {
366
+ void R2D_GL_DrawTexture(GLfloat coordinates[], GLfloat texture_coordinates[], GLfloat color[], int texture_id) {
367
367
  #if GLES
368
- R2D_GLES_DrawImage(img);
368
+ R2D_GLES_DrawTexture(coordinates, texture_coordinates, color, texture_id);
369
369
  #else
370
370
  if (R2D_GL2) {
371
- R2D_GL2_DrawImage(img);
371
+ R2D_GL2_DrawTexture(coordinates, texture_coordinates, color, texture_id);
372
372
  } else {
373
- R2D_GL3_DrawImage(img);
374
- }
375
- #endif
376
- }
377
-
378
-
379
- /*
380
- * Draw sprite
381
- */
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) {
400
- #if GLES
401
- R2D_GLES_DrawTile(img, x, y, tw, th, tx1, ty1, tx2, ty2, tx3, ty3, tx4, ty4);
402
- #else
403
- if (R2D_GL2) {
404
- R2D_GL2_DrawTile(img, x, y, tw, th, tx1, ty1, tx2, ty2, tx3, ty3, tx4, ty4);
405
- } else {
406
- R2D_GL3_DrawTile(img, x, y, tw, th, tx1, ty1, tx2, ty2, tx3, ty3, tx4, ty4);
407
- }
408
- #endif
409
- }
410
-
411
-
412
- /*
413
- * Draw text
414
- */
415
- void R2D_GL_DrawText(R2D_Text *txt) {
416
- #if GLES
417
- R2D_GLES_DrawText(txt);
418
- #else
419
- if (R2D_GL2) {
420
- R2D_GL2_DrawText(txt);
421
- } else {
422
- R2D_GL3_DrawText(txt);
373
+ R2D_GL3_DrawTexture(coordinates, texture_coordinates, color, texture_id);
423
374
  }
424
375
  #endif
425
376
  }
data/ext/ruby2d/gl2.c CHANGED
@@ -64,98 +64,23 @@ void R2D_GL2_DrawTriangle(GLfloat x1, GLfloat y1,
64
64
 
65
65
 
66
66
  /*
67
- * Draw texture
67
+ * Draw a texture (New method with vertices pre-calculated)
68
68
  */
69
- static void R2D_GL2_DrawTexture(int x, int y, int w, int h,
70
- GLfloat angle, GLfloat rx, GLfloat ry,
71
- GLfloat r, GLfloat g, GLfloat b, GLfloat a,
72
- GLfloat tx1, GLfloat ty1, GLfloat tx2, GLfloat ty2,
73
- GLfloat tx3, GLfloat ty3, GLfloat tx4, GLfloat ty4,
74
- GLuint texture_id) {
75
-
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
-
81
- // Rotate vertices
82
- if (angle != 0) {
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
- }
88
-
69
+ void R2D_GL2_DrawTexture(GLfloat coordinates[], GLfloat texture_coordinates[], GLfloat color[], int texture_id) {
89
70
  glEnable(GL_TEXTURE_2D);
90
71
 
91
72
  glBindTexture(GL_TEXTURE_2D, texture_id);
92
73
 
93
74
  glBegin(GL_QUADS);
94
- glColor4f(r, g, b, a);
95
- glTexCoord2f(tx1, ty1); glVertex2f(v1.x, v1.y);
96
- glTexCoord2f(tx2, ty2); glVertex2f(v2.x, v2.y);
97
- glTexCoord2f(tx3, ty3); glVertex2f(v3.x, v3.y);
98
- glTexCoord2f(tx4, ty4); glVertex2f(v4.x, v4.y);
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]);
99
80
  glEnd();
100
81
 
101
82
  glDisable(GL_TEXTURE_2D);
102
- }
103
-
104
-
105
- /*
106
- * Draw image
107
- */
108
- void R2D_GL2_DrawImage(R2D_Image *img) {
109
- R2D_GL2_DrawTexture(
110
- img->x, img->y, img->width, img->height,
111
- img->rotate, img->rx, img->ry,
112
- img->color.r, img->color.g, img->color.b, img->color.a,
113
- 0.f, 0.f, 1.f, 0.f, 1.f, 1.f, 0.f, 1.f,
114
- img->texture_id
115
- );
116
- }
117
-
118
-
119
- /*
120
- * Draw sprite
121
- */
122
- void R2D_GL2_DrawSprite(R2D_Sprite *spr) {
123
- R2D_GL2_DrawTexture(
124
- spr->x, spr->y, spr->width, spr->height,
125
- spr->rotate, spr->rx, spr->ry,
126
- spr->color.r, spr->color.g, spr->color.b, spr->color.a,
127
- spr->tx1, spr->ty1, spr->tx2, spr->ty2, spr->tx3, spr->ty3, spr->tx4, spr->ty4,
128
- spr->img->texture_id
129
- );
130
- }
131
-
83
+ };
132
84
 
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
-
148
- /*
149
- * Draw text
150
- */
151
- void R2D_GL2_DrawText(R2D_Text *txt) {
152
- R2D_GL2_DrawTexture(
153
- txt->x, txt->y, txt->width, txt->height,
154
- txt->rotate, txt->rx, txt->ry,
155
- txt->color.r, txt->color.g, txt->color.b, txt->color.a,
156
- 0.f, 0.f, 1.f, 0.f, 1.f, 1.f, 0.f, 1.f,
157
- txt->texture_id
158
- );
159
- }
160
85
 
161
86
  #endif
data/ext/ruby2d/gl3.c CHANGED
@@ -10,12 +10,10 @@ static GLuint vboSize; // size of the VBO in bytes
10
10
  static GLfloat *vboData; // pointer to the VBO data
11
11
  static GLfloat *vboDataCurrent; // pointer to the data for the current vertices
12
12
  static GLuint vboDataIndex = 0; // index of the current object being rendered
13
- static GLuint vboObjCapacity = 2500; // number of objects the VBO can store
13
+ static GLuint vboObjCapacity = 7500; // number of objects the VBO can store
14
+ static GLuint verticesTextureIds[7500]; // store the texture_id of each vertices
14
15
  static GLuint shaderProgram; // triangle shader program
15
16
  static GLuint texShaderProgram; // texture shader program
16
- static GLuint indices[] = // indices for rendering textured quads
17
- { 0, 1, 2,
18
- 2, 3, 0 };
19
17
 
20
18
 
21
19
  /*
@@ -106,7 +104,7 @@ int R2D_GL3_Init() {
106
104
  // Create a vertex buffer object and allocate data
107
105
  glGenBuffers(1, &vbo);
108
106
  glBindBuffer(GL_ARRAY_BUFFER, vbo);
109
- vboSize = vboObjCapacity * sizeof(GLfloat) * 24;
107
+ vboSize = vboObjCapacity * sizeof(GLfloat) * 8;
110
108
  vboData = (GLfloat *) malloc(vboSize);
111
109
  vboDataCurrent = vboData;
112
110
 
@@ -207,17 +205,39 @@ int R2D_GL3_Init() {
207
205
  * Render the vertex buffer and reset it
208
206
  */
209
207
  void R2D_GL3_FlushBuffers() {
210
-
211
- // Use the triangle shader program
212
- glUseProgram(shaderProgram);
213
-
214
208
  // Bind to the vertex buffer object and update its data
215
209
  glBindBuffer(GL_ARRAY_BUFFER, vbo);
210
+
216
211
  glBufferData(GL_ARRAY_BUFFER, vboSize, NULL, GL_DYNAMIC_DRAW);
217
- glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(GLfloat) * vboDataIndex * 24, vboData);
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);
218
236
 
219
- // Render all the triangles in the buffer
220
- glDrawArrays(GL_TRIANGLES, 0, (GLsizei)(vboDataIndex * 3));
237
+ lastTextureId = verticesTextureIds[i];
238
+ verticesOffset = i;
239
+ }
240
+ }
221
241
 
222
242
  // Reset the buffer object index and data pointer
223
243
  vboDataIndex = 0;
@@ -236,10 +256,10 @@ void R2D_GL3_DrawTriangle(GLfloat x1, GLfloat y1,
236
256
  GLfloat r3, GLfloat g3, GLfloat b3, GLfloat a3) {
237
257
 
238
258
  // If buffer is full, flush it
239
- if (vboDataIndex >= vboObjCapacity) R2D_GL3_FlushBuffers();
259
+ if (vboDataIndex + 3 >= vboObjCapacity) R2D_GL3_FlushBuffers();
240
260
 
241
261
  // Set the triangle data into a formatted array
242
- GLfloat vertices[] =
262
+ GLfloat vertices[24] =
243
263
  { x1, y1, r1, g1, b1, a1, 0, 0,
244
264
  x2, y2, r2, g2, b2, a2, 0, 0,
245
265
  x3, y3, r3, g3, b3, a3, 0, 0 };
@@ -248,116 +268,38 @@ void R2D_GL3_DrawTriangle(GLfloat x1, GLfloat y1,
248
268
  memcpy(vboDataCurrent, vertices, sizeof(vertices));
249
269
 
250
270
  // Increment the buffer object index and the vertex data pointer for next use
251
- vboDataIndex++;
271
+ verticesTextureIds[vboDataIndex] = verticesTextureIds[vboDataIndex + 1] = verticesTextureIds[vboDataIndex + 2] = 0;
272
+ vboDataIndex += 3;
252
273
  vboDataCurrent = (GLfloat *)((char *)vboDataCurrent + (sizeof(GLfloat) * 24));
253
274
  }
254
275
 
255
276
 
256
277
  /*
257
- * Draw a texture
278
+ * Draw a texture (New method with vertices pre-calculated)
258
279
  */
259
- static void R2D_GL3_DrawTexture(int x, int y, int w, int h,
260
- GLfloat angle, GLfloat rx, GLfloat ry,
261
- GLfloat r, GLfloat g, GLfloat b, GLfloat a,
262
- GLfloat tx1, GLfloat ty1, GLfloat tx2, GLfloat ty2,
263
- GLfloat tx3, GLfloat ty3, GLfloat tx4, GLfloat ty4,
264
- GLuint texture_id) {
265
-
266
- // Currently, textures are not buffered, so we have to flush all buffers so
267
- // textures get rendered in the correct Z order
268
- R2D_GL3_FlushBuffers();
269
-
270
- // Set up the vertex points
271
- R2D_GL_Point v1 = { .x = x, .y = y };
272
- R2D_GL_Point v2 = { .x = x + w, .y = y };
273
- R2D_GL_Point v3 = { .x = x + w, .y = y + h };
274
- R2D_GL_Point v4 = { .x = x, .y = y + h };
275
-
276
- // Rotate vertices
277
- if (angle != 0) {
278
- v1 = R2D_RotatePoint(v1, angle, rx, ry);
279
- v2 = R2D_RotatePoint(v2, angle, rx, ry);
280
- v3 = R2D_RotatePoint(v3, angle, rx, ry);
281
- v4 = R2D_RotatePoint(v4, angle, rx, ry);
282
- }
283
-
284
- // Set the textured quad data into a formatted array
285
- GLfloat vertices[] =
286
- // vertex coords | colors | x, y texture coords
287
- { v1.x, v1.y, r, g, b, a, tx1, ty1, // Top-left
288
- v2.x, v2.y, r, g, b, a, tx2, ty2, // Top-right
289
- v3.x, v3.y, r, g, b, a, tx3, ty3, // Bottom-right
290
- v4.x, v4.y, r, g, b, a, tx4, ty4 }; // Bottom-left
291
-
292
- // Use the texture shader program
293
- glUseProgram(texShaderProgram);
294
-
295
- // Bind the texture using the provided ID
296
- glBindTexture(GL_TEXTURE_2D, texture_id);
297
-
298
- // Create and Initialize the vertex data and array indices
299
- glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
300
- glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_STATIC_DRAW);
301
-
302
- // Render the textured quad
303
- glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0);
304
- }
305
-
306
-
307
- /*
308
- * Draw image
309
- */
310
- void R2D_GL3_DrawImage(R2D_Image *img) {
311
- R2D_GL3_DrawTexture(
312
- img->x, img->y, img->width, img->height,
313
- img->rotate, img->rx, img->ry,
314
- img->color.r, img->color.g, img->color.b, img->color.a,
315
- 0.f, 0.f, 1.f, 0.f, 1.f, 1.f, 0.f, 1.f,
316
- img->texture_id
317
- );
318
- }
319
-
320
-
321
- /*
322
- * Draw sprite
323
- */
324
- void R2D_GL3_DrawSprite(R2D_Sprite *spr) {
325
- R2D_GL3_DrawTexture(
326
- spr->x, spr->y, spr->width, spr->height,
327
- spr->rotate, spr->rx, spr->ry,
328
- spr->color.r, spr->color.g, spr->color.b, spr->color.a,
329
- spr->tx1, spr->ty1, spr->tx2, spr->ty2, spr->tx3, spr->ty3, spr->tx4, spr->ty4,
330
- spr->img->texture_id
331
- );
332
- }
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
+ };
333
295
 
296
+ // Copy the vertex data into the current position of the buffer
297
+ memcpy(vboDataCurrent, vertices, sizeof(vertices));
334
298
 
335
- /*
336
- * Draw a tile
337
- */
338
- void R2D_GL3_DrawTile(R2D_Image *img, int x, int y, int tw, int th, GLfloat tx1, GLfloat ty1, GLfloat tx2,
339
- GLfloat ty2, GLfloat tx3, GLfloat ty3, GLfloat tx4, GLfloat ty4) {
340
- R2D_GL3_DrawTexture(
341
- x, y, tw, th,
342
- img->rotate, img->rx, img->ry,
343
- img->color.r, img->color.g, img->color.b, img->color.a,
344
- tx1, ty1, tx2, ty2, tx3, ty3, tx4, ty4,
345
- img->texture_id
346
- );
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));
347
302
  }
348
303
 
349
304
 
350
- /*
351
- * Draw text
352
- */
353
- void R2D_GL3_DrawText(R2D_Text *txt) {
354
- R2D_GL3_DrawTexture(
355
- txt->x, txt->y, txt->width, txt->height,
356
- txt->rotate, txt->rx, txt->ry,
357
- txt->color.r, txt->color.g, txt->color.b, txt->color.a,
358
- 0.f, 0.f, 1.f, 0.f, 1.f, 1.f, 0.f, 1.f,
359
- txt->texture_id
360
- );
361
- }
362
-
363
305
  #endif