allegro4r 0.0.1-x86-mswin32-60

Sign up to get free protection for your applications and to get access to all the features.
Files changed (60) hide show
  1. data/History.txt +4 -0
  2. data/Manifest.txt +59 -0
  3. data/README.txt +94 -0
  4. data/examples/exdbuf.rb +58 -0
  5. data/examples/exfixed.rb +46 -0
  6. data/examples/exflame.rb +200 -0
  7. data/examples/exflip.rb +87 -0
  8. data/examples/exfont.rb +70 -0
  9. data/examples/exhello.rb +46 -0
  10. data/examples/exjoy.rb +206 -0
  11. data/examples/exkeys.rb +216 -0
  12. data/examples/exmem.rb +50 -0
  13. data/examples/exmidi.rb +97 -0
  14. data/examples/exmouse.rb +149 -0
  15. data/examples/expal.rb +70 -0
  16. data/examples/expat.rb +62 -0
  17. data/examples/exsample.rb +89 -0
  18. data/examples/extimer.rb +84 -0
  19. data/examples/unifont.dat +0 -0
  20. data/ext/a4r_API_BITMAP.c +27 -0
  21. data/ext/a4r_API_DIGI_DRIVER.c +14 -0
  22. data/ext/a4r_API_GFX_DRIVER.c +14 -0
  23. data/ext/a4r_API_JOYSTICK_AXIS_INFO.c +53 -0
  24. data/ext/a4r_API_JOYSTICK_BUTTON_INFO.c +27 -0
  25. data/ext/a4r_API_JOYSTICK_DRIVER.c +14 -0
  26. data/ext/a4r_API_JOYSTICK_INFO.c +84 -0
  27. data/ext/a4r_API_JOYSTICK_STICK_INFO.c +62 -0
  28. data/ext/a4r_API_KEYBOARD_DRIVER.c +14 -0
  29. data/ext/a4r_API_MIDI_DRIVER.c +14 -0
  30. data/ext/a4r_API_MOUSE_DRIVER.c +14 -0
  31. data/ext/a4r_API_PALETTE.c +63 -0
  32. data/ext/a4r_API_RGB.c +118 -0
  33. data/ext/a4r_API_TIMER_DRIVER.c +14 -0
  34. data/ext/a4r_API_bitmap_objects.c +310 -0
  35. data/ext/a4r_API_blitting_and_sprites.c +86 -0
  36. data/ext/a4r_API_digital_sample_routines.c +83 -0
  37. data/ext/a4r_API_direct_access_to_video_memory.c +102 -0
  38. data/ext/a4r_API_drawing_primitives.c +114 -0
  39. data/ext/a4r_API_file_and_compression_routines.c +27 -0
  40. data/ext/a4r_API_fixed_point_math_routines.c +98 -0
  41. data/ext/a4r_API_fonts.c +147 -0
  42. data/ext/a4r_API_graphics_modes.c +155 -0
  43. data/ext/a4r_API_joystick_routines.c +213 -0
  44. data/ext/a4r_API_keyboard_routines.c +420 -0
  45. data/ext/a4r_API_misc.c +133 -0
  46. data/ext/a4r_API_mouse_routines.c +220 -0
  47. data/ext/a4r_API_music_routines_midi.c +147 -0
  48. data/ext/a4r_API_palette_routines.c +112 -0
  49. data/ext/a4r_API_sound_init_routines.c +29 -0
  50. data/ext/a4r_API_text_output.c +178 -0
  51. data/ext/a4r_API_timer_routines.c +250 -0
  52. data/ext/a4r_API_transparency_and_patterned_drawing.c +87 -0
  53. data/ext/a4r_API_truecolor_pixel_formats.c +44 -0
  54. data/ext/a4r_API_unicode_routines.c +53 -0
  55. data/ext/a4r_API_using_allegro.c +98 -0
  56. data/ext/allegro4r.c +866 -0
  57. data/ext/allegro4r.h +311 -0
  58. data/ext/allegro4r.so +0 -0
  59. data/ext/extconf.rb +11 -0
  60. metadata +113 -0
data/History.txt ADDED
@@ -0,0 +1,4 @@
1
+ === 0.0.1 / 2009-04-17
2
+
3
+ * Initial Release.
4
+ * Added Ruby ports and API support for the Allegro examples exhello, exmem, expal, expat, exflame, exdbuf, exflip, exfixed, exfont, exmouse, extimer, exkeys (limited support), exjoy, exsample, and exmidi.
data/Manifest.txt ADDED
@@ -0,0 +1,59 @@
1
+ ext/a4r_API_BITMAP.c
2
+ ext/a4r_API_bitmap_objects.c
3
+ ext/a4r_API_blitting_and_sprites.c
4
+ ext/a4r_API_digital_sample_routines.c
5
+ ext/a4r_API_DIGI_DRIVER.c
6
+ ext/a4r_API_direct_access_to_video_memory.c
7
+ ext/a4r_API_drawing_primitives.c
8
+ ext/a4r_API_file_and_compression_routines.c
9
+ ext/a4r_API_fixed_point_math_routines.c
10
+ ext/a4r_API_fonts.c
11
+ ext/a4r_API_GFX_DRIVER.c
12
+ ext/a4r_API_graphics_modes.c
13
+ ext/a4r_API_JOYSTICK_AXIS_INFO.c
14
+ ext/a4r_API_JOYSTICK_BUTTON_INFO.c
15
+ ext/a4r_API_JOYSTICK_DRIVER.c
16
+ ext/a4r_API_JOYSTICK_INFO.c
17
+ ext/a4r_API_joystick_routines.c
18
+ ext/a4r_API_JOYSTICK_STICK_INFO.c
19
+ ext/a4r_API_KEYBOARD_DRIVER.c
20
+ ext/a4r_API_keyboard_routines.c
21
+ ext/a4r_API_MIDI_DRIVER.c
22
+ ext/a4r_API_misc.c
23
+ ext/a4r_API_MOUSE_DRIVER.c
24
+ ext/a4r_API_mouse_routines.c
25
+ ext/a4r_API_music_routines_midi.c
26
+ ext/a4r_API_PALETTE.c
27
+ ext/a4r_API_palette_routines.c
28
+ ext/a4r_API_RGB.c
29
+ ext/a4r_API_sound_init_routines.c
30
+ ext/a4r_API_text_output.c
31
+ ext/a4r_API_TIMER_DRIVER.c
32
+ ext/a4r_API_timer_routines.c
33
+ ext/a4r_API_transparency_and_patterned_drawing.c
34
+ ext/a4r_API_truecolor_pixel_formats.c
35
+ ext/a4r_API_unicode_routines.c
36
+ ext/a4r_API_using_allegro.c
37
+ ext/allegro4r.c
38
+ ext/allegro4r.h
39
+ ext/extconf.rb
40
+ examples/exdbuf.rb
41
+ examples/exfixed.rb
42
+ examples/exflame.rb
43
+ examples/exflip.rb
44
+ examples/exfont.rb
45
+ examples/exhello.rb
46
+ examples/exjoy.rb
47
+ examples/exkeys.rb
48
+ examples/exmem.rb
49
+ examples/exmidi.rb
50
+ examples/exmouse.rb
51
+ examples/expal.rb
52
+ examples/expat.rb
53
+ examples/exsample.rb
54
+ examples/extimer.rb
55
+ examples/unifont.dat
56
+ Manifest.txt
57
+ README.txt
58
+ History.txt
59
+ ext/allegro4r.so
data/README.txt ADDED
@@ -0,0 +1,94 @@
1
+ ______ ___ ___ __ __
2
+ /\ _ \ /\_ \ /\_ \ /\ \\ \
3
+ \ \ \L\ \\//\ \ \//\ \ __ __ _ __ ___\ \ \\ \ _ __
4
+ \ \ __ \ \ \ \ \ \ \ /'__`\ /'_ `\/\`'__\/ __`\ \ \\ \_ /\`'__\
5
+ \ \ \/\ \ \_\ \_ \_\ \_/\ __//\ \L\ \ \ \//\ \L\ \ \__ ,__\ \ \/
6
+ \ \_\ \_\/\____\/\____\ \____\ \____ \ \_\\ \____/\/_/\_\_/\ \_\
7
+ \/_/\/_/\/____/\/____/\/____/\/___L\ \/_/ \/___/ \/_/ \/_/
8
+ /\____/
9
+ \_/__/ Version 0.0.1
10
+
11
+ = Allegro4r
12
+
13
+ http://allegro4r.rubyforge.org
14
+
15
+ Ruby binding to the Allegro game programming library. <http://alleg.sourceforge.net>
16
+
17
+ == REQUIREMENTS:
18
+
19
+ * Allegro 4.2.2 <http://alleg.sourceforge.net/wip.html>
20
+
21
+ == INSTALL:
22
+
23
+ * Install Allegro 4.2.2
24
+
25
+ Windows:: The easiest way to install Allegro is to download the precompiled binaries found here[http://www.allegro.cc/files/].
26
+ Download the MinGW binary version. For 32 bit Windows, put the files in the System32 directory. For 64 bit Windows, put the files in the SysWOW64 directory.
27
+
28
+ Linux:: For Debian based Linux (e.g. Ubuntu), install the allegro4.2 or liballegro4.2 package: <tt>sudo apt-get install allegro4.2</tt>
29
+ More package information can be found here[http://packages.debian.org/source/lenny/allegro4.2].
30
+
31
+ * <tt>gem install allegro4r</tt>
32
+
33
+ == EXAMPLES:
34
+
35
+ See code examples in the examples directory.
36
+
37
+ == HISTORY:
38
+
39
+ See History.txt
40
+
41
+ == LICENSE:
42
+
43
+ (The MIT License)
44
+
45
+ Copyright (c) 2009 Jason Frey
46
+
47
+ Permission is hereby granted, free of charge, to any person obtaining
48
+ a copy of this software and associated documentation files (the
49
+ 'Software'), to deal in the Software without restriction, including
50
+ without limitation the rights to use, copy, modify, merge, publish,
51
+ distribute, sublicense, and/or sell copies of the Software, and to
52
+ permit persons to whom the Software is furnished to do so, subject to
53
+ the following conditions:
54
+
55
+ The above copyright notice and this permission notice shall be
56
+ included in all copies or substantial portions of the Software.
57
+
58
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
59
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
60
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
61
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
62
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
63
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
64
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
65
+
66
+ Except as contained in this notice, the name(s) of the above copyright
67
+ holders shall not be used in advertising or otherwise to promote the
68
+ sale, use, or other dealings in this Software without prior written
69
+ authorization.
70
+
71
+ == ALLEGRO LICENSE:
72
+
73
+ Allegro is gift-ware. It was created by a number of people working in
74
+ cooperation, and is given to you freely as a gift. You may use, modify,
75
+ redistribute, and generally hack it about in any way you like, and you do not
76
+ have to give us anything in return.
77
+
78
+ However, if you like this product you are encouraged to thank us by making a
79
+ return gift to the Allegro community. This could be by writing an add-on
80
+ package, providing a useful bug report, making an improvement to the library,
81
+ or perhaps just releasing the sources of your program so that other people can
82
+ learn from them. If you redistribute parts of this code or make a game using
83
+ it, it would be nice if you mentioned Allegro somewhere in the credits, but
84
+ you are not required to do this. We trust you not to abuse our generosity.
85
+
86
+ By Shawn Hargreaves, 18 October 1998.
87
+
88
+ DISCLAIMER: THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
89
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
90
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT.
91
+ IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE
92
+ LIABLE FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR
93
+ OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
94
+ OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,58 @@
1
+ #
2
+ # Example program (C Version) for the Allegro library, by Shawn Hargreaves.
3
+ # (Ruby port by Jason Frey)
4
+ #
5
+ # This program demonstrates the use of double buffering.
6
+ # It moves a circle across the screen, first just erasing and
7
+ # redrawing directly to the screen, then with a double buffer.
8
+ #
9
+
10
+ require 'rubygems'
11
+ require 'allegro4r'
12
+ include Allegro4r::API
13
+
14
+ exit 1 if allegro_init != 0
15
+ install_timer
16
+ install_keyboard
17
+
18
+ if set_gfx_mode(GFX_AUTODETECT, 320, 200, 0, 0) != 0
19
+ if set_gfx_mode(GFX_SAFE, 320, 200, 0, 0) != 0
20
+ set_gfx_mode(GFX_TEXT, 0, 0, 0, 0)
21
+ allegro_message("Unable to set any graphic mode\n%s\n" % allegro_error)
22
+ exit 1
23
+ end
24
+ end
25
+
26
+ set_palette(desktop_palette)
27
+
28
+ # allocate the memory buffer
29
+ buffer = create_bitmap(SCREEN_W(), SCREEN_H())
30
+
31
+ # First without any buffering...
32
+ # Note use of the global retrace_counter to control the speed. We also
33
+ # compensate screen size (GFX_SAFE) with a virtual 320 screen width.
34
+ clear_keybuf
35
+ c = retrace_count + 32
36
+ while retrace_count - c <= 320 + 32
37
+ acquire_screen
38
+ clear_to_color(screen, makecol(255, 255, 255))
39
+ circlefill(screen, (retrace_count - c) * SCREEN_W()/320, SCREEN_H()/2, 32, makecol(0, 0, 0))
40
+ textprintf_ex(screen, font, 0, 0, makecol(0, 0, 0), -1, "No buffering (%s)" % gfx_driver.name)
41
+ release_screen
42
+
43
+ break if keypressed
44
+ end
45
+
46
+ # and now with a double buffer...
47
+ clear_keybuf
48
+ c = retrace_count + 32;
49
+ while retrace_count - c <= 320 + 32
50
+ clear_to_color(buffer, makecol(255, 255, 255))
51
+ circlefill(buffer, (retrace_count - c) * SCREEN_W()/320, SCREEN_H()/2, 32, makecol(0, 0, 0))
52
+ textprintf_ex(buffer, font, 0, 0, makecol(0, 0, 0), -1, "Double buffered (%s)" % gfx_driver.name)
53
+ blit(buffer, screen, 0, 0, 0, 0, SCREEN_W(), SCREEN_H())
54
+
55
+ break if keypressed
56
+ end
57
+
58
+ destroy_bitmap(buffer)
@@ -0,0 +1,46 @@
1
+ #
2
+ # Example program (C Version) for the Allegro library, by Shawn Hargreaves.
3
+ # (Ruby port by Jason Frey)
4
+ #
5
+ # This program demonstrates how to use fixed point numbers, which
6
+ # are signed 32-bit integers storing the integer part in the
7
+ # upper 16 bits and the decimal part in the 16 lower bits. This
8
+ # example also uses the unusual approach of communicating with
9
+ # the user exclusively via the allegro_message() function.
10
+ #
11
+
12
+ require 'rubygems'
13
+ require 'allegro4r'
14
+ include Allegro4r::API
15
+
16
+ exit 1 if allegro_init != 0
17
+
18
+ # convert integers to fixed point like this
19
+ x = itofix(10)
20
+
21
+ # convert floating point to fixed point like this
22
+ y = ftofix(3.14)
23
+
24
+ # fixed point variables can be assigned, added, subtracted, negated,
25
+ # and compared just like integers, eg:
26
+ z = x + y
27
+ allegro_message("%f + %f = %f\n" % [fixtof(x), fixtof(y), fixtof(z)])
28
+
29
+ # you can't add integers or floating point to fixed point, though:
30
+ # z = x + 3
31
+ # would give the wrong result.
32
+
33
+ # fixed point variables can be multiplied or divided by integers or
34
+ # floating point numbers, eg:
35
+ z = y * 2
36
+ allegro_message("%f * 2 = %f\n" % [fixtof(y), fixtof(z)])
37
+
38
+ # you can't multiply or divide two fixed point numbers, though:
39
+ # z = x * y;
40
+ # would give the wrong result. Use fixmul() and fixdiv() instead, eg:
41
+ z = fixmul(x, y)
42
+ allegro_message("%f * %f = %f\n" % [fixtof(x), fixtof(y), fixtof(z)])
43
+
44
+ # fixed point trig and square root are also available, eg:
45
+ z = fixsqrt(x)
46
+ allegro_message("fixsqrt(%f) = %f\n" % [fixtof(x), fixtof(z)])
@@ -0,0 +1,200 @@
1
+ #
2
+ # Example program (C Version) for the Allegro library, by Shawn Hargreaves.
3
+ # (Ruby port by Jason Frey)
4
+ #
5
+ # This program demonstrates how to write directly to video memory.
6
+ # It implements a simple fire effect, first by calling getpixel() and
7
+ # putpixel(), then by accessing video memory directly a byte at a
8
+ # time, and finally using block memory copy operations.
9
+ #
10
+
11
+ require 'rubygems'
12
+ require 'allegro4r'
13
+ include Allegro4r::API
14
+
15
+ # The fire is formed from several 'hotspots' which are moved randomly
16
+ # across the bottom of the screen.
17
+ FIRE_HOTSPOTS = 48
18
+ $hotspot = Array.new(FIRE_HOTSPOTS, 0)
19
+
20
+ # This function updates the bottom line of the screen with a pattern
21
+ # of varying intensities which are then moved upwards and faded out
22
+ # by the code in main.
23
+ def draw_bottom_line_of_fire
24
+ # zero the buffer
25
+ (0...SCREEN_W()).each do |c|
26
+ $temp[c] = 0
27
+ end
28
+
29
+ (0...FIRE_HOTSPOTS).each do |c|
30
+ ($hotspot[c] - 20...$hotspot[c] + 20).each do |c2|
31
+ if c2 >= 0 && c2 < SCREEN_W()
32
+ $temp[c2] = MIN($temp[c2] + 20 - ABS($hotspot[c] - c2), 192)
33
+ end
34
+ end
35
+
36
+ # move the hotspots
37
+ $hotspot[c] += (AL_RAND() & 7) - 3
38
+ if $hotspot[c] < 0
39
+ $hotspot[c] += SCREEN_W()
40
+ elsif $hotspot[c] >= SCREEN_W()
41
+ $hotspot[c] -= SCREEN_W()
42
+ end
43
+ end
44
+
45
+ # display the buffer
46
+ (0...SCREEN_W()).each do |c|
47
+ putpixel(screen, c, SCREEN_H() - 1, $temp[c])
48
+ end
49
+ end
50
+
51
+ palette = PALETTE.new
52
+
53
+ exit 1 if allegro_init != 0
54
+ install_keyboard
55
+ if set_gfx_mode(GFX_AUTODETECT, 320, 200, 0, 0) != 0
56
+ if set_gfx_mode(GFX_AUTODETECT, 640, 480, 0, 0) != 0
57
+ allegro_message("Error setting graphics mode\n%s\n" % allegro_error)
58
+ exit 1
59
+ end
60
+ end
61
+
62
+ begin
63
+ $temp = "\0" * SCREEN_W()
64
+ rescue NoMemoryError
65
+ set_gfx_mode(GFX_TEXT, 0, 0, 0, 0)
66
+ allegro_message("Not enough memory? This is a joke right!?!\n")
67
+ exit 0
68
+ end
69
+
70
+ (0...FIRE_HOTSPOTS).each do |c|
71
+ $hotspot[c] = AL_RAND() % SCREEN_W()
72
+ end
73
+
74
+ # fill our palette with a gradually altering sequence of colors
75
+ (0...64).each do |c|
76
+ palette[c].r = c;
77
+ palette[c].g = 0;
78
+ palette[c].b = 0;
79
+ end
80
+ (64...128).each do |c|
81
+ palette[c].r = 63;
82
+ palette[c].g = c - 64;
83
+ palette[c].b = 0;
84
+ end
85
+ (128...192).each do |c|
86
+ palette[c].r = 63;
87
+ palette[c].g = 63;
88
+ palette[c].b = c - 128;
89
+ end
90
+ (192...256).each do |c|
91
+ palette[c].r = 63;
92
+ palette[c].g = 63;
93
+ palette[c].b = 63;
94
+ end
95
+
96
+ set_palette(palette)
97
+
98
+ textout_ex(screen, font, "Using get/putpixel", 0, 0, makecol(255,255,255), makecol(0, 0, 0))
99
+
100
+ # using getpixel and putpixel is slow :-)
101
+ while !keypressed
102
+ acquire_screen
103
+
104
+ draw_bottom_line_of_fire
105
+
106
+ (64...SCREEN_H() - 1).each do |y|
107
+ # read line
108
+ (0...SCREEN_W()).each do |x|
109
+ c = getpixel(screen, x, y + 1)
110
+
111
+ c -= 1 if c > 0
112
+
113
+ putpixel(screen, x, y, c)
114
+ end
115
+ end
116
+ release_screen
117
+ end
118
+
119
+ clear_keybuf
120
+ textout_ex(screen, font, "Using direct memory writes", 0, 0, makecol(255,255,255), makecol(0, 0, 0))
121
+
122
+ # It is much faster if we access the screen memory directly. This
123
+ # time we read an entire line of the screen into our own buffer,
124
+ # modify it there, and then write the whole line back in one go.
125
+ # That is to avoid having to keep switching back and forth between
126
+ # different scanlines: if we only copied one pixel at a time, we
127
+ # would have to call bmp_write_line for every single pixel rather
128
+ # than just twice per line.
129
+ while !keypressed
130
+ acquire_screen
131
+ draw_bottom_line_of_fire
132
+
133
+ bmp_select(screen)
134
+
135
+ (64...SCREEN_H() - 1).each do |y|
136
+ # get an address for reading line y+1
137
+ address = bmp_read_line(screen, y + 1)
138
+
139
+ # read line with farptr functions
140
+ (0...SCREEN_W()).each do |x|
141
+ $temp[x] = bmp_read8(address + x)
142
+ end
143
+
144
+ # adjust it
145
+ (0...SCREEN_W()).each do |x|
146
+ $temp[x] -= 1 if $temp[x] > 0
147
+ end
148
+
149
+ # get an address for writing line y
150
+ address = bmp_write_line(screen, y)
151
+
152
+ # write line with farptr functions
153
+ (0...SCREEN_W()).each do |x|
154
+ bmp_write8(address + x, $temp[x,1])
155
+ end
156
+ end
157
+
158
+ bmp_unwrite_line(screen)
159
+ release_screen
160
+ end
161
+
162
+ clear_keybuf
163
+ textout_ex(screen, font, "Using block data transfers", 0, 0, makecol(255,255,255), makecol(0, 0, 0))
164
+
165
+ # It is even faster if we transfer the data in 32 bit chunks, rather
166
+ # than only one pixel at a time. This method may not work on really
167
+ # unusual machine architectures, but should be ok on just about
168
+ # anything that you are practically likely to come across.
169
+ while !keypressed
170
+ acquire_screen
171
+ draw_bottom_line_of_fire
172
+
173
+ bmp_select(screen)
174
+
175
+ (64...SCREEN_H() - 1).each do |y|
176
+ # get an address for reading line y+1
177
+ address = bmp_read_line(screen, y + 1)
178
+
179
+ # read line in 32 bit chunks
180
+ (0...SCREEN_W()).step(4) do |x| # JF - sizeof(uint32_t)
181
+ $temp[x...x + 4] = bmp_read32(address + x)
182
+ end
183
+
184
+ # adjust it
185
+ (0...SCREEN_W()).each do |x|
186
+ $temp[x] -= 1 if $temp[x] > 0
187
+ end
188
+
189
+ # get an address for writing line y
190
+ address = bmp_write_line(screen, y)
191
+
192
+ # write line in 32 bit chunks
193
+ (0...SCREEN_W()).step(4) do |x| # JF - sizeof(uint32_t)
194
+ bmp_write32(address + x, $temp[x...x + 4])
195
+ end
196
+ end
197
+
198
+ bmp_unwrite_line(screen)
199
+ release_screen
200
+ end
@@ -0,0 +1,87 @@
1
+ #
2
+ # Example program (C Version) for the Allegro library, by Shawn Hargreaves.
3
+ # (Ruby port by Jason Frey)
4
+ #
5
+ # This program moves a circle across the screen, first with a
6
+ # double buffer and then using page flips.
7
+ #
8
+
9
+ require 'rubygems'
10
+ require 'allegro4r'
11
+ include Allegro4r::API
12
+
13
+ exit 1 if allegro_init != 0
14
+ install_timer
15
+ install_keyboard
16
+
17
+ # Some platforms do page flipping by making one large screen that you
18
+ # can then scroll, while others give you several smaller, unique
19
+ # surfaces. If you use the create_video_bitmap() function, the same
20
+ # code can work on either kind of platform, but you have to be careful
21
+ # how you set the video mode in the first place. We want two pages of
22
+ # 320x200 video memory, but if we just ask for that, on DOS Allegro
23
+ # might use a VGA driver that won't later be able to give us a second
24
+ # page of vram. But if we ask for the full 320x400 virtual screen that
25
+ # we want, the call will fail when using DirectX drivers that can't do
26
+ # this. So we try two different mode sets, first asking for the 320x400
27
+ # size, and if that doesn't work, for 320x200.
28
+ if set_gfx_mode(GFX_AUTODETECT, 320, 200, 0, 400) != 0
29
+ if set_gfx_mode(GFX_AUTODETECT, 320, 200, 0, 0) != 0
30
+ if set_gfx_mode(GFX_SAFE, 320, 200, 0, 0) != 0
31
+ set_gfx_mode(GFX_TEXT, 0, 0, 0, 0)
32
+ allegro_message("Unable to set any graphic mode\n%s\n" % allegro_error)
33
+ exit 1
34
+ end
35
+ end
36
+ end
37
+
38
+ set_palette(desktop_palette)
39
+
40
+ # allocate the memory buffer
41
+ buffer = create_bitmap(SCREEN_W(), SCREEN_H())
42
+
43
+ # first with a double buffer...
44
+ clear_keybuf
45
+ c = retrace_count + 32
46
+ while retrace_count - c <= SCREEN_W() + 32
47
+ clear_to_color(buffer, makecol(255, 255, 255))
48
+ circlefill(buffer, retrace_count - c, SCREEN_H()/2, 32, makecol(0, 0, 0))
49
+ textprintf_ex(buffer, font, 0, 0, makecol(0, 0, 0), -1, "Double buffered (%s)" % gfx_driver.name)
50
+ blit(buffer, screen, 0, 0, 0, 0, SCREEN_W(), SCREEN_H())
51
+
52
+ break if keypressed
53
+ end
54
+
55
+ destroy_bitmap(buffer)
56
+
57
+ # now create two video memory bitmaps for the page flipping
58
+ page1 = create_video_bitmap(SCREEN_W(), SCREEN_H())
59
+ page2 = create_video_bitmap(SCREEN_W(), SCREEN_H())
60
+
61
+ if page1.nil? || page2.nil?
62
+ set_gfx_mode(GFX_TEXT, 0, 0, 0, 0)
63
+ allegro_message("Unable to create two video memory pages\n")
64
+ exit 1
65
+ end
66
+
67
+ active_page = page2
68
+
69
+ # do the animation using page flips...
70
+ clear_keybuf
71
+ (-32..SCREEN_W() + 32).each do |c|
72
+ clear_to_color(active_page, makecol(255, 255, 255))
73
+ circlefill(active_page, c, SCREEN_H()/2, 32, makecol(0, 0, 0))
74
+ textprintf_ex(active_page, font, 0, 0, makecol(0, 0, 0), -1, "Page flipping (%s)" % gfx_driver.name)
75
+ show_video_bitmap(active_page)
76
+
77
+ if (active_page == page1)
78
+ active_page = page2
79
+ else
80
+ active_page = page1
81
+ end
82
+
83
+ break if keypressed
84
+ end
85
+
86
+ destroy_bitmap(page1)
87
+ destroy_bitmap(page2)
@@ -0,0 +1,70 @@
1
+ #
2
+ # Example program (C version) for the Allegro library, by Evert Glebbeek.
3
+ # (Ruby port by Jason Frey)
4
+ #
5
+ # This is a very simple program showing how to load and manipulate fonts.
6
+ #
7
+
8
+ require 'rubygems'
9
+ require 'allegro4r'
10
+ include Allegro4r::API
11
+
12
+ # you should always do this at the start of Allegro programs
13
+ exit 1 if allegro_init != 0
14
+
15
+ # set up the keyboard handler
16
+ install_keyboard
17
+
18
+ # set a graphics mode sized 320x200
19
+ if set_gfx_mode(GFX_AUTODETECT, 320, 200, 0, 0) != 0
20
+ if set_gfx_mode(GFX_SAFE, 320, 200, 0, 0) != 0
21
+ set_gfx_mode(GFX_TEXT, 0, 0, 0, 0)
22
+ allegro_message("Unable to set any graphic mode\n%s\n" % allegro_error)
23
+ exit 1
24
+ end
25
+ end
26
+
27
+ # set the color palette
28
+ set_palette(desktop_palette)
29
+
30
+ # clear the screen to white
31
+ clear_to_color(screen, makecol(255, 255, 255))
32
+
33
+ # We will use the lower case letters from Allegro's normal font and the
34
+ # uppercase letters from the font in unifont.dat
35
+ f1 = load_font("unifont.dat", nil, nil)
36
+ if f1.nil?
37
+ set_gfx_mode(GFX_TEXT, 0, 0, 0, 0)
38
+ allegro_message("Cannot find unifont.dat in current directory.\n")
39
+ exit 1
40
+ end
41
+
42
+ # Extract character ranges
43
+ f2 = extract_font_range(font, ' '[0], ?A - 1)
44
+ f3 = extract_font_range(f1, ?A, ?Z);
45
+ f4 = extract_font_range(font, ?Z + 1, ?z)
46
+
47
+ # Merge fonts
48
+ Allegro4r::API.font = merge_fonts(f4, f5 = merge_fonts(f2, f3))
49
+
50
+ # Destroy temporary fonts
51
+ destroy_font(f1)
52
+ destroy_font(f2)
53
+ destroy_font(f3)
54
+ destroy_font(f4)
55
+ destroy_font(f5)
56
+
57
+ # you don't need to do this, but on some platforms (eg. Windows) things
58
+ # will be drawn more quickly if you always acquire the screen before
59
+ # trying to draw onto it.
60
+ acquire_screen
61
+
62
+ # write some text to the screen with black letters and transparent
63
+ # background
64
+ textout_centre_ex(screen, font, "Hello, world!", SCREEN_W()/2, SCREEN_H()/2, makecol(0, 0, 0), -1)
65
+
66
+ # you must always release bitmaps before calling any input functions
67
+ release_screen
68
+
69
+ # wait for a key press
70
+ readkey
@@ -0,0 +1,46 @@
1
+ #
2
+ # Example program (C version) for the Allegro library, by Shawn Hargreaves.
3
+ # (Ruby port by Jason Frey)
4
+ #
5
+ # This is a very simple program showing how to get into graphics
6
+ # mode and draw text onto the screen.
7
+ #
8
+
9
+ require 'rubygems'
10
+ require 'allegro4r'
11
+ include Allegro4r::API
12
+
13
+ # you should always do this at the start of Allegro programs
14
+ exit 1 if allegro_init != 0
15
+
16
+ # set up the keyboard handler
17
+ install_keyboard
18
+
19
+ # set a graphics mode sized 320x200
20
+ if set_gfx_mode(GFX_AUTODETECT, 320, 200, 0, 0) != 0
21
+ if set_gfx_mode(GFX_SAFE, 320, 200, 0, 0) != 0
22
+ set_gfx_mode(GFX_TEXT, 0, 0, 0, 0)
23
+ allegro_message("Unable to set any graphic mode\n%s\n" % allegro_error)
24
+ exit 1
25
+ end
26
+ end
27
+
28
+ # set the color palette
29
+ set_palette(desktop_palette)
30
+
31
+ # clear the screen to white
32
+ clear_to_color(screen, makecol(255, 255, 255))
33
+
34
+ # you don't need to do this, but on some platforms (eg. Windows) things
35
+ # will be drawn more quickly if you always acquire the screen before
36
+ # trying to draw onto it.
37
+ acquire_screen
38
+
39
+ # write some text to the screen with black letters and transparent background
40
+ textout_centre_ex(screen, font, "Hello, world!", SCREEN_W()/2, SCREEN_H()/2, makecol(0, 0, 0), -1)
41
+
42
+ # you must always release bitmaps before calling any input functions
43
+ release_screen
44
+
45
+ # wait for a key press
46
+ readkey