rubygame 2.3.0-x86-linux
Sign up to get free protection for your applications and to get access to all the features.
- data/CREDITS +60 -0
- data/LICENSE +504 -0
- data/NEWS +252 -0
- data/README +123 -0
- data/ROADMAP +109 -0
- data/Rakefile +438 -0
- data/doc/extended_readme.rdoc +49 -0
- data/doc/getting_started.rdoc +47 -0
- data/doc/macosx_install.rdoc +70 -0
- data/doc/windows_install.rdoc +123 -0
- data/ext/rubygame/rubygame_core.so +0 -0
- data/ext/rubygame/rubygame_event.c +644 -0
- data/ext/rubygame/rubygame_event.h +48 -0
- data/ext/rubygame/rubygame_event.o +0 -0
- data/ext/rubygame/rubygame_gfx.c +942 -0
- data/ext/rubygame/rubygame_gfx.h +101 -0
- data/ext/rubygame/rubygame_gfx.o +0 -0
- data/ext/rubygame/rubygame_gfx.so +0 -0
- data/ext/rubygame/rubygame_gl.c +154 -0
- data/ext/rubygame/rubygame_gl.h +32 -0
- data/ext/rubygame/rubygame_gl.o +0 -0
- data/ext/rubygame/rubygame_image.c +252 -0
- data/ext/rubygame/rubygame_image.h +41 -0
- data/ext/rubygame/rubygame_image.o +0 -0
- data/ext/rubygame/rubygame_image.so +0 -0
- data/ext/rubygame/rubygame_joystick.c +247 -0
- data/ext/rubygame/rubygame_joystick.h +41 -0
- data/ext/rubygame/rubygame_joystick.o +0 -0
- data/ext/rubygame/rubygame_main.c +155 -0
- data/ext/rubygame/rubygame_main.h +36 -0
- data/ext/rubygame/rubygame_main.o +0 -0
- data/ext/rubygame/rubygame_mixer.c +1024 -0
- data/ext/rubygame/rubygame_mixer.h +36 -0
- data/ext/rubygame/rubygame_mixer.o +0 -0
- data/ext/rubygame/rubygame_mixer.so +0 -0
- data/ext/rubygame/rubygame_music.c +1017 -0
- data/ext/rubygame/rubygame_music.h +29 -0
- data/ext/rubygame/rubygame_music.o +0 -0
- data/ext/rubygame/rubygame_screen.c +448 -0
- data/ext/rubygame/rubygame_screen.h +43 -0
- data/ext/rubygame/rubygame_screen.o +0 -0
- data/ext/rubygame/rubygame_shared.c +272 -0
- data/ext/rubygame/rubygame_shared.h +68 -0
- data/ext/rubygame/rubygame_shared.o +0 -0
- data/ext/rubygame/rubygame_sound.c +863 -0
- data/ext/rubygame/rubygame_sound.h +29 -0
- data/ext/rubygame/rubygame_sound.o +0 -0
- data/ext/rubygame/rubygame_surface.c +1151 -0
- data/ext/rubygame/rubygame_surface.h +62 -0
- data/ext/rubygame/rubygame_surface.o +0 -0
- data/ext/rubygame/rubygame_time.c +183 -0
- data/ext/rubygame/rubygame_time.h +32 -0
- data/ext/rubygame/rubygame_time.o +0 -0
- data/ext/rubygame/rubygame_ttf.c +599 -0
- data/ext/rubygame/rubygame_ttf.h +69 -0
- data/ext/rubygame/rubygame_ttf.o +0 -0
- data/ext/rubygame/rubygame_ttf.so +0 -0
- data/lib/rubygame.rb +41 -0
- data/lib/rubygame/clock.rb +128 -0
- data/lib/rubygame/color.rb +79 -0
- data/lib/rubygame/color/models/base.rb +111 -0
- data/lib/rubygame/color/models/hsl.rb +153 -0
- data/lib/rubygame/color/models/hsv.rb +149 -0
- data/lib/rubygame/color/models/rgb.rb +78 -0
- data/lib/rubygame/color/palettes/css.rb +49 -0
- data/lib/rubygame/color/palettes/palette.rb +100 -0
- data/lib/rubygame/color/palettes/x11.rb +177 -0
- data/lib/rubygame/constants.rb +238 -0
- data/lib/rubygame/event.rb +313 -0
- data/lib/rubygame/ftor.rb +370 -0
- data/lib/rubygame/hotspot.rb +265 -0
- data/lib/rubygame/keyconstants.rb +237 -0
- data/lib/rubygame/mediabag.rb +94 -0
- data/lib/rubygame/named_resource.rb +254 -0
- data/lib/rubygame/queue.rb +288 -0
- data/lib/rubygame/rect.rb +612 -0
- data/lib/rubygame/sfont.rb +223 -0
- data/lib/rubygame/sprite.rb +511 -0
- data/samples/FreeSans.ttf +0 -0
- data/samples/GPL.txt +340 -0
- data/samples/README +40 -0
- data/samples/chimp.bmp +0 -0
- data/samples/chimp.rb +302 -0
- data/samples/demo_gl.rb +151 -0
- data/samples/demo_gl_tex.rb +197 -0
- data/samples/demo_music.rb +77 -0
- data/samples/demo_rubygame.rb +296 -0
- data/samples/demo_sfont.rb +52 -0
- data/samples/demo_ttf.rb +193 -0
- data/samples/demo_utf8.rb +53 -0
- data/samples/fist.bmp +0 -0
- data/samples/load_and_blit.rb +22 -0
- data/samples/panda.png +0 -0
- data/samples/punch.wav +0 -0
- data/samples/ruby.png +0 -0
- data/samples/song.ogg +0 -0
- data/samples/term16.png +0 -0
- data/samples/whiff.wav +0 -0
- data/test/audio_spec.rb +236 -0
- data/test/color_spec.rb +544 -0
- data/test/image.png +0 -0
- data/test/music_spec.rb +727 -0
- data/test/named_resource_spec.rb +211 -0
- data/test/short.ogg +0 -0
- data/test/sound_spec.rb +564 -0
- data/test/surface_spec.rb +219 -0
- data/test/test_crop.rb +45 -0
- data/test/test_rect.rb +841 -0
- metadata +174 -0
@@ -0,0 +1,101 @@
|
|
1
|
+
/*
|
2
|
+
*--
|
3
|
+
* Rubygame -- Ruby code and bindings to SDL to facilitate game creation
|
4
|
+
* Copyright (C) 2004-2007 John Croisant
|
5
|
+
*
|
6
|
+
* This library is free software; you can redistribute it and/or
|
7
|
+
* modify it under the terms of the GNU Lesser General Public
|
8
|
+
* License as published by the Free Software Foundation; either
|
9
|
+
* version 2.1 of the License, or (at your option) any later version.
|
10
|
+
*
|
11
|
+
* This library is distributed in the hope that it will be useful,
|
12
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
14
|
+
* Lesser General Public License for more details.
|
15
|
+
*
|
16
|
+
* You should have received a copy of the GNU Lesser General Public
|
17
|
+
* License along with this library; if not, write to the Free Software
|
18
|
+
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
19
|
+
*++
|
20
|
+
*/
|
21
|
+
|
22
|
+
#ifndef _RUBYGAME_GFX_H
|
23
|
+
#define _RUBYGAME_GFX_H
|
24
|
+
|
25
|
+
#include <SDL_gfxPrimitives.h>
|
26
|
+
#include <SDL_rotozoom.h>
|
27
|
+
|
28
|
+
#ifndef SDL_GFXPRIMITIVES_MAJOR
|
29
|
+
#define SDL_GFXPRIMITIVES_MAJOR 0
|
30
|
+
#endif
|
31
|
+
|
32
|
+
#ifndef SDL_GFXPRIMITIVES_MINOR
|
33
|
+
#define SDL_GFXPRIMITIVES_MINOR 0
|
34
|
+
#endif
|
35
|
+
|
36
|
+
#ifndef SDL_GFXPRIMITIVES_MICRO
|
37
|
+
#define SDL_GFXPRIMITIVES_MICRO 0
|
38
|
+
#endif
|
39
|
+
|
40
|
+
|
41
|
+
/* If we have at least version 2.0.12 of SDL_gfxPrimitives, draw_pie calls
|
42
|
+
filledPieRGBA, otherwise it calls filledpieRGBA (lowercase pie)*/
|
43
|
+
#ifndef HAVE_UPPERCASEPIE
|
44
|
+
#if ((SDL_GFXPRIMITIVES_MAJOR > 2) || (SDL_GFXPRIMITIVES_MAJOR == 2 && SDL_GFXPRIMITIVES_MINOR > 0) || (SDL_GFXPRIMITIVES_MAJOR == 2 && SDL_GFXPRIMITIVES_MINOR == 0 && SDL_GFXPRIMITIVES_MICRO >= 12))
|
45
|
+
#define HAVE_UPPERCASEPIE
|
46
|
+
#endif
|
47
|
+
#endif
|
48
|
+
|
49
|
+
/* Separate X/Y rotozoom scaling was not supported prior to 2.0.13. */
|
50
|
+
/* Check if we have at least version 2.0.13 of SDL_gfxPrimitives */
|
51
|
+
#ifndef HAVE_ROTOZOOMXY
|
52
|
+
#if ((SDL_GFXPRIMITIVES_MAJOR > 2) || (SDL_GFXPRIMITIVES_MAJOR == 2 && SDL_GFXPRIMITIVES_MINOR > 0) || (SDL_GFXPRIMITIVES_MAJOR == 2 && SDL_GFXPRIMITIVES_MINOR == 0 && SDL_GFXPRIMITIVES_MICRO >= 13))
|
53
|
+
#define HAVE_ROTOZOOMXY
|
54
|
+
#endif
|
55
|
+
#endif
|
56
|
+
|
57
|
+
/* Non-filled pie shapes (arcs) were not supported prior to 2.0.11. */
|
58
|
+
/* Check if we have at least version 2.0.11 of SDL_gfxPrimitives */
|
59
|
+
#ifndef HAVE_NONFILLEDPIE
|
60
|
+
#if ((SDL_GFXPRIMITIVES_MAJOR > 2) || (SDL_GFXPRIMITIVES_MAJOR == 2 && SDL_GFXPRIMITIVES_MINOR > 0) || (SDL_GFXPRIMITIVES_MAJOR == 2 && SDL_GFXPRIMITIVES_MINOR == 0 && SDL_GFXPRIMITIVES_MICRO >= 11))
|
61
|
+
#define HAVE_NONFILLEDPIE
|
62
|
+
#endif
|
63
|
+
#endif
|
64
|
+
|
65
|
+
extern void Init_rubygame_gfx();
|
66
|
+
extern void extract_xy(VALUE, Sint16*, Sint16*);
|
67
|
+
|
68
|
+
extern void draw_line(VALUE, VALUE, VALUE, VALUE, int);
|
69
|
+
extern VALUE rbgm_draw_line(VALUE, VALUE, VALUE, VALUE);
|
70
|
+
extern VALUE rbgm_draw_aaline(VALUE, VALUE, VALUE, VALUE);
|
71
|
+
|
72
|
+
extern void draw_rect(VALUE, VALUE, VALUE, VALUE, int);
|
73
|
+
extern VALUE rbgm_draw_rect(VALUE, VALUE, VALUE, VALUE);
|
74
|
+
extern VALUE rbgm_draw_fillrect(VALUE, VALUE, VALUE, VALUE);
|
75
|
+
|
76
|
+
extern void draw_circle(VALUE, VALUE, VALUE, VALUE, int, int);
|
77
|
+
extern VALUE rbgm_draw_circle(VALUE, VALUE, VALUE, VALUE);
|
78
|
+
extern VALUE rbgm_draw_aacircle(VALUE, VALUE, VALUE, VALUE);
|
79
|
+
extern VALUE rbgm_draw_fillcircle(VALUE, VALUE, VALUE, VALUE);
|
80
|
+
|
81
|
+
extern void draw_ellipse(VALUE, VALUE, VALUE, VALUE, int, int);
|
82
|
+
extern VALUE rbgm_draw_ellipse(VALUE, VALUE, VALUE, VALUE);
|
83
|
+
extern VALUE rbgm_draw_aaellipse(VALUE, VALUE, VALUE, VALUE);
|
84
|
+
extern VALUE rbgm_draw_fillellipse(VALUE, VALUE, VALUE, VALUE);
|
85
|
+
|
86
|
+
extern void draw_pie(VALUE, VALUE, VALUE, VALUE, VALUE, int);
|
87
|
+
extern VALUE rbgm_draw_pie(VALUE, VALUE, VALUE, VALUE, VALUE);
|
88
|
+
extern VALUE rbgm_draw_fillpie(VALUE, VALUE, VALUE, VALUE, VALUE);
|
89
|
+
|
90
|
+
extern void draw_polygon(VALUE, VALUE, VALUE, int, int);
|
91
|
+
extern VALUE rbgm_draw_polygon(VALUE, VALUE, VALUE);
|
92
|
+
extern VALUE rbgm_draw_aapolygon(VALUE, VALUE, VALUE);
|
93
|
+
extern VALUE rbgm_draw_fillpolygon(VALUE, VALUE, VALUE);
|
94
|
+
|
95
|
+
extern VALUE rbgm_transform_rotozoom(int, VALUE*, VALUE);
|
96
|
+
extern VALUE rbgm_transform_rotozoomsize(int, VALUE*, VALUE);
|
97
|
+
|
98
|
+
extern VALUE rbgm_transform_zoom(int, VALUE*, VALUE);
|
99
|
+
extern VALUE rbgm_transform_zoomsize(int, VALUE*, VALUE);
|
100
|
+
|
101
|
+
#endif
|
Binary file
|
Binary file
|
@@ -0,0 +1,154 @@
|
|
1
|
+
/*
|
2
|
+
* OpenGL attribute methods.
|
3
|
+
* --
|
4
|
+
* Rubygame -- Ruby classes and bindings to SDL to facilitate game creation
|
5
|
+
* Copyright (C) 2004-2007 John Croisant
|
6
|
+
*
|
7
|
+
* This library is free software; you can redistribute it and/or
|
8
|
+
* modify it under the terms of the GNU Lesser General Public
|
9
|
+
* License as published by the Free Software Foundation; either
|
10
|
+
* version 2.1 of the License, or (at your option) any later version.
|
11
|
+
*
|
12
|
+
* This library is distributed in the hope that it will be useful,
|
13
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
14
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
15
|
+
* Lesser General Public License for more details.
|
16
|
+
*
|
17
|
+
* You should have received a copy of the GNU Lesser General Public
|
18
|
+
* License along with this library; if not, write to the Free Software
|
19
|
+
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
20
|
+
* ++
|
21
|
+
*/
|
22
|
+
|
23
|
+
#include "rubygame_shared.h"
|
24
|
+
#include "rubygame_gl.h"
|
25
|
+
|
26
|
+
/* --
|
27
|
+
* Most code is directly from Ruby/SDL's rubysdl_opengl.c file.
|
28
|
+
*
|
29
|
+
* Many thanks for saving me some time. :)
|
30
|
+
* ++
|
31
|
+
*/
|
32
|
+
|
33
|
+
VALUE mGL;
|
34
|
+
void Rubygame_Init_GL();
|
35
|
+
void Define_GL_Constants();
|
36
|
+
|
37
|
+
#ifdef HAVE_OPENGL
|
38
|
+
|
39
|
+
VALUE rbgm_gl_getattrib(VALUE, VALUE);
|
40
|
+
VALUE rbgm_gl_setattrib(VALUE,VALUE,VALUE);
|
41
|
+
VALUE rbgm_gl_swapbuffers(VALUE);
|
42
|
+
|
43
|
+
/* call-seq:
|
44
|
+
* get_attrib( attrib ) -> Integer
|
45
|
+
*
|
46
|
+
* Return the value of the the SDL/OpenGL attribute identified by +attrib+,
|
47
|
+
* which should be one of the constants defined in the Rubygame::GL module.
|
48
|
+
* See #set_attrib for a list of attribute constants.
|
49
|
+
*
|
50
|
+
* This method is useful after using #set_attrib and calling Screen#set_mode,
|
51
|
+
* to make sure the attribute is the expected value.
|
52
|
+
*/
|
53
|
+
VALUE rbgm_gl_getattrib(VALUE module, VALUE attr)
|
54
|
+
{
|
55
|
+
int val;
|
56
|
+
if(SDL_GL_GetAttribute(NUM2INT(attr),&val)==-1)
|
57
|
+
rb_raise(eSDLError,"GL get attribute failed: %s",SDL_GetError());
|
58
|
+
return INT2NUM(val);
|
59
|
+
}
|
60
|
+
|
61
|
+
/* call-seq:
|
62
|
+
* set_attrib( attrib, value ) -> nil
|
63
|
+
*
|
64
|
+
* Set the SDL/OpenGL attribute +attrib+ to +value+. This should be called
|
65
|
+
* *before* you call Screen#set_mode with the OPENGL flag. You may wish to
|
66
|
+
* use #get_attrib after calling Screen#set_mode to confirm that the attribute
|
67
|
+
* is set to the desired value.
|
68
|
+
*
|
69
|
+
* The full list of SDL/OpenGL attribute identifier constants (located under
|
70
|
+
* the Rubygame::GL module) is as follows:
|
71
|
+
*
|
72
|
+
* RED_SIZE:: Size of framebuffer red component, in bits.
|
73
|
+
* GREEN_SIZE:: Size of framebuffer green component, in bits.
|
74
|
+
* BLUE_SIZE:: Size of framebuffer blue component, in bits.
|
75
|
+
* ALPHA_SIZE:: Size of framebuffer alpha (opacity) component, in bits.
|
76
|
+
* BUFFER_SIZE:: Size of framebuffer, in bits.
|
77
|
+
* DOUBLEBUFFER:: Enable or disable double-buffering.
|
78
|
+
* DEPTH_SIZE:: Size of depth buffer, in bits.
|
79
|
+
* STENCIL_SIZE:: Size of stencil buffer, in bits.
|
80
|
+
* ACCUM_RED_SIZE:: Size of accumulation buffer red component, in bits.
|
81
|
+
* ACCUM_GREEN_SIZE:: Size of accumulation buffer green component, in bits.
|
82
|
+
* ACCUM_BLUE_SIZE:: Size of accumulation buffer blue component, in bits.
|
83
|
+
* ACCUM_ALPHA_SIZE:: Size of accumulation buffer alpha component, in bits.
|
84
|
+
*
|
85
|
+
*/
|
86
|
+
VALUE rbgm_gl_setattrib(VALUE module,VALUE attr,VALUE val)
|
87
|
+
{
|
88
|
+
if(SDL_GL_SetAttribute(NUM2INT(attr),NUM2INT(val))==-1)
|
89
|
+
rb_raise(eSDLError,"GL set attribute failed: %s",SDL_GetError());
|
90
|
+
return Qnil;
|
91
|
+
}
|
92
|
+
|
93
|
+
/* call-seq:
|
94
|
+
* swap_buffers( ) -> nil
|
95
|
+
*
|
96
|
+
* Swap the back and front buffers, for double-buffered OpenGL displays.
|
97
|
+
* Should be safe to use (albeit with no effect) on single-buffered OpenGL
|
98
|
+
* displays.
|
99
|
+
*/
|
100
|
+
VALUE rbgm_gl_swapbuffers(VALUE module)
|
101
|
+
{
|
102
|
+
SDL_GL_SwapBuffers();
|
103
|
+
return Qnil;
|
104
|
+
}
|
105
|
+
|
106
|
+
#endif
|
107
|
+
|
108
|
+
/* Document-module: Rubygame::GL
|
109
|
+
*
|
110
|
+
* The GL module provides an interface to SDL's OpenGL-related functions,
|
111
|
+
* allowing a Rubygame application to create hardware-accelerated 3D graphics
|
112
|
+
* with OpenGL.
|
113
|
+
*
|
114
|
+
* Please note that Rubygame itself does not provide an interface to OpenGL
|
115
|
+
* functions -- only functions which allow Rubygame to work together with
|
116
|
+
* OpenGL. You will need to use another library, for example
|
117
|
+
* ruby-opengl[http://ruby-opengl.rubyforge.org/],
|
118
|
+
* to actually create graphics with OpenGL.
|
119
|
+
*
|
120
|
+
* Users who wish to use Rubygame Surfaces as textures in OpenGL should
|
121
|
+
* see also the Surface#pixels method.
|
122
|
+
*/
|
123
|
+
void Rubygame_Init_GL()
|
124
|
+
{
|
125
|
+
#if 0
|
126
|
+
mRubygame = rb_define_module("Rubygame");
|
127
|
+
#endif
|
128
|
+
|
129
|
+
mGL = rb_define_module_under(mRubygame,"GL");
|
130
|
+
Define_GL_Constants();
|
131
|
+
|
132
|
+
#ifdef HAVE_OPENGL
|
133
|
+
rb_define_module_function(mGL,"get_attrib", rbgm_gl_getattrib, 1);
|
134
|
+
rb_define_module_function(mGL,"set_attrib", rbgm_gl_setattrib, 2);
|
135
|
+
rb_define_module_function(mGL,"swap_buffers", rbgm_gl_swapbuffers, 0);
|
136
|
+
#endif
|
137
|
+
|
138
|
+
}
|
139
|
+
|
140
|
+
void Define_GL_Constants()
|
141
|
+
{
|
142
|
+
rb_define_const(mGL,"RED_SIZE",INT2NUM(SDL_GL_RED_SIZE));
|
143
|
+
rb_define_const(mGL,"GREEN_SIZE",INT2NUM(SDL_GL_GREEN_SIZE));
|
144
|
+
rb_define_const(mGL,"BLUE_SIZE",INT2NUM(SDL_GL_BLUE_SIZE));
|
145
|
+
rb_define_const(mGL,"ALPHA_SIZE",INT2NUM(SDL_GL_ALPHA_SIZE));
|
146
|
+
rb_define_const(mGL,"BUFFER_SIZE",INT2NUM(SDL_GL_BUFFER_SIZE));
|
147
|
+
rb_define_const(mGL,"DOUBLEBUFFER",INT2NUM(SDL_GL_DOUBLEBUFFER));
|
148
|
+
rb_define_const(mGL,"DEPTH_SIZE",INT2NUM(SDL_GL_DEPTH_SIZE));
|
149
|
+
rb_define_const(mGL,"STENCIL_SIZE",INT2NUM(SDL_GL_STENCIL_SIZE));
|
150
|
+
rb_define_const(mGL,"ACCUM_RED_SIZE",INT2NUM(SDL_GL_ACCUM_RED_SIZE));
|
151
|
+
rb_define_const(mGL,"ACCUM_GREEN_SIZE",INT2NUM(SDL_GL_ACCUM_GREEN_SIZE));
|
152
|
+
rb_define_const(mGL,"ACCUM_BLUE_SIZE",INT2NUM(SDL_GL_ACCUM_BLUE_SIZE));
|
153
|
+
rb_define_const(mGL,"ACCUM_ALPHA_SIZE",INT2NUM(SDL_GL_ACCUM_ALPHA_SIZE));
|
154
|
+
}
|
@@ -0,0 +1,32 @@
|
|
1
|
+
/*
|
2
|
+
* Rubygame -- Ruby code and bindings to SDL to facilitate game creation
|
3
|
+
* Copyright (C) 2004-2007 John Croisant
|
4
|
+
*
|
5
|
+
* This library is free software; you can redistribute it and/or
|
6
|
+
* modify it under the terms of the GNU Lesser General Public
|
7
|
+
* License as published by the Free Software Foundation; either
|
8
|
+
* version 2.1 of the License, or (at your option) any later version.
|
9
|
+
*
|
10
|
+
* This library is distributed in the hope that it will be useful,
|
11
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
13
|
+
* Lesser General Public License for more details.
|
14
|
+
*
|
15
|
+
* You should have received a copy of the GNU Lesser General Public
|
16
|
+
* License along with this library; if not, write to the Free Software
|
17
|
+
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
18
|
+
*
|
19
|
+
*/
|
20
|
+
|
21
|
+
#ifndef _RUBYGAME_GL_H
|
22
|
+
#define _RUBYGAME_GL_H
|
23
|
+
|
24
|
+
extern VALUE mGL;
|
25
|
+
extern void Rubygame_Init_GL();
|
26
|
+
extern void Define_GL_Constants();
|
27
|
+
|
28
|
+
extern VALUE rbgm_gl_getattrib(VALUE, VALUE);
|
29
|
+
extern VALUE rbgm_gl_setattrib(VALUE,VALUE,VALUE);
|
30
|
+
extern VALUE rbgm_gl_swapbuffers(VALUE);
|
31
|
+
|
32
|
+
#endif
|
Binary file
|
@@ -0,0 +1,252 @@
|
|
1
|
+
/*
|
2
|
+
* Interface to SDL_image library, for loading image files to Surfaces.
|
3
|
+
*--
|
4
|
+
* Rubygame -- Ruby code and bindings to SDL to facilitate game creation
|
5
|
+
* Copyright (C) 2004-2007 John Croisant
|
6
|
+
*
|
7
|
+
* This library is free software; you can redistribute it and/or
|
8
|
+
* modify it under the terms of the GNU Lesser General Public
|
9
|
+
* License as published by the Free Software Foundation; either
|
10
|
+
* version 2.1 of the License, or (at your option) any later version.
|
11
|
+
*
|
12
|
+
* This library is distributed in the hope that it will be useful,
|
13
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
14
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
15
|
+
* Lesser General Public License for more details.
|
16
|
+
*
|
17
|
+
* You should have received a copy of the GNU Lesser General Public
|
18
|
+
* License along with this library; if not, write to the Free Software
|
19
|
+
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
20
|
+
*++
|
21
|
+
*/
|
22
|
+
|
23
|
+
#include "rubygame_shared.h"
|
24
|
+
#include "rubygame_surface.h"
|
25
|
+
#include "rubygame_image.h"
|
26
|
+
|
27
|
+
void Rubygame_Init_Image();
|
28
|
+
VALUE rbgm_image_load(VALUE, VALUE);
|
29
|
+
VALUE rbgm_from_string(int, VALUE*, VALUE);
|
30
|
+
|
31
|
+
/*
|
32
|
+
* call-seq:
|
33
|
+
* Surface.load_image( filename ) -> Surface
|
34
|
+
*
|
35
|
+
* **NOTE:** This method name is DEPRECATED and will be removed in
|
36
|
+
* Rubygame 3.0. Please use the Surface.load instead.
|
37
|
+
*
|
38
|
+
* Load an image file from the disk to a Surface. If the image has an alpha
|
39
|
+
* channel (e.g. PNG with transparency), the Surface will as well. If the
|
40
|
+
* image cannot be loaded (for example if the image format is unsupported),
|
41
|
+
* will raise SDLError.
|
42
|
+
*
|
43
|
+
* This method is only usable if Rubygame was compiled with the SDL_image
|
44
|
+
* library; you can check Rubygame::VERSIONS[:sdl_image] to see if it was.
|
45
|
+
*
|
46
|
+
* This method takes this argument:
|
47
|
+
* filename:: a string containing the relative or absolute path to the
|
48
|
+
* image file. The file must have the proper file extension,
|
49
|
+
* as it is used to determine image format.
|
50
|
+
*
|
51
|
+
* These formats may be supported, but some may not be available on a
|
52
|
+
* particular system.
|
53
|
+
* BMP:: "Windows Bitmap" format.
|
54
|
+
* GIF:: "Graphics Interchange Format."
|
55
|
+
* JPG:: "Independent JPEG Group" format.
|
56
|
+
* LBM:: "Linear Bitmap" format (?)
|
57
|
+
* PCX:: "PC Paintbrush" format
|
58
|
+
* PNG:: "Portable Network Graphics" format.
|
59
|
+
* PNM:: "Portable Any Map" format. (i.e., PPM, PGM, or PBM)
|
60
|
+
* TGA:: "Truevision TARGA" format.
|
61
|
+
* TIF:: "Tagged Image File Format"
|
62
|
+
* XCF:: "eXperimental Computing Facility" (GIMP native format).
|
63
|
+
* XPM:: "XPixMap" format.
|
64
|
+
*/
|
65
|
+
VALUE rbgm_image_load_image( VALUE class, VALUE filename )
|
66
|
+
{
|
67
|
+
|
68
|
+
/* This feature will be removed in Rubygame 3.0. */
|
69
|
+
rg_deprecated("Rubygame::Surface.load_image", "3.0");
|
70
|
+
|
71
|
+
char *name;
|
72
|
+
SDL_Surface *surf;
|
73
|
+
|
74
|
+
name = StringValuePtr(filename);
|
75
|
+
surf = IMG_Load( name );
|
76
|
+
if(surf == NULL)
|
77
|
+
{
|
78
|
+
rb_raise(eSDLError,"Couldn't load image `%s': %s", name, IMG_GetError());
|
79
|
+
}
|
80
|
+
return Data_Wrap_Struct( cSurface,0,SDL_FreeSurface,surf );
|
81
|
+
}
|
82
|
+
|
83
|
+
/*
|
84
|
+
* call-seq:
|
85
|
+
* Surface.load( filename ) -> Surface
|
86
|
+
*
|
87
|
+
* Load an image file from the disk to a Surface. If the image has an alpha
|
88
|
+
* channel (e.g. PNG with transparency), the Surface will as well. If the
|
89
|
+
* image cannot be loaded (for example if the image format is unsupported),
|
90
|
+
* will raise SDLError.
|
91
|
+
*
|
92
|
+
* This method is only usable if Rubygame was compiled with the SDL_image
|
93
|
+
* library; you can check Rubygame::VERSIONS[:sdl_image] to see if it was.
|
94
|
+
*
|
95
|
+
* This method takes this argument:
|
96
|
+
* filename:: a string containing the relative or absolute path to the
|
97
|
+
* image file. The file must have the proper file extension,
|
98
|
+
* as it is used to determine image format.
|
99
|
+
*
|
100
|
+
* These formats may be supported, but some may not be available on a
|
101
|
+
* particular system.
|
102
|
+
* BMP:: "Windows Bitmap" format.
|
103
|
+
* GIF:: "Graphics Interchange Format."
|
104
|
+
* JPG:: "Independent JPEG Group" format.
|
105
|
+
* LBM:: "Linear Bitmap" format (?)
|
106
|
+
* PCX:: "PC Paintbrush" format
|
107
|
+
* PNG:: "Portable Network Graphics" format.
|
108
|
+
* PNM:: "Portable Any Map" format. (i.e., PPM, PGM, or PBM)
|
109
|
+
* TGA:: "Truevision TARGA" format.
|
110
|
+
* TIF:: "Tagged Image File Format"
|
111
|
+
* XCF:: "eXperimental Computing Facility" (GIMP native format).
|
112
|
+
* XPM:: "XPixMap" format.
|
113
|
+
*/
|
114
|
+
VALUE rbgm_image_load( VALUE class, VALUE filename )
|
115
|
+
{
|
116
|
+
char *name;
|
117
|
+
SDL_Surface *surf;
|
118
|
+
|
119
|
+
name = StringValuePtr(filename);
|
120
|
+
surf = IMG_Load( name );
|
121
|
+
if(surf == NULL)
|
122
|
+
{
|
123
|
+
rb_raise(eSDLError,"Couldn't load image `%s': %s", name, IMG_GetError());
|
124
|
+
}
|
125
|
+
return Data_Wrap_Struct( cSurface,0,SDL_FreeSurface,surf );
|
126
|
+
}
|
127
|
+
|
128
|
+
|
129
|
+
/*
|
130
|
+
* call-seq:
|
131
|
+
* Surface.autoload( filename ) -> Surface or nil
|
132
|
+
*
|
133
|
+
* Searches each directory in Surface.autoload_dirs for a file with
|
134
|
+
* the given filename. If it finds that file, loads it and returns
|
135
|
+
* a Surface instance. If it doesn't find the file, returns nil.
|
136
|
+
*
|
137
|
+
* See Rubygame::NamedResource for more information about this
|
138
|
+
* functionality.
|
139
|
+
*
|
140
|
+
*/
|
141
|
+
VALUE rbgm_image_autoload( VALUE class, VALUE namev )
|
142
|
+
{
|
143
|
+
VALUE pathv = rb_funcall( class, rb_intern("find_file"), 1, namev );
|
144
|
+
|
145
|
+
if( RTEST(pathv) )
|
146
|
+
{
|
147
|
+
return rbgm_image_load( class, pathv );
|
148
|
+
}
|
149
|
+
else
|
150
|
+
{
|
151
|
+
return Qnil;
|
152
|
+
}
|
153
|
+
}
|
154
|
+
|
155
|
+
/*
|
156
|
+
* call-seq:
|
157
|
+
* Surface.load_from_string( data [,type] ) -> Surface
|
158
|
+
*
|
159
|
+
* Load an image file from memory (in the form of the given data) to a Surface.
|
160
|
+
* If the image has an alpha channel (e.g. PNG with transparency), the Surface
|
161
|
+
* will as well. If the image cannot be loaded (for example if the image
|
162
|
+
* format is unsupported), will raise SDLError.
|
163
|
+
*
|
164
|
+
* This method is only usable if Rubygame was compiled with the SDL_image
|
165
|
+
* library; you can check Rubygame::VERSIONS[:sdl_image] to see if it was.
|
166
|
+
*
|
167
|
+
* This method takes these arguments:
|
168
|
+
* data:: a string containing the data for the image, such as IO::read would
|
169
|
+
* return.
|
170
|
+
* type:: The type of file that the image is (i.e. 'TGA'). Case is not
|
171
|
+
* important. If absent, the library will try to automatically
|
172
|
+
* detect the type.
|
173
|
+
*
|
174
|
+
* These formats may be supported, but some may not be available on a
|
175
|
+
* particular system.
|
176
|
+
* BMP:: "Windows Bitmap" format.
|
177
|
+
* GIF:: "Graphics Interchange Format."
|
178
|
+
* JPG:: "Independent JPEG Group" format.
|
179
|
+
* LBM:: "Linear Bitmap" format (?)
|
180
|
+
* PCX:: "PC Paintbrush" format
|
181
|
+
* PNG:: "Portable Network Graphics" format.
|
182
|
+
* PNM:: "Portable Any Map" format. (i.e., PPM, PGM, or PBM)
|
183
|
+
* TGA:: "Truevision TARGA" format.
|
184
|
+
* TIF:: "Tagged Image File Format"
|
185
|
+
* XCF:: "eXperimental Computing Facility" (GIMP native format).
|
186
|
+
* XPM:: "XPixMap" format.
|
187
|
+
*/
|
188
|
+
VALUE rbgm_image_load_from_string( int argc, VALUE *argv, VALUE obj)
|
189
|
+
{
|
190
|
+
Check_Type(argv[0], T_STRING);
|
191
|
+
/* There's probably a better way of using a string as raw data than this,
|
192
|
+
* but I don't know it. */
|
193
|
+
void *raw = (void *)RSTRING_PTR(argv[0]);
|
194
|
+
int len = RSTRING_LEN(argv[0]);
|
195
|
+
|
196
|
+
SDL_RWops *rw = SDL_RWFromMem(raw,len);
|
197
|
+
|
198
|
+
SDL_Surface *surf;
|
199
|
+
if(argc > 1) {
|
200
|
+
Check_Type(argv[1], T_STRING);
|
201
|
+
surf = IMG_LoadTyped_RW(rw, 1,StringValuePtr(argv[1]));
|
202
|
+
} else {
|
203
|
+
surf = IMG_Load_RW(rw,1);
|
204
|
+
}
|
205
|
+
|
206
|
+
if(surf == NULL)
|
207
|
+
{
|
208
|
+
rb_raise(eSDLError,"Couldn't load image from string: %s", IMG_GetError());
|
209
|
+
}
|
210
|
+
return Data_Wrap_Struct( cSurface, 0, SDL_FreeSurface, surf);
|
211
|
+
}
|
212
|
+
|
213
|
+
/*
|
214
|
+
* Document-class: Rubygame::Surface
|
215
|
+
*
|
216
|
+
* Surface represents an image, a block of colored pixels arranged in a 2D grid.
|
217
|
+
* You can load image files to a new Surface with #load_image, or create
|
218
|
+
* an empty one with Surface.new and draw shapes on it with #draw_line,
|
219
|
+
* #draw_circle, and all the rest.
|
220
|
+
*
|
221
|
+
* One of the most important Surface concepts is #blit, copying image
|
222
|
+
* data from one Surface onto another. By blitting Surfaces onto the
|
223
|
+
* Screen (which is a special type of Surface) and then using Screen#update,
|
224
|
+
* you can make images appear for the player to see.
|
225
|
+
*
|
226
|
+
* As of Rubygame 2.3.0, Surface includes the Rubygame::NamedResource mixin
|
227
|
+
* module, which can perform autoloading of images on demand, among other
|
228
|
+
* things.
|
229
|
+
*/
|
230
|
+
void Init_rubygame_image()
|
231
|
+
{
|
232
|
+
|
233
|
+
#if 0
|
234
|
+
mRubygame = rb_define_module("Rubygame");
|
235
|
+
cSurface = rb_define_class_under(mRubygame,"Surface",rb_cObject);
|
236
|
+
#endif
|
237
|
+
|
238
|
+
Init_rubygame_shared();
|
239
|
+
|
240
|
+
rb_hash_aset(rb_ivar_get(mRubygame,rb_intern("VERSIONS")),
|
241
|
+
ID2SYM(rb_intern("sdl_image")),
|
242
|
+
rb_ary_new3(3,
|
243
|
+
INT2NUM(SDL_IMAGE_MAJOR_VERSION),
|
244
|
+
INT2NUM(SDL_IMAGE_MINOR_VERSION),
|
245
|
+
INT2NUM(SDL_IMAGE_PATCHLEVEL)));
|
246
|
+
|
247
|
+
/* Image methods */
|
248
|
+
rb_define_singleton_method(cSurface, "load_image", rbgm_image_load_image, 1);
|
249
|
+
rb_define_singleton_method(cSurface, "load", rbgm_image_load, 1);
|
250
|
+
rb_define_singleton_method(cSurface, "autoload", rbgm_image_autoload, 1);
|
251
|
+
rb_define_singleton_method(cSurface, "load_from_string", rbgm_image_load_from_string, -1);
|
252
|
+
}
|