ruby2d 0.9.0 → 0.9.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,403 @@
1
+ // window.c
2
+
3
+ #include "../include/simple2d.h"
4
+
5
+
6
+ /*
7
+ * Create a window
8
+ */
9
+ S2D_Window *S2D_CreateWindow(const char *title, int width, int height,
10
+ S2D_Update update, S2D_Render render, int flags) {
11
+
12
+ S2D_Init();
13
+
14
+ SDL_DisplayMode dm;
15
+ SDL_GetCurrentDisplayMode(0, &dm);
16
+ S2D_Log(S2D_INFO, "Current display mode is %dx%dpx @ %dhz", dm.w, dm.h, dm.refresh_rate);
17
+
18
+ width = width == S2D_DISPLAY_WIDTH ? dm.w : width;
19
+ height = height == S2D_DISPLAY_HEIGHT ? dm.h : height;
20
+
21
+ // Allocate window and set default values
22
+ S2D_Window *window = (S2D_Window *) malloc(sizeof(S2D_Window));
23
+ window->sdl = NULL;
24
+ window->glcontext = NULL;
25
+ window->title = title;
26
+ window->width = width;
27
+ window->height = height;
28
+ window->orig_width = width;
29
+ window->orig_height = height;
30
+ window->viewport.width = width;
31
+ window->viewport.height = height;
32
+ window->viewport.mode = S2D_SCALE;
33
+ window->update = update;
34
+ window->render = render;
35
+ window->flags = flags;
36
+ window->on_key = NULL;
37
+ window->on_mouse = NULL;
38
+ window->on_controller = NULL;
39
+ window->vsync = true;
40
+ window->fps_cap = 60;
41
+ window->background.r = 0.0;
42
+ window->background.g = 0.0;
43
+ window->background.b = 0.0;
44
+ window->background.a = 1.0;
45
+ window->icon = NULL;
46
+ window->close = true;
47
+
48
+ // Return the window structure
49
+ return window;
50
+ }
51
+
52
+
53
+ /*
54
+ * Show the window
55
+ */
56
+ int S2D_Show(S2D_Window *window) {
57
+
58
+ if (!window) {
59
+ S2D_Error("S2D_Show", "Window cannot be shown (because it's NULL)");
60
+ return 1;
61
+ }
62
+
63
+ // Create SDL window
64
+ window->sdl = SDL_CreateWindow(
65
+ window->title, // title
66
+ SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, // window position
67
+ window->width, window->height, // window size
68
+ SDL_WINDOW_OPENGL | window->flags // flags
69
+ );
70
+
71
+ if (!window->sdl) S2D_Error("SDL_CreateWindow", SDL_GetError());
72
+ if (window->icon) S2D_SetIcon(window, window->icon);
73
+
74
+ // The window created by SDL might not actually be the requested size.
75
+ // If it's not the same, retrieve and store the actual window size.
76
+ int actual_width, actual_height;
77
+ SDL_GetWindowSize(window->sdl, &actual_width, &actual_height);
78
+
79
+ if ((window->width != actual_width) || (window->height != actual_height)) {
80
+ S2D_Log(S2D_INFO,
81
+ "Scaling window to %ix%i (requested size was %ix%i)",
82
+ actual_width, actual_height, window->width, window->height
83
+ );
84
+ window->width = actual_width;
85
+ window->height = actual_height;
86
+ window->orig_width = actual_width;
87
+ window->orig_height = actual_height;
88
+ }
89
+
90
+ // Set Up OpenGL /////////////////////////////////////////////////////////////
91
+
92
+ S2D_GL_Init(window);
93
+
94
+ // Set Main Loop Data ////////////////////////////////////////////////////////
95
+
96
+ const Uint8 *key_state;
97
+
98
+ Uint32 frames = 0; // Total frames since start
99
+ Uint32 frames_last_sec = 0; // Frames in the last second
100
+ Uint32 start_ms = SDL_GetTicks(); // Elapsed time since start
101
+ Uint32 next_second_ms = SDL_GetTicks(); // The last time plus a second
102
+ Uint32 begin_ms = start_ms; // Time at beginning of loop
103
+ Uint32 end_ms; // Time at end of loop
104
+ Uint32 elapsed_ms; // Total elapsed time
105
+ Uint32 loop_ms; // Elapsed time of loop
106
+ int delay_ms; // Amount of delay to achieve desired frame rate
107
+ const double decay_rate = 0.5; // Determines how fast an average decays over time
108
+ double fps = window->fps_cap; // Moving average of actual FPS, initial value a guess
109
+
110
+ // Enable VSync
111
+ if (window->vsync) {
112
+ if (!SDL_SetHint(SDL_HINT_RENDER_VSYNC, "1")) {
113
+ S2D_Log(S2D_WARN, "VSync cannot be enabled");
114
+ }
115
+ }
116
+
117
+ window->close = false;
118
+
119
+ // Main Loop /////////////////////////////////////////////////////////////////
120
+
121
+ while (!window->close) {
122
+
123
+ // Clear Frame /////////////////////////////////////////////////////////////
124
+
125
+ S2D_GL_Clear(window->background);
126
+
127
+ // Set FPS /////////////////////////////////////////////////////////////////
128
+
129
+ frames++;
130
+ frames_last_sec++;
131
+ end_ms = SDL_GetTicks();
132
+ elapsed_ms = end_ms - start_ms;
133
+
134
+ // Calculate the frame rate using an exponential moving average
135
+ if (next_second_ms < end_ms) {
136
+ fps = decay_rate * fps + (1.0 - decay_rate) * frames_last_sec;
137
+ frames_last_sec = 0;
138
+ next_second_ms = SDL_GetTicks() + 1000;
139
+ }
140
+
141
+ loop_ms = end_ms - begin_ms;
142
+ delay_ms = (1000 / window->fps_cap) - loop_ms;
143
+
144
+ if (delay_ms < 0) delay_ms = 0;
145
+
146
+ // Note: `loop_ms + delay_ms` should equal `1000 / fps_cap`
147
+
148
+ SDL_Delay(delay_ms);
149
+ begin_ms = SDL_GetTicks();
150
+
151
+ // Handle Input and Window Events //////////////////////////////////////////
152
+
153
+ int mx, my; // mouse x, y coordinates
154
+
155
+ SDL_Event e;
156
+ while (SDL_PollEvent(&e)) {
157
+ switch (e.type) {
158
+
159
+ case SDL_KEYDOWN:
160
+ if (window->on_key && e.key.repeat == 0) {
161
+ S2D_Event event = {
162
+ .type = S2D_KEY_DOWN, .key = SDL_GetScancodeName(e.key.keysym.scancode)
163
+ };
164
+ window->on_key(event);
165
+ }
166
+ break;
167
+
168
+ case SDL_KEYUP:
169
+ if (window->on_key) {
170
+ S2D_Event event = {
171
+ .type = S2D_KEY_UP, .key = SDL_GetScancodeName(e.key.keysym.scancode)
172
+ };
173
+ window->on_key(event);
174
+ }
175
+ break;
176
+
177
+ case SDL_MOUSEBUTTONDOWN: case SDL_MOUSEBUTTONUP:
178
+ if (window->on_mouse) {
179
+ S2D_GetMouseOnViewport(window, e.button.x, e.button.y, &mx, &my);
180
+ S2D_Event event = {
181
+ .button = e.button.button, .x = mx, .y = my
182
+ };
183
+ event.type = e.type == SDL_MOUSEBUTTONDOWN ? S2D_MOUSE_DOWN : S2D_MOUSE_UP;
184
+ event.dblclick = e.button.clicks == 2 ? true : false;
185
+ window->on_mouse(event);
186
+ }
187
+ break;
188
+
189
+ case SDL_MOUSEWHEEL:
190
+ if (window->on_mouse) {
191
+ S2D_Event event = {
192
+ .type = S2D_MOUSE_SCROLL, .direction = e.wheel.direction,
193
+ .delta_x = e.wheel.x, .delta_y = -e.wheel.y
194
+ };
195
+ window->on_mouse(event);
196
+ }
197
+ break;
198
+
199
+ case SDL_MOUSEMOTION:
200
+ if (window->on_mouse) {
201
+ S2D_GetMouseOnViewport(window, e.motion.x, e.motion.y, &mx, &my);
202
+ S2D_Event event = {
203
+ .type = S2D_MOUSE_MOVE,
204
+ .x = mx, .y = my, .delta_x = e.motion.xrel, .delta_y = e.motion.yrel
205
+ };
206
+ window->on_mouse(event);
207
+ }
208
+ break;
209
+
210
+ case SDL_CONTROLLERAXISMOTION:
211
+ if (window->on_controller) {
212
+ S2D_Event event = {
213
+ .which = e.caxis.which, .type = S2D_AXIS,
214
+ .axis = e.caxis.axis, .value = e.caxis.value
215
+ };
216
+ window->on_controller(event);
217
+ }
218
+ break;
219
+
220
+ case SDL_JOYAXISMOTION:
221
+ if (window->on_controller && !S2D_IsController(e.jbutton.which)) {
222
+ S2D_Event event = {
223
+ .which = e.jaxis.which, .type = S2D_AXIS,
224
+ .axis = e.jaxis.axis, .value = e.jaxis.value
225
+ };
226
+ window->on_controller(event);
227
+ }
228
+ break;
229
+
230
+ case SDL_CONTROLLERBUTTONDOWN: case SDL_CONTROLLERBUTTONUP:
231
+ if (window->on_controller) {
232
+ S2D_Event event = {
233
+ .which = e.cbutton.which, .button = e.cbutton.button
234
+ };
235
+ event.type = e.type == SDL_CONTROLLERBUTTONDOWN ? S2D_BUTTON_DOWN : S2D_BUTTON_UP;
236
+ window->on_controller(event);
237
+ }
238
+ break;
239
+
240
+ case SDL_JOYBUTTONDOWN: case SDL_JOYBUTTONUP:
241
+ if (window->on_controller && !S2D_IsController(e.jbutton.which)) {
242
+ S2D_Event event = {
243
+ .which = e.jbutton.which, .button = e.jbutton.button
244
+ };
245
+ event.type = e.type == SDL_JOYBUTTONDOWN ? S2D_BUTTON_DOWN : S2D_BUTTON_UP;
246
+ window->on_controller(event);
247
+ }
248
+ break;
249
+
250
+ case SDL_JOYDEVICEADDED:
251
+ S2D_Log(S2D_INFO, "Controller connected (%i total)", SDL_NumJoysticks());
252
+ S2D_OpenControllers();
253
+ break;
254
+
255
+ case SDL_JOYDEVICEREMOVED:
256
+ if (S2D_IsController(e.jdevice.which)) {
257
+ S2D_Log(S2D_INFO, "Controller #%i: %s removed (%i remaining)", e.jdevice.which, SDL_GameControllerName(SDL_GameControllerFromInstanceID(e.jdevice.which)), SDL_NumJoysticks());
258
+ SDL_GameControllerClose(SDL_GameControllerFromInstanceID(e.jdevice.which));
259
+ } else {
260
+ S2D_Log(S2D_INFO, "Controller #%i: %s removed (%i remaining)", e.jdevice.which, SDL_JoystickName(SDL_JoystickFromInstanceID(e.jdevice.which)), SDL_NumJoysticks());
261
+ SDL_JoystickClose(SDL_JoystickFromInstanceID(e.jdevice.which));
262
+ }
263
+ break;
264
+
265
+ case SDL_WINDOWEVENT:
266
+ switch (e.window.event) {
267
+ case SDL_WINDOWEVENT_RESIZED:
268
+ // Store new window size, set viewport
269
+ window->width = e.window.data1;
270
+ window->height = e.window.data2;
271
+ S2D_GL_SetViewport(window);
272
+ break;
273
+ }
274
+ break;
275
+
276
+ case SDL_QUIT:
277
+ S2D_Close(window);
278
+ break;
279
+ }
280
+ }
281
+
282
+ // Detect keys held down
283
+ int num_keys;
284
+ key_state = SDL_GetKeyboardState(&num_keys);
285
+
286
+ for (int i = 0; i < num_keys; i++) {
287
+ if (window->on_key) {
288
+ if (key_state[i] == 1) {
289
+ S2D_Event event = {
290
+ .type = S2D_KEY_HELD, .key = SDL_GetScancodeName(i)
291
+ };
292
+ window->on_key(event);
293
+ }
294
+ }
295
+ }
296
+
297
+ // Get and store mouse position relative to the viewport
298
+ int wx, wy; // mouse x, y coordinates relative to the window
299
+ SDL_GetMouseState(&wx, &wy);
300
+ S2D_GetMouseOnViewport(window, wx, wy, &window->mouse.x, &window->mouse.y);
301
+
302
+ // Update Window State /////////////////////////////////////////////////////
303
+
304
+ // Store new values in the window
305
+ window->frames = frames;
306
+ window->elapsed_ms = elapsed_ms;
307
+ window->loop_ms = loop_ms;
308
+ window->delay_ms = delay_ms;
309
+ window->fps = fps;
310
+
311
+ // Call update and render callbacks
312
+ if (window->update) window->update();
313
+ if (window->render) window->render();
314
+
315
+ // Draw Frame //////////////////////////////////////////////////////////////
316
+ SDL_GL_SwapWindow(window->sdl);
317
+ }
318
+
319
+ return 0;
320
+ }
321
+
322
+
323
+ /*
324
+ * Set the icon for the window
325
+ */
326
+ void S2D_SetIcon(S2D_Window *window, const char *icon) {
327
+ S2D_Image *img = S2D_CreateImage(icon);
328
+ if (img) {
329
+ window->icon = icon;
330
+ SDL_SetWindowIcon(window->sdl, img->surface);
331
+ S2D_FreeImage(img);
332
+ } else {
333
+ S2D_Log(S2D_WARN, "Could not set window icon");
334
+ }
335
+ }
336
+
337
+
338
+ /*
339
+ * Take a screenshot of the window
340
+ */
341
+ void S2D_Screenshot(S2D_Window *window, const char *path) {
342
+
343
+ #if GLES
344
+ S2D_Error("S2D_Screenshot", "Not supported in OpenGL ES");
345
+ #else
346
+ // Create a surface the size of the window
347
+ SDL_Surface *surface = SDL_CreateRGBSurface(
348
+ SDL_SWSURFACE, window->width, window->height, 24,
349
+ 0x000000FF, 0x0000FF00, 0x00FF0000, 0
350
+ );
351
+
352
+ // Grab the pixels from the front buffer, save to surface
353
+ glReadBuffer(GL_FRONT);
354
+ glReadPixels(0, 0, window->width, window->height, GL_RGB, GL_UNSIGNED_BYTE, surface->pixels);
355
+
356
+ // Flip image vertically
357
+
358
+ void *temp_row = (void *)malloc(surface->pitch);
359
+ if (!temp_row) {
360
+ S2D_Error("S2D_Screenshot", "Out of memory!");
361
+ SDL_FreeSurface(surface);
362
+ return;
363
+ }
364
+
365
+ int height_div_2 = (int) (surface->h * 0.5);
366
+
367
+ for (int index = 0; index < height_div_2; index++) {
368
+ memcpy((Uint8 *)temp_row,(Uint8 *)(surface->pixels) + surface->pitch * index, surface->pitch);
369
+ memcpy((Uint8 *)(surface->pixels) + surface->pitch * index, (Uint8 *)(surface->pixels) + surface->pitch * (surface->h - index-1), surface->pitch);
370
+ memcpy((Uint8 *)(surface->pixels) + surface->pitch * (surface->h - index-1), temp_row, surface->pitch);
371
+ }
372
+
373
+ free(temp_row);
374
+
375
+ // Save image to disk
376
+ IMG_SavePNG(surface, path);
377
+ SDL_FreeSurface(surface);
378
+ #endif
379
+ }
380
+
381
+
382
+ /*
383
+ * Close the window
384
+ */
385
+ int S2D_Close(S2D_Window *window) {
386
+ if (!window->close) {
387
+ S2D_Log(S2D_INFO, "Closing window");
388
+ window->close = true;
389
+ }
390
+ return 0;
391
+ }
392
+
393
+
394
+ /*
395
+ * Free all resources
396
+ */
397
+ int S2D_FreeWindow(S2D_Window *window) {
398
+ S2D_Close(window);
399
+ SDL_GL_DeleteContext(window->glcontext);
400
+ SDL_DestroyWindow(window->sdl);
401
+ free(window);
402
+ return 0;
403
+ }
@@ -2,7 +2,25 @@ require 'mkmf'
2
2
  require_relative '../../lib/ruby2d/colorize'
3
3
 
4
4
  S2D_VERSION = '1.1.0' # Simple 2D minimum version required
5
- $errors = [] # Array to capture errors
5
+ $errors = [] # Holds errors
6
+
7
+ # Set the OS platform
8
+ case RUBY_PLATFORM
9
+ when /darwin/
10
+ $platform = :macos
11
+ when /linux/
12
+ $platform = :linux
13
+ if `cat /etc/os-release` =~ /raspbian/
14
+ $platform = :linux_rpi
15
+ end
16
+ when /mingw/
17
+ $platform = :windows
18
+ else
19
+ $platform = nil
20
+ end
21
+
22
+
23
+ # Helper functions #############################################################
6
24
 
7
25
  # Print installation errors
8
26
  def print_errors
@@ -12,15 +30,15 @@ def print_errors
12
30
  #{"======================================================================"}"
13
31
  end
14
32
 
33
+
15
34
  # Check that Simple 2D is installed and meets minimum version requirements
16
35
  def check_s2d
17
36
 
18
37
  # Simple 2D not installed
19
38
  if `which simple2d`.empty?
20
39
  $errors << "Ruby 2D uses a native library called Simple 2D, which was not found." <<
21
- "To install, follow the instructions at #{"ruby2d.com/learn".bold}"
22
- print_errors
23
- exit
40
+ "To install, follow the instructions at #{"ruby2d.com".bold}"
41
+ print_errors; exit
24
42
 
25
43
  # Simple 2D installed, checking version
26
44
  else
@@ -28,26 +46,79 @@ def check_s2d
28
46
  $errors << "Simple 2D needs to be updated for this version of Ruby 2D." <<
29
47
  "Run the following, then try reinstalling this gem:\n" <<
30
48
  " simple2d update".bold
31
- print_errors
32
- exit
49
+ print_errors; exit
33
50
  end
34
51
  end
35
52
  end
36
53
 
54
+
55
+ # Add compiler and linker flags
56
+ def add_flags(type, flags)
57
+ case type
58
+ when :c
59
+ $CFLAGS << " #{flags} "
60
+ when :ld
61
+ $LDFLAGS << " #{flags} "
62
+ end
63
+ end
64
+
65
+
66
+ # Check SDL libraries on Linux
67
+ def check_sdl_linux
68
+ unless have_library('SDL2') && have_library('SDL2_image') && have_library('SDL2_mixer') && have_library('SDL2_ttf')
69
+
70
+ $errors << "Couldn't find packages needed by Ruby 2D."
71
+
72
+ # Fedora and CentOS
73
+ if system('which yum')
74
+ $errors << "Install the following packages using `yum` (or `dnf`) and try again:\n" <<
75
+ " SDL2-devel SDL2_image-devel SDL2_mixer-devel SDL2_ttf-devel".bold
76
+
77
+ # Arch
78
+ elsif system('which pacman')
79
+ $errors << "Install the following packages using `pacman` and try again:\n" <<
80
+ " sdl2 sdl2_image sdl2_mixer sdl2_ttf".bold
81
+
82
+ # openSUSE
83
+ elsif system('which zypper')
84
+ $errors << "Install the following packages using `zypper` and try again:\n" <<
85
+ " libSDL2-devel libSDL2_image-devel libSDL2_mixer-devel libSDL2_ttf-devel".bold
86
+
87
+ # Ubuntu, Debian, and Mint
88
+ # `apt` must be last because openSUSE has it aliased to `zypper`
89
+ elsif system('which apt')
90
+ $errors << "Install the following packages using `apt` and try again:\n" <<
91
+ " libsdl2-dev libsdl2-image-dev libsdl2-mixer-dev libsdl2-ttf-dev".bold
92
+ end
93
+
94
+ $errors << "" << "See #{"ruby2d.com".bold} for additional help."
95
+ print_errors; exit
96
+ end
97
+ end
98
+
99
+
100
+ # Set Raspberry Pi flags
101
+ def set_rpi_flags
102
+ if $platform == :linux_rpi
103
+ add_flags(:c, '-I/opt/vc/include')
104
+ add_flags(:ld, '-L/opt/vc/lib -lbrcmGLESv2')
105
+ end
106
+ end
107
+
108
+
37
109
  # Use the Simple 2D, SDL, and other libraries installed by the user (not those bundled with the gem)
38
110
  def use_usr_libs
39
111
  check_s2d
40
112
 
41
113
  # Add flags
42
- $CFLAGS << ' -std=c11 -I/usr/local/include'
43
- if `cat /etc/os-release` =~ /raspbian/ # Raspberry Pi
44
- $CFLAGS << ' -I/opt/vc/include'
45
- end
46
- $LDFLAGS << ' ' << `bash simple2d --libs`
47
- $LDFLAGS.gsub!(/\n/, ' ') # remove newlines in flags, they cause problems
114
+ set_rpi_flags
115
+ add_flags(:c, '-I/usr/local/include')
116
+ add_flags(:ld, `bash simple2d --libs`)
48
117
  end
49
118
 
50
119
 
120
+ # Configure native extension ###################################################
121
+
51
122
  # Build Ruby 2D native extention using libraries installed by user
52
123
  # To use install flag: `gem install ruby2d -- libs`
53
124
  if ARGV.include? 'libs'
@@ -55,27 +126,36 @@ if ARGV.include? 'libs'
55
126
 
56
127
  # Use libraries provided by the gem (default)
57
128
  else
58
- $CFLAGS << ' -std=c11 -I../../assets/include'
59
- case RUBY_PLATFORM
129
+ add_flags(:c, '-std=c11')
60
130
 
61
- # macOS
62
- when /darwin/
63
- # $LDFLAGS << " -L../../assets/macos/lib -lsimple2d -lSDL2 -lSDL2_image -lSDL2_mixer -lSDL2_ttf -ljpeg -lpng16 -ltiff -lwebp -lmpg123 -logg -lflac -lvorbis -lvorbisfile -lfreetype -Wl,-framework,Cocoa -Wl,-framework,ForceFeedback"
131
+ case $platform
64
132
 
133
+ when :macos
134
+ add_flags(:c, '-I../../assets/include')
65
135
  ldir = "#{Dir.pwd}/../../assets/macos/lib"
66
- $LDFLAGS << " #{ldir}/libsimple2d.a #{ldir}/libSDL2.a #{ldir}/libSDL2_image.a #{ldir}/libSDL2_mixer.a #{ldir}/libSDL2_ttf.a \
67
- #{ldir}/libjpeg.a #{ldir}/libpng16.a #{ldir}/libtiff.a #{ldir}/libwebp.a \
68
- #{ldir}/libmpg123.a #{ldir}/libogg.a #{ldir}/libflac.a #{ldir}/libvorbis.a #{ldir}/libvorbisfile.a \
69
- #{ldir}/libfreetype.a -Wl,-framework,Cocoa -Wl,-framework,ForceFeedback"
70
-
71
- # Linux
72
- when /linux/
73
- # TODO: Implement static compilation for Linux
74
- use_usr_libs
75
136
 
76
- # Windows / MinGW
77
- when /mingw/
78
- $LDFLAGS << " -L../../assets/mingw/lib -lsimple2d -lSDL2 -lSDL2_image -lSDL2_mixer -lSDL2_ttf -lmingw32 -lopengl32 -lglew32"
137
+ add_flags(:ld, "#{ldir}/libsimple2d.a")
138
+ add_flags(:ld, "#{ldir}/libSDL2.a #{ldir}/libSDL2_image.a #{ldir}/libSDL2_mixer.a #{ldir}/libSDL2_ttf.a")
139
+ add_flags(:ld, "#{ldir}/libjpeg.a #{ldir}/libpng16.a #{ldir}/libtiff.a #{ldir}/libwebp.a")
140
+ add_flags(:ld, "#{ldir}/libmpg123.a #{ldir}/libogg.a #{ldir}/libflac.a #{ldir}/libvorbis.a #{ldir}/libvorbisfile.a")
141
+ add_flags(:ld, "#{ldir}/libfreetype.a")
142
+ add_flags(:ld, "-Wl,-framework,Cocoa -Wl,-framework,ForceFeedback")
143
+
144
+ when :linux, :linux_rpi
145
+ check_sdl_linux
146
+ simple2d_dir = "#{Dir.pwd}/../../assets/linux/simple2d"
147
+
148
+ `(cd #{simple2d_dir} && make)`
149
+
150
+ set_rpi_flags
151
+ add_flags(:c, "-I#{simple2d_dir}/include")
152
+ add_flags(:ld, "#{simple2d_dir}/build/libsimple2d.a -lSDL2 -lSDL2_image -lSDL2_mixer -lSDL2_ttf -lm")
153
+ if $platform == :linux then add_flags(:ld, '-lGL') end
154
+
155
+ when :windows
156
+ add_flags(:c, '-I../../assets/include')
157
+ add_flags(:ld, '-L../../assets/mingw/lib -lsimple2d -lSDL2 -lSDL2_image -lSDL2_mixer -lSDL2_ttf')
158
+ add_flags(:ld, '-lmingw32 -lopengl32 -lglew32')
79
159
 
80
160
  # If can't detect the platform, use libraries installed by the user
81
161
  else
@@ -83,6 +163,7 @@ else
83
163
  end
84
164
  end
85
165
 
166
+ $LDFLAGS.gsub!(/\n/, ' ') # remove newlines in flags, they can cause problems
86
167
 
87
168
  # Create the Makefile
88
169
  create_makefile('ruby2d/ruby2d')