ruby2d 0.9.4 → 0.11.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/assets/include/SDL2/SDL.h +4 -1
- data/assets/include/SDL2/SDL_assert.h +3 -1
- data/assets/include/SDL2/SDL_atomic.h +1 -1
- data/assets/include/SDL2/SDL_audio.h +1 -1
- data/assets/include/SDL2/SDL_bits.h +1 -1
- data/assets/include/SDL2/SDL_blendmode.h +4 -1
- data/assets/include/SDL2/SDL_clipboard.h +1 -1
- data/assets/include/SDL2/SDL_config.h +1 -1
- data/assets/include/SDL2/SDL_config_android.h +7 -3
- data/assets/include/SDL2/SDL_config_iphoneos.h +16 -10
- data/assets/include/SDL2/SDL_config_macosx.h +40 -14
- data/assets/include/SDL2/SDL_config_minimal.h +1 -1
- data/assets/include/SDL2/SDL_config_os2.h +26 -8
- data/assets/include/SDL2/SDL_config_pandora.h +4 -2
- data/assets/include/SDL2/SDL_config_psp.h +2 -1
- data/assets/include/SDL2/SDL_config_windows.h +40 -9
- data/assets/include/SDL2/SDL_config_winrt.h +5 -2
- data/assets/include/SDL2/SDL_config_wiz.h +5 -2
- data/assets/include/SDL2/SDL_copying.h +1 -1
- data/assets/include/SDL2/SDL_cpuinfo.h +32 -3
- data/assets/include/SDL2/SDL_egl.h +4 -1
- data/assets/include/SDL2/SDL_endian.h +6 -3
- data/assets/include/SDL2/SDL_error.h +38 -2
- data/assets/include/SDL2/SDL_events.h +64 -28
- data/assets/include/SDL2/SDL_filesystem.h +1 -1
- data/assets/include/SDL2/SDL_gamecontroller.h +160 -9
- data/assets/include/SDL2/SDL_gesture.h +1 -1
- data/assets/include/SDL2/SDL_haptic.h +10 -1
- data/assets/include/SDL2/SDL_hints.h +316 -4
- data/assets/include/SDL2/SDL_joystick.h +115 -24
- data/assets/include/SDL2/SDL_keyboard.h +1 -1
- data/assets/include/SDL2/SDL_keycode.h +11 -9
- data/assets/include/SDL2/SDL_loadso.h +1 -1
- data/assets/include/SDL2/SDL_locale.h +101 -0
- data/assets/include/SDL2/SDL_log.h +3 -3
- data/assets/include/SDL2/SDL_main.h +1 -1
- data/assets/include/SDL2/SDL_messagebox.h +6 -4
- data/assets/include/SDL2/SDL_metal.h +117 -0
- data/assets/include/SDL2/SDL_misc.h +75 -0
- data/assets/include/SDL2/SDL_mouse.h +1 -1
- data/assets/include/SDL2/SDL_mutex.h +1 -1
- data/assets/include/SDL2/SDL_name.h +1 -1
- data/assets/include/SDL2/SDL_opengl.h +1 -1
- data/assets/include/SDL2/SDL_opengl_glext.h +3 -0
- data/assets/include/SDL2/SDL_opengles.h +1 -1
- data/assets/include/SDL2/SDL_opengles2.h +1 -1
- data/assets/include/SDL2/SDL_pixels.h +25 -16
- data/assets/include/SDL2/SDL_platform.h +1 -1
- data/assets/include/SDL2/SDL_power.h +1 -1
- data/assets/include/SDL2/SDL_quit.h +1 -1
- data/assets/include/SDL2/SDL_rect.h +1 -1
- data/assets/include/SDL2/SDL_render.h +63 -3
- data/assets/include/SDL2/SDL_revision.h +2 -2
- data/assets/include/SDL2/SDL_rwops.h +2 -10
- data/assets/include/SDL2/SDL_scancode.h +1 -1
- data/assets/include/SDL2/SDL_sensor.h +25 -9
- data/assets/include/SDL2/SDL_shape.h +1 -1
- data/assets/include/SDL2/SDL_stdinc.h +44 -4
- data/assets/include/SDL2/SDL_surface.h +11 -2
- data/assets/include/SDL2/SDL_system.h +50 -4
- data/assets/include/SDL2/SDL_syswm.h +29 -2
- data/assets/include/SDL2/SDL_test.h +1 -1
- data/assets/include/SDL2/SDL_test_assert.h +1 -1
- data/assets/include/SDL2/SDL_test_common.h +14 -1
- data/assets/include/SDL2/SDL_test_compare.h +1 -1
- data/assets/include/SDL2/SDL_test_crc32.h +1 -1
- data/assets/include/SDL2/SDL_test_font.h +1 -1
- data/assets/include/SDL2/SDL_test_fuzzer.h +1 -1
- data/assets/include/SDL2/SDL_test_harness.h +1 -1
- data/assets/include/SDL2/SDL_test_images.h +1 -1
- data/assets/include/SDL2/SDL_test_log.h +1 -1
- data/assets/include/SDL2/SDL_test_md5.h +1 -1
- data/assets/include/SDL2/SDL_test_memory.h +1 -1
- data/assets/include/SDL2/SDL_test_random.h +1 -1
- data/assets/include/SDL2/SDL_thread.h +34 -11
- data/assets/include/SDL2/SDL_timer.h +1 -1
- data/assets/include/SDL2/SDL_touch.h +1 -1
- data/assets/include/SDL2/SDL_types.h +1 -1
- data/assets/include/SDL2/SDL_version.h +2 -2
- data/assets/include/SDL2/SDL_video.h +11 -5
- data/assets/include/SDL2/SDL_vulkan.h +6 -8
- data/assets/include/SDL2/begin_code.h +5 -9
- data/assets/include/SDL2/close_code.h +1 -1
- data/assets/macos/lib/libFLAC.a +0 -0
- data/assets/macos/lib/libSDL2.a +0 -0
- data/assets/macos/lib/libSDL2_image.a +0 -0
- data/assets/macos/lib/libSDL2_mixer.a +0 -0
- data/assets/macos/lib/libSDL2_ttf.a +0 -0
- data/assets/macos/lib/libfreetype.a +0 -0
- data/assets/macos/lib/libjpeg.a +0 -0
- data/assets/macos/lib/libmodplug.a +0 -0
- data/assets/macos/lib/libmpg123.a +0 -0
- data/assets/macos/lib/libogg.a +0 -0
- data/assets/macos/lib/libpng16.a +0 -0
- data/assets/macos/lib/libtiff.a +0 -0
- data/assets/macos/lib/libvorbis.a +0 -0
- data/assets/macos/lib/libvorbisfile.a +0 -0
- data/assets/macos/lib/libwebp.a +0 -0
- data/assets/mingw/bin/SDL2.dll +0 -0
- data/assets/mingw/lib/libSDL2.a +0 -0
- data/assets/mingw/lib/libSDL2.dll.a +0 -0
- data/assets/mingw/lib/libSDL2_test.a +0 -0
- data/assets/mingw/lib/libSDL2main.a +0 -0
- data/bin/ruby2d +1 -0
- data/{assets/linux/simple2d/src/simple2d.c → ext/ruby2d/common.c} +32 -32
- data/{assets/linux/simple2d/src → ext/ruby2d}/controllers.c +17 -17
- data/ext/ruby2d/extconf.rb +37 -59
- data/ext/ruby2d/font.c +35 -0
- data/{assets/linux/simple2d/src → ext/ruby2d}/gl.c +66 -98
- data/ext/ruby2d/gl2.c +86 -0
- data/{assets/linux/simple2d/src → ext/ruby2d}/gl3.c +69 -112
- data/{assets/linux/simple2d/src → ext/ruby2d}/gles.c +22 -81
- data/ext/ruby2d/image.c +58 -0
- data/{assets/linux/simple2d/src → ext/ruby2d}/input.c +8 -8
- data/{assets/linux/simple2d/src → ext/ruby2d}/music.c +30 -17
- data/ext/ruby2d/ruby2d.c +449 -439
- data/ext/ruby2d/ruby2d.h +652 -0
- data/{assets/linux/simple2d/src → ext/ruby2d}/shapes.c +18 -18
- data/{assets/linux/simple2d/src → ext/ruby2d}/sound.c +39 -14
- data/ext/ruby2d/text.c +22 -0
- data/{assets/linux/simple2d/src → ext/ruby2d}/window.c +63 -63
- data/lib/ruby2d/circle.rb +21 -3
- data/lib/ruby2d/cli/build.rb +4 -7
- data/lib/ruby2d/dsl.rb +16 -9
- data/lib/ruby2d/entity.rb +17 -0
- data/lib/ruby2d/font.rb +23 -3
- data/lib/ruby2d/image.rb +35 -7
- data/lib/ruby2d/line.rb +23 -1
- data/lib/ruby2d/music.rb +5 -0
- data/lib/ruby2d/pixel.rb +17 -0
- data/lib/ruby2d/quad.rb +21 -1
- data/lib/ruby2d/rectangle.rb +12 -3
- data/lib/ruby2d/renderable.rb +4 -20
- data/lib/ruby2d/sound.rb +30 -0
- data/lib/ruby2d/sprite.rb +57 -75
- data/lib/ruby2d/square.rb +10 -1
- data/lib/ruby2d/text.rb +55 -12
- data/lib/ruby2d/texture.rb +28 -0
- data/lib/ruby2d/tileset.rb +87 -0
- data/lib/ruby2d/triangle.rb +19 -1
- data/lib/ruby2d/version.rb +1 -1
- data/lib/ruby2d/vertices.rb +84 -0
- data/lib/ruby2d/window.rb +259 -22
- data/lib/ruby2d.rb +6 -1
- metadata +30 -26
- data/assets/include/simple2d.h +0 -757
- data/assets/linux/simple2d/Makefile +0 -260
- data/assets/linux/simple2d/bin/simple2d.sh +0 -1318
- data/assets/linux/simple2d/include/simple2d.h +0 -757
- data/assets/linux/simple2d/src/gl2.c +0 -146
- data/assets/linux/simple2d/src/image.c +0 -138
- data/assets/linux/simple2d/src/sprite.c +0 -147
- data/assets/linux/simple2d/src/text.c +0 -129
- data/assets/macos/lib/libsimple2d.a +0 -0
- data/assets/mingw/lib/libsimple2d.a +0 -0
@@ -1,15 +1,15 @@
|
|
1
|
-
//
|
1
|
+
// Ruby 2D OpenGL Functions
|
2
2
|
|
3
|
-
#include "
|
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
|
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
|
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
|
24
|
-
|
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
|
32
|
-
|
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->
|
39
|
-
window->
|
40
|
-
window->
|
41
|
-
window->
|
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
|
49
|
+
void R2D_GL_StoreContextInfo(R2D_Window *window) {
|
50
50
|
|
51
|
-
window->
|
52
|
-
window->
|
53
|
-
window->
|
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->
|
58
|
-
window->
|
57
|
+
window->R2D_GL_MAJOR_VERSION = 0;
|
58
|
+
window->R2D_GL_MINOR_VERSION = 0;
|
59
59
|
#else
|
60
|
-
glGetIntegerv(GL_MAJOR_VERSION, &window->
|
61
|
-
glGetIntegerv(GL_MINOR_VERSION, &window->
|
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->
|
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
|
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
|
-
|
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
|
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
|
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
|
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
|
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
|
174
|
+
case R2D_EXPAND:
|
175
175
|
ortho_w = w;
|
176
176
|
ortho_h = h;
|
177
177
|
break;
|
178
178
|
|
179
|
-
case
|
180
|
-
|
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
|
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
|
-
|
197
|
+
R2D_GLES_ApplyProjection(orthoMatrix);
|
198
198
|
#else
|
199
|
-
if (
|
200
|
-
|
199
|
+
if (R2D_GL2) {
|
200
|
+
R2D_GL2_ApplyProjection(ortho_w, ortho_h);
|
201
201
|
} else {
|
202
|
-
|
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
|
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
|
-
|
248
|
-
|
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)
|
255
|
+
if (GLEW_OK != err) R2D_Error("GLEW", glewGetErrorString(err));
|
256
256
|
#endif
|
257
|
-
|
258
|
-
|
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
|
-
|
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
|
-
|
279
|
-
|
280
|
-
|
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
|
-
|
285
|
-
|
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
|
-
|
293
|
-
if (
|
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
|
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
|
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
|
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
|
-
|
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 (
|
351
|
-
|
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
|
-
|
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
|
364
|
+
* Draw a texture
|
365
365
|
*/
|
366
|
-
void
|
366
|
+
void R2D_GL_DrawTexture(GLfloat coordinates[], GLfloat texture_coordinates[], GLfloat color[], int texture_id) {
|
367
367
|
#if GLES
|
368
|
-
|
368
|
+
R2D_GLES_DrawTexture(coordinates, texture_coordinates, color, texture_id);
|
369
369
|
#else
|
370
|
-
if (
|
371
|
-
|
370
|
+
if (R2D_GL2) {
|
371
|
+
R2D_GL2_DrawTexture(coordinates, texture_coordinates, color, texture_id);
|
372
372
|
} else {
|
373
|
-
|
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
|
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:
|
385
|
+
// TODO: R2D_GLES_FlushBuffers();
|
418
386
|
#else
|
419
|
-
if (!
|
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
|
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
|