Cleaned folder

git-svn-id: https://sfml.svn.sourceforge.net/svnroot/sfml/branches/sfml2@1588 4e206d99-4929-0410-ac5d-dfc041789085
This commit is contained in:
groogy 2010-11-02 10:10:38 +00:00
parent b7fc208177
commit b1a9967d56
78 changed files with 0 additions and 33618 deletions

View File

@ -1,41 +0,0 @@
RubySFML - Copyright (c) 2007 Sean O'Neil and Laurent Gomila
RubySFML relies on a lot of third-party open-source software, and since it is
a library itself, I need to make sure everyone who uses it is aware of the
various licenses it comes with, as well as to give credit where credit is due.
If you distribute applications that use RubySFML, you may also be required to
give credit where credit is due.
*** Third-party software ***
Ruby 1.8.6 - Ruby license
RubyGems 0.9.4 - Ruby license
ruby-opengl - MIT license
SFML - zlib/png license
zlib - zlib/png license
Freetype - Freetype license (BSD-style with a credit clause)
OpenAL - LGPL license
DevIL - LGPL license
libsndfile - LGPL license
*** The RubySFML library itself (zlib/png) ***
This software is provided 'as-is', without any express or
implied warranty. In no event will the authors be held
liable for any damages arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute
it freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented;
you must not claim that you wrote the original software.
If you use this software in a product, an acknowledgment
in the product documentation would be appreciated but
is not required.
2. Altered source versions must be plainly marked as such,
and must not be misrepresented as being the original software.
3. This notice may not be removed or altered from any
source distribution.

View File

@ -1,28 +0,0 @@
To build/run RubySFML in Windows:
1) Install Ruby for Windows using the one-click installer.
(RubySFML can't use it until it starts being built with VS 2005,
but it needs to be installed to run the Rakefile.)
2) Run "gem install rake" to install Ruby's version of make.
3) Open a DOS box to this folder.
4) Make sure all the VS2005 environment vars are set. If necessary, run:
<VS2005 Path>\VC\bin\vcvars32.bat
5) Run "rake" in this folder. The default build target will:
* Download/unpack/compile/install the ruby-1.8.6 source tarball.
* Install Ruby Gems (not strictly necessary, but everyone will want it).
* Configure/compile/install the RubySFML extension.
* Build RubySFML.zip with everything you need to distribute Windows binaries.
(At under 3.7MB, it has all the Ruby bins/libs plus all the SFML bins.)
6) At this point you can use any of these commands to run the test program:
* test.bat
* rake test
* bin\ruby test.rb
NOTE: This build of Ruby does not have all the extensions included in the
one-click installer. Some notable ones missing at the moment are
DBI, OpenSSL, and Expat.

View File

@ -1,28 +0,0 @@
Pour compiler/utiliser RubySFML sous Windows :
1) Installez Ruby pour Windows en utilisant l'installeur "one-click" (sur le site officiel de Ruby).
(RubySFML ne peut pas l'utiliser car elle doit être recompilée avec VS 2005,
mais il doit tout de même être installé afin de pouvoir exécuter le Rakefile)
2) Exécutez la commande "gem install rake" pour installer la version Ruby de make.
3) Ouvrez une invite de commande DOS depuis ce répertoire
4) Assurez-vous que les variables d'environnement pour VS 2005 sont correctement définies. Si nécessaire, exécutez le
fichier suivant :
<Chemin VS2005>\VC\bin\vcvars32.bat
5) Exécutez la commande "rake" depuis ce répertoire. La compilation par défaut va :
* Télécharger / décompresser / compiler / installer Ruby 1.8.6
* Installer Ruby Gems (pas strictement nécessaire, mais à peu près tout le monde en aura besoin)
* Configurer / compiler / installer RubySFML
* Construire RubySFML.zip avec tout ce dont vous avez besoin pour distribuer vos binaires Windows.
(Avec moins de 3.7 Mo, il contient tous les binaires et bibliothèques Ruby plus tous les binaires SFML)
6) Maintenant, vous pouvez utiliser l'une de ces 3 commandes pour exécuter le programme de test :
* test.bat
* rake test
* bin\ruby test.rb
NOTE : Cette compilation de Ruby ne contient pas toutes les extensions de l'installeur "one-click".
Parmi les plus importantes manquantes, on peut noter DBI, OpenSSL et Expat.

View File

@ -1,167 +0,0 @@
# Rake doc: http://rake.rubyforge.org/files/doc/rakefile_rdoc.html
require 'rake'
require 'net/ftp'
require 'net/http'
require 'uri'
include Rake
ENV["RUBYOPT"] = nil
EXTENSION = "RubySFML"
RUBY_VER = "ruby-1.8.6-p111"
GEMS_VER = "rubygems-0.9.4"
ROOT_DIR = Dir.pwd
RUBY_DIR = "#{ROOT_DIR}/#{RUBY_VER}"
GEMS_DIR = "#{ROOT_DIR}/#{GEMS_VER}"
EXTENSION_DIR = "#{ROOT_DIR}/#{EXTENSION}"
RUBY_URL = "ftp://ftp.ruby-lang.org/pub/ruby/1.8/#{RUBY_VER}.tar.gz"
# These are needed to build Ruby's zlib extension
raise "You forgot to run vcvars32.bat!" unless ENV['INCLUDE'] and ENV['LIB']
ENV['INCLUDE'] += ";#{ROOT_DIR}/../extlibs/headers;#{ROOT_DIR}/zlib"
ENV['LIB'] += ";#{ROOT_DIR}/../extlibs/libs-vc2005;#{ROOT_DIR}/zlib"
# Need this for the Unix utils, like gzip.exe and tar.exe, to run
ENV['PATH'] += ";#{ROOT_DIR}"
desc "Deletes all compiled and installed Ruby files for a clean rebuild"
task :cleanRuby do |t|
rm_r "bin" rescue nil
rm_r "lib" rescue nil
rm_r "man" rescue nil
rm_r RUBY_DIR rescue nil
rm_r GEMS_DIR rescue nil
rm "#{RUBY_VER}.tar" rescue nil
rm "#{RUBY_VER}.tar.gz" rescue nil
end
desc "Gets the Ruby source code from the FTP server"
task :getRuby do |t|
tar = "#{RUBY_VER}.tar"
tgz = "#{tar}.gz"
unless File.exists?(tar) or File.exists?(tgz)
puts "Downloading #{RUBY_URL}. Please wait..."
Net::FTP.open("ftp.ruby-lang.org") do |ftp|
ftp.login
files = ftp.chdir("pub/ruby/1.8")
ftp.getbinaryfile(tgz, tgz)
end
end
end
desc "Unpacks the Ruby source tarball"
task :unpackRuby => [:getRuby] do |t|
unless File.exists?(RUBY_DIR)
tar = "#{RUBY_VER}.tar"
tgz = "#{tar}.gz"
sh "gzip", "-d", tgz if File.exists?(tgz)
sh "tar", "-xvf", tar
end
unless File.exists?(GEMS_DIR)
sh "unzip", "#{GEMS_VER}.zip"
end
end
desc "Builds ruby.exe from the source code"
task :buildRuby => [:unpackRuby] do |t|
unless File.exists? "#{RUBY_DIR}/ruby.exe"
Dir.chdir RUBY_DIR
sh "win32\\configure.bat", "--target=i686-mswin32"
sh "nmake"
Dir.chdir ROOT_DIR
end
end
desc "Installs #{RUBY_VER} and copies the extlibs into the bin folder"
task :installRuby => [:buildRuby] do |t|
unless File.exists? "#{ROOT_DIR}/bin/ruby.exe"
Dir.chdir RUBY_DIR
sh "nmake", "DESTDIR=\"#{ROOT_DIR}\"", "install"
Dir.chdir ROOT_DIR
end
unless File.exists? "bin/zlib1.dll"
cp Dir["../extlibs/bin/*.dll"], "bin"
cp Dir["zlib/*.dll"], "bin"
cp "#{RUBY_DIR}/.ext/i386-mswin32_80/zlib.so", "lib/ruby/1.8/i386-mswin32"
end
unless File.exists? "#{ROOT_DIR}/lib/ruby/site_ruby/1.8/rubygems.rb"
Dir.chdir GEMS_DIR
sh "../bin/ruby.exe", "setup.rb"
rm_r "#{ROOT_DIR}/lib/ruby/gems/1.8/doc/rubygems-0.9.4" rescue nil
Dir.chdir ROOT_DIR
end
end
desc "Deletes all compiled and installed RubySFML files for a clean rebuild"
task :cleanExtension do |t|
dirs = [EXTENSION_DIR, "#{ROOT_DIR}/RubyOpenGL/gl", "#{ROOT_DIR}/RubyOpenGL/glu"]
dirs.each {|d|
rm Dir["#{d}/*.so"]
rm Dir["#{d}/*.def"]
rm Dir["#{d}/*.pdb"]
rm Dir["#{d}/*.lib"]
rm Dir["#{d}/*.exp"]
rm Dir["#{d}/*.log"]
rm Dir["#{d}/*.obj"]
rm "#{d}/Makefile" rescue nil
}
rm "#{ROOT_DIR}/lib/ruby/site_ruby/1.8/i386-msvcr80/RubySFML.so" rescue nil
rm "#{ROOT_DIR}/lib/ruby/site_ruby/1.8/i386-msvcr80/gl.so" rescue nil
rm "#{ROOT_DIR}/lib/ruby/site_ruby/1.8/i386-msvcr80/glu.so" rescue nil
end
desc "Builds the SFMLRuby extension"
task :buildExtension => [:installRuby] do |t|
unless File.exists? "#{ROOT_DIR}/lib/ruby/site_ruby/1.8/i386-msvcr80/gl.so" and File.exists? "#{ROOT_DIR}/lib/ruby/site_ruby/1.8/i386-msvcr80/glu.so"
Dir.chdir "#{ROOT_DIR}/RubyOpenGL/gl"
sh "../../bin/ruby.exe", "extconf.rb"
sh "nmake"
cp "gl.so", "#{ROOT_DIR}/lib/ruby/site_ruby/1.8/i386-msvcr80"
Dir.chdir "#{ROOT_DIR}/RubyOpenGL/glu"
sh "../../bin/ruby.exe", "extconf.rb"
sh "nmake"
cp "glu.so", "#{ROOT_DIR}/lib/ruby/site_ruby/1.8/i386-msvcr80"
Dir.chdir ROOT_DIR
end
inc = "../../include"
lib = "../../lib/vc2005"
ext = "#{EXTENSION_DIR}/RubySFML.so"
File.delete(ext) unless uptodate?(ext, Dir["../lib/vc2005/*.lib"]) rescue nil
Dir.chdir EXTENSION_DIR
sh "../bin/ruby.exe", "extconf-win.rb", "--with-SFML-include=#{inc}", "--with-SFML-lib=#{lib}"
sh "nmake"
cp "RubySFML.so", "#{ROOT_DIR}/lib/ruby/site_ruby/1.8/i386-msvcr80"
cp "RubySFML.rb", "#{ROOT_DIR}/lib/ruby/site_ruby/1.8"
Dir.chdir ROOT_DIR
end
desc "Builds everything and runs test.rb"
task :test => [:buildExtension] do |t|
Dir.chdir "#{ROOT_DIR}/test"
sh "../bin/ruby.exe", "test.rb"
Dir.chdir ROOT_DIR
end
desc "Zips up the compiled binaries for distribution"
task :package => [:buildExtension] do |t|
sh "zip", "-r", "RubySFML.zip", "LICENSE.txt", "bin", "doc", "lib", "test"
end
desc "Deletes all files generated by this build"
task :clean => [:cleanExtension, :cleanRuby] do |t|
rm "RubySFML.zip" rescue nil
end
desc "Deletes and rebuilds everything"
task :rebuild => [:clean, :package] do |t|
rm "RubySFML.zip" rescue nil
end
desc "(Same as 'rake package')"
task :default => [:package]

View File

@ -1,333 +0,0 @@
/*
* Last edit by previous maintainer:
* 2000/01/06 16:37:43, kusano
*
* Copyright (C) 1999 - 2005 Yoshi <yoshi@giganet.net>
* Copyright (C) 2006 John M. Gabriele <jmg3000@gmail.com>
* Copyright (C) 2007 James Adam <james@lazyatom.com>
*
* This program is distributed under the terms of the MIT license.
* See the included MIT-LICENSE file for the terms of this license.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef _RBOGL_H_
#define _RBOGL_H_
#include <ruby.h>
#ifdef __APPLE__
#include <OpenGL/gl.h>
#include <mach-o/dyld.h>
#include <stdlib.h>
#include <string.h>
#elif defined WIN32
#include <windows.h>
#include <GL/gl.h>
#else
#include <GL/gl.h>
#include <GL/glx.h>
#endif
#include "gl-enums.h"
#ifdef __APPLE__
#ifndef APIENTRY
#define APIENTRY /* to nothing */
#endif
#endif
typedef struct RArray RArray;
extern VALUE cProc;
#define LOAD_GL_FUNC(_NAME_) \
if (fptr_##_NAME_==NULL) \
fptr_##_NAME_ = load_gl_function(#_NAME_, 1);
#define FORCE_PIXEL_STORE_MODE \
glPushClientAttrib(GL_CLIENT_PIXEL_STORE_BIT); \
glPixelStorei(GL_PACK_ALIGNMENT, 1); \
glPixelStorei(GL_PACK_SKIP_PIXELS, 0); \
glPixelStorei(GL_PACK_SKIP_ROWS, 0); \
glPixelStorei(GL_PACK_ROW_LENGTH, 0); \
glPixelStorei(GL_PACK_SKIP_IMAGES, 0); \
glPixelStorei(GL_PACK_IMAGE_HEIGHT, 0);
/* glPixelStorei(GL_PACK_SKIP_VOLUMES_SGIS, 0);
glPixelStorei(GL_PACK_IMAGE_DEPTH_SGIS, 0); */
#define RESTORE_PIXEL_STORE_MODE \
glPopClientAttrib();
/* -------------------------------------------------------------------- */
#ifndef NUM2DBL
#define NUM2DBL(_val) num2double(_val)
static inline double num2double( VALUE val )
{
struct RFloat* flt;
if (NIL_P(val)) return 0;
flt = RFLOAT(f_float(0, val));
return flt->value;
}
#endif
/* -------------------------------------------------------------------- */
#define ARY2INTEGRAL(_type_,_convert_) \
static inline int ary2c##_type_( arg, cary, maxlen ) \
VALUE arg; \
GL##_type_ cary[]; \
int maxlen; \
{ \
int i; \
struct RArray* ary; \
VALUE entry; \
ary = RARRAY(rb_Array(arg)); \
if (maxlen < 1) \
maxlen = ary->len; \
else \
maxlen = maxlen < ary->len ? maxlen : ary->len; \
for (i=0; i < maxlen; i++) \
{ \
entry = rb_ary_entry((VALUE)ary,i); \
cary[i] = (GL##_type_)_convert_(entry); \
} \
return i; \
}
ARY2INTEGRAL(int,NUM2INT)
ARY2INTEGRAL(uint,NUM2UINT)
ARY2INTEGRAL(byte,NUM2INT)
ARY2INTEGRAL(ubyte,NUM2INT)
ARY2INTEGRAL(short,NUM2INT)
ARY2INTEGRAL(ushort,NUM2INT)
ARY2INTEGRAL(boolean,NUM2INT)
#undef ARY2INTEGRAL
/* -------------------------------------------------------------------- */
static inline int ary2cflt(arg, cary, maxlen)
VALUE arg;
float cary[];
int maxlen;
{
int i;
struct RArray* ary;
ary = RARRAY(rb_Array(arg));
if (maxlen < 1)
maxlen = ary->len;
else
maxlen = maxlen < ary->len ? maxlen : ary->len;
for (i=0; i < maxlen; i++)
cary[i] = (float)NUM2DBL(rb_ary_entry((VALUE)ary,i));
return i;
}
/* -------------------------------------------------------------------- */
static inline int ary2cdbl(arg, cary, maxlen)
VALUE arg;
double cary[];
int maxlen;
{
int i;
struct RArray* ary;
ary = RARRAY(rb_Array(arg));
if (maxlen < 1)
maxlen = ary->len;
else
maxlen = maxlen < ary->len ? maxlen : ary->len;
for (i=0; i < maxlen; i++)
cary[i] = NUM2DBL(rb_ary_entry((VALUE)ary,i));
return i;
}
/* -------------------------------------------------------------------- */
static inline void mary2ary(src, ary)
VALUE src;
VALUE ary;
{
struct RArray* tmp_ary;
int i;
tmp_ary = RARRAY(rb_Array(src));
for (i = 0; i < tmp_ary->len; i++)
{
if (TYPE(tmp_ary->ptr[i]) == T_ARRAY)
mary2ary((VALUE)tmp_ary->ptr[i], ary);
else
rb_ary_push(ary, tmp_ary->ptr[i]);
}
}
/* -------------------------------------------------------------------- */
static inline void ary2cmat4x4dbl(ary, cary)
VALUE ary;
double cary[];
{
int i,j;
RArray *ary_r,*ary_c;
memset(cary, 0x0, sizeof(double[4*4]));
ary_c = RARRAY(rb_Array(ary));
if (TYPE(ary_c->ptr[0]) != T_ARRAY)
ary2cdbl((VALUE)ary_c, cary, 16);
else
{
for (i = 0; i < ary_c->len && i < 4; i++)
{
ary_r = RARRAY(rb_Array(ary_c->ptr[i]));
for(j = 0; j < ary_r->len && j < 4; j++)
cary[i*4+j] = (GLdouble)NUM2DBL(ary_r->ptr[j]);
}
}
}
static inline void ary2cmat4x4flt(ary, cary)
VALUE ary;
float cary[];
{
int i,j;
RArray *ary_r,*ary_c;
memset(cary, 0x0, sizeof(float[4*4]));
ary_c = RARRAY(rb_Array(ary));
if (TYPE(ary_c->ptr[0]) != T_ARRAY)
ary2cflt((VALUE)ary_c, cary, 16);
else
{
for (i = 0; i < ary_c->len && i < 4; i++)
{
ary_r = RARRAY(rb_Array(ary_c->ptr[i]));
for(j = 0; j < ary_r->len && j < 4; j++)
cary[i*4+j] = (GLfloat)NUM2DBL(ary_r->ptr[j]);
}
}
}
/* -------------------------------------------------------------------- */
/*Need to find proper size for glReadPixels array*/
static inline int glformat_size(GLenum format)
{
switch(format)
{
case GL_COLOR_INDEX:
case GL_RED:
case GL_GREEN:
case GL_BLUE:
case GL_ALPHA:
case GL_STENCIL_INDEX:
case GL_DEPTH_COMPONENT:
case GL_LUMINANCE:
return 1;
case GL_LUMINANCE_ALPHA:
return 2;
case GL_RGB:
case GL_BGR_EXT:
return 3;
case GL_RGBA:
case GL_BGRA_EXT:
case GL_ABGR_EXT:
return 4;
case 1:
case 2:
case 3:
case 4:
return format;
default:
return -1;
}
}
/* -------------------------------------------------------------------- */
static inline int gltype_size(GLenum type)
{
switch(type)
{
case GL_BYTE:
case GL_UNSIGNED_BYTE:
case GL_UNSIGNED_BYTE_3_3_2:
case GL_UNSIGNED_BYTE_2_3_3_REV:
return 1;
case GL_SHORT:
case GL_UNSIGNED_SHORT:
case GL_UNSIGNED_SHORT_5_6_5:
case GL_UNSIGNED_SHORT_5_6_5_REV:
case GL_UNSIGNED_SHORT_4_4_4_4:
case GL_UNSIGNED_SHORT_4_4_4_4_REV:
case GL_UNSIGNED_SHORT_5_5_5_1:
case GL_UNSIGNED_SHORT_1_5_5_5_REV:
return 2;
case GL_INT:
case GL_UNSIGNED_INT:
case GL_FLOAT:
case GL_UNSIGNED_INT_8_8_8_8:
case GL_UNSIGNED_INT_8_8_8_8_REV:
case GL_UNSIGNED_INT_10_10_10_2:
case GL_UNSIGNED_INT_2_10_10_10_REV:
return 4;
case GL_BITMAP:
return 0;
default:
return -1;
}
}
/* -------------------------------------------------------------------- */
static inline VALUE allocate_buffer_with_string( int size )
{
return rb_str_new(NULL, size);
}
/* -------------------------------------------------------------------- */
static inline void *load_gl_function(const char *name,int raise)
{
void *func_ptr = NULL;
#if defined(__APPLE__)
static const struct mach_header* library = NULL;
char* symbolName;
NSSymbol symbol;
if (library == NULL)
library = NSAddImage("/System/Library/Frameworks/OpenGL.framework/Versions/Current/OpenGL",NSADDIMAGE_OPTION_RETURN_ON_ERROR);
if (library == NULL)
rb_raise(rb_eRuntimeError,"Can't load OpenGL library for dynamic loading");
/* prepend a '_' for the Unix C symbol mangling convention */
symbolName = ALLOC_N(char,strlen(name) + 2);
symbolName[0] = '_';
strcpy(symbolName+1, name);
symbol = NSLookupSymbolInImage(library,symbolName,NSLOOKUPSYMBOLINIMAGE_OPTION_BIND | NSLOOKUPSYMBOLINIMAGE_OPTION_RETURN_ON_ERROR);
xfree(symbolName);
if (symbol == NULL)
func_ptr = NULL;
else
func_ptr = NSAddressOfSymbol(symbol);
#elif defined(WIN32) || defined(_WIN32)
func_ptr = wglGetProcAddress((LPCSTR)name);
#elif defined(GLX_VERSION_1_4)
func_ptr = glXGetProcAddress((const GLubyte *)name);
#else
func_ptr = glXGetProcAddressARB((const GLubyte *)name);
#endif
if (func_ptr == NULL && raise == 1)
rb_raise(rb_eNotImpError,"Function %s is not available at this machine",name);
return func_ptr;
}
#endif /* _RBOGL_H_ */

File diff suppressed because it is too large Load Diff

View File

@ -1,20 +0,0 @@
require "mkmf"
$CFLAGS = "/MD /O2 /EHsc /DWIN32 /DNDEBUG /D_WINDOWS"
#$CFLAGS = "/MD /Zi /EHsc /DWIN32 /DNDEBUG /D_WINDOWS"
#$LDFLAGS = "/Zi"
libs = [
"opengl32",
"glu32",
]
libs.each {|lib|
unless have_library(lib)
puts "Unable to find #{lib}.lib!"
puts
exit
end
}
create_makefile("gl")

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,725 +0,0 @@
/*
* Copyright (C) 2007 Jan Dvorak <jan.dvorak@kraxnet.cz>
*
* This program is distributed under the terms of the MIT license.
* See the included MIT-LICENSE file for the terms of this license.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifdef __APPLE__
#include <OpenGL/gl.h>
#elif defined WIN32
#include <windows.h>
#include <GL/gl.h>
#else
#include <GL/gl.h>
#endif
#include "../common/common.h"
/* OpenGL 1.3 functions */
static void (APIENTRY * fptr_glActiveTexture)(GLenum);
static VALUE
gl_ActiveTexture(obj,arg1)
VALUE obj,arg1;
{
GLenum texture;
LOAD_GL_FUNC(glActiveTexture)
texture = (GLenum)NUM2INT(arg1);
fptr_glActiveTexture(texture);
return Qnil;
}
static void (APIENTRY * fptr_glClientActiveTexture)(GLenum);
static VALUE
gl_ClientActiveTexture(obj,arg1)
VALUE obj,arg1;
{
GLenum texture;
LOAD_GL_FUNC(glClientActiveTexture)
texture = (GLenum)NUM2INT(arg1);
fptr_glClientActiveTexture(texture);
return Qnil;
}
static void (APIENTRY * fptr_glMultiTexCoord1d)(GLenum,GLdouble);
static VALUE
gl_MultiTexCoord1d(obj,arg1,arg2)
VALUE obj,arg1,arg2;
{
GLenum target;
GLdouble s;
LOAD_GL_FUNC(glMultiTexCoord1d)
target = (GLenum)NUM2INT(arg1);
s = (GLdouble)NUM2DBL(arg2);
fptr_glMultiTexCoord1d(target,s);
return Qnil;
}
static void (APIENTRY * fptr_glMultiTexCoord1f)(GLenum,GLfloat);
static VALUE
gl_MultiTexCoord1f(obj,arg1,arg2)
VALUE obj,arg1,arg2;
{
GLenum target;
GLfloat s;
LOAD_GL_FUNC(glMultiTexCoord1f)
target = (GLenum)NUM2INT(arg1);
s = (GLfloat)NUM2DBL(arg2);
fptr_glMultiTexCoord1f(target,s);
return Qnil;
}
static void (APIENTRY * fptr_glMultiTexCoord1i)(GLenum,GLint);
static VALUE
gl_MultiTexCoord1i(obj,arg1,arg2)
VALUE obj,arg1,arg2;
{
GLenum target;
GLint s;
LOAD_GL_FUNC(glMultiTexCoord1i)
target = (GLenum)NUM2INT(arg1);
s = (GLint)NUM2INT(arg2);
fptr_glMultiTexCoord1i(target,s);
return Qnil;
}
static void (APIENTRY * fptr_glMultiTexCoord1s)(GLenum,GLshort);
static VALUE
gl_MultiTexCoord1s(obj,arg1,arg2)
VALUE obj,arg1,arg2;
{
GLenum target;
GLshort s;
LOAD_GL_FUNC(glMultiTexCoord1s)
target = (GLenum)NUM2INT(arg1);
s = (GLshort)NUM2INT(arg2);
fptr_glMultiTexCoord1s(target,s);
return Qnil;
}
static void (APIENTRY * fptr_glMultiTexCoord2d)(GLenum,GLdouble,GLdouble);
static VALUE
gl_MultiTexCoord2d(obj,arg1,arg2,arg3)
VALUE obj,arg1,arg2,arg3;
{
GLenum target;
GLdouble s;
GLdouble t;
LOAD_GL_FUNC(glMultiTexCoord2d)
target = (GLenum)NUM2INT(arg1);
s = (GLdouble)NUM2DBL(arg2);
t = (GLdouble)NUM2DBL(arg3);
fptr_glMultiTexCoord2d(target,s,t);
return Qnil;
}
static void (APIENTRY * fptr_glMultiTexCoord2f)(GLenum,GLfloat,GLfloat);
static VALUE
gl_MultiTexCoord2f(obj,arg1,arg2,arg3)
VALUE obj,arg1,arg2,arg3;
{
GLenum target;
GLfloat s;
GLfloat t;
LOAD_GL_FUNC(glMultiTexCoord2f)
target = (GLenum)NUM2INT(arg1);
s = (GLfloat)NUM2DBL(arg2);
t = (GLfloat)NUM2DBL(arg3);
fptr_glMultiTexCoord2f(target,s,t);
return Qnil;
}
static void (APIENTRY * fptr_glMultiTexCoord2i)(GLenum,GLint,GLint);
static VALUE
gl_MultiTexCoord2i(obj,arg1,arg2,arg3)
VALUE obj,arg1,arg2,arg3;
{
GLenum target;
GLint s;
GLint t;
LOAD_GL_FUNC(glMultiTexCoord2i)
target = (GLenum)NUM2INT(arg1);
s = (GLint)NUM2INT(arg2);
t = (GLint)NUM2INT(arg3);
fptr_glMultiTexCoord2i(target,s,t);
return Qnil;
}
static void (APIENTRY * fptr_glMultiTexCoord2s)(GLenum,GLshort,GLshort);
static VALUE
gl_MultiTexCoord2s(obj,arg1,arg2,arg3)
VALUE obj,arg1,arg2,arg3;
{
GLenum target;
GLshort s;
GLshort t;
LOAD_GL_FUNC(glMultiTexCoord2s)
target = (GLenum)NUM2INT(arg1);
s = (GLshort)NUM2INT(arg2);
t = (GLshort)NUM2INT(arg3);
fptr_glMultiTexCoord2s(target,s,t);
return Qnil;
}
static void (APIENTRY * fptr_glMultiTexCoord3d)(GLenum,GLdouble,GLdouble,GLdouble);
static VALUE
gl_MultiTexCoord3d(obj,arg1,arg2,arg3,arg4)
VALUE obj,arg1,arg2,arg3,arg4;
{
GLenum target;
GLdouble s;
GLdouble t;
GLdouble r;
LOAD_GL_FUNC(glMultiTexCoord3d)
target = (GLenum)NUM2INT(arg1);
s = (GLdouble)NUM2DBL(arg2);
t = (GLdouble)NUM2DBL(arg3);
r = (GLdouble)NUM2DBL(arg4);
fptr_glMultiTexCoord3d(target,s,t,r);
return Qnil;
}
static void (APIENTRY * fptr_glMultiTexCoord3f)(GLenum,GLfloat,GLfloat,GLfloat);
static VALUE
gl_MultiTexCoord3f(obj,arg1,arg2,arg3,arg4)
VALUE obj,arg1,arg2,arg3,arg4;
{
GLenum target;
GLfloat s;
GLfloat t;
GLfloat r;
LOAD_GL_FUNC(glMultiTexCoord3f)
target = (GLenum)NUM2INT(arg1);
s = (GLfloat)NUM2DBL(arg2);
t = (GLfloat)NUM2DBL(arg3);
r = (GLfloat)NUM2DBL(arg4);
fptr_glMultiTexCoord3f(target,s,t,r);
return Qnil;
}
static void (APIENTRY * fptr_glMultiTexCoord3i)(GLenum,GLint,GLint,GLint);
static VALUE
gl_MultiTexCoord3i(obj,arg1,arg2,arg3,arg4)
VALUE obj,arg1,arg2,arg3,arg4;
{
GLenum target;
GLint s;
GLint t;
GLint r;
LOAD_GL_FUNC(glMultiTexCoord3i)
target = (GLenum)NUM2INT(arg1);
s = (GLint)NUM2INT(arg2);
t = (GLint)NUM2INT(arg3);
r = (GLint)NUM2INT(arg4);
fptr_glMultiTexCoord3i(target,s,t,r);
return Qnil;
}
static void (APIENTRY * fptr_glMultiTexCoord3s)(GLenum,GLshort,GLshort,GLshort);
static VALUE
gl_MultiTexCoord3s(obj,arg1,arg2,arg3,arg4)
VALUE obj,arg1,arg2,arg3,arg4;
{
GLenum target;
GLshort s;
GLshort t;
GLshort r;
LOAD_GL_FUNC(glMultiTexCoord3s)
target = (GLenum)NUM2INT(arg1);
s = (GLshort)NUM2INT(arg2);
t = (GLshort)NUM2INT(arg3);
r = (GLshort)NUM2INT(arg4);
fptr_glMultiTexCoord3s(target,s,t,r);
return Qnil;
}
static void (APIENTRY * fptr_glMultiTexCoord4d)(GLenum,GLdouble,GLdouble,GLdouble,GLdouble);
static VALUE
gl_MultiTexCoord4d(obj,arg1,arg2,arg3,arg4,arg5)
VALUE obj,arg1,arg2,arg3,arg4,arg5;
{
GLenum target;
GLdouble s;
GLdouble t;
GLdouble r;
GLdouble q;
LOAD_GL_FUNC(glMultiTexCoord4d)
target = (GLenum)NUM2INT(arg1);
s = (GLdouble)NUM2DBL(arg2);
t = (GLdouble)NUM2DBL(arg3);
r = (GLdouble)NUM2DBL(arg4);
q = (GLdouble)NUM2DBL(arg5);
fptr_glMultiTexCoord4d(target,s,t,r,q);
return Qnil;
}
static void (APIENTRY * fptr_glMultiTexCoord4f)(GLenum,GLfloat,GLfloat,GLfloat,GLfloat);
static VALUE
gl_MultiTexCoord4f(obj,arg1,arg2,arg3,arg4,arg5)
VALUE obj,arg1,arg2,arg3,arg4,arg5;
{
GLenum target;
GLfloat s;
GLfloat t;
GLfloat r;
GLfloat q;
LOAD_GL_FUNC(glMultiTexCoord4f)
target = (GLenum)NUM2INT(arg1);
s = (GLfloat)NUM2DBL(arg2);
t = (GLfloat)NUM2DBL(arg3);
r = (GLfloat)NUM2DBL(arg4);
q = (GLfloat)NUM2DBL(arg5);
fptr_glMultiTexCoord4f(target,s,t,r,q);
return Qnil;
}
static void (APIENTRY * fptr_glMultiTexCoord4i)(GLenum,GLint,GLint,GLint,GLint);
static VALUE
gl_MultiTexCoord4i(obj,arg1,arg2,arg3,arg4,arg5)
VALUE obj,arg1,arg2,arg3,arg4,arg5;
{
GLenum target;
GLint s;
GLint t;
GLint r;
GLint q;
LOAD_GL_FUNC(glMultiTexCoord4i)
target = (GLenum)NUM2INT(arg1);
s = (GLint)NUM2INT(arg2);
t = (GLint)NUM2INT(arg3);
r = (GLint)NUM2INT(arg4);
q = (GLint)NUM2INT(arg5);
fptr_glMultiTexCoord4i(target,s,t,r,q);
return Qnil;
}
static void (APIENTRY * fptr_glMultiTexCoord4s)(GLenum,GLshort,GLshort,GLshort,GLshort);
static VALUE
gl_MultiTexCoord4s(obj,arg1,arg2,arg3,arg4,arg5)
VALUE obj,arg1,arg2,arg3,arg4,arg5;
{
GLenum target;
GLshort s;
GLshort t;
GLshort r;
GLshort q;
LOAD_GL_FUNC(glMultiTexCoord4s)
target = (GLenum)NUM2INT(arg1);
s = (GLshort)NUM2INT(arg2);
t = (GLshort)NUM2INT(arg3);
r = (GLshort)NUM2INT(arg4);
q = (GLshort)NUM2INT(arg5);
fptr_glMultiTexCoord4s(target,s,t,r,q);
return Qnil;
}
#define GLMULTITEXCOORD_VFUNC(_type_) \
static VALUE \
gl_MultiTexCoord##_type_##v(argc,argv,obj) \
int argc; \
VALUE *argv; \
VALUE obj; \
{ \
int num; \
VALUE args[5]; \
RArray *ary; \
switch (num = rb_scan_args(argc, argv, "23", &args[0], &args[1], &args[2], &args[3],&args[4])) { \
case 2: \
if (TYPE(args[1]) == T_ARRAY) { \
ary = RARRAY(args[1]); \
switch (ary->len) { \
case 1: \
gl_MultiTexCoord1##_type_(obj,args[0],ary->ptr[0]); \
break; \
case 2: \
gl_MultiTexCoord2##_type_(obj,args[0],ary->ptr[0],ary->ptr[1]); \
break; \
case 3: \
gl_MultiTexCoord3##_type_(obj,args[0],ary->ptr[0],ary->ptr[1],ary->ptr[2]); \
break; \
case 4: \
gl_MultiTexCoord4##_type_(obj,args[0],ary->ptr[0],ary->ptr[1],ary->ptr[2],ary->ptr[3]); \
break; \
default: \
rb_raise(rb_eArgError, "array length:%d", num); \
} \
} \
else { \
gl_MultiTexCoord1##_type_(obj,args[0], args[1]); \
break; \
} \
break; \
case 3: \
gl_MultiTexCoord2##_type_(obj,args[0], args[1], args[2]); \
break; \
case 4: \
gl_MultiTexCoord3##_type_(obj,args[0], args[1], args[2], args[3]); \
break; \
case 5: \
gl_MultiTexCoord4##_type_(obj,args[0], args[1], args[2], args[3], args[4]); \
break; \
default: \
rb_raise(rb_eArgError, "too many arguments"); \
break; \
} \
return Qnil; \
}
GLMULTITEXCOORD_VFUNC(d)
GLMULTITEXCOORD_VFUNC(f)
GLMULTITEXCOORD_VFUNC(i)
GLMULTITEXCOORD_VFUNC(s)
#undef GLTEXCOORD_VFUNC
static void (APIENTRY * fptr_glLoadTransposeMatrixf)(const GLfloat[]);
static VALUE
gl_LoadTransposeMatrixf(obj,arg1)
VALUE obj,arg1;
{
GLfloat m[4*4];
LOAD_GL_FUNC(glLoadTransposeMatrixf)
ary2cmat4x4flt(arg1, m);
fptr_glLoadTransposeMatrixf(m);
return Qnil;
}
static void (APIENTRY * fptr_glLoadTransposeMatrixd)(const GLdouble[]);
static VALUE
gl_LoadTransposeMatrixd(obj,arg1)
VALUE obj,arg1;
{
GLdouble m[4*4];
LOAD_GL_FUNC(glLoadTransposeMatrixd)
ary2cmat4x4dbl(arg1, m);
fptr_glLoadTransposeMatrixd(m);
return Qnil;
}
static void (APIENTRY * fptr_glMultTransposeMatrixf)(const GLfloat[]);
static VALUE
gl_MultTransposeMatrixf(obj,arg1)
VALUE obj,arg1;
{
GLfloat m[4*4];
LOAD_GL_FUNC(glMultTransposeMatrixf)
ary2cmat4x4flt(arg1, m);
fptr_glMultTransposeMatrixf(m);
return Qnil;
}
static void (APIENTRY * fptr_glMultTransposeMatrixd)(const GLdouble[]);
static VALUE
gl_MultTransposeMatrixd(obj,arg1)
VALUE obj,arg1;
{
GLdouble m[4*4];
LOAD_GL_FUNC(glMultTransposeMatrixd)
ary2cmat4x4dbl(arg1, m);
fptr_glMultTransposeMatrixd(m);
return Qnil;
}
static void (APIENTRY * fptr_glSampleCoverage)(GLclampf,GLboolean);
static VALUE
gl_SampleCoverage(obj,arg1,arg2)
VALUE obj,arg1,arg2;
{
GLclampf value;
GLboolean invert;
LOAD_GL_FUNC(glSampleCoverage)
value = (GLclampf)NUM2DBL(arg1);
invert = (GLboolean)NUM2INT(arg2);
fptr_glSampleCoverage(value,invert);
return Qnil;
}
static void (APIENTRY * fptr_glCompressedTexImage3D)(GLenum,GLint,GLenum,GLsizei,GLsizei,GLsizei,GLint,GLsizei,GLvoid*);
static VALUE
gl_CompressedTexImage3D(obj,arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9)
VALUE obj,arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9;
{
GLenum target;
GLint level;
GLenum internalformat;
GLsizei width;
GLsizei height;
GLsizei depth;
GLint border;
GLsizei imagesize;
GLvoid *pixels;
LOAD_GL_FUNC(glCompressedTexImage3D)
target = (GLenum)NUM2INT(arg1);
level = (GLint)NUM2INT(arg2);
internalformat = (GLenum)NUM2INT(arg3);
width = (GLsizei)NUM2UINT(arg4);
height = (GLsizei)NUM2UINT(arg5);
depth = (GLsizei)NUM2UINT(arg6);
border = (GLint)NUM2INT(arg7);
imagesize = (GLsizei)NUM2UINT(arg8);
if (TYPE(arg9) == T_STRING) {
if (RSTRING(arg9)->len < imagesize)
rb_raise(rb_eArgError, "string length:%d",RSTRING(arg9)->len);
pixels = RSTRING(arg9)->ptr;
} else if (NIL_P(arg9)) {
pixels = NULL;
} else {
Check_Type(arg9,T_STRING); /* force exception */
return Qnil;
}
fptr_glCompressedTexImage3D(target,level,internalformat,width,height,depth,border,imagesize,pixels);
return Qnil;
}
static void (APIENTRY * fptr_glCompressedTexImage2D)(GLenum,GLint,GLenum,GLsizei,GLsizei,GLint,GLsizei,GLvoid*);
static VALUE
gl_CompressedTexImage2D(obj,arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8)
VALUE obj,arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8;
{
GLenum target;
GLint level;
GLenum internalformat;
GLsizei width;
GLsizei height;
GLint border;
GLsizei imagesize;
GLvoid *pixels;
LOAD_GL_FUNC(glCompressedTexImage2D)
target = (GLenum)NUM2INT(arg1);
level = (GLint)NUM2INT(arg2);
internalformat = (GLenum)NUM2INT(arg3);
width = (GLsizei)NUM2UINT(arg4);
height = (GLsizei)NUM2UINT(arg5);
border = (GLint)NUM2INT(arg6);
imagesize = (GLsizei)NUM2UINT(arg7);
if (TYPE(arg8) == T_STRING) {
if (RSTRING(arg8)->len < imagesize)
rb_raise(rb_eArgError, "string length:%d",RSTRING(arg8)->len);
pixels = RSTRING(arg8)->ptr;
} else if (NIL_P(arg8)) {
pixels = NULL;
} else {
Check_Type(arg8,T_STRING); /* force exception */
return Qnil;
}
fptr_glCompressedTexImage2D(target,level,internalformat,width,height,border,imagesize,pixels);
return Qnil;
}
static void (APIENTRY * fptr_glCompressedTexImage1D)(GLenum,GLint,GLenum,GLsizei,GLint,GLsizei,GLvoid*);
static VALUE
gl_CompressedTexImage1D(obj,arg1,arg2,arg3,arg4,arg5,arg6,arg7)
VALUE obj,arg1,arg2,arg3,arg4,arg5,arg6,arg7;
{
GLenum target;
GLint level;
GLenum internalformat;
GLsizei width;
GLint border;
GLsizei imagesize;
GLvoid *pixels;
LOAD_GL_FUNC(glCompressedTexImage1D)
target = (GLenum)NUM2INT(arg1);
level = (GLint)NUM2INT(arg2);
internalformat = (GLenum)NUM2INT(arg3);
width = (GLsizei)NUM2UINT(arg4);
border = (GLint)NUM2INT(arg5);
imagesize = (GLsizei)NUM2UINT(arg6);
if (TYPE(arg7) == T_STRING) {
if (RSTRING(arg7)->len < imagesize)
rb_raise(rb_eArgError, "string length:%d",RSTRING(arg7)->len);
pixels = RSTRING(arg7)->ptr;
} else if (NIL_P(arg7)) {
pixels = NULL;
} else {
Check_Type(arg7,T_STRING); /* force exception */
return Qnil;
}
fptr_glCompressedTexImage1D(target,level,internalformat,width,border,imagesize,pixels);
return Qnil;
}
static void (APIENTRY * fptr_glCompressedTexSubImage3D)(GLenum,GLint,GLint,GLint,GLint,GLsizei,GLsizei,GLsizei,GLenum,GLsizei,GLvoid*);
static VALUE
gl_CompressedTexSubImage3D(obj,arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9,arg10,arg11)
VALUE obj,arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9,arg10,arg11;
{
GLenum target;
GLint level;
GLint xoffset;
GLint yoffset;
GLint zoffset;
GLsizei width;
GLsizei height;
GLsizei depth;
GLenum format;
GLsizei imagesize;
GLvoid *pixels;
LOAD_GL_FUNC(glCompressedTexSubImage3D)
target = (GLenum)NUM2INT(arg1);
level = (GLint)NUM2INT(arg2);
xoffset = (GLint)NUM2INT(arg3);
yoffset = (GLint)NUM2INT(arg4);
zoffset = (GLint)NUM2INT(arg5);
width = (GLsizei)NUM2UINT(arg6);
height = (GLsizei)NUM2UINT(arg7);
depth = (GLsizei)NUM2UINT(arg8);
format = (GLenum)NUM2INT(arg9);
imagesize = (GLsizei)NUM2UINT(arg10);
if (TYPE(arg11) == T_STRING) {
if (RSTRING(arg11)->len < imagesize)
rb_raise(rb_eArgError, "string length:%d",RSTRING(arg11)->len);
pixels = RSTRING(arg11)->ptr;
} else {
Check_Type(arg11,T_STRING); /* force exception */
return Qnil;
}
fptr_glCompressedTexSubImage3D(target,level,xoffset,yoffset,zoffset,width,height,depth,format,imagesize,pixels);
return Qnil;
}
static void (APIENTRY * fptr_glCompressedTexSubImage2D)(GLenum,GLint,GLint,GLint,GLsizei,GLsizei,GLenum,GLsizei,GLvoid*);
static VALUE
gl_CompressedTexSubImage2D(obj,arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9)
VALUE obj,arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9;
{
GLenum target;
GLint level;
GLint xoffset;
GLint yoffset;
GLsizei width;
GLsizei height;
GLenum format;
GLsizei imagesize;
GLvoid *pixels;
LOAD_GL_FUNC(glCompressedTexSubImage2D)
target = (GLenum)NUM2INT(arg1);
level = (GLint)NUM2INT(arg2);
xoffset = (GLint)NUM2INT(arg3);
yoffset = (GLint)NUM2INT(arg4);
width = (GLsizei)NUM2UINT(arg5);
height = (GLsizei)NUM2UINT(arg6);
format = (GLenum)NUM2INT(arg7);
imagesize = (GLsizei)NUM2UINT(arg8);
if (TYPE(arg9) == T_STRING) {
if (RSTRING(arg9)->len < imagesize)
rb_raise(rb_eArgError, "string length:%d",RSTRING(arg9)->len);
pixels = RSTRING(arg9)->ptr;
} else {
Check_Type(arg9,T_STRING); /* force exception */
return Qnil;
}
fptr_glCompressedTexSubImage2D(target,level,xoffset,yoffset,width,height,format,imagesize,pixels);
return Qnil;
}
static void (APIENTRY * fptr_glCompressedTexSubImage1D)(GLenum,GLint,GLint,GLsizei,GLenum,GLsizei,GLvoid*);
static VALUE
gl_CompressedTexSubImage1D(obj,arg1,arg2,arg3,arg4,arg5,arg6,arg7)
VALUE obj,arg1,arg2,arg3,arg4,arg5,arg6,arg7;
{
GLenum target;
GLint level;
GLint xoffset;
GLsizei width;
GLenum format;
GLsizei imagesize;
GLvoid *pixels;
LOAD_GL_FUNC(glCompressedTexSubImage1D)
target = (GLenum)NUM2INT(arg1);
level = (GLint)NUM2INT(arg2);
xoffset = (GLint)NUM2INT(arg3);
width = (GLsizei)NUM2UINT(arg4);
format = (GLenum)NUM2INT(arg5);
imagesize = (GLsizei)NUM2UINT(arg6);
if (TYPE(arg7) == T_STRING) {
if (RSTRING(arg7)->len < imagesize)
rb_raise(rb_eArgError, "string length:%d",RSTRING(arg7)->len);
pixels = RSTRING(arg7)->ptr;
} else {
Check_Type(arg7,T_STRING); /* force exception */
return Qnil;
}
fptr_glCompressedTexSubImage1D(target,level,xoffset,width,format,imagesize,pixels);
return Qnil;
}
static void (APIENTRY * fptr_glGetCompressedTexImage)(GLenum,GLint,GLvoid*);
static VALUE
gl_GetCompressedTexImage(obj,arg1,arg2)
VALUE obj,arg1,arg2;
{
GLenum target;
GLint lod;
GLsizei size = 0;
VALUE data;
LOAD_GL_FUNC(glGetCompressedTexImage)
target = (GLenum)NUM2INT(arg1);
lod = (GLenum)NUM2INT(arg2);
glGetTexLevelParameteriv(target,lod,GL_TEXTURE_COMPRESSED_IMAGE_SIZE,&size); /* 1.0 function */
data = allocate_buffer_with_string(size);
fptr_glGetCompressedTexImage(target,lod,(GLvoid*)RSTRING(data)->ptr);
return data;
}
void gl_init_functions_1_3(VALUE module)
{
rb_define_module_function(module, "glActiveTexture", gl_ActiveTexture, 1);
rb_define_module_function(module, "glClientActiveTexture", gl_ClientActiveTexture, 1);
rb_define_module_function(module, "glMultiTexCoord1d", gl_MultiTexCoord1d, 2);
rb_define_module_function(module, "glMultiTexCoord1f", gl_MultiTexCoord1f, 2);
rb_define_module_function(module, "glMultiTexCoord1i", gl_MultiTexCoord1i, 2);
rb_define_module_function(module, "glMultiTexCoord1s", gl_MultiTexCoord1s, 2);
rb_define_module_function(module, "glMultiTexCoord2d", gl_MultiTexCoord2d, 3);
rb_define_module_function(module, "glMultiTexCoord2f", gl_MultiTexCoord2f, 3);
rb_define_module_function(module, "glMultiTexCoord2i", gl_MultiTexCoord2i, 3);
rb_define_module_function(module, "glMultiTexCoord2s", gl_MultiTexCoord2s, 3);
rb_define_module_function(module, "glMultiTexCoord3d", gl_MultiTexCoord3d, 4);
rb_define_module_function(module, "glMultiTexCoord3f", gl_MultiTexCoord3f, 4);
rb_define_module_function(module, "glMultiTexCoord3i", gl_MultiTexCoord3i, 4);
rb_define_module_function(module, "glMultiTexCoord3s", gl_MultiTexCoord3s, 4);
rb_define_module_function(module, "glMultiTexCoord4d", gl_MultiTexCoord4d, 5);
rb_define_module_function(module, "glMultiTexCoord4f", gl_MultiTexCoord4f, 5);
rb_define_module_function(module, "glMultiTexCoord4i", gl_MultiTexCoord4i, 5);
rb_define_module_function(module, "glMultiTexCoord4s", gl_MultiTexCoord4s, 5);
rb_define_module_function(module, "glLoadTransposeMatrixf", gl_LoadTransposeMatrixf, 1);
rb_define_module_function(module, "glLoadTransposeMatrixd", gl_LoadTransposeMatrixd, 1);
rb_define_module_function(module, "glMultTransposeMatrixf", gl_MultTransposeMatrixf, 1);
rb_define_module_function(module, "glMultTransposeMatrixd", gl_MultTransposeMatrixd, 1);
rb_define_module_function(module, "glSampleCoverage", gl_SampleCoverage, 2);
rb_define_module_function(module, "glCompressedTexImage3D", gl_CompressedTexImage3D, 9);
rb_define_module_function(module, "glCompressedTexImage2D", gl_CompressedTexImage2D, 8);
rb_define_module_function(module, "glCompressedTexImage1D", gl_CompressedTexImage1D, 7);
rb_define_module_function(module, "glCompressedTexSubImage3D", gl_CompressedTexSubImage3D, 11);
rb_define_module_function(module, "glCompressedTexSubImage2D", gl_CompressedTexSubImage2D, 9);
rb_define_module_function(module, "glCompressedTexSubImage1D", gl_CompressedTexSubImage1D, 7);
rb_define_module_function(module, "glGetCompressedTexImage", gl_GetCompressedTexImage, 2);
/* Additional functions */
rb_define_module_function(module, "glMultiTexCoord", gl_MultiTexCoorddv, -1);
rb_define_module_function(module, "glMultiTexCoord1dv", gl_MultiTexCoorddv, -1);
rb_define_module_function(module, "glMultiTexCoord1fv", gl_MultiTexCoordfv, -1);
rb_define_module_function(module, "glMultiTexCoord1iv", gl_MultiTexCoordiv, -1);
rb_define_module_function(module, "glMultiTexCoord1sv", gl_MultiTexCoordsv, -1);
rb_define_module_function(module, "glMultiTexCoord2dv", gl_MultiTexCoorddv, -1);
rb_define_module_function(module, "glMultiTexCoord2fv", gl_MultiTexCoordfv, -1);
rb_define_module_function(module, "glMultiTexCoord2iv", gl_MultiTexCoordiv, -1);
rb_define_module_function(module, "glMultiTexCoord2sv", gl_MultiTexCoordsv, -1);
rb_define_module_function(module, "glMultiTexCoord3dv", gl_MultiTexCoorddv, -1);
rb_define_module_function(module, "glMultiTexCoord3fv", gl_MultiTexCoordfv, -1);
rb_define_module_function(module, "glMultiTexCoord3iv", gl_MultiTexCoordiv, -1);
rb_define_module_function(module, "glMultiTexCoord3sv", gl_MultiTexCoordsv, -1);
rb_define_module_function(module, "glMultiTexCoord4dv", gl_MultiTexCoorddv, -1);
rb_define_module_function(module, "glMultiTexCoord4fv", gl_MultiTexCoordfv, -1);
rb_define_module_function(module, "glMultiTexCoord4iv", gl_MultiTexCoordiv, -1);
rb_define_module_function(module, "glMultiTexCoord4sv", gl_MultiTexCoordsv, -1);
}

View File

@ -1,647 +0,0 @@
/*
* Copyright (C) 2007 Jan Dvorak <jan.dvorak@kraxnet.cz>
*
* This program is distributed under the terms of the MIT license.
* See the included MIT-LICENSE file for the terms of this license.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifdef __APPLE__
#include <OpenGL/gl.h>
#elif defined WIN32
#include <windows.h>
#include <GL/gl.h>
#else
#include <GL/gl.h>
#endif
#include "../common/common.h"
/* OpenGL 1.4 functions */
static void (APIENTRY * fptr_glBlendFuncSeparate)(GLenum,GLenum,GLenum,GLenum);
static VALUE
gl_BlendFuncSeparate(obj,arg1,arg2,arg3,arg4)
VALUE obj,arg1,arg2,arg3,arg4;
{
GLenum srcRGB;
GLenum dstRGB;
GLenum srcAlpha;
GLenum dstAlpha;
LOAD_GL_FUNC(glBlendFuncSeparate)
srcRGB = (GLenum)NUM2INT(arg1);
dstRGB = (GLenum)NUM2INT(arg2);
srcAlpha = (GLenum)NUM2INT(arg3);
dstAlpha = (GLenum)NUM2INT(arg4);
fptr_glBlendFuncSeparate(srcRGB,dstRGB,srcAlpha,dstAlpha);
return Qnil;
}
static void (APIENTRY * fptr_glFogCoordf)(GLfloat);
static VALUE
gl_FogCoordf(obj,arg1)
VALUE obj,arg1;
{
GLfloat coord;
LOAD_GL_FUNC(glFogCoordf)
coord=(GLfloat)NUM2DBL(arg1);
fptr_glFogCoordf(coord);
return Qnil;
}
static void (APIENTRY * fptr_glFogCoordfv)(GLfloat *);
static VALUE
gl_FogCoordfv(obj,arg1)
VALUE obj,arg1;
{
GLfloat coord;
LOAD_GL_FUNC(glFogCoordfv)
Check_Type(arg1,T_ARRAY);
ary2cflt(arg1,&coord,1);
fptr_glFogCoordfv(&coord);
return Qnil;
}
static void (APIENTRY * fptr_glFogCoordd)(GLdouble);
static VALUE
gl_FogCoordd(obj,arg1)
VALUE obj,arg1;
{
GLdouble coord;
LOAD_GL_FUNC(glFogCoordd)
coord=(GLdouble)NUM2DBL(arg1);
fptr_glFogCoordd(coord);
return Qnil;
}
static void (APIENTRY * fptr_glFogCoorddv)(GLdouble *);
static VALUE
gl_FogCoorddv(obj,arg1)
VALUE obj,arg1;
{
GLdouble coord;
LOAD_GL_FUNC(glFogCoorddv)
Check_Type(arg1,T_ARRAY);
ary2cdbl(arg1,&coord,1);
fptr_glFogCoorddv(&coord);
return Qnil;
}
extern VALUE g_FogCoord_ptr;
static void (APIENTRY * fptr_glFogCoordPointer)(GLenum,GLsizei,const GLvoid *);
static VALUE
gl_FogCoordPointer(obj,arg1,arg2,arg3)
VALUE obj,arg1,arg2,arg3;
{
GLenum type;
GLsizei stride;
LOAD_GL_FUNC(glFogCoordPointer)
type = (GLenum)NUM2INT(arg1);
stride = (GLsizei)NUM2UINT(arg2);
Check_Type(arg3, T_STRING);
rb_str_freeze(arg3);
g_FogCoord_ptr = arg3;
fptr_glFogCoordPointer(type, stride, (const GLvoid*)RSTRING(arg3)->ptr);
return Qnil;
}
static void (APIENTRY * fptr_glMultiDrawArrays)(GLenum,GLint*,GLsizei*,GLsizei);
static VALUE
gl_MultiDrawArrays(obj,arg1,arg2,arg3,arg4)
VALUE obj,arg1,arg2,arg3,arg4;
{
/* TODO: check ary1,ary2 if len < primcount then raise */
/* stringy ? */
GLenum mode;
GLsizei primcount;
GLint *ary1;
GLsizei *ary2;
LOAD_GL_FUNC(glMultiDrawArrays)
mode = (GLenum)NUM2INT(arg1);
primcount = (GLsizei)NUM2UINT(arg4);
ary1 = ALLOC_N(GLint,primcount);
ary2 = ALLOC_N(GLsizei,primcount);
ary2cint(arg2,ary1,primcount);
ary2cint(arg3,ary2,primcount);
fptr_glMultiDrawArrays(mode,ary1,ary2,primcount);
xfree(ary1);
xfree(ary2);
return Qnil;
}
static void (APIENTRY * fptr_glMultiDrawElements)(GLenum,const GLsizei *,GLenum,GLvoid **,GLsizei);
static VALUE
gl_MultiDrawElements(obj,arg1,arg2,arg3)
VALUE obj,arg1,arg2,arg3;
{
GLenum mode;
GLenum type;
GLsizei *counts;
GLvoid **indices;
GLint size;
RArray *ary;
int i;
LOAD_GL_FUNC(glMultiDrawElements)
mode = (GLenum)NUM2INT(arg1);
type = (GLenum)NUM2INT(arg2);
Check_Type(arg3,T_ARRAY);
ary = RARRAY(arg3);
size = ary->len;
counts = ALLOC_N(GLsizei,size);
indices = ALLOC_N(GLvoid*,size);
for (i=0;i<size;i++) {
indices[i] = RSTRING(ary->ptr[i])->ptr;
counts[i] = RSTRING(ary->ptr[i])->len;
}
fptr_glMultiDrawElements(mode,counts,type,indices,size);
xfree(counts);
xfree(indices);
return Qnil;
}
static void (APIENTRY * fptr_glPointParameterf)(GLenum,GLfloat);
static VALUE
gl_PointParameterf(obj,arg1,arg2)
VALUE obj,arg1,arg2;
{
GLenum pname;
GLfloat param;
LOAD_GL_FUNC(glPointParameterf)
pname = (GLenum)NUM2INT(arg1);
param = (GLfloat)NUM2INT(arg2);
fptr_glPointParameterf(pname,param);
return Qnil;
}
static void (APIENTRY * fptr_glPointParameterfv)(GLenum,GLfloat *);
static VALUE
gl_PointParameterfv(obj,arg1,arg2)
VALUE obj,arg1,arg2;
{
GLenum pname;
GLfloat params[3] = {0.0,0.0,0.0};
GLint size;
LOAD_GL_FUNC(glPointParameterfv)
pname = (GLenum)NUM2INT(arg1);
Check_Type(arg2,T_ARRAY);
if (pname==GL_POINT_DISTANCE_ATTENUATION)
size = 3;
else
size = 1;
ary2cflt(arg2,params,size);
fptr_glPointParameterfv(pname,params);
return Qnil;
}
static void (APIENTRY * fptr_glPointParameteri)(GLenum,GLint);
static VALUE
gl_PointParameteri(obj,arg1,arg2)
VALUE obj,arg1,arg2;
{
GLenum pname;
GLint param;
LOAD_GL_FUNC(glPointParameteri)
pname = (GLenum)NUM2INT(arg1);
param = (GLint)NUM2INT(arg2);
fptr_glPointParameteri(pname,param);
return Qnil;
}
static void (APIENTRY * fptr_glPointParameteriv)(GLenum,GLint *);
static VALUE
gl_PointParameteriv(obj,arg1,arg2)
VALUE obj,arg1,arg2;
{
GLenum pname;
GLint params[3] = {0.0,0.0,0.0};
GLint size;
LOAD_GL_FUNC(glPointParameteriv)
pname = (GLenum)NUM2INT(arg1);
Check_Type(arg2,T_ARRAY);
if (pname==GL_POINT_DISTANCE_ATTENUATION)
size = 3;
else
size = 1;
ary2cint(arg2,params,size);
fptr_glPointParameteriv(pname,params);
return Qnil;
}
static void (APIENTRY * fptr_glSecondaryColor3b)(GLbyte,GLbyte,GLbyte);
static VALUE
gl_SecondaryColor3b(obj,arg1,arg2,arg3)
VALUE obj,arg1,arg2,arg3;
{
GLbyte red;
GLbyte green;
GLbyte blue;
LOAD_GL_FUNC(glSecondaryColor3b)
red = (GLbyte)NUM2INT(arg1);
green = (GLbyte)NUM2INT(arg2);
blue = (GLbyte)NUM2INT(arg3);
fptr_glSecondaryColor3b(red,green,blue);
return Qnil;
}
static void (APIENTRY * fptr_glSecondaryColor3d)(GLdouble,GLdouble,GLdouble);
static VALUE
gl_SecondaryColor3d(obj,arg1,arg2,arg3)
VALUE obj,arg1,arg2,arg3;
{
GLdouble red;
GLdouble green;
GLdouble blue;
LOAD_GL_FUNC(glSecondaryColor3d)
red = (GLdouble)NUM2DBL(arg1);
green = (GLdouble)NUM2DBL(arg2);
blue = (GLdouble)NUM2DBL(arg3);
fptr_glSecondaryColor3d(red,green,blue);
return Qnil;
}
static void (APIENTRY * fptr_glSecondaryColor3f)(GLfloat,GLfloat,GLfloat);
static VALUE
gl_SecondaryColor3f(obj,arg1,arg2,arg3)
VALUE obj,arg1,arg2,arg3;
{
GLfloat red;
GLfloat green;
GLfloat blue;
LOAD_GL_FUNC(glSecondaryColor3f)
red = (GLfloat)NUM2DBL(arg1);
green = (GLfloat)NUM2DBL(arg2);
blue = (GLfloat)NUM2DBL(arg3);
fptr_glSecondaryColor3f(red,green,blue);
return Qnil;
}
static void (APIENTRY * fptr_glSecondaryColor3i)(GLint,GLint,GLint);
static VALUE
gl_SecondaryColor3i(obj,arg1,arg2,arg3)
VALUE obj,arg1,arg2,arg3;
{
GLint red;
GLint green;
GLint blue;
LOAD_GL_FUNC(glSecondaryColor3i)
red = (GLint)NUM2INT(arg1);
green = (GLint)NUM2INT(arg2);
blue = (GLint)NUM2INT(arg3);
fptr_glSecondaryColor3i(red,green,blue);
return Qnil;
}
static void (APIENTRY * fptr_glSecondaryColor3s)(GLshort,GLshort,GLshort);
static VALUE
gl_SecondaryColor3s(obj,arg1,arg2,arg3)
VALUE obj,arg1,arg2,arg3;
{
GLshort red;
GLshort green;
GLshort blue;
LOAD_GL_FUNC(glSecondaryColor3s)
red = (GLshort)NUM2INT(arg1);
green = (GLshort)NUM2INT(arg2);
blue = (GLshort)NUM2INT(arg3);
fptr_glSecondaryColor3s(red,green,blue);
return Qnil;
}
static void (APIENTRY * fptr_glSecondaryColor3ub)(GLubyte,GLubyte,GLubyte);
static VALUE
gl_SecondaryColor3ub(obj,arg1,arg2,arg3)
VALUE obj,arg1,arg2,arg3;
{
GLubyte red;
GLubyte green;
GLubyte blue;
LOAD_GL_FUNC(glSecondaryColor3ub)
red = (GLubyte)NUM2INT(arg1);
green = (GLubyte)NUM2INT(arg2);
blue = (GLubyte)NUM2INT(arg3);
fptr_glSecondaryColor3ub(red,green,blue);
return Qnil;
}
static void (APIENTRY * fptr_glSecondaryColor3ui)(GLuint,GLuint,GLuint);
static VALUE
gl_SecondaryColor3ui(obj,arg1,arg2,arg3)
VALUE obj,arg1,arg2,arg3;
{
GLuint red;
GLuint green;
GLuint blue;
LOAD_GL_FUNC(glSecondaryColor3ui)
red = (GLuint)NUM2UINT(arg1);
green = (GLuint)NUM2UINT(arg2);
blue = (GLuint)NUM2UINT(arg3);
fptr_glSecondaryColor3ui(red,green,blue);
return Qnil;
}
static void (APIENTRY * fptr_glSecondaryColor3us)(GLushort,GLushort,GLushort);
static VALUE
gl_SecondaryColor3us(obj,arg1,arg2,arg3)
VALUE obj,arg1,arg2,arg3;
{
GLushort red;
GLushort green;
GLushort blue;
LOAD_GL_FUNC(glSecondaryColor3us)
red = (GLushort)NUM2INT(arg1);
green = (GLushort)NUM2INT(arg2);
blue = (GLushort)NUM2INT(arg3);
fptr_glSecondaryColor3us(red,green,blue);
return Qnil;
}
#define GLSECONDARYCOLOR_VFUNC(_type_) \
static VALUE \
gl_SecondaryColor##_type_##v(argc,argv,obj) \
int argc; \
VALUE *argv; \
VALUE obj; \
{ \
int num; \
VALUE args[3]; \
RArray *ary; \
switch (num = rb_scan_args(argc, argv, "12", &args[0], &args[1], &args[2])) { \
case 1: \
if (TYPE(args[0]) == T_ARRAY) { \
ary = RARRAY(args[0]); \
switch (ary->len) { \
case 3: \
gl_SecondaryColor3##_type_(obj,ary->ptr[0],ary->ptr[1],ary->ptr[2]); \
break; \
default: \
rb_raise(rb_eArgError, "array length:%d", num); \
} \
} \
else \
rb_raise(rb_eArgError, "array length:%d", num); \
break; \
case 3: \
gl_SecondaryColor3##_type_(obj,args[0], args[1], args[2]); \
break; \
default: \
rb_raise(rb_eArgError, "too many arguments"); \
break; \
} \
return Qnil; \
}
GLSECONDARYCOLOR_VFUNC(b)
GLSECONDARYCOLOR_VFUNC(d)
GLSECONDARYCOLOR_VFUNC(f)
GLSECONDARYCOLOR_VFUNC(i)
GLSECONDARYCOLOR_VFUNC(s)
GLSECONDARYCOLOR_VFUNC(ui)
GLSECONDARYCOLOR_VFUNC(ub)
GLSECONDARYCOLOR_VFUNC(us)
#undef GLSECONDARYCOLOR_VFUNC
extern VALUE g_SecondaryColor_ptr;
static void (APIENTRY * fptr_glSecondaryColorPointer)(GLint,GLenum,GLsizei,const GLvoid *);
static VALUE
gl_SecondaryColorPointer(obj,arg1,arg2,arg3,arg4)
VALUE obj,arg1,arg2,arg3,arg4;
{
GLint size;
GLenum type;
GLsizei stride;
LOAD_GL_FUNC(glSecondaryColorPointer)
size = (GLint)NUM2INT(arg1);
type = (GLenum)NUM2INT(arg2);
stride = (GLsizei)NUM2UINT(arg3);
Check_Type(arg4, T_STRING);
rb_str_freeze(arg4);
g_SecondaryColor_ptr = arg4;
fptr_glSecondaryColorPointer(size,type, stride, (const GLvoid*)RSTRING(arg4)->ptr);
return Qnil;
}
static void (APIENTRY * fptr_glWindowPos2d)(GLdouble,GLdouble);
static VALUE
gl_WindowPos2d(obj,arg1,arg2)
VALUE obj,arg1,arg2;
{
GLdouble x;
GLdouble y;
LOAD_GL_FUNC(glWindowPos2d)
x = (GLdouble)NUM2DBL(arg1);
y = (GLdouble)NUM2DBL(arg2);
fptr_glWindowPos2d(x,y);
return Qnil;
}
static void (APIENTRY * fptr_glWindowPos2f)(GLfloat,GLfloat);
static VALUE
gl_WindowPos2f(obj,arg1,arg2)
VALUE obj,arg1,arg2;
{
GLfloat x;
GLfloat y;
LOAD_GL_FUNC(glWindowPos2f)
x = (GLfloat)NUM2DBL(arg1);
y = (GLfloat)NUM2DBL(arg2);
fptr_glWindowPos2f(x,y);
return Qnil;
}
static void (APIENTRY * fptr_glWindowPos2i)(GLint,GLint);
static VALUE
gl_WindowPos2i(obj,arg1,arg2)
VALUE obj,arg1,arg2;
{
GLint x;
GLint y;
LOAD_GL_FUNC(glWindowPos2i)
x = (GLint)NUM2INT(arg1);
y = (GLint)NUM2INT(arg2);
fptr_glWindowPos2i(x,y);
return Qnil;
}
static void (APIENTRY * fptr_glWindowPos2s)(GLshort,GLshort);
static VALUE
gl_WindowPos2s(obj,arg1,arg2)
VALUE obj,arg1,arg2;
{
GLshort x;
GLshort y;
LOAD_GL_FUNC(glWindowPos2s)
x = (GLshort)NUM2INT(arg1);
y = (GLshort)NUM2INT(arg2);
fptr_glWindowPos2s(x,y);
return Qnil;
}
static void (APIENTRY * fptr_glWindowPos3d)(GLdouble,GLdouble,GLdouble);
static VALUE
gl_WindowPos3d(obj,arg1,arg2,arg3)
VALUE obj,arg1,arg2,arg3;
{
GLdouble x;
GLdouble y;
GLdouble z;
LOAD_GL_FUNC(glWindowPos3d)
x = (GLdouble)NUM2DBL(arg1);
y = (GLdouble)NUM2DBL(arg2);
z = (GLdouble)NUM2DBL(arg3);
fptr_glWindowPos3d(x,y,z);
return Qnil;
}
static void (APIENTRY * fptr_glWindowPos3f)(GLfloat,GLfloat,GLfloat);
static VALUE
gl_WindowPos3f(obj,arg1,arg2,arg3)
VALUE obj,arg1,arg2,arg3;
{
GLfloat x;
GLfloat y;
GLfloat z;
LOAD_GL_FUNC(glWindowPos3f)
x = (GLfloat)NUM2DBL(arg1);
y = (GLfloat)NUM2DBL(arg2);
z = (GLfloat)NUM2DBL(arg3);
fptr_glWindowPos3f(x,y,z);
return Qnil;
}
static void (APIENTRY * fptr_glWindowPos3i)(GLint,GLint,GLint);
static VALUE
gl_WindowPos3i(obj,arg1,arg2,arg3)
VALUE obj,arg1,arg2,arg3;
{
GLint x;
GLint y;
GLint z;
LOAD_GL_FUNC(glWindowPos3i)
x = (GLint)NUM2INT(arg1);
y = (GLint)NUM2INT(arg2);
z = (GLint)NUM2INT(arg3);
fptr_glWindowPos3i(x,y,z);
return Qnil;
}
static void (APIENTRY * fptr_glWindowPos3s)(GLshort,GLshort,GLshort);
static VALUE
gl_WindowPos3s(obj,arg1,arg2,arg3)
VALUE obj,arg1,arg2,arg3;
{
GLshort x;
GLshort y;
GLshort z;
LOAD_GL_FUNC(glWindowPos3s)
x = (GLshort)NUM2INT(arg1);
y = (GLshort)NUM2INT(arg2);
z = (GLshort)NUM2INT(arg3);
fptr_glWindowPos3s(x,y,z);
return Qnil;
}
#define GLWINDOWPOS_VFUNC(_type_) \
static VALUE \
gl_WindowPos##_type_##v(argc,argv,obj) \
int argc; \
VALUE *argv; \
VALUE obj; \
{ \
int num; \
VALUE args[3]; \
RArray *ary; \
switch (num = rb_scan_args(argc, argv, "12", &args[0], &args[1], &args[2])) { \
case 1: \
if (TYPE(args[0]) == T_ARRAY) { \
ary = RARRAY(args[0]); \
switch (ary->len) { \
case 2: \
gl_WindowPos2##_type_(obj,ary->ptr[0],ary->ptr[1]); \
break; \
case 3: \
gl_WindowPos3##_type_(obj,ary->ptr[0],ary->ptr[1],ary->ptr[2]); \
break; \
default: \
rb_raise(rb_eArgError, "array length:%d", num); \
} \
} \
else \
rb_raise(rb_eArgError, "array length:%d", num); \
break; \
case 2: \
gl_WindowPos2##_type_(obj,args[0], args[1]); \
break; \
case 3: \
gl_WindowPos3##_type_(obj,args[0], args[1], args[2]); \
break; \
default: \
rb_raise(rb_eArgError, "too many arguments"); \
break; \
} \
return Qnil; \
}
GLWINDOWPOS_VFUNC(d)
GLWINDOWPOS_VFUNC(f)
GLWINDOWPOS_VFUNC(i)
GLWINDOWPOS_VFUNC(s)
#undef GLWINDOWPOS_VFUNC
void gl_init_functions_1_4(VALUE module)
{
rb_define_module_function(module, "glBlendFuncSeparate", gl_BlendFuncSeparate, 4);
rb_define_module_function(module, "glFogCoordf", gl_FogCoordf, 1);
rb_define_module_function(module, "glFogCoordfv", gl_FogCoordfv, 1);
rb_define_module_function(module, "glFogCoordd", gl_FogCoordd, 1);
rb_define_module_function(module, "glFogCoorddv", gl_FogCoorddv, 1);
rb_define_module_function(module, "glFogCoordPointer", gl_FogCoordPointer, 3);
rb_define_module_function(module, "glMultiDrawArrays", gl_MultiDrawArrays, 4);
rb_define_module_function(module, "glMultiDrawElements", gl_MultiDrawElements, 3);
rb_define_module_function(module, "glPointParameterf", gl_PointParameterf, 2);
rb_define_module_function(module, "glPointParameterfv", gl_PointParameterfv, 2);
rb_define_module_function(module, "glPointParameteri", gl_PointParameteri, 2);
rb_define_module_function(module, "glPointParameteriv", gl_PointParameteriv, 2);
rb_define_module_function(module, "glSecondaryColor3b", gl_SecondaryColor3b, 3);
rb_define_module_function(module, "glSecondaryColor3d", gl_SecondaryColor3d, 3);
rb_define_module_function(module, "glSecondaryColor3f", gl_SecondaryColor3f, 3);
rb_define_module_function(module, "glSecondaryColor3i", gl_SecondaryColor3i, 3);
rb_define_module_function(module, "glSecondaryColor3s", gl_SecondaryColor3s, 3);
rb_define_module_function(module, "glSecondaryColor3ub", gl_SecondaryColor3ub, 3);
rb_define_module_function(module, "glSecondaryColor3ui", gl_SecondaryColor3ui, 3);
rb_define_module_function(module, "glSecondaryColor3us", gl_SecondaryColor3us, 3);
rb_define_module_function(module, "glSecondaryColorPointer", gl_SecondaryColorPointer, 4);
rb_define_module_function(module, "glWindowPos2d", gl_WindowPos2d, 2);
rb_define_module_function(module, "glWindowPos2f", gl_WindowPos2f, 2);
rb_define_module_function(module, "glWindowPos2i", gl_WindowPos2i, 2);
rb_define_module_function(module, "glWindowPos2s", gl_WindowPos2s, 2);
rb_define_module_function(module, "glWindowPos3d", gl_WindowPos3d, 3);
rb_define_module_function(module, "glWindowPos3f", gl_WindowPos3f, 3);
rb_define_module_function(module, "glWindowPos3i", gl_WindowPos3i, 3);
rb_define_module_function(module, "glWindowPos3s", gl_WindowPos3s, 3);
/* Additional Functions */
rb_define_module_function(module, "glSecondaryColor3bv", gl_SecondaryColorbv, -1);
rb_define_module_function(module, "glSecondaryColor3dv", gl_SecondaryColordv, -1);
rb_define_module_function(module, "glSecondaryColor3fv", gl_SecondaryColorfv, -1);
rb_define_module_function(module, "glSecondaryColor3iv", gl_SecondaryColoriv, -1);
rb_define_module_function(module, "glSecondaryColor3sv", gl_SecondaryColorsv, -1);
rb_define_module_function(module, "glSecondaryColor3ubv", gl_SecondaryColorubv, -1);
rb_define_module_function(module, "glSecondaryColor3uiv", gl_SecondaryColoruiv, -1);
rb_define_module_function(module, "glSecondaryColor3usv", gl_SecondaryColorusv, -1);
rb_define_module_function(module, "glWindowPos2dv", gl_WindowPosdv, -1);
rb_define_module_function(module, "glWindowPos2fv", gl_WindowPosfv, -1);
rb_define_module_function(module, "glWindowPos2iv", gl_WindowPosiv, -1);
rb_define_module_function(module, "glWindowPos2sv", gl_WindowPossv, -1);
rb_define_module_function(module, "glWindowPos3dv", gl_WindowPosdv, -1);
rb_define_module_function(module, "glWindowPos3fv", gl_WindowPosfv, -1);
rb_define_module_function(module, "glWindowPos3iv", gl_WindowPosiv, -1);
rb_define_module_function(module, "glWindowPos3sv", gl_WindowPossv, -1);
}

View File

@ -1,362 +0,0 @@
/*
* Copyright (C) 2007 Jan Dvorak <jan.dvorak@kraxnet.cz>
*
* This program is distributed under the terms of the MIT license.
* See the included MIT-LICENSE file for the terms of this license.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifdef __APPLE__
#include <OpenGL/gl.h>
#elif defined WIN32
#include <windows.h>
#include <GL/gl.h>
#else
#include <GL/gl.h>
#endif
#include "../common/common.h"
/* OpenGL 1.5 functions */
static void (APIENTRY * fptr_glGenQueries)(GLsizei,GLuint *);
static VALUE
gl_GenQueries(obj,arg1)
VALUE obj,arg1;
{
GLsizei n;
GLuint *queries;
RArray *ret;
int i;
LOAD_GL_FUNC(glGenQueries)
n = (GLsizei)NUM2UINT(arg1);
queries = ALLOC_N(GLuint, n);
fptr_glGenQueries(n, queries);
ret = RARRAY(rb_ary_new2(n));
for (i = 0; i < n; i++)
rb_ary_push((VALUE)ret, INT2NUM(queries[i]));
xfree(queries);
return (VALUE)ret;
}
static void (APIENTRY * fptr_glDeleteQueries)(GLsizei,GLuint *);
static VALUE
gl_DeleteQueries(obj,arg1)
VALUE obj,arg1;
{
GLsizei n;
GLuint *queries;
LOAD_GL_FUNC(glDeleteQueries)
Check_Type(arg1,T_ARRAY);
n = RARRAY(arg1)->len;
queries = ALLOC_N(GLuint,n);
ary2cuint(arg1,queries,n);
fptr_glDeleteQueries( n, queries);
xfree(queries);
return Qnil;
}
static GLboolean (APIENTRY * fptr_glIsQuery)(GLuint);
static VALUE
gl_IsQuery(obj,arg1)
VALUE obj,arg1;
{
GLuint query;
GLboolean ret;
LOAD_GL_FUNC(glIsQuery)
query = (GLuint)NUM2UINT(arg1);
ret = fptr_glIsQuery(query);
return INT2NUM(ret);
}
static void (APIENTRY * fptr_glBeginQuery)(GLenum,GLuint);
static VALUE
gl_BeginQuery(obj,arg1,arg2)
VALUE obj,arg1,arg2;
{
GLenum target;
GLuint id;
LOAD_GL_FUNC(glBeginQuery)
target = (GLenum)NUM2INT(arg1);
id = (GLuint)NUM2UINT(arg2);
fptr_glBeginQuery(target,id);
return Qnil;
}
static void (APIENTRY * fptr_glEndQuery)(GLenum);
static VALUE
gl_EndQuery(obj,arg1)
VALUE obj,arg1;
{
GLenum target;
LOAD_GL_FUNC(glEndQuery)
target = (GLenum)NUM2INT(arg1);
fptr_glEndQuery(target);
return Qnil;
}
static void (APIENTRY * fptr_glGetQueryiv)(GLenum,GLenum,GLint *);
static VALUE
gl_GetQueryiv(obj,arg1,arg2)
VALUE obj,arg1,arg2;
{
GLenum target;
GLenum pname;
GLint params = 0;
VALUE retary;
LOAD_GL_FUNC(glGetQueryiv)
target = (GLenum)NUM2INT(arg1);
pname = (GLenum)NUM2INT(arg2);
fptr_glGetQueryiv(target,pname,&params);
retary = rb_ary_new2(1);
rb_ary_push(retary, INT2NUM(params));
return retary;
}
static void (APIENTRY * fptr_glGetQueryObjectiv)(GLuint,GLenum,GLint *);
static VALUE
gl_GetQueryObjectiv(obj,arg1,arg2)
VALUE obj,arg1,arg2;
{
GLuint id;
GLenum pname;
GLint params = 0;
VALUE retary;
LOAD_GL_FUNC(glGetQueryObjectiv)
id = (GLuint)NUM2UINT(arg1);
pname = (GLenum)NUM2INT(arg2);
fptr_glGetQueryObjectiv(id,pname,&params);
retary = rb_ary_new2(1);
rb_ary_push(retary,INT2NUM(params));
return retary;
}
static void (APIENTRY * fptr_glGetQueryObjectuiv)(GLuint,GLenum,GLuint *);
static VALUE
gl_GetQueryObjectuiv(obj,arg1,arg2,arg3)
VALUE obj,arg1,arg2,arg3;
{
GLuint id;
GLenum pname;
GLuint params = 0;
VALUE retary;
LOAD_GL_FUNC(glGetQueryObjectuiv)
id = (GLuint)NUM2UINT(arg1);
pname = (GLenum)NUM2INT(arg2);
fptr_glGetQueryObjectuiv(id,pname,&params);
retary = rb_ary_new2(1);
rb_ary_push(retary,INT2NUM(params));
return retary;
}
static void (APIENTRY * fptr_glBindBuffer)(GLenum,GLuint);
static VALUE
gl_BindBuffer(obj,arg1,arg2)
VALUE obj,arg1,arg2;
{
GLenum target;
GLuint buffer;
LOAD_GL_FUNC(glBindBuffer)
target = (GLenum)NUM2INT(arg1);
buffer = (GLenum)NUM2INT(arg2);
fptr_glBindBuffer(target,buffer);
return Qnil;
}
static void (APIENTRY * fptr_glDeleteBuffers)(GLsizei,GLuint *);
static VALUE
gl_DeleteBuffers(obj,arg1)
VALUE obj,arg1;
{
GLsizei n;
GLuint *buffers;
LOAD_GL_FUNC(glDeleteBuffers)
Check_Type(arg1,T_ARRAY);
n = RARRAY(arg1)->len;
buffers = ALLOC_N(GLuint,n);
ary2cuint(arg1,buffers,n);
fptr_glDeleteBuffers(n, buffers);
xfree(buffers);
return Qnil;
}
static void (APIENTRY * fptr_glGenBuffers)(GLsizei,GLuint *);
static VALUE
gl_GenBuffers(obj,arg1)
VALUE obj,arg1;
{
GLsizei n;
GLuint *buffers;
RArray *ret;
int i;
LOAD_GL_FUNC(glGenBuffers)
n = (GLsizei)NUM2UINT(arg1);
buffers = ALLOC_N(GLuint, n);
fptr_glGenBuffers(n, buffers);
ret = RARRAY(rb_ary_new2(n));
for (i = 0; i < n; i++)
rb_ary_push((VALUE)ret, INT2NUM(buffers[i]));
xfree(buffers);
return (VALUE)ret;
}
static GLboolean (APIENTRY * fptr_glIsBuffer)(GLuint);
static VALUE
gl_IsBuffer(obj,arg1)
VALUE obj,arg1;
{
GLuint buffer;
GLboolean ret;
LOAD_GL_FUNC(glIsBuffer)
buffer = (GLuint)NUM2UINT(arg1);
ret = fptr_glIsBuffer(buffer);
return INT2NUM(ret);
}
static void (APIENTRY * fptr_glBufferData)(GLenum,GLsizeiptr,GLvoid *,GLenum);
static VALUE
gl_BufferData(obj,arg1,arg2,arg3,arg4)
VALUE obj,arg1,arg2,arg3,arg4;
{
GLenum target;
GLsizeiptr size;
GLenum usage;
LOAD_GL_FUNC(glBufferData)
target = (GLenum)NUM2INT(arg1);
size = (GLsizeiptr)NUM2INT(arg2);
usage = (GLenum)NUM2INT(arg4);
if (TYPE(arg3) == T_STRING) {
fptr_glBufferData(target,size,(GLvoid *)RSTRING(arg3)->ptr,usage);
} else if (NIL_P(arg3)) {
fptr_glBufferData(target,size,NULL,usage);
} else {
Check_Type(arg3,T_STRING); /* force exception */
}
return Qnil;
}
static void (APIENTRY * fptr_glBufferSubData)(GLenum,GLintptr,GLsizeiptr,GLvoid *);
static VALUE
gl_BufferSubData(obj,arg1,arg2,arg3,arg4)
VALUE obj,arg1,arg2,arg3,arg4;
{
GLenum target;
GLintptr offset;
GLsizeiptr size;
LOAD_GL_FUNC(glBufferSubData)
target = (GLenum)NUM2INT(arg1);
offset = (GLintptr)NUM2INT(arg2);
size = (GLsizeiptr)NUM2INT(arg3);
Check_Type(arg4,T_STRING);
fptr_glBufferSubData(target,offset,size,(GLvoid *)RSTRING(arg4)->ptr);
return Qnil;
}
static void (APIENTRY * fptr_glGetBufferSubData)(GLenum,GLintptr,GLsizeiptr,GLvoid *);
static VALUE
gl_GetBufferSubData(obj,arg1,arg2,arg3)
VALUE obj,arg1,arg2,arg3;
{
GLenum target;
GLintptr offset;
GLsizeiptr size;
VALUE data;
LOAD_GL_FUNC(glGetBufferSubData)
target = (GLenum)NUM2INT(arg1);
offset = (GLintptr)NUM2INT(arg2);
size = (GLsizeiptr)NUM2INT(arg3);
data = allocate_buffer_with_string(size);
fptr_glGetBufferSubData(target,offset,size,(GLvoid *)RSTRING(data)->ptr);
return data;
}
static void (APIENTRY * fptr_glGetBufferParameteriv)(GLenum,GLenum,GLint *);
static VALUE
gl_GetBufferParameteriv(obj,arg1,arg2)
VALUE obj,arg1,arg2;
{
GLenum target;
GLenum value;
GLint data = 0;
VALUE retary;
LOAD_GL_FUNC(glGetBufferParameteriv)
target = (GLenum)NUM2INT(arg1);
value = (GLenum)NUM2INT(arg2);
fptr_glGetBufferParameteriv(target,value,&data);
retary = rb_ary_new2(1);
rb_ary_push(retary,INT2NUM(data));
return retary;
}
static GLvoid * (APIENTRY * fptr_glMapBuffer)(GLenum,GLenum);
static VALUE
gl_MapBuffer(obj,arg1,arg2)
VALUE obj,arg1,arg2;
{
GLenum target;
GLenum access;
GLint size = 0;
VALUE data;
GLvoid *buffer_ptr;
LOAD_GL_FUNC(glMapBuffer)
LOAD_GL_FUNC(glGetBufferParameteriv)
target = (GLenum)NUM2INT(arg1);
access = (GLenum)NUM2INT(arg2);
fptr_glGetBufferParameteriv(target,GL_BUFFER_SIZE,&size);
buffer_ptr = fptr_glMapBuffer(target,access);
data = allocate_buffer_with_string(size);
memcpy(RSTRING(data)->ptr, buffer_ptr, size);
return data;
}
static GLboolean (APIENTRY * fptr_glUnmapBuffer)(GLenum);
static VALUE
gl_UnmapBuffer(obj,arg1)
VALUE obj,arg1;
{
GLenum target;
GLboolean ret;
LOAD_GL_FUNC(glUnmapBuffer)
target = (GLenum)NUM2INT(arg1);
ret = fptr_glUnmapBuffer(target);
return INT2NUM(ret);
}
static void (APIENTRY * fptr_glGetBufferPointerv)(GLenum,GLenum,GLvoid **);
static VALUE
gl_GetBufferPointerv(obj,arg1,arg2,arg3)
VALUE obj,arg1,arg2,arg3;
{
LOAD_GL_FUNC(glGetBufferPointerv)
/* not implemented */
return Qnil;
}
void gl_init_functions_1_5(VALUE module)
{
rb_define_module_function(module, "glGenQueries", gl_GenQueries, 1);
rb_define_module_function(module, "glDeleteQueries", gl_DeleteQueries, 1);
rb_define_module_function(module, "glIsQuery", gl_IsQuery, 1);
rb_define_module_function(module, "glBeginQuery", gl_BeginQuery, 2);
rb_define_module_function(module, "glEndQuery", gl_EndQuery, 1);
rb_define_module_function(module, "glGetQueryiv", gl_GetQueryiv, 2);
rb_define_module_function(module, "glGetQueryObjectiv", gl_GetQueryObjectiv, 2);
rb_define_module_function(module, "glGetQueryObjectuiv", gl_GetQueryObjectuiv, 2);
rb_define_module_function(module, "glBindBuffer", gl_BindBuffer, 2);
rb_define_module_function(module, "glDeleteBuffers", gl_DeleteBuffers, 1);
rb_define_module_function(module, "glGenBuffers", gl_GenBuffers, 1);
rb_define_module_function(module, "glIsBuffer", gl_IsBuffer, 1);
rb_define_module_function(module, "glBufferData", gl_BufferData, 4);
rb_define_module_function(module, "glBufferSubData", gl_BufferSubData, 4);
rb_define_module_function(module, "glGetBufferSubData", gl_GetBufferSubData, 3);
rb_define_module_function(module, "glMapBuffer", gl_MapBuffer, 2);
rb_define_module_function(module, "glUnmapBuffer", gl_UnmapBuffer, 1);
rb_define_module_function(module, "glGetBufferParameteriv", gl_GetBufferParameteriv, 2);
rb_define_module_function(module, "glGetBufferPointerv", gl_GetBufferPointerv, 3);
}

File diff suppressed because it is too large Load Diff

View File

@ -1,154 +0,0 @@
/*
* Copyright (C) 2007 Jan Dvorak <jan.dvorak@kraxnet.cz>
*
* This program is distributed under the terms of the MIT license.
* See the included MIT-LICENSE file for the terms of this license.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifdef __APPLE__
#include <OpenGL/gl.h>
#elif defined WIN32
#include <windows.h>
#include <GL/gl.h>
#else
#include <GL/gl.h>
#endif
#include "../common/common.h"
static void (APIENTRY * fptr_glUniformMatrix2x3fv)(GLint,GLsizei,GLboolean,GLfloat *);
static VALUE
gl_UniformMatrix2x3fv(obj,arg1,arg2,arg3,arg4)
VALUE obj,arg1,arg2,arg3,arg4;
{
GLint location;
GLsizei count;
GLboolean transpose;
GLfloat *value;
LOAD_GL_FUNC(glUniformMatrix2x3fv)
location = (GLint)NUM2INT(arg1);
count = (GLint)NUM2INT(arg2);
transpose = (GLboolean)NUM2INT(arg3);
value = ALLOC_N(GLfloat, 2*3*count);
ary2cflt(arg4,value,2*3*count);
fptr_glUniformMatrix2x3fv(location,count,transpose,value);
xfree(value);
return Qnil;
}
static void (APIENTRY * fptr_glUniformMatrix3x2fv)(GLint,GLsizei,GLboolean,GLfloat *);
static VALUE
gl_UniformMatrix3x2fv(obj,arg1,arg2,arg3,arg4)
VALUE obj,arg1,arg2,arg3,arg4;
{
GLint location;
GLsizei count;
GLboolean transpose;
GLfloat *value;
LOAD_GL_FUNC(glUniformMatrix3x2fv)
location = (GLint)NUM2INT(arg1);
count = (GLint)NUM2INT(arg2);
transpose = (GLboolean)NUM2INT(arg3);
value = ALLOC_N(GLfloat, 3*2*count);
ary2cflt(arg4,value,3*2*count);
fptr_glUniformMatrix3x2fv(location,count,transpose,value);
xfree(value);
return Qnil;
}
static void (APIENTRY * fptr_glUniformMatrix2x4fv)(GLint,GLsizei,GLboolean,GLfloat *);
static VALUE
gl_UniformMatrix2x4fv(obj,arg1,arg2,arg3,arg4)
VALUE obj,arg1,arg2,arg3,arg4;
{
GLint location;
GLsizei count;
GLboolean transpose;
GLfloat *value;
LOAD_GL_FUNC(glUniformMatrix2x4fv)
location = (GLint)NUM2INT(arg1);
count = (GLint)NUM2INT(arg2);
transpose = (GLboolean)NUM2INT(arg3);
value = ALLOC_N(GLfloat, 2*4*count);
ary2cflt(arg4,value,2*4*count);
fptr_glUniformMatrix2x4fv(location,count,transpose,value);
xfree(value);
return Qnil;
}
static void (APIENTRY * fptr_glUniformMatrix4x2fv)(GLint,GLsizei,GLboolean,GLfloat *);
static VALUE
gl_UniformMatrix4x2fv(obj,arg1,arg2,arg3,arg4)
VALUE obj,arg1,arg2,arg3,arg4;
{
GLint location;
GLsizei count;
GLboolean transpose;
GLfloat *value;
LOAD_GL_FUNC(glUniformMatrix4x2fv)
location = (GLint)NUM2INT(arg1);
count = (GLint)NUM2INT(arg2);
transpose = (GLboolean)NUM2INT(arg3);
value = ALLOC_N(GLfloat, 4*2*count);
ary2cflt(arg4,value,4*2*count);
fptr_glUniformMatrix4x2fv(location,count,transpose,value);
xfree(value);
return Qnil;
}
static void (APIENTRY * fptr_glUniformMatrix3x4fv)(GLint,GLsizei,GLboolean,GLfloat *);
static VALUE
gl_UniformMatrix3x4fv(obj,arg1,arg2,arg3,arg4)
VALUE obj,arg1,arg2,arg3,arg4;
{
GLint location;
GLsizei count;
GLboolean transpose;
GLfloat *value;
LOAD_GL_FUNC(glUniformMatrix3x4fv)
location = (GLint)NUM2INT(arg1);
count = (GLint)NUM2INT(arg2);
transpose = (GLboolean)NUM2INT(arg3);
value = ALLOC_N(GLfloat, 3*4*count);
ary2cflt(arg4,value,3*4*count);
fptr_glUniformMatrix3x4fv(location,count,transpose,value);
xfree(value);
return Qnil;
}
static void (APIENTRY * fptr_glUniformMatrix4x3fv)(GLint,GLsizei,GLboolean,GLfloat *);
static VALUE
gl_UniformMatrix4x3fv(obj,arg1,arg2,arg3,arg4)
VALUE obj,arg1,arg2,arg3,arg4;
{
GLint location;
GLsizei count;
GLboolean transpose;
GLfloat *value;
LOAD_GL_FUNC(glUniformMatrix4x3fv)
location = (GLint)NUM2INT(arg1);
count = (GLint)NUM2INT(arg2);
transpose = (GLboolean)NUM2INT(arg3);
value = ALLOC_N(GLfloat, 4*3*count);
ary2cflt(arg4,value,4*3*count);
fptr_glUniformMatrix4x3fv(location,count,transpose,value);
xfree(value);
return Qnil;
}
void gl_init_functions_2_1(VALUE module)
{
rb_define_module_function(module, "glUniformMatrix2x3fv", gl_UniformMatrix2x3fv, 4);
rb_define_module_function(module, "glUniformMatrix3x2fv", gl_UniformMatrix3x2fv, 4);
rb_define_module_function(module, "glUniformMatrix2x4fv", gl_UniformMatrix2x4fv, 4);
rb_define_module_function(module, "glUniformMatrix4x2fv", gl_UniformMatrix4x2fv, 4);
rb_define_module_function(module, "glUniformMatrix3x4fv", gl_UniformMatrix3x4fv, 4);
rb_define_module_function(module, "glUniformMatrix4x3fv", gl_UniformMatrix4x3fv, 4);
}

File diff suppressed because it is too large Load Diff

View File

@ -1,87 +0,0 @@
/*
* Copyright (C) 1999 - 2005 Yoshi <yoshi@giganet.net>
* Copyright (C) 2006 John M. Gabriele <jmg3000@gmail.com>
*
* This program is distributed under the terms of the MIT license.
* See the included MIT-LICENSE file for the terms of this license.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifdef __APPLE__
#include <OpenGL/gl.h>
#elif defined WIN32
#include <windows.h>
#include <GL/gl.h>
#else
#include <GL/gl.h>
#endif
#include "../common/common.h"
#ifdef WIN32
#define DLLEXPORT __declspec(dllexport)
#else
#define DLLEXPORT
#endif
static VALUE module;
void gl_init_enums(VALUE);
void gl_init_functions_1_0__1_1(VALUE);
void gl_init_functions_1_2(VALUE);
void gl_init_functions_1_3(VALUE);
void gl_init_functions_1_4(VALUE);
void gl_init_functions_1_5(VALUE);
void gl_init_functions_2_0(VALUE);
void gl_init_functions_2_1(VALUE);
VALUE IsFunctionAvailable(char *name)
{
GLvoid *ret;
ret = load_gl_function(name,0); /* won't raise */
if (ret==NULL)
return Qfalse;
else
return Qtrue;
}
static VALUE
IsAvailable(obj,arg1)
VALUE obj,arg1;
{
char *name = RSTRING(arg1)->ptr;
Check_Type(arg1, T_STRING);
if (name && name[0] && (name[0]=='G' || name[0]=='W')) { /* GL_, GLX_, WGL_ extension */
char buf[512+128];
if (strlen(name)>(512))
return Qfalse;
if (glGetString(GL_EXTENSIONS)==0)
return Qfalse;
sprintf(buf,"Gl.glGetString(Gl::GL_EXTENSIONS).split(' ').include?('%s')", name);
return rb_eval_string(buf);
} else { /* function */
return IsFunctionAvailable(name);
}
}
DLLEXPORT void Init_gl()
{
module = rb_define_module("Gl");
gl_init_enums(module);
gl_init_functions_1_0__1_1(module);
gl_init_functions_1_2(module);
gl_init_functions_1_3(module);
gl_init_functions_1_4(module);
gl_init_functions_1_5(module);
gl_init_functions_2_0(module);
gl_init_functions_2_1(module);
rb_define_module_function(module, "is_available?", IsAvailable, 1);
}

View File

@ -1,20 +0,0 @@
require "mkmf"
$CFLAGS = "/MD /O2 /EHsc /DWIN32 /DNDEBUG /D_WINDOWS"
#$CFLAGS = "/MD /Zi /EHsc /DWIN32 /DNDEBUG /D_WINDOWS"
#$LDFLAGS = "/Zi"
libs = [
"opengl32",
"glu32",
]
libs.each {|lib|
unless have_library(lib)
puts "Unable to find #{lib}.lib!"
puts
exit
end
}
create_makefile("glu")

File diff suppressed because it is too large Load Diff

View File

@ -1,213 +0,0 @@
////////////////////////////////////////////////////////////
//
// RubySFML - Ruby extension for the SFML library
// Copyright (C) 2007 Sean O'Neil and Laurent Gomila
// (sean.p.oneil@gmail.com and laurent.gom@gmail.com)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
// you must not claim that you wrote the original software.
// If you use this software in a product, an acknowledgment
// in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
// and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
////////////////////////////////////////////////////////////
#include <SFML/System.hpp>
#include <SFML/Window.hpp>
#include <SFML/Window/OpenGLCaps.hpp>
#include <SFML/Graphics.hpp>
#include <SFML/Audio.hpp>
#include "RubySFML.h"
using namespace sf;
VALUE NOARGV[1];
VALUE g_vModule;
/*
* Returns true if the specified OpenGL extension is supported, false otherwise.
*/
VALUE SFML_checkExtension(VALUE vClass, VALUE vName) {
return OpenGLCaps::CheckExtension(STR2CSTR(vName)) ? Qtrue : Qfalse;
}
/*
* Returns the maximum texture size on the current display hardware.
*/
VALUE SFML_getMaxTextureSize() {
return INT2NUM(OpenGLCaps::GetMaxTextureSize());
}
/*
* Returns the maximum texture units on the current display hardware.
*/
VALUE SFML_getMaxTextureUnits() {
return INT2NUM(OpenGLCaps::GetMaxTextureUnits());
}
extern "C" void Init_RubySFML() {
g_vModule = rb_define_module("SFML");
DEFINE_MODULE_METHOD(checkExtension, checkExtension, 1);
DEFINE_MODULE_METHOD(checkExtension, getMaxTextureSize, 0);
DEFINE_MODULE_METHOD(checkExtension, getMaxTextureUnits, 0);
Init_Clock();
Init_Color();
Init_Drawable();
Init_Event();
Init_FloatRect();
Init_Image();
Init_Input();
Init_IntRect();
Init_Music();
Init_PostFX();
Init_RenderWindow();
Init_Sound();
Init_SoundBuffer();
Init_SoundBufferRecorder();
Init_Sprite();
Init_String();
Init_VideoMode();
Init_View();
Init_Window();
// Window style constants
VALUE vStyle = rb_define_module_under(g_vModule, "Style");
rb_define_const(g_cWindow, "Resize", INT2FIX(Style::Resize));
rb_define_const(g_cWindow, "Close", INT2FIX(Style::Close));
rb_define_const(g_cWindow, "Fullscreen", INT2FIX(Style::Fullscreen));
// Sound constants
rb_define_const(g_cSound, "Stopped", INT2FIX(Sound::Stopped));
rb_define_const(g_cSound, "Paused", INT2FIX(Sound::Paused));
rb_define_const(g_cSound, "Playing", INT2FIX(Sound::Playing));
// Event constants
rb_define_const(g_cEvent, "Closed", INT2FIX(Event::Closed));
rb_define_const(g_cEvent, "Resized", INT2FIX(Event::Resized));
rb_define_const(g_cEvent, "LostFocus", INT2FIX(Event::LostFocus));
rb_define_const(g_cEvent, "GainedFocus", INT2FIX(Event::GainedFocus));
rb_define_const(g_cEvent, "TextEntered", INT2FIX(Event::TextEntered));
rb_define_const(g_cEvent, "KeyPressed", INT2FIX(Event::KeyPressed));
rb_define_const(g_cEvent, "KeyReleased", INT2FIX(Event::KeyReleased));
rb_define_const(g_cEvent, "MouseWheelMoved", INT2FIX(Event::MouseWheelMoved));
rb_define_const(g_cEvent, "MouseButtonPressed", INT2FIX(Event::MouseButtonPressed));
rb_define_const(g_cEvent, "MouseButtonReleased", INT2FIX(Event::MouseButtonReleased));
rb_define_const(g_cEvent, "MouseMoved", INT2FIX(Event::MouseMoved));
rb_define_const(g_cEvent, "JoyButtonPressed", INT2FIX(Event::JoyButtonPressed));
rb_define_const(g_cEvent, "JoyButtonReleased", INT2FIX(Event::JoyButtonReleased));
rb_define_const(g_cEvent, "JoyMoved", INT2FIX(Event::JoyMoved));
// Mouse constants
VALUE vMouse = rb_define_module_under(g_vModule, "Mouse");
rb_define_const(vMouse, "Left", INT2FIX(Mouse::Left));
rb_define_const(vMouse, "Right", INT2FIX(Mouse::Right));
rb_define_const(vMouse, "Middle", INT2FIX(Mouse::Middle));
rb_define_const(vMouse, "XButton1", INT2FIX(Mouse::XButton1));
rb_define_const(vMouse, "XButton2", INT2FIX(Mouse::XButton2));
// Joystick constants
VALUE vJoy = rb_define_module_under(g_vModule, "Joy");
rb_define_const(vJoy, "AxisX", INT2FIX(Joy::AxisX));
rb_define_const(vJoy, "AxisY", INT2FIX(Joy::AxisY));
rb_define_const(vJoy, "AxisZ", INT2FIX(Joy::AxisZ));
rb_define_const(vJoy, "AxisR", INT2FIX(Joy::AxisR));
rb_define_const(vJoy, "AxisU", INT2FIX(Joy::AxisU));
rb_define_const(vJoy, "AxisV", INT2FIX(Joy::AxisV));
rb_define_const(vJoy, "AxisPOV", INT2FIX(Joy::AxisPOV));
// Keyboard constants
VALUE vKey = rb_define_module_under(g_vModule, "Key");
rb_define_const(vKey, "A", INT2FIX(Key::A));
rb_define_const(vKey, "B", INT2FIX(Key::B));
rb_define_const(vKey, "C", INT2FIX(Key::C));
rb_define_const(vKey, "D", INT2FIX(Key::D));
rb_define_const(vKey, "E", INT2FIX(Key::E));
rb_define_const(vKey, "F", INT2FIX(Key::F));
rb_define_const(vKey, "G", INT2FIX(Key::G));
rb_define_const(vKey, "H", INT2FIX(Key::H));
rb_define_const(vKey, "I", INT2FIX(Key::I));
rb_define_const(vKey, "J", INT2FIX(Key::J));
rb_define_const(vKey, "K", INT2FIX(Key::K));
rb_define_const(vKey, "L", INT2FIX(Key::L));
rb_define_const(vKey, "M", INT2FIX(Key::M));
rb_define_const(vKey, "N", INT2FIX(Key::N));
rb_define_const(vKey, "O", INT2FIX(Key::O));
rb_define_const(vKey, "P", INT2FIX(Key::P));
rb_define_const(vKey, "Q", INT2FIX(Key::Q));
rb_define_const(vKey, "R", INT2FIX(Key::R));
rb_define_const(vKey, "S", INT2FIX(Key::S));
rb_define_const(vKey, "T", INT2FIX(Key::T));
rb_define_const(vKey, "U", INT2FIX(Key::U));
rb_define_const(vKey, "V", INT2FIX(Key::V));
rb_define_const(vKey, "W", INT2FIX(Key::W));
rb_define_const(vKey, "X", INT2FIX(Key::X));
rb_define_const(vKey, "Y", INT2FIX(Key::Y));
rb_define_const(vKey, "Z", INT2FIX(Key::Z));
rb_define_const(vKey, "Num0", INT2FIX(Key::Num0));
rb_define_const(vKey, "Num1", INT2FIX(Key::Num1));
rb_define_const(vKey, "Num2", INT2FIX(Key::Num2));
rb_define_const(vKey, "Num3", INT2FIX(Key::Num3));
rb_define_const(vKey, "Num4", INT2FIX(Key::Num4));
rb_define_const(vKey, "Num5", INT2FIX(Key::Num5));
rb_define_const(vKey, "Num6", INT2FIX(Key::Num6));
rb_define_const(vKey, "Num7", INT2FIX(Key::Num7));
rb_define_const(vKey, "Num8", INT2FIX(Key::Num8));
rb_define_const(vKey, "Num9", INT2FIX(Key::Num9));
rb_define_const(vKey, "Escape", INT2FIX(Key::Escape));
rb_define_const(vKey, "Space", INT2FIX(Key::Space));
rb_define_const(vKey, "Return", INT2FIX(Key::Return));
rb_define_const(vKey, "Back", INT2FIX(Key::Space));
rb_define_const(vKey, "Tab", INT2FIX(Key::Tab));
rb_define_const(vKey, "PageUp", INT2FIX(Key::PageUp));
rb_define_const(vKey, "PageDown", INT2FIX(Key::PageDown));
rb_define_const(vKey, "End", INT2FIX(Key::End));
rb_define_const(vKey, "Home", INT2FIX(Key::Home));
rb_define_const(vKey, "Insert", INT2FIX(Key::Insert));
rb_define_const(vKey, "Delete", INT2FIX(Key::Delete));
rb_define_const(vKey, "Add", INT2FIX(Key::Add));
rb_define_const(vKey, "Subtract", INT2FIX(Key::Subtract));
rb_define_const(vKey, "Multiply", INT2FIX(Key::Multiply));
rb_define_const(vKey, "Divide", INT2FIX(Key::Divide));
rb_define_const(vKey, "Left", INT2FIX(Key::Left));
rb_define_const(vKey, "Right", INT2FIX(Key::Right));
rb_define_const(vKey, "Up", INT2FIX(Key::Up));
rb_define_const(vKey, "Down", INT2FIX(Key::Down));
rb_define_const(vKey, "Numpad0", INT2FIX(Key::Numpad0));
rb_define_const(vKey, "Numpad1", INT2FIX(Key::Numpad1));
rb_define_const(vKey, "Numpad2", INT2FIX(Key::Numpad2));
rb_define_const(vKey, "Numpad3", INT2FIX(Key::Numpad3));
rb_define_const(vKey, "Numpad4", INT2FIX(Key::Numpad4));
rb_define_const(vKey, "Numpad5", INT2FIX(Key::Numpad5));
rb_define_const(vKey, "Numpad6", INT2FIX(Key::Numpad6));
rb_define_const(vKey, "Numpad7", INT2FIX(Key::Numpad7));
rb_define_const(vKey, "Numpad8", INT2FIX(Key::Numpad8));
rb_define_const(vKey, "Numpad9", INT2FIX(Key::Numpad9));
rb_define_const(vKey, "F1", INT2FIX(Key::F1));
rb_define_const(vKey, "F2", INT2FIX(Key::F2));
rb_define_const(vKey, "F3", INT2FIX(Key::F3));
rb_define_const(vKey, "F4", INT2FIX(Key::F4));
rb_define_const(vKey, "F5", INT2FIX(Key::F5));
rb_define_const(vKey, "F6", INT2FIX(Key::F6));
rb_define_const(vKey, "F7", INT2FIX(Key::F7));
rb_define_const(vKey, "F8", INT2FIX(Key::F8));
rb_define_const(vKey, "F9", INT2FIX(Key::F9));
rb_define_const(vKey, "F10", INT2FIX(Key::F10));
rb_define_const(vKey, "F11", INT2FIX(Key::F11));
rb_define_const(vKey, "F12", INT2FIX(Key::F12));
rb_define_const(vKey, "F13", INT2FIX(Key::F13));
rb_define_const(vKey, "F14", INT2FIX(Key::F14));
rb_define_const(vKey, "F15", INT2FIX(Key::F15));
rb_define_const(vKey, "Pause", INT2FIX(Key::Pause));
}

View File

@ -1,88 +0,0 @@
////////////////////////////////////////////////////////////
//
// RubySFML - Ruby extension for the SFML library
// Copyright (C) 2007 Sean O'Neil and Laurent Gomila
// (sean.p.oneil@gmail.com and laurent.gom@gmail.com)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
// you must not claim that you wrote the original software.
// If you use this software in a product, an acknowledgment
// in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
// and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
////////////////////////////////////////////////////////////
#include "ruby_helper.h"
extern VALUE NOARGV[1];
// SFML Ruby module object
extern VALUE g_vModule;
// SFML Ruby class objects
extern VALUE g_cClock;
extern VALUE g_cColor;
extern VALUE g_cDrawable;
extern VALUE g_cEvent;
extern VALUE g_cFloatRect;
extern VALUE g_cImage;
extern VALUE g_cInput;
extern VALUE g_cIntRect;
extern VALUE g_cMusic;
extern VALUE g_cPostFX;
extern VALUE g_cRenderWindow;
extern VALUE g_cSound;
extern VALUE g_cSoundBuffer;
extern VALUE g_cSoundBufferRecorder;
extern VALUE g_cSprite;
extern VALUE g_cString;
extern VALUE g_cVideoMode;
extern VALUE g_cView;
extern VALUE g_cWindow;
// SMFL Ruby class init functions
extern void Init_Clock();
extern void Init_Color();
extern void Init_Drawable();
extern void Init_Event();
extern void Init_FloatRect();
extern void Init_Image();
extern void Init_Input();
extern void Init_IntRect();
extern void Init_Music();
extern void Init_PostFX();
extern void Init_RenderWindow();
extern void Init_Sound();
extern void Init_SoundBuffer();
extern void Init_SoundBufferRecorder();
extern void Init_Sprite();
extern void Init_String();
extern void Init_VideoMode();
extern void Init_View();
extern void Init_Window();
extern void Color_free(void *p);
extern VALUE Color_new(int argc, VALUE *argv, VALUE vClass);
extern void Event_free(void *p);
extern VALUE Event_new(int argc, VALUE *argv, VALUE vClass);
extern void FloatRect_free(void *p);
extern VALUE FloatRect_new(int argc, VALUE *argv, VALUE vClass);
extern void Image_free(void *p);
extern VALUE Image_new(int argc, VALUE *argv, VALUE vClass);
extern void IntRect_free(void *p);
extern VALUE IntRect_new(int argc, VALUE *argv, VALUE vClass);

View File

@ -1,83 +0,0 @@
require "RubySFML.so"
module SFML
# A simple class for dealing with tiled sprites.
class TSprite < Sprite
# Use to set/get the tile column
attr_accessor :tx
# Use to set/get the tile row
attr_accessor :ty
# Pass in the image, the tile width, and the tile height.
def initialize(image, w, h)
super(image)
@tx, @ty, @tw, @th = 0, 0, w, h
setRotationCenter(@tw/2, @th/2)
end
# Overrides Sprite::render to call setSubRect() for you to choose a
# tile based on tx and ty before the sprite is rendered.
def render(win)
l, t = @tw*@tx, @th*@ty
setSubRect(IntRect.new(l, t, l+@tw, t+@th))
super(win)
end
end
# A simple class for dealing with sprites and 2D velocity/acceleration
class VSprite < TSprite
# Use to get/set the x component of the velocity vector
attr_accessor :vx
# Use to get/set the y component of the velocity vector
attr_accessor :vy
# Pass in the image, the tile width, and the tile height.
def initialize(image, w, h)
super(image, w, h)
@vx = @vy = 0.0
end
# Specify a number of degrees to rotate left
def turn_left(degrees) rotate(degrees); end
# Specify a number of degrees to rotate right
def turn_right(degrees) rotate(-degrees); end
# Returns the magnitude of the velocity vector
def speed
return Math.sqrt(@vx**2 + @vy**2)
end
# Returns the direction of the velocity vector
def direction
s = speed
return [@vx/s, @vy/s]
end
# Accelerates the sprite in the direction vector v by the amount "thrust"
def accelerate(v, thrust)
@vx += v[0] * thrust
@vy += v[1] * thrust
end
# Scales the speed component of the velocity
def scale_speed(amount)
@vx *= amount
@vy *= amount
end
# Moves the sprite in the direction vector v by the amound d
def move(v, d)
self.x += v[0] * d
self.y += v[1] * d
end
# Updates the sprite's position based on its velocity and its time slice
def update(time)
self.x += @vx * time
self.y += @vy * time
end
end
end

View File

@ -1,26 +0,0 @@
require "mkmf"
dir_config('SFML')
libs = [
"GL",
"GLU",
"sfml-system",
"sfml-window",
"sfml-graphics",
"sfml-audio",
]
libs.each {|lib|
unless have_library(lib)
puts "Unable to find #{lib}.lib!"
puts "Please specify the path to them using:"
puts "--with-SFML-lib=lib_path"
puts "--with-SFML-include=include_path"
puts
exit
end
}
create_makefile("RubySFML")

View File

@ -1,30 +0,0 @@
require "mkmf"
$CFLAGS = "/MD /O2 /EHsc /DWIN32 /DNDEBUG /D_WINDOWS"
#$CFLAGS = "/MD /Zi /EHsc /DWIN32 /DNDEBUG /D_WINDOWS"
#$LDFLAGS = "/Zi"
dir_config('SFML')
libs = [
"gdi32",
"opengl32",
"glu32",
"sfml-system-s",
"sfml-window-s",
"sfml-graphics-s",
"sfml-audio-s",
]
libs.each {|lib|
unless have_library(lib)
puts "Unable to find #{lib}.lib!"
puts "Please specify the path to them using:"
puts "--with-SFML-lib=lib_path"
puts "--with-SFML-include=include_path"
puts
exit
end
}
create_makefile("RubySFML")

View File

@ -1,846 +0,0 @@
////////////////////////////////////////////////////////////
//
// RubySFML - Ruby extension for the SFML library
// Copyright (C) 2007 Sean O'Neil and Laurent Gomila
// (sean.p.oneil@gmail.com and laurent.gom@gmail.com)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
// you must not claim that you wrote the original software.
// If you use this software in a product, an acknowledgment
// in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
// and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
////////////////////////////////////////////////////////////
#ifndef __ruby_helper_h__
#define __ruby_helper_h__
#define NOMINMAX
#include <string>
#include <algorithm>
#include <iostream>
#if defined(_WIN32) || defined(__WIN32__)
#include <winsock2.h>
#endif
#include <ruby.h>
#if defined(_WIN32) || defined(__WIN32__)
#define DECL __cdecl
#else
#define DECL __attribute__((cdecl))
#endif
// Copies a string, makes the first character upper case, and then returns it
inline std::string fupr(const char *p) {
std::string str = p;
str[0] = toupper(str[0]);
return str;
}
#define IS(v, c) rb_obj_class(v) == c
#define ISKO(v, c) rb_obj_is_kind_of(v, c)
#define ISNUM(v) ISKO(v, rb_cNumeric)
#define ISSTR(v) ISKO(v, rb_cString)
#define DECLARE_PTR_VAR(MyClass, MyVar, expr)\
MyClass *p##MyVar = expr;\
VALUE v##MyVar = p##MyVar == NULL ? Qnil : Data_Wrap_Struct(g_c##MyClass, 0, 0, p##MyVar)
#define DECLARE_OBJ_VAR(MyClass, MyVar, expr)\
VALUE v##MyVar = MyClass##_new(0, NOARGV, g_c##MyClass);\
MyClass *p##MyVar = NULL;\
Data_Get_Struct(v##MyVar, MyClass, p##MyVar);\
*p##MyVar = expr
#define GET_OBJ_VAR(MyClass, MyVar)\
MyClass *p##MyVar = NULL;\
Data_Get_Struct(v##MyVar, MyClass, p##MyVar)
#define DEFINE_CLASS_METHOD(MyClass, MyMethod, n)\
rb_define_singleton_method(g_c##MyClass, #MyMethod,\
(unsigned long (DECL *)(...))MyClass##_##MyMethod, n)
#define DEFINE_CLASS_METHOD2(MyClass, MyMethod, RubyMethod, n)\
rb_define_singleton_method(g_c##MyClass, #RubyMethod,\
(unsigned long (DECL *)(...))MyClass##_##MyMethod, n)
#define DEFINE_INSTANCE_METHOD(MyClass, MyMethod, n)\
rb_define_method(g_c##MyClass, #MyMethod,\
(unsigned long (DECL *)(...))MyClass##_##MyMethod, n)
#define DEFINE_INSTANCE_METHOD2(MyClass, MyMethod, RubyMethod, n)\
rb_define_method(g_c##MyClass, #RubyMethod,\
(unsigned long (DECL *)(...))MyClass##_##MyMethod, n)
// Use to define a standard getter method (for any type of member)
// (Defines both obj.variableName and obj.getVariableName)
#define DEFINE_GETTER(MyClass, MyField) \
rb_define_method(g_c##MyClass, #MyField, \
(unsigned long (DECL *)(...))MyClass##_get_##MyField, 0);\
rb_define_method(g_c##MyClass, (std::string("get")+fupr(#MyField)).c_str(), \
(unsigned long (DECL *)(...))MyClass##_get_##MyField, 0)
// Use to define a standard setter method (for any type of member)
// (Defines both obj.variableName = v and obj.setVariableName v)
#define DEFINE_SETTER(MyClass, MyField) \
rb_define_method(g_c##MyClass, #MyField "=", \
(unsigned long (DECL *)(...))MyClass##_set_##MyField, 1);\
rb_define_method(g_c##MyClass, (std::string("set")+fupr(#MyField)).c_str(), \
(unsigned long (DECL *)(...))MyClass##_set_##MyField, 1)
// Use to define standard getter and setter methods (for any type of member)
#define DEFINE_RW(MyClass, MyField) \
DEFINE_GETTER(MyClass, MyField);\
DEFINE_SETTER(MyClass, MyField)
// Use to define a standard getter method (for any type of member)
// (Defines both obj.variableName and obj.getVariableName)
#define DEFINE_GETTER2(MyClass, MyField, RubyField) \
rb_define_method(g_c##MyClass, #RubyField, \
(unsigned long (DECL *)(...))MyClass##_get_##MyField, 0);\
rb_define_method(g_c##MyClass, (std::string("get")+fupr(#RubyField)).c_str(), \
(unsigned long (DECL *)(...))MyClass##_get_##MyField, 0)
// Use to define a standard setter method (for any type of member)
// (Defines both obj.variableName = v and obj.setVariableName v)
#define DEFINE_SETTER2(MyClass, MyField, RubyField) \
rb_define_method(g_c##MyClass, #RubyField "=", \
(unsigned long (DECL *)(...))MyClass##_set_##MyField, 1);\
rb_define_method(g_c##MyClass, (std::string("set")+fupr(#RubyField)).c_str(), \
(unsigned long (DECL *)(...))MyClass##_set_##MyField, 1)
// Use to define standard getter and setter methods (for any type of member)
#define DEFINE_RW2(MyClass, MyField, RubyField) \
DEFINE_GETTER2(MyClass, MyField, RubyField);\
DEFINE_SETTER2(MyClass, MyField, RubyField)
// Use to define a static getter method (for any type of member)
// (Defines both Class.variableName and Class.getVariableName)
#define DEFINE_STATIC_GETTER(MyClass, MyField) \
rb_define_singleton_method(g_c##MyClass, #MyField, \
(unsigned long (DECL *)(...))MyClass##_get_##MyField, 0);\
rb_define_singleton_method(g_c##MyClass, (std::string("get")+fupr(#MyField)).c_str(), \
(unsigned long (DECL *)(...))MyClass##_get_##MyField, 0)
// Use to define a static setter method (for any type of member)
// (Defines both Class.variableName = v and Class.setVariableName v)
#define DEFINE_STATIC_SETTER(MyClass, MyField) \
rb_define_singleton_method(g_c##MyClass, #MyField "=", \
(unsigned long (DECL *)(...))MyClass##_set_##MyField, 1);\
rb_define_singleton_method(g_c##MyClass, (std::string("set")+fupr(#MyField)).c_str(), \
(unsigned long (DECL *)(...))MyClass##_set_##MyField, 1)
// Use to define static getter and setter methods (for any type of member)
#define DEFINE_STATIC_RW(MyClass, MyField) \
DEFINE_STATIC_GETTER(MyClass, MyField);\
DEFINE_STATIC_SETTER(MyClass, MyField)
#define DEFINE_MODULE_CONST(MyConst)\
rb_define_const(g_vModule, #MyConst, INT2FIX(MyConst))
#define DEFINE_MODULE_METHOD(MyMethod, RubyMethod, n)\
rb_define_singleton_method(g_vModule, #RubyMethod,\
(unsigned long (DECL *)(...))SFML_##MyMethod, n)
#define DEFINE_INT_CONST(MyClass, MyConst)\
rb_define_const(g_c##MyClass, #MyConst, INT2FIX(MyClass::MyConst))
#define DEFINE_PTR_CONST(MyClass, MyConst, expr)\
rb_define_const(g_c##MyClass, #MyConst, Data_Wrap_Struct(g_c##MyClass, 0, 0, expr))
#define DECLARE_VOID_METHOD(MyClass, MyMethod)\
static VALUE MyClass##_##MyMethod(VALUE vSelf)\
{\
MyClass *ptr;\
Data_Get_Struct(vSelf, MyClass, ptr);\
ptr->MyMethod();\
return vSelf;\
}\
// Use to declare standard free, new, and init methods with 0 parameters
#define DECLARE_FREE_NEW_INIT0(MyClass)\
static void MyClass##_free(void *p)\
{\
delete (MyClass *)p;\
}\
static VALUE MyClass##_new(VALUE vClass)\
{\
VALUE argv[1];\
MyClass *ptr = new MyClass;\
VALUE tData = Data_Wrap_Struct(vClass, 0, MyClass##_free, ptr);\
rb_obj_call_init(tData, 0, argv);\
return tData;\
}\
static VALUE MyClass##_initialize(VALUE vSelf)\
{\
return vSelf;\
}
// Use to declare standard free and new methods with 1 parameter
#define DECLARE_FREE_NEW1(MyClass)\
static void MyClass##_free(void *p)\
{\
delete (MyClass *)p;\
}\
static VALUE MyClass##_new(VALUE vClass, VALUE v1)\
{\
VALUE argv[1];\
argv[0] = v1;\
MyClass *ptr = new MyClass;\
VALUE tData = Data_Wrap_Struct(vClass, 0, MyClass##_free, ptr);\
rb_obj_call_init(tData, 1, argv);\
return tData;\
}
// Use to define standard free, new, and init methods with n parameters
// (Also declares a free method)
#define DEFINE_CLASS_NEW_INIT(MyClass, n)\
g_c##MyClass = rb_define_class(#MyClass, rb_cObject);\
DEFINE_CLASS_METHOD(MyClass, new, n);\
DEFINE_INSTANCE_METHOD(MyClass, initialize, n);
// Use to declare a standard getter method for a public int member
#define DECLARE_INT_GETTER(MyClass, MyField)\
static VALUE MyClass##_get_##MyField(VALUE vSelf)\
{\
MyClass *ptr;\
Data_Get_Struct(vSelf, MyClass, ptr);\
return INT2NUM((int)ptr->MyField);\
}
// Use to declare a static getter method for a public int member
#define DECLARE_STATIC_INT_GETTER(MyClass, MyField)\
static VALUE MyClass##_get_##MyField(VALUE vClass)\
{\
return INT2NUM((int)MyClass::MyField);\
}
// Use to declare a standard setter method for a public int member
#define DECLARE_INT_SETTER(MyClass, MyField)\
static VALUE MyClass##_set_##MyField(VALUE vSelf, VALUE v)\
{\
MyClass *ptr;\
Data_Get_Struct(vSelf, MyClass, ptr);\
ptr->MyField = NUM2INT(v);\
return v;\
}
// Use to declare a static setter method for a public int member
#define DECLARE_STATIC_INT_SETTER(MyClass, MyField)\
static VALUE MyClass##_set_##MyField(VALUE vClass)\
{\
MyClass::MyField = NUM2INT(v);\
return v;\
}
// Use to declare standard getter and setter methods for a public int member
#define DECLARE_INT_RW(MyClass, MyField)\
DECLARE_INT_GETTER(MyClass, MyField)\
DECLARE_INT_SETTER(MyClass, MyField)
// Use to declare static getter and setter methods for a public int member
#define DECLARE_STATIC_INT_RW(MyClass, MyField)\
DECLARE_STATIC_INT_GETTER(MyClass, MyField)\
DECLARE_STATIC_INT_SETTER(MyClass, MyField)
// Use to declare a standard setter method for a public enum member
#define DECLARE_ENUM_SETTER(MyClass, MyField, EnumType)\
static VALUE MyClass##_set_##MyField(VALUE vSelf, VALUE v)\
{\
MyClass *ptr;\
Data_Get_Struct(vSelf, MyClass, ptr);\
ptr->MyField = (EnumType)NUM2INT(v);\
return v;\
}
// Use to declare a standard setter method for a public enum member
#define DECLARE_STATIC_ENUM_SETTER(MyClass, MyField, EnumType)\
static VALUE MyClass##_set_##MyField(VALUE vSelf, VALUE v)\
{\
MyClass::MyField = (EnumType)NUM2INT(v);\
return v;\
}
// Use to declare standard getter and setter methods for a public enum member
#define DECLARE_ENUM_RW(MyClass, MyField, EnumType)\
DECLARE_INT_GETTER(MyClass, MyField)\
DECLARE_ENUM_SETTER(MyClass, MyField, EnumType)
// Use to declare standard getter and setter methods for a public enum member
#define DECLARE_STATIC_ENUM_RW(MyClass, MyField, EnumType)\
DECLARE_STATIC_INT_GETTER(MyClass, MyField)\
DECLARE_STATIC_ENUM_SETTER(MyClass, MyField, EnumType)
// Use to declare a standard getter method for a public bool member
#define DECLARE_BOOL_GETTER(MyClass, MyField)\
static VALUE MyClass##_get_##MyField(VALUE vSelf)\
{\
MyClass *ptr;\
Data_Get_Struct(vSelf, MyClass, ptr);\
return ptr->MyField ? Qtrue : Qfalse;\
}
// Use to declare a static getter method for a public bool member
#define DECLARE_STATIC_BOOL_GETTER(MyClass, MyField)\
static VALUE MyClass##_get_##MyField(VALUE vClass)\
{\
return MyClass::MyField ? Qtrue : Qfalse;\
}
// Use to declare a standard setter method for a public bool member
#define DECLARE_BOOL_SETTER(MyClass, MyField)\
static VALUE MyClass##_set_##MyField(VALUE vSelf, VALUE v)\
{\
MyClass *ptr;\
Data_Get_Struct(vSelf, MyClass, ptr);\
ptr->MyField = RTEST(v) ? true : false;\
return v;\
}
// Use to declare a static setter method for a public bool member
#define DECLARE_STATIC_BOOL_SETTER(MyClass, MyField)\
static VALUE MyClass##_set_##MyField(VALUE vClass, VALUE v)\
{\
MyClass::MyField = RTEST(v) ? true : false;\
return v;\
}
// Use to declare standard getter and setter methods for a public int member
#define DECLARE_BOOL_RW(MyClass, MyField)\
DECLARE_BOOL_GETTER(MyClass, MyField)\
DECLARE_BOOL_SETTER(MyClass, MyField)
// Use to declare standard getter and setter methods for a public int member
#define DECLARE_STATIC_BOOL_RW(MyClass, MyField)\
DECLARE_STATIC_BOOL_GETTER(MyClass, MyField)\
DECLARE_STATIC_BOOL_SETTER(MyClass, MyField)
// Use to declare a standard getter method for a public double member
#define DECLARE_DOUBLE_GETTER(MyClass, MyField)\
static VALUE MyClass##_get_##MyField(VALUE vSelf)\
{\
MyClass *ptr;\
Data_Get_Struct(vSelf, MyClass, ptr);\
return rb_float_new((double)ptr->MyField);\
}
// Use to declare a static getter method for a public double member
#define DECLARE_STATIC_DOUBLE_GETTER(MyClass, MyField)\
static VALUE MyClass##_get_##MyField(VALUE vSelf)\
{\
return rb_float_new((double)MyClass::MyField);\
}
// Use to declare a standard setter method for a public double member
#define DECLARE_DOUBLE_SETTER(MyClass, MyField)\
static VALUE MyClass##_set_##MyField(VALUE vSelf, VALUE v)\
{\
MyClass *ptr;\
Data_Get_Struct(vSelf, MyClass, ptr);\
ptr->MyField = (float)NUM2DBL(v);\
return v;\
}
// Use to declare a static setter method for a public double member
#define DECLARE_STATIC_DOUBLE_SETTER(MyClass, MyField)\
static VALUE MyClass##_set_##MyField(VALUE vSelf, VALUE v)\
{\
MyClass::MyField = NUM2DBL(v);\
return v;\
}
// Use to declare standard getter and setter methods for a public double member
#define DECLARE_DOUBLE_RW(MyClass, MyField)\
DECLARE_DOUBLE_GETTER(MyClass, MyField)\
DECLARE_DOUBLE_SETTER(MyClass, MyField)
// Use to declare standard getter and setter methods for a public double member
#define DECLARE_STATIC_DOUBLE_RW(MyClass, MyField)\
DECLARE_DOUBLE_STATIC_GETTER(MyClass, MyField)\
DECLARE_DOUBLE_STATIC_SETTER(MyClass, MyField)
// Use to declare a standard getter method for a public std::string member
#define DECLARE_STRING_GETTER(MyClass, MyField)\
static VALUE MyClass##_get_##MyField(VALUE vSelf)\
{\
MyClass *ptr;\
Data_Get_Struct(vSelf, MyClass, ptr);\
return rb_str_new2(ptr->MyField.c_str());\
}
// Use to declare a static getter method for a public std::string member
#define DECLARE_STATIC_STRING_GETTER(MyClass, MyField)\
static VALUE MyClass##_get_##MyField(VALUE vSelf)\
{\
return rb_str_new2(MyClass::MyField.c_str());\
}
// Use to declare a standard setter method for a public std::string member
#define DECLARE_STRING_SETTER(MyClass, MyField)\
static VALUE MyClass##_set_##MyField(VALUE vSelf, VALUE v)\
{\
MyClass *ptr;\
Data_Get_Struct(vSelf, MyClass, ptr);\
ptr->MyField = STR2CSTR(v);\
return v;\
}
// Use to declare a static setter method for a public std::string member
#define DECLARE_STATIC_STRING_SETTER(MyClass, MyField)\
static VALUE MyClass##_set_##MyField(VALUE vSelf, VALUE v)\
{\
MyClass::MyField = STR2CSTR(v);\
return v;\
}
// Use to declare standard getter and setter methods for a public std::string member
#define DECLARE_STRING_RW(MyClass, MyField)\
DECLARE_STRING_GETTER(MyClass, MyField)\
DECLARE_STRING_SETTER(MyClass, MyField)
// Use to declare standard getter and setter methods for a public int member
#define DECLARE_STATIC_STRING_RW(MyClass, MyField)\
DECLARE_STATIC_STRING_GETTER(MyClass, MyField)\
DECLARE_STATIC_STRING_SETTER(MyClass, MyField)
// Use to declare a standard getter method for a public short member
#define DECLARE_SHORT_GETTER(MyClass, MyField)\
static VALUE MyClass##_get_##MyField(VALUE vSelf)\
{\
MyClass *ptr;\
Data_Get_Struct(vSelf, MyClass, ptr);\
return INT2FIX((int)ptr->MyField);\
}
// Use to declare a standard getter method for a public short member
#define DECLARE_STATIC_SHORT_GETTER(MyClass, MyField)\
static VALUE MyClass##_get_##MyField(VALUE vSelf)\
{\
return INT2FIX((int)MyClass->MyField);\
}
// Use to declare a standard setter method for a public short member
#define DECLARE_SHORT_SETTER(MyClass, MyField)\
static VALUE MyClass##_set_##MyField(VALUE vSelf, VALUE v)\
{\
MyClass *ptr;\
Data_Get_Struct(vSelf, MyClass, ptr);\
ptr->MyField = (short)FIX2INT(v);\
return v;\
}
// Use to declare a standard setter method for a public short member
#define DECLARE_STATIC_SHORT_SETTER(MyClass, MyField)\
static VALUE MyClass##_set_##MyField(VALUE vSelf, VALUE v)\
{\
MyClass::MyField = (short)FIX2INT(v);\
return v;\
}
// Use to declare standard getter and setter methods for a public short member
#define DECLARE_SHORT_RW(MyClass, MyField)\
DECLARE_SHORT_GETTER(MyClass, MyField)\
DECLARE_SHORT_SETTER(MyClass, MyField)
// Use to declare standard getter and setter methods for a public short member
#define DECLARE_STATIC_SHORT_RW(MyClass, MyField)\
DECLARE_STATIC_SHORT_GETTER(MyClass, MyField)\
DECLARE_STATIC_SHORT_SETTER(MyClass, MyField)
// Use to declare a standard getter method for a public object member
#define DECLARE_OBJ_GETTER(MyClass, MyField, FieldType)\
static VALUE MyClass##_get_##MyField(VALUE vSelf)\
{\
MyClass *pSelf;\
Data_Get_Struct(vSelf, MyClass, pSelf);\
VALUE vRet = FieldType##_new(0, NOARGV, g_c##FieldType);\
FieldType *pRet;\
Data_Get_Struct(vRet, FieldType, pRet);\
*pRet = pSelf->MyField;\
return vRet;\
}
// Use to declare a static getter method for a public object member
#define DECLARE_STATIC_OBJ_GETTER(MyClass, MyField, FieldType)\
static VALUE MyClass##_get_##MyField(VALUE vSelf)\
{\
VALUE vRet = FieldType##_new(0, NOARGV, g_c##FieldType);\
FieldType *pRet;\
Data_Get_Struct(vRet, FieldType, pRet);\
*pRet = MyClass::MyField;\
return vRet;\
}
// Use to declare a standard setter method for a public object member
#define DECLARE_OBJ_SETTER(MyClass, MyField, FieldType)\
static VALUE MyClass##_set_##MyField(VALUE vSelf, VALUE v)\
{\
MyClass *pSelf;\
Data_Get_Struct(vSelf, MyClass, pSelf);\
FieldType *pV;\
Data_Get_Struct(v, FieldType, pV);\
pSelf->MyField = *pV;\
return Qnil;\
}
// Use to declare a static setter method for a public object member
#define DECLARE_STATIC_OBJ_SETTER(MyClass, MyField, FieldType)\
static VALUE MyClass##_set_##MyField(VALUE vClass, VALUE v)\
{\
FieldType *pV;\
Data_Get_Struct(v, FieldType, pV);\
MyClass::MyField = *pV;\
return Qnil;\
}
// Use to declare standard getter and setter methods for a public object member
#define DECLARE_OBJ_RW(MyClass, MyField, FieldType)\
DECLARE_OBJ_GETTER(MyClass, MyField, FieldType)\
DECLARE_OBJ_SETTER(MyClass, MyField, FieldType)
// Use to declare static getter and setter methods for a public object member
#define DECLARE_STATIC_OBJ_RW(MyClass, MyField, FieldType)\
DECLARE_STATIC_OBJ_GETTER(MyClass, MyField, FieldType)\
DECLARE_STATIC_OBJ_SETTER(MyClass, MyField, FieldType)
// Use to declare a standard getter method for a public unsigned short member
#define DECLARE_USHORT_GETTER(MyClass, MyField)\
static VALUE MyClass##_get_##MyField(VALUE vSelf)\
{\
MyClass *ptr;\
Data_Get_Struct(vSelf, MyClass, ptr);\
return INT2FIX((int)ptr->MyField);\
}
// Use to declare a standard getter method for a public unsigned short member
#define DECLARE_STATIC_USHORT_GETTER(MyClass, MyField)\
static VALUE MyClass##_get_##MyField(VALUE vSelf)\
{\
return INT2FIX((int)MyClass->MyField);\
}
// Use to declare a standard setter method for a public unsigned short member
#define DECLARE_USHORT_SETTER(MyClass, MyField)\
static VALUE MyClass##_set_##MyField(VALUE vSelf, VALUE v)\
{\
MyClass *ptr;\
Data_Get_Struct(vSelf, MyClass, ptr);\
ptr->MyField = (unsigned short)FIX2INT(v);\
return v;\
}
// Use to declare a standard setter method for a public unsigned short member
#define DECLARE_STATIC_USHORT_SETTER(MyClass, MyField)\
static VALUE MyClass##_set_##MyField(VALUE vSelf, VALUE v)\
{\
MyClass::MyField = (unsigned short)FIX2INT(v);\
return v;\
}
// Use to declare standard getter and setter methods for a public unsigned short member
#define DECLARE_USHORT_RW(MyClass, MyField)\
DECLARE_USHORT_GETTER(MyClass, MyField)\
DECLARE_USHORT_SETTER(MyClass, MyField)
// Use to declare standard getter and setter methods for a public unsigned short member
#define DECLARE_STATIC_USHORT_RW(MyClass, MyField)\
DECLARE_STATIC_USHORT_GETTER(MyClass, MyField)\
DECLARE_STATIC_USHORT_SETTER(MyClass, MyField)
// Use to declare a standard getter method for a public unsigned char member
#define DECLARE_UCHAR_GETTER(MyClass, MyField)\
static VALUE MyClass##_get_##MyField(VALUE vSelf)\
{\
MyClass *ptr;\
Data_Get_Struct(vSelf, MyClass, ptr);\
return INT2FIX((int)ptr->MyField);\
}
// Use to declare a standard getter method for a public unsigned char member
#define DECLARE_STATIC_UCHAR_GETTER(MyClass, MyField)\
static VALUE MyClass##_get_##MyField(VALUE vSelf)\
{\
return INT2FIX((int)MyClass->MyField);\
}
// Use to declare a standard setter method for a public unsigned char member
#define DECLARE_UCHAR_SETTER(MyClass, MyField)\
static VALUE MyClass##_set_##MyField(VALUE vSelf, VALUE v)\
{\
MyClass *ptr;\
Data_Get_Struct(vSelf, MyClass, ptr);\
ptr->MyField = (unsigned char)FIX2INT(v);\
return v;\
}
// Use to declare a standard setter method for a public unsigned char member
#define DECLARE_STATIC_UCHAR_SETTER(MyClass, MyField)\
static VALUE MyClass##_set_##MyField(VALUE vSelf, VALUE v)\
{\
MyClass::MyField = (unsigned char)FIX2INT(v);\
return v;\
}
// Use to declare standard getter and setter methods for a public unsigned char member
#define DECLARE_UCHAR_RW(MyClass, MyField)\
DECLARE_UCHAR_GETTER(MyClass, MyField)\
DECLARE_UCHAR_SETTER(MyClass, MyField)
// Use to declare standard getter and setter methods for a public unsigned char member
#define DECLARE_STATIC_UCHAR_RW(MyClass, MyField)\
DECLARE_STATIC_UCHAR_GETTER(MyClass, MyField)\
DECLARE_STATIC_UCHAR_SETTER(MyClass, MyField)
// Use to declare a standard getter method for a public char member
#define DECLARE_CHAR_GETTER(MyClass, MyField)\
static VALUE MyClass##_get_##MyField(VALUE vSelf)\
{\
MyClass *ptr;\
Data_Get_Struct(vSelf, MyClass, ptr);\
return INT2FIX((int)ptr->MyField);\
}
// Use to declare a standard getter method for a public char member
#define DECLARE_STATIC_CHAR_GETTER(MyClass, MyField)\
static VALUE MyClass##_get_##MyField(VALUE vSelf)\
{\
return INT2FIX((int)MyClass->MyField);\
}
// Use to declare a standard setter method for a public char member
#define DECLARE_CHAR_SETTER(MyClass, MyField)\
static VALUE MyClass##_set_##MyField(VALUE vSelf, VALUE v)\
{\
MyClass *ptr;\
Data_Get_Struct(vSelf, MyClass, ptr);\
ptr->MyField = (char)FIX2INT(v);\
return v;\
}
// Use to declare a standard setter method for a public char member
#define DECLARE_STATIC_CHAR_SETTER(MyClass, MyField)\
static VALUE MyClass##_set_##MyField(VALUE vSelf, VALUE v)\
{\
MyClass::MyField = (char)FIX2INT(v);\
return v;\
}
// Use to declare standard getter and setter methods for a public char member
#define DECLARE_CHAR_RW(MyClass, MyField)\
DECLARE_CHAR_GETTER(MyClass, MyField)\
DECLARE_CHAR_SETTER(MyClass, MyField)
// Use to declare standard getter and setter methods for a public char member
#define DECLARE_STATIC_CHAR_RW(MyClass, MyField)\
DECLARE_STATIC_CHAR_GETTER(MyClass, MyField)\
DECLARE_STATIC_CHAR_SETTER(MyClass, MyField)
// Use to declare a standard getter method for a public int64 member
#define DECLARE_INT64_GETTER(MyClass, MyField)\
static VALUE MyClass##_get_##MyField(VALUE vSelf)\
{\
MyClass *ptr;\
Data_Get_Struct(vSelf, MyClass, ptr);\
return LL2NUM(ptr->MyField);\
}
// Use to declare a static getter method for a public int64 member
#define DECLARE_STATIC_INT64_GETTER(MyClass, MyField)\
static VALUE MyClass##_get_##MyField(VALUE vClass)\
{\
return LL2NUM(MyClass::MyField);\
}
// Use to declare a standard setter method for a public int64 member
#define DECLARE_INT64_SETTER(MyClass, MyField)\
static VALUE MyClass##_set_##MyField(VALUE vSelf, VALUE v)\
{\
MyClass *ptr;\
Data_Get_Struct(vSelf, MyClass, ptr);\
ptr->MyField = NUM2LL(v);\
return v;\
}
// Use to declare a static setter method for a public int64 member
#define DECLARE_STATIC_INT64_SETTER(MyClass, MyField)\
static VALUE MyClass##_set_##MyField(VALUE vClass)\
{\
MyClass::MyField = NUM2LL(v);\
return v;\
}
// Use to declare standard getter and setter methods for a public int64 member
#define DECLARE_INT64_RW(MyClass, MyField)\
DECLARE_INT64_GETTER(MyClass, MyField)\
DECLARE_INT64_SETTER(MyClass, MyField)
// Use to declare static getter and setter methods for a public int64 member
#define DECLARE_STATIC_INT64_RW(MyClass, MyField)\
DECLARE_STATIC_INT64_GETTER(MyClass, MyField)\
DECLARE_STATIC_INT64_SETTER(MyClass, MyField)
// Use to declare a standard getter method for a public uint64 member
#define DECLARE_UINT64_GETTER(MyClass, MyField)\
static VALUE MyClass##_get_##MyField(VALUE vSelf)\
{\
MyClass *ptr;\
Data_Get_Struct(vSelf, MyClass, ptr);\
return ULL2NUM(ptr->MyField);\
}
// Use to declare a static getter method for a public uint64 member
#define DECLARE_STATIC_UINT64_GETTER(MyClass, MyField)\
static VALUE MyClass##_get_##MyField(VALUE vClass)\
{\
return ULL2NUM(MyClass::MyField);\
}
// Use to declare a standard setter method for a public uint64 member
#define DECLARE_UINT64_SETTER(MyClass, MyField)\
static VALUE MyClass##_set_##MyField(VALUE vSelf, VALUE v)\
{\
MyClass *ptr;\
Data_Get_Struct(vSelf, MyClass, ptr);\
ptr->MyField = NUM2ULL(v);\
return v;\
}
// Use to declare a static setter method for a public uint64 member
#define DECLARE_USTATIC_INT64_SETTER(MyClass, MyField)\
static VALUE MyClass##_set_##MyField(VALUE vClass)\
{\
MyClass::MyField = NUM2ULL(v);\
return v;\
}
// Use to declare standard getter and setter methods for a public uint64 member
#define DECLARE_UINT64_RW(MyClass, MyField)\
DECLARE_UINT64_GETTER(MyClass, MyField)\
DECLARE_UINT64_SETTER(MyClass, MyField)
// Use to declare static getter and setter methods for a public uint64 member
#define DECLARE_STATIC_UINT64_RW(MyClass, MyField)\
DECLARE_STATIC_UINT64_GETTER(MyClass, MyField)\
DECLARE_STATIC_UINT64_SETTER(MyClass, MyField)
#define DECLARE_INT_ARR_GETTER(MyClass, MyField, Size)\
static VALUE MyClass##_get_##MyField(VALUE vSelf)\
{\
MyClass *pSelf;\
Data_Get_Struct(vSelf, MyClass, pSelf);\
VALUE v = rb_ary_new();\
for(int i=0; i<Size; i++)\
rb_ary_push(v, INT2FIX(pSelf->MyField[i]));\
return v;\
}
#define DECLARE_INT_ARR_SETTER(MyClass, MyField, Size)\
static VALUE MyClass##_set_##MyField(VALUE vSelf, VALUE v)\
{\
MyClass *pSelf;\
Data_Get_Struct(vSelf, MyClass, pSelf);\
for(int i=0; i<Size; i++)\
pSelf->MyField[i] = FIX2INT(rb_ary_entry(v, i));\
return v;\
}
#define DECLARE_INT_ARR_RW(MyClass, MyField, Size)\
DECLARE_INT_ARR_GETTER(MyClass, MyField, Size);\
DECLARE_INT_ARR_SETTER(MyClass, MyField, Size)
#define DECLARE_DOUBLE_ARR_GETTER(MyClass, MyField, Size)\
static VALUE MyClass##_get_##MyField(VALUE vSelf)\
{\
MyClass *pSelf;\
Data_Get_Struct(vSelf, MyClass, pSelf);\
VALUE v = rb_ary_new();\
for(int i=0; i<Size; i++)\
rb_ary_push(v, rb_float_new(pSelf->MyField[i]));\
return v;\
}
#define DECLARE_DOUBLE_ARR_SETTER(MyClass, MyField, Size)\
static VALUE MyClass##_set_##MyField(VALUE vSelf, VALUE v)\
{\
MyClass *pSelf;\
Data_Get_Struct(vSelf, MyClass, pSelf);\
for(int i=0; i<Size; i++)\
pSelf->MyField[i] = NUM2DBL(rb_ary_entry(v, i));\
return v;\
}
#define DECLARE_DOUBLE_ARR_RW(MyClass, MyField, Size)\
DECLARE_DOUBLE_ARR_GETTER(MyClass, MyField, Size);\
DECLARE_DOUBLE_ARR_SETTER(MyClass, MyField, Size)
#define DECLARE_ADDR_GETTER(MyClass, MyField, FieldType)\
static VALUE MyClass##_get_##MyField(VALUE vSelf)\
{\
MyClass *pSelf;\
Data_Get_Struct(vSelf, MyClass, pSelf);\
VALUE vRet = Data_Wrap_Struct(g_c##FieldType, 0, 0, &pSelf->MyField);\
return vRet;\
}
// Use to declare a standard getter method for a public object pointer member
#define DECLARE_PTR_GETTER(MyClass, MyField, FieldType)\
static VALUE MyClass##_get_##MyField(VALUE vSelf)\
{\
MyClass *pSelf;\
Data_Get_Struct(vSelf, MyClass, pSelf);\
VALUE vRet = Data_Wrap_Struct(g_c##FieldType, 0, 0, pSelf->MyField);\
return vRet;\
}
// Use to declare a standard getter method for a public object reference member
#define DECLARE_REF_GETTER(MyClass, MyField, FieldType)\
static VALUE MyClass##_get_##MyField(VALUE vSelf)\
{\
MyClass *pSelf;\
Data_Get_Struct(vSelf, MyClass, pSelf);\
pSelf->MyField->ReferenceCountedObject_refCount.increment();\
VALUE vRet = Data_Wrap_Struct(g_c##FieldType, 0, FieldType##_free, pSelf->MyField.pointer());\
return vRet;\
}
// Use to declare a standard setter method for a public object reference member
#define DECLARE_REF_SETTER(MyClass, MyField, FieldType)\
static VALUE MyClass##_set_##MyField(VALUE vSelf, VALUE v)\
{\
MyClass *pSelf;\
Data_Get_Struct(vSelf, MyClass, pSelf);\
FieldType *pV;\
Data_Get_Struct(v, FieldType, pV);\
pSelf->MyField = pV;\
return Qnil;\
}
// Use to declare standard getter and setter methods for a public object member
#define DECLARE_REF_RW(MyClass, MyField, FieldType)\
DECLARE_REF_GETTER(MyClass, MyField, FieldType)\
DECLARE_REF_SETTER(MyClass, MyField, FieldType)
#endif // __ruby_helper_h__

View File

@ -1,86 +0,0 @@
////////////////////////////////////////////////////////////
//
// RubySFML - Ruby extension for the SFML library
// Copyright (C) 2007 Sean O'Neil and Laurent Gomila
// (sean.p.oneil@gmail.com and laurent.gom@gmail.com)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
// you must not claim that you wrote the original software.
// If you use this software in a product, an acknowledgment
// in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
// and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
////////////////////////////////////////////////////////////
#include <SFML/Window.hpp>
#include "RubySFML.h"
using namespace sf;
VALUE g_cClock;
void Clock_free(void *p) { delete (Clock *)p; }
VALUE Clock_new(int argc, VALUE *argv, VALUE vClass) {
Clock *ptr = new Clock();
VALUE tData = Data_Wrap_Struct(vClass, 0, Clock_free, ptr);
rb_obj_call_init(tData, argc, argv);
return tData;
}
static VALUE Clock_initialize(int argc, VALUE *argv, VALUE vSelf) {
// Get C++ object pointer from vSelf
Clock *pSelf;
Data_Get_Struct(vSelf, Clock, pSelf);
if(argc == 0) {
// Nothing to initialize
} else
rb_raise(rb_eTypeError, "wrong argument type(s)");
return vSelf;
}
static VALUE Clock_to_s(VALUE vSelf) {
// Get C++ object pointer from vSelf
Clock *pSelf;
Data_Get_Struct(vSelf, Clock, pSelf);
char szBuffer[256];
sprintf(szBuffer, "Elapsed Time=%f", pSelf->GetElapsedTime());
return rb_str_new2(szBuffer);
}
static VALUE Clock_get_elapsedTime(VALUE vSelf) {
// Get C++ object pointer from vSelf
Clock *pSelf;
Data_Get_Struct(vSelf, Clock, pSelf);
return rb_float_new(pSelf->GetElapsedTime());
}
static VALUE Clock_reset(VALUE vSelf) {
// Get C++ object pointer from vSelf
Clock *pSelf;
Data_Get_Struct(vSelf, Clock, pSelf);
pSelf->Reset();
return Qnil;
}
void Init_Clock()
{
g_cClock = rb_define_class_under(g_vModule, "Clock", rb_cObject);
DEFINE_CLASS_METHOD(Clock, new, -1);
DEFINE_INSTANCE_METHOD(Clock, initialize, -1);
DEFINE_GETTER(Clock, elapsedTime);
DEFINE_INSTANCE_METHOD(Clock, to_s, 0);
DEFINE_INSTANCE_METHOD2(Clock, get_elapsedTime, to_f, 0);
DEFINE_INSTANCE_METHOD(Clock, reset, 0);
}

View File

@ -1,120 +0,0 @@
////////////////////////////////////////////////////////////
//
// RubySFML - Ruby extension for the SFML library
// Copyright (C) 2007 Sean O'Neil and Laurent Gomila
// (sean.p.oneil@gmail.com and laurent.gom@gmail.com)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
// you must not claim that you wrote the original software.
// If you use this software in a product, an acknowledgment
// in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
// and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
////////////////////////////////////////////////////////////
#include <SFML/Graphics.hpp>
#include "RubySFML.h"
using namespace sf;
VALUE g_cColor;
DECLARE_STATIC_OBJ_GETTER(Color, Black, Color);
DECLARE_STATIC_OBJ_GETTER(Color, White, Color);
DECLARE_STATIC_OBJ_GETTER(Color, Red, Color);
DECLARE_STATIC_OBJ_GETTER(Color, Green, Color);
DECLARE_STATIC_OBJ_GETTER(Color, Blue, Color);
DECLARE_STATIC_OBJ_GETTER(Color, Yellow, Color);
DECLARE_STATIC_OBJ_GETTER(Color, Magenta, Color);
DECLARE_STATIC_OBJ_GETTER(Color, Cyan, Color);
DECLARE_INT_RW(Color, r);
DECLARE_INT_RW(Color, g);
DECLARE_INT_RW(Color, b);
DECLARE_INT_RW(Color, a);
void Color_free(void *p) { delete (Color *)p; }
VALUE Color_new(int argc, VALUE *argv, VALUE vClass) {
Color *ptr = new Color();
VALUE tData = Data_Wrap_Struct(vClass, 0, Color_free, ptr);
rb_obj_call_init(tData, argc, argv);
return tData;
}
static VALUE Color_initialize(int argc, VALUE *argv, VALUE vSelf) {
// Get C++ object pointer from vSelf
Color *pSelf;
Data_Get_Struct(vSelf, Color, pSelf);
if(argc == 0) {
// Nothing to initialize
} else if(argc == 1 && ISNUM(argv[0])) {
DWORD dw = NUM2UINT(argv[0]);
*pSelf = Color(
(dw >> 24) & 0xFF,
(dw >> 16) & 0xFF,
(dw >> 8) & 0xFF,
(dw >> 0) & 0xFF);
} else if(argc >= 3 && argc <= 4 &&
ISNUM(argv[0]) && ISNUM(argv[1]) && ISNUM(argv[2]) &&
(argc < 4 || ISNUM(argv[3]))) {
pSelf->r = (unsigned char)NUM2INT(argv[0]);
pSelf->g = (unsigned char)NUM2INT(argv[1]);
pSelf->b = (unsigned char)NUM2INT(argv[2]);
pSelf->a = argc < 4 ? 255 : (unsigned char)NUM2INT(argv[3]);
} else
rb_raise(rb_eTypeError, "wrong argument type(s)");
return vSelf;
}
static VALUE Color_to_s(VALUE vSelf)
{
// Get C++ object pointer from vSelf
Color *pSelf;
Data_Get_Struct(vSelf, Color, pSelf);
char szBuffer[256];
sprintf(szBuffer, "r=%d, g=%d, b=%d, a=%d", pSelf->r, pSelf->g, pSelf->b, pSelf->a);
return rb_str_new2(szBuffer);
}
static VALUE Color_toRGBA(VALUE vSelf)
{
// Get C++ object pointer from vSelf
Color *pSelf;
Data_Get_Struct(vSelf, Color, pSelf);
return UINT2NUM((pSelf->r << 24) | (pSelf->g << 16) | (pSelf->b << 8) | pSelf->a);
}
void Init_Color()
{
g_cColor = rb_define_class_under(g_vModule, "Color", rb_cObject);
DEFINE_CLASS_METHOD(Color, new, -1);
DEFINE_INSTANCE_METHOD(Color, initialize, -1);
DEFINE_STATIC_GETTER(Color, Black);
DEFINE_STATIC_GETTER(Color, White);
DEFINE_STATIC_GETTER(Color, Red);
DEFINE_STATIC_GETTER(Color, Green);
DEFINE_STATIC_GETTER(Color, Blue);
DEFINE_STATIC_GETTER(Color, Yellow);
DEFINE_STATIC_GETTER(Color, Magenta);
DEFINE_STATIC_GETTER(Color, Cyan);
DEFINE_RW(Color, r);
DEFINE_RW(Color, g);
DEFINE_RW(Color, b);
DEFINE_RW(Color, a);
DEFINE_INSTANCE_METHOD(Color, to_s, 0);
DEFINE_INSTANCE_METHOD(Color, toRGBA, 0);
DEFINE_INSTANCE_METHOD2(Color, toRGBA, to_i, 0);
}

View File

@ -1,285 +0,0 @@
////////////////////////////////////////////////////////////
//
// RubySFML - Ruby extension for the SFML library
// Copyright (C) 2007 Sean O'Neil and Laurent Gomila
// (sean.p.oneil@gmail.com and laurent.gom@gmail.com)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
// you must not claim that you wrote the original software.
// If you use this software in a product, an acknowledgment
// in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
// and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
////////////////////////////////////////////////////////////
#include <SFML/Graphics.hpp>
#include "RubySFML.h"
#include <math.h>
#ifdef _MSC_VER
#define COSF cosf
#define SINF sinf
#else
#define COSF cos
#define SINF sin
#endif
using namespace sf;
#define PI 3.14159265f
// Wrapper for Drawable that calls the Ruby version of virtual methods in case a Ruby class derives from this one
class rDrawable : public Drawable {
protected:
VALUE m_vSelf, m_vClass;
ID m_idRender;
bool m_bRender;
virtual void Render(const RenderWindow &Window) const {
// If this method is overridden in Ruby, call it
if(m_bRender) {
VALUE vWindow = Data_Wrap_Struct(g_cRenderWindow, 0, 0, (void*)&Window);
VALUE vRet = rb_funcall(m_vSelf, m_idRender, 1, vWindow);
} else // else raise error (pure virtual method)
rb_raise(rb_eRuntimeError, "Pure virtual method Drawable::Render() called, but not defined.");
}
public:
// Call as soon as you get a Ruby VALUE pointing to this object
void rInit(VALUE vSelf) {
// Need these for rb_funcall
m_vSelf = vSelf;
m_vClass = CLASS_OF(m_vSelf);
// Initialize members for Render() virtual method
m_idRender = rb_intern("render");
m_bRender = rb_method_boundp(m_vClass, m_idRender, 0) == Qtrue;
}
};
VALUE g_cDrawable;
void Drawable_free(void *p) { delete (Drawable *)p; }
VALUE Drawable_new(int argc, VALUE *argv, VALUE vClass) {
rDrawable *ptr = new rDrawable();
VALUE tData = Data_Wrap_Struct(vClass, 0, Drawable_free, ptr);
ptr->rInit(tData);
rb_obj_call_init(tData, argc, argv);
return tData;
}
static VALUE Drawable_initialize(int argc, VALUE *argv, VALUE vSelf) {
// Get C++ object pointer from vSelf
Drawable *pSelf;
Data_Get_Struct(vSelf, Drawable, pSelf);
if(argc == 0) {
// Nothing to initialize
} else if(argc >= 1 && argc <= 5 && (argc < 5 || IS(argv[4], g_cColor))) {
if(argc >= 1)
pSelf->SetLeft((float)NUM2DBL(argv[0]));
if(argc >= 2)
pSelf->SetTop((float)NUM2DBL(argv[1]));
if(argc >= 3) {
if(ISNUM(argv[2])) {
float f = (float)NUM2DBL(argv[2]);
pSelf->SetScale(f, f);
} else if(IS(argv[2], rb_cArray)) {
float x = (float)NUM2DBL(rb_ary_entry(argv[2], 0));
float y = (float)NUM2DBL(rb_ary_entry(argv[2], 1));
pSelf->SetScale(x, y);
}
}
if(argc >= 4)
pSelf->SetRotation((float)NUM2DBL(argv[3]));
if(argc >= 5)
pSelf->SetColor(*(Color *)DATA_PTR(argv[4]));
} else
rb_raise(rb_eTypeError, "wrong argument type(s)");
return vSelf;
}
static VALUE Drawable_to_s(VALUE vSelf) {
// Get C++ object pointer from vSelf
Drawable *pSelf;
Data_Get_Struct(vSelf, Drawable, pSelf);
char szBuffer[256];
sprintf(szBuffer, "Left=%f, Top=%f, Scale=[%f,%f], Rotation=%f", pSelf->GetLeft(), pSelf->GetTop(), pSelf->GetScaleX(), pSelf->GetScaleX(), pSelf->GetRotation());
return rb_str_new2(szBuffer);
}
static VALUE Drawable_set_left(VALUE vSelf, VALUE vLeft) {
// Get C++ object pointer from vSelf
Drawable *pSelf;
Data_Get_Struct(vSelf, Drawable, pSelf);
pSelf->SetLeft((float)NUM2DBL(vLeft));
return Qnil;
}
static VALUE Drawable_set_top(VALUE vSelf, VALUE vTop) {
// Get C++ object pointer from vSelf
Drawable *pSelf;
Data_Get_Struct(vSelf, Drawable, pSelf);
pSelf->SetTop((float)NUM2DBL(vTop));
return Qnil;
}
static VALUE Drawable_set_scale(VALUE vSelf, VALUE vScale) {
// Get C++ object pointer from vSelf
Drawable *pSelf;
Data_Get_Struct(vSelf, Drawable, pSelf);
if(ISNUM(vScale)) {
float f = (float)NUM2DBL(vScale);
pSelf->SetScale(f, f);
} else if(IS(vScale, rb_cArray)) {
float x = (float)NUM2DBL(rb_ary_entry(vScale, 0));
float y = (float)NUM2DBL(rb_ary_entry(vScale, 1));
pSelf->SetScale(x, y);
} else
rb_raise(rb_eTypeError, "wrong argument type(s)");
return Qnil;
}
static VALUE Drawable_set_rotation(VALUE vSelf, VALUE vRotation) {
// Get C++ object pointer from vSelf
Drawable *pSelf;
Data_Get_Struct(vSelf, Drawable, pSelf);
pSelf->SetRotation((float)NUM2DBL(vRotation));
return Qnil;
}
static VALUE Drawable_setRotationCenter(VALUE vSelf, VALUE vX, VALUE vY) {
// Get C++ object pointer from vSelf
Drawable *pSelf;
Data_Get_Struct(vSelf, Drawable, pSelf);
pSelf->SetRotationCenter((float)NUM2DBL(vX), (float)NUM2DBL(vY));
return Qnil;
}
static VALUE Drawable_set_color(VALUE vSelf, VALUE vColor) {
// Get C++ object pointer from vSelf
Drawable *pSelf;
Data_Get_Struct(vSelf, Drawable, pSelf);
if(!IS(vColor, g_cColor))
rb_raise(rb_eTypeError, "wrong argument type(s)");
pSelf->SetColor(*(Color *)DATA_PTR(vColor));
return Qnil;
}
static VALUE Drawable_get_left(VALUE vSelf) {
// Get C++ object pointer from vSelf
Drawable *pSelf;
Data_Get_Struct(vSelf, Drawable, pSelf);
return rb_float_new(pSelf->GetLeft());
}
static VALUE Drawable_get_top(VALUE vSelf) {
// Get C++ object pointer from vSelf
Drawable *pSelf;
Data_Get_Struct(vSelf, Drawable, pSelf);
return rb_float_new(pSelf->GetTop());
}
static VALUE Drawable_get_scale(VALUE vSelf) {
// Get C++ object pointer from vSelf
Drawable *pSelf;
Data_Get_Struct(vSelf, Drawable, pSelf);
float x = pSelf->GetScaleX();
float y = pSelf->GetScaleY();
VALUE vArr = rb_ary_new();
rb_ary_push(vArr, rb_float_new(x));
rb_ary_push(vArr, rb_float_new(y));
return vArr;
}
static VALUE Drawable_get_rotation(VALUE vSelf) {
// Get C++ object pointer from vSelf
Drawable *pSelf;
Data_Get_Struct(vSelf, Drawable, pSelf);
return rb_float_new(pSelf->GetRotation());
}
static VALUE Drawable_get_upVector(VALUE vSelf) {
// Get C++ object pointer from vSelf
Drawable *pSelf;
Data_Get_Struct(vSelf, Drawable, pSelf);
float f = (pSelf->GetRotation() + 90) * (PI/180.0f);
VALUE v = rb_ary_new();
rb_ary_push(v, rb_float_new(COSF(f)));
rb_ary_push(v, rb_float_new(-SINF(f)));
return v;
}
static VALUE Drawable_get_rightVector(VALUE vSelf) {
// Get C++ object pointer from vSelf
Drawable *pSelf;
Data_Get_Struct(vSelf, Drawable, pSelf);
float f = pSelf->GetRotation() * (PI/180.0f);
VALUE v = rb_ary_new();
rb_ary_push(v, rb_float_new(COSF(f)));
rb_ary_push(v, rb_float_new(-SINF(f)));
return v;
}
static VALUE Drawable_get_color(VALUE vSelf) {
// Get C++ object pointer from vSelf
Drawable *pSelf;
Data_Get_Struct(vSelf, Drawable, pSelf);
DECLARE_OBJ_VAR(Color, Color, pSelf->GetColor());
return vColor;
}
static VALUE Drawable_setPosition(VALUE vSelf, float vX, float vY) {
// Get C++ object pointer from vSelf
Drawable *pSelf;
Data_Get_Struct(vSelf, Drawable, pSelf);
pSelf->SetPosition((float)NUM2DBL(vX), (float)NUM2DBL(vY));
return Qnil;
}
static VALUE Drawable_move(VALUE vSelf, float vX, float vY) {
// Get C++ object pointer from vSelf
Drawable *pSelf;
Data_Get_Struct(vSelf, Drawable, pSelf);
pSelf->Move((float)NUM2DBL(vX), (float)NUM2DBL(vY));
return Qnil;
}
static VALUE Drawable_rotate(VALUE vSelf, VALUE vRotate) {
// Get C++ object pointer from vSelf
Drawable *pSelf;
Data_Get_Struct(vSelf, Drawable, pSelf);
pSelf->Rotate((float)NUM2DBL(vRotate));
return Qnil;
}
void Init_Drawable()
{
g_cDrawable = rb_define_class_under(g_vModule, "Drawable", rb_cObject);
DEFINE_CLASS_METHOD(Drawable, new, -1);
DEFINE_INSTANCE_METHOD(Drawable, initialize, -1);
DEFINE_RW(Drawable, left);
DEFINE_RW(Drawable, top);
DEFINE_RW(Drawable, scale);
DEFINE_RW(Drawable, color);
DEFINE_RW(Drawable, rotation);
DEFINE_GETTER(Drawable, upVector);
DEFINE_GETTER(Drawable, rightVector);
DEFINE_INSTANCE_METHOD(Drawable, to_s, 0);
DEFINE_INSTANCE_METHOD(Drawable, setRotationCenter, 2);
DEFINE_INSTANCE_METHOD(Drawable, setPosition, 2);
DEFINE_INSTANCE_METHOD(Drawable, move, 2);
DEFINE_INSTANCE_METHOD(Drawable, rotate, 1);
}

View File

@ -1,270 +0,0 @@
////////////////////////////////////////////////////////////
//
// RubySFML - Ruby extension for the SFML library
// Copyright (C) 2007 Sean O'Neil and Laurent Gomila
// (sean.p.oneil@gmail.com and laurent.gom@gmail.com)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
// you must not claim that you wrote the original software.
// If you use this software in a product, an acknowledgment
// in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
// and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
////////////////////////////////////////////////////////////
#include <SFML/Window.hpp>
#include "RubySFML.h"
using namespace sf;
VALUE g_cEvent;
void Event_free(void *p) { delete (Event *)p; }
VALUE Event_new(int argc, VALUE *argv, VALUE vClass) {
Event *ptr = new Event();
VALUE tData = Data_Wrap_Struct(vClass, 0, Event_free, ptr);
rb_obj_call_init(tData, argc, argv);
return tData;
}
static VALUE Event_initialize(int argc, VALUE *argv, VALUE vSelf) {
// Get C++ object pointer from vSelf
Event *pSelf;
Data_Get_Struct(vSelf, Event, pSelf);
if(argc == 0) {
// Nothing to initialize
} else
rb_raise(rb_eTypeError, "wrong argument type(s)");
return vSelf;
}
static VALUE Event_to_s(VALUE vSelf) {
// Get C++ object pointer from vSelf
Event *pSelf;
Data_Get_Struct(vSelf, Event, pSelf);
char szBuffer[1024];
szBuffer[0] = 0;
switch(pSelf->Type) {
case Event::Closed:
strcpy(szBuffer, "Closed");
break;
case Event::Resized:
sprintf(szBuffer, "Resized: Width=%d, Height=%d", pSelf->Size.Width, pSelf->Size.Height);
break;
case Event::LostFocus:
strcpy(szBuffer, "LostFocus");
break;
case Event::GainedFocus:
strcpy(szBuffer, "GainedFocus");
break;
case Event::TextEntered:
sprintf(szBuffer, "TextEntered: %C", pSelf->Text.Unicode);
break;
case Event::KeyPressed:
sprintf(szBuffer, "KeyPressed: Code=%d, Alt=%s, Ctrl=%s, Shift=%s", pSelf->Key.Code, pSelf->Key.Alt ? "true" : "false", pSelf->Key.Control ? "true" : "false", pSelf->Key.Shift ? "true" : "false");
break;
case Event::KeyReleased:
sprintf(szBuffer, "KeyReleased: Code=%d, Alt=%s, Ctrl=%s, Shift=%s", pSelf->Key.Code, pSelf->Key.Alt ? "true" : "false", pSelf->Key.Control ? "true" : "false", pSelf->Key.Shift ? "true" : "false");
break;
case Event::MouseWheelMoved:
sprintf(szBuffer, "MouseWheelMoved: Delta=%d", pSelf->MouseWheel.Delta);
case Event::MouseButtonPressed:
sprintf(szBuffer, "MouseButtonPressed: Button=%d", pSelf->MouseButton.Button);
break;
case Event::MouseButtonReleased:
sprintf(szBuffer, "MouseButtonReleased: Button=%d", pSelf->MouseButton.Button);
break;
case Event::MouseMoved:
sprintf(szBuffer, "MouseMoved: X=%d, Y=%d", pSelf->MouseMove.X, pSelf->MouseMove.Y);
break;
case Event::JoyButtonPressed:
sprintf(szBuffer, "JoyButtonPressed: Button=%d", pSelf->JoyButton.Button);
break;
case Event::JoyButtonReleased:
sprintf(szBuffer, "JoyButtonReleased: Button=%d", pSelf->JoyButton.Button);
break;
case Event::JoyMoved:
sprintf(szBuffer, "JoyMoved: Axis=%d, Pos=%f", pSelf->JoyMove.Axis, pSelf->JoyMove.Position);
break;
default:
sprintf(szBuffer, "Unsupported event type: %d", pSelf->Type);
break;
}
return rb_str_new2(szBuffer);
}
static VALUE Event_type(VALUE vSelf) {
// Get C++ object pointer from vSelf
Event *pSelf;
Data_Get_Struct(vSelf, Event, pSelf);
return INT2FIX(pSelf->Type);
}
static VALUE Event_char(VALUE vSelf) {
// Get C++ object pointer from vSelf
Event *pSelf;
Data_Get_Struct(vSelf, Event, pSelf);
char szBuffer[4];
sprintf(szBuffer, "%C", pSelf->Text.Unicode);
return rb_str_new2(szBuffer);
}
static VALUE Event_code(VALUE vSelf) {
// Get C++ object pointer from vSelf
Event *pSelf;
Data_Get_Struct(vSelf, Event, pSelf);
if(pSelf->Type == Event::KeyPressed || pSelf->Type == Event::KeyReleased)
return INT2FIX(pSelf->Key.Code);
rb_raise(rb_eTypeError, "wrong event type");
}
static VALUE Event_alt(VALUE vSelf) {
// Get C++ object pointer from vSelf
Event *pSelf;
Data_Get_Struct(vSelf, Event, pSelf);
if(pSelf->Type == Event::KeyPressed || pSelf->Type == Event::KeyReleased)
return pSelf->Key.Alt ? Qtrue : Qfalse;
rb_raise(rb_eTypeError, "wrong event type");
}
static VALUE Event_control(VALUE vSelf) {
// Get C++ object pointer from vSelf
Event *pSelf;
Data_Get_Struct(vSelf, Event, pSelf);
if(pSelf->Type == Event::KeyPressed || pSelf->Type == Event::KeyReleased)
return pSelf->Key.Control ? Qtrue : Qfalse;
rb_raise(rb_eTypeError, "wrong event type");
}
static VALUE Event_shift(VALUE vSelf) {
// Get C++ object pointer from vSelf
Event *pSelf;
Data_Get_Struct(vSelf, Event, pSelf);
if(pSelf->Type == Event::KeyPressed || pSelf->Type == Event::KeyReleased)
return pSelf->Key.Shift ? Qtrue : Qfalse;
rb_raise(rb_eTypeError, "wrong event type");
}
static VALUE Event_delta(VALUE vSelf) {
// Get C++ object pointer from vSelf
Event *pSelf;
Data_Get_Struct(vSelf, Event, pSelf);
if(pSelf->Type == Event::MouseWheelMoved)
return INT2FIX(pSelf->MouseWheel.Delta);
rb_raise(rb_eTypeError, "wrong event type");
}
static VALUE Event_buttons(VALUE vSelf) {
// Get C++ object pointer from vSelf
Event *pSelf;
Data_Get_Struct(vSelf, Event, pSelf);
if(pSelf->Type == Event::MouseButtonPressed || pSelf->Type == Event::MouseButtonReleased)
return INT2FIX(pSelf->MouseButton.Button);
rb_raise(rb_eTypeError, "wrong event type");
}
static VALUE Event_button(VALUE vSelf) {
// Get C++ object pointer from vSelf
Event *pSelf;
Data_Get_Struct(vSelf, Event, pSelf);
if(pSelf->Type == Event::JoyButtonPressed || pSelf->Type == Event::JoyButtonReleased)
return INT2FIX(pSelf->JoyButton.Button);
rb_raise(rb_eTypeError, "wrong event type");
}
static VALUE Event_x(VALUE vSelf) {
// Get C++ object pointer from vSelf
Event *pSelf;
Data_Get_Struct(vSelf, Event, pSelf);
if(pSelf->Type == Event::MouseMoved)
return INT2FIX(pSelf->MouseMove.X);
rb_raise(rb_eTypeError, "wrong event type");
}
static VALUE Event_y(VALUE vSelf) {
// Get C++ object pointer from vSelf
Event *pSelf;
Data_Get_Struct(vSelf, Event, pSelf);
if(pSelf->Type == Event::MouseMoved)
return INT2FIX(pSelf->MouseMove.Y);
rb_raise(rb_eTypeError, "wrong event type");
}
static VALUE Event_axis(VALUE vSelf) {
// Get C++ object pointer from vSelf
Event *pSelf;
Data_Get_Struct(vSelf, Event, pSelf);
if(pSelf->Type == Event::JoyMoved)
return INT2FIX(pSelf->JoyMove.Axis);
rb_raise(rb_eTypeError, "wrong event type");
}
static VALUE Event_pos(VALUE vSelf) {
// Get C++ object pointer from vSelf
Event *pSelf;
Data_Get_Struct(vSelf, Event, pSelf);
if(pSelf->Type == Event::JoyMoved)
return rb_float_new(pSelf->JoyMove.Position);
rb_raise(rb_eTypeError, "wrong event type");
}
static VALUE Event_width(VALUE vSelf) {
// Get C++ object pointer from vSelf
Event *pSelf;
Data_Get_Struct(vSelf, Event, pSelf);
if(pSelf->Type == Event::Resized)
return INT2FIX(pSelf->Size.Width);
rb_raise(rb_eTypeError, "wrong event type");
}
static VALUE Event_height(VALUE vSelf) {
// Get C++ object pointer from vSelf
Event *pSelf;
Data_Get_Struct(vSelf, Event, pSelf);
if(pSelf->Type == Event::Resized)
return INT2FIX(pSelf->Size.Height);
rb_raise(rb_eTypeError, "wrong event type");
}
void Init_Event()
{
g_cEvent = rb_define_class_under(g_vModule, "Event", rb_cObject);
DEFINE_CLASS_METHOD(Event, new, -1);
DEFINE_INSTANCE_METHOD(Event, initialize, -1);
// For any event type
DEFINE_INSTANCE_METHOD(Event, to_s, 0);
DEFINE_INSTANCE_METHOD(Event, type, 0);
// For text events
DEFINE_INSTANCE_METHOD(Event, char, 0);
// For keyboard event types
DEFINE_INSTANCE_METHOD(Event, code, 0);
DEFINE_INSTANCE_METHOD(Event, alt, 0);
DEFINE_INSTANCE_METHOD(Event, control, 0);
DEFINE_INSTANCE_METHOD(Event, shift, 0);
// For mouse/joystick event types
DEFINE_INSTANCE_METHOD(Event, delta, 0);
DEFINE_INSTANCE_METHOD(Event, buttons, 0);
DEFINE_INSTANCE_METHOD(Event, button, 0);
DEFINE_INSTANCE_METHOD(Event, x, 0);
DEFINE_INSTANCE_METHOD(Event, y, 0);
DEFINE_INSTANCE_METHOD(Event, axis, 0);
DEFINE_INSTANCE_METHOD(Event, pos, 0);
// For size event types
DEFINE_INSTANCE_METHOD(Event, width, 0);
DEFINE_INSTANCE_METHOD(Event, height, 0);
}

View File

@ -1,155 +0,0 @@
////////////////////////////////////////////////////////////
//
// RubySFML - Ruby extension for the SFML library
// Copyright (C) 2007 Sean O'Neil and Laurent Gomila
// (sean.p.oneil@gmail.com and laurent.gom@gmail.com)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
// you must not claim that you wrote the original software.
// If you use this software in a product, an acknowledgment
// in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
// and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
////////////////////////////////////////////////////////////
#include <SFML/Graphics.hpp>
#include "RubySFML.h"
using namespace sf;
VALUE g_cFloatRect;
DECLARE_DOUBLE_RW(FloatRect, Left);
DECLARE_DOUBLE_RW(FloatRect, Top);
DECLARE_DOUBLE_RW(FloatRect, Right);
DECLARE_DOUBLE_RW(FloatRect, Bottom);
void FloatRect_free(void *p) { delete (FloatRect *)p; }
VALUE FloatRect_new(int argc, VALUE *argv, VALUE vClass) {
FloatRect *ptr = new FloatRect();
VALUE tData = Data_Wrap_Struct(vClass, 0, FloatRect_free, ptr);
rb_obj_call_init(tData, argc, argv);
return tData;
}
static VALUE FloatRect_initialize(int argc, VALUE *argv, VALUE vSelf) {
// Get C++ object pointer from vSelf
FloatRect *pSelf;
Data_Get_Struct(vSelf, FloatRect, pSelf);
if(argc == 0) {
// Nothing to initialize
} else if(argc == 4 &&
ISNUM(argv[0]) &&
ISNUM(argv[1]) &&
ISNUM(argv[2]) &&
ISNUM(argv[3])) {
pSelf->Left = (float)NUM2DBL(argv[0]);
pSelf->Top = (float)NUM2DBL(argv[1]);
pSelf->Right = (float)NUM2DBL(argv[2]);
pSelf->Bottom = (float)NUM2DBL(argv[3]);
} else
rb_raise(rb_eTypeError, "wrong argument type(s)");
return vSelf;
}
static VALUE FloatRect_to_s(VALUE vSelf)
{
// Get C++ object pointer from vSelf
FloatRect *pSelf;
Data_Get_Struct(vSelf, FloatRect, pSelf);
char szBuffer[256];
sprintf(szBuffer, "Left=%f, Top=%f, Right=%f, Bottom=%f", pSelf->Left, pSelf->Top, pSelf->Right, pSelf->Bottom);
return rb_str_new2(szBuffer);
}
static VALUE FloatRect_get_Width(VALUE vSelf)
{
// Get C++ object pointer from vSelf
FloatRect *pSelf;
Data_Get_Struct(vSelf, FloatRect, pSelf);
return rb_float_new(pSelf->GetWidth());
}
static VALUE FloatRect_set_Width(VALUE vSelf, VALUE vWidth)
{
// Get C++ object pointer from vSelf
FloatRect *pSelf;
Data_Get_Struct(vSelf, FloatRect, pSelf);
float nWidth = (float)NUM2DBL(vWidth);
pSelf->Right = pSelf->Left + nWidth;
return vWidth;
}
static VALUE FloatRect_get_Height(VALUE vSelf)
{
// Get C++ object pointer from vSelf
FloatRect *pSelf;
Data_Get_Struct(vSelf, FloatRect, pSelf);
return rb_float_new(pSelf->GetHeight());
}
static VALUE FloatRect_set_Height(VALUE vSelf, VALUE vHeight)
{
// Get C++ object pointer from vSelf
FloatRect *pSelf;
Data_Get_Struct(vSelf, FloatRect, pSelf);
float nHeight = (float)NUM2DBL(vHeight);
pSelf->Bottom = pSelf->Top + nHeight;
return vHeight;
}
static VALUE FloatRect_contains(VALUE vSelf, VALUE x, VALUE y)
{
// Get C++ object pointer from vSelf
FloatRect *pSelf;
Data_Get_Struct(vSelf, FloatRect, pSelf);
return pSelf->Contains((float)NUM2DBL(x), (float)NUM2DBL(y)) ? Qtrue : Qfalse;
}
static VALUE FloatRect_intersects(VALUE vSelf, VALUE vRect)
{
// Get C++ object pointer from vSelf
FloatRect *pSelf = NULL, *pRect = NULL;
FloatRect r;
Data_Get_Struct(vSelf, FloatRect, pSelf);
Data_Get_Struct(vRect, FloatRect, pRect);
if(!pSelf->Intersects(*pRect, &r))
return Qnil;
DECLARE_OBJ_VAR(FloatRect, Result, r);
return vResult;
}
void Init_FloatRect()
{
g_cFloatRect = rb_define_class_under(g_vModule, "FloatRect", rb_cObject);
DEFINE_CLASS_METHOD(FloatRect, new, -1);
DEFINE_INSTANCE_METHOD(FloatRect, initialize, -1);
DEFINE_RW2(FloatRect, Left, left);
DEFINE_RW2(FloatRect, Left, l);
DEFINE_RW2(FloatRect, Top, top);
DEFINE_RW2(FloatRect, Top, t);
DEFINE_RW2(FloatRect, Right, right);
DEFINE_RW2(FloatRect, Right, r);
DEFINE_RW2(FloatRect, Bottom, bottom);
DEFINE_RW2(FloatRect, Bottom, b);
DEFINE_RW2(FloatRect, Width, width);
DEFINE_RW2(FloatRect, Width, w);
DEFINE_RW2(FloatRect, Height, height);
DEFINE_RW2(FloatRect, Height, h);
DEFINE_INSTANCE_METHOD(FloatRect, to_s, 0);
DEFINE_INSTANCE_METHOD(FloatRect, contains, 2);
DEFINE_INSTANCE_METHOD(FloatRect, intersects, 1);
}

View File

@ -1,238 +0,0 @@
////////////////////////////////////////////////////////////
//
// RubySFML - Ruby extension for the SFML library
// Copyright (C) 2007 Sean O'Neil and Laurent Gomila
// (sean.p.oneil@gmail.com and laurent.gom@gmail.com)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
// you must not claim that you wrote the original software.
// If you use this software in a product, an acknowledgment
// in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
// and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
////////////////////////////////////////////////////////////
#include <SFML/Graphics.hpp>
#include "RubySFML.h"
using namespace sf;
VALUE g_cImage;
void Image_free(void *p) { delete (Image *)p; }
VALUE Image_new(int argc, VALUE *argv, VALUE vClass) {
Image *ptr = new Image();
VALUE tData = Data_Wrap_Struct(vClass, 0, Image_free, ptr);
rb_obj_call_init(tData, argc, argv);
return tData;
}
static VALUE Image_initialize(int argc, VALUE *argv, VALUE vSelf) {
// Get C++ object pointer from vSelf
Image *pSelf;
Data_Get_Struct(vSelf, Image, pSelf);
if(argc == 0) {
// Nothing to initialize
} else if(argc == 1 && IS(argv[0], g_cImage)) {
*pSelf = *(Image *)DATA_PTR(argv[0]);
} else if(argc == 1 && ISSTR(argv[0])) {
if(!pSelf->LoadFromFile(STR2CSTR(argv[0])))
rb_raise(rb_eRuntimeError, "Failed to load specified image file");
} else if(argc >= 2 && argc <= 3 &&
ISNUM(argv[0]) &&
ISNUM(argv[1]) &&
(argc < 3 || IS(argv[2], g_cColor))) {
pSelf->Create(NUM2INT(argv[0]), NUM2INT(argv[1]),
argc < 3 ? Color::Black : *(Color *)DATA_PTR(argv[2]));
} else if(argc == 2 &&
ISSTR(argv[0]) &&
ISNUM(argv[1])) {
pSelf->LoadFromMemory(STR2CSTR(argv[2]), NUM2INT(argv[0]));
} else
rb_raise(rb_eTypeError, "wrong argument type(s)");
return vSelf;
}
static VALUE Image_to_s(VALUE vSelf) {
// Get C++ object pointer from vSelf
Image *pSelf;
Data_Get_Struct(vSelf, Image, pSelf);
char szBuffer[256];
sprintf(szBuffer, "Width=%d, Height=%d", pSelf->GetWidth(), pSelf->GetHeight());
return rb_str_new2(szBuffer);
}
static VALUE Image_loadFromFile(VALUE vSelf, VALUE vPath) {
// Get C++ object pointer from vSelf
Image *pSelf;
Data_Get_Struct(vSelf, Image, pSelf);
return pSelf->LoadFromFile(STR2CSTR(vPath)) ? Qtrue : Qfalse;
}
static VALUE Image_saveToFile(VALUE vSelf, VALUE vPath) {
// Get C++ object pointer from vSelf
Image *pSelf;
Data_Get_Struct(vSelf, Image, pSelf);
return pSelf->SaveToFile(STR2CSTR(vPath)) ? Qtrue : Qfalse;
}
static VALUE Image_create(VALUE vSelf, VALUE vWidth, VALUE vHeight, VALUE vColor) {
// Get C++ object pointer from vSelf
Image *pSelf;
Data_Get_Struct(vSelf, Image, pSelf);
if(!IS(vColor, g_cColor))
rb_raise(rb_eTypeError, "wrong argument type(s)");
return pSelf->Create(NUM2INT(vWidth), NUM2INT(vHeight), *(Color *)DATA_PTR(vColor));
}
static VALUE Image_loadFromMemory(VALUE vSelf, VALUE vData, VALUE vSize) {
// Get C++ object pointer from vSelf
Image *pSelf;
Data_Get_Struct(vSelf, Image, pSelf);
return pSelf->LoadFromMemory(STR2CSTR(vData), NUM2INT(vSize));
}
static VALUE Image_createMaskFromColor(VALUE vSelf, VALUE vColor) {
// Get C++ object pointer from vSelf
Image *pSelf;
Data_Get_Struct(vSelf, Image, pSelf);
if(IS(vColor, g_cColor))
pSelf->CreateMaskFromColor(*(Color *)DATA_PTR(vColor));
else if(ISNUM(vColor)) {
DWORD dw = NUM2UINT(vColor);
Color c((dw >> 24) & 0xFF, (dw >> 16) & 0xFF, (dw >> 8) & 0xFF, (dw >> 0) & 0xFF);
pSelf->CreateMaskFromColor(c);
} else
rb_raise(rb_eTypeError, "wrong argument type(s)");
return Qnil;
}
static VALUE Image_resize(VALUE vSelf, VALUE vWidth, VALUE vHeight, VALUE vColor) {
// Get C++ object pointer from vSelf
Image *pSelf;
Data_Get_Struct(vSelf, Image, pSelf);
if(IS(vColor, g_cColor))
return pSelf->Resize(NUM2INT(vWidth), NUM2INT(vHeight), *(Color *)DATA_PTR(vColor));
else if(ISNUM(vColor)) {
DWORD dw = NUM2UINT(vColor);
Color c((dw >> 24) & 0xFF, (dw >> 16) & 0xFF, (dw >> 8) & 0xFF, (dw >> 0) & 0xFF);
return pSelf->Resize(NUM2INT(vWidth), NUM2INT(vHeight), c);
} else
rb_raise(rb_eTypeError, "wrong argument type(s)");
return Qnil;
}
static VALUE Image_setPixel(VALUE vSelf, VALUE vX, VALUE vY, VALUE vColor) {
// Get C++ object pointer from vSelf
Image *pSelf;
Data_Get_Struct(vSelf, Image, pSelf);
if(IS(vColor, g_cColor))
pSelf->SetPixel(NUM2INT(vX), NUM2INT(vY), *(Color *)DATA_PTR(vColor));
else if(ISNUM(vColor)) {
DWORD dw = NUM2UINT(vColor);
Color c((dw >> 24) & 0xFF, (dw >> 16) & 0xFF, (dw >> 8) & 0xFF, (dw >> 0) & 0xFF);
pSelf->SetPixel(NUM2INT(vX), NUM2INT(vY), c);
} else
rb_raise(rb_eTypeError, "wrong argument type(s)");
return Qnil;
}
static VALUE Image_getPixel(VALUE vSelf, VALUE vX, VALUE vY) {
// Get C++ object pointer from vSelf
Image *pSelf;
Data_Get_Struct(vSelf, Image, pSelf);
DECLARE_OBJ_VAR(Color, Color, pSelf->GetPixel(NUM2INT(vX), NUM2INT(vY)));
return vColor;
}
static VALUE Image_bind(VALUE vSelf) {
// Get C++ object pointer from vSelf
Image *pSelf;
Data_Get_Struct(vSelf, Image, pSelf);
pSelf->Bind();
return Qnil;
}
static VALUE Image_set_smooth(VALUE vSelf, VALUE vSmooth) {
// Get C++ object pointer from vSelf
Image *pSelf;
Data_Get_Struct(vSelf, Image, pSelf);
pSelf->SetSmooth(RTEST(vSmooth));
return Qnil;
}
static VALUE Image_set_repeat(VALUE vSelf, VALUE vRepeat) {
// Get C++ object pointer from vSelf
Image *pSelf;
Data_Get_Struct(vSelf, Image, pSelf);
pSelf->SetRepeat(RTEST(vRepeat));
return Qnil;
}
static VALUE Image_get_width(VALUE vSelf) {
// Get C++ object pointer from vSelf
Image *pSelf;
Data_Get_Struct(vSelf, Image, pSelf);
return INT2FIX(pSelf->GetWidth());
}
static VALUE Image_get_height(VALUE vSelf) {
// Get C++ object pointer from vSelf
Image *pSelf;
Data_Get_Struct(vSelf, Image, pSelf);
return INT2FIX(pSelf->GetHeight());
}
static VALUE Image_getTexCoords(VALUE vSelf, VALUE vRect) {
// Get C++ object pointer from vSelf
Image *pSelf;
Data_Get_Struct(vSelf, Image, pSelf);
if(!IS(vRect, g_cIntRect))
rb_raise(rb_eTypeError, "wrong argument type(s)");
DECLARE_OBJ_VAR(FloatRect, Coord, pSelf->GetTexCoords(*(IntRect *)DATA_PTR(vRect)));
return vCoord;
}
static VALUE Image_getValidTextureSize(VALUE vClass, VALUE vSize) {
// Get C++ object pointer from vSelf
return INT2FIX(Image::GetValidTextureSize(NUM2INT(vSize)));
}
void Init_Image()
{
g_cImage = rb_define_class_under(g_vModule, "Image", rb_cObject);
DEFINE_CLASS_METHOD(Image, new, -1);
DEFINE_CLASS_METHOD(Image, getValidTextureSize, 1);
DEFINE_INSTANCE_METHOD(Image, initialize, -1);
DEFINE_SETTER(Image, smooth);
DEFINE_SETTER(Image, repeat);
DEFINE_GETTER(Image, width);
DEFINE_GETTER2(Image, width, w);
DEFINE_GETTER(Image, height);
DEFINE_GETTER2(Image, height, h);
DEFINE_INSTANCE_METHOD(Image, to_s, 0);
DEFINE_INSTANCE_METHOD(Image, loadFromFile, 1);
DEFINE_INSTANCE_METHOD(Image, saveToFile, 1);
DEFINE_INSTANCE_METHOD(Image, create, 3);
DEFINE_INSTANCE_METHOD(Image, loadFromMemory, 2);
DEFINE_INSTANCE_METHOD(Image, createMaskFromColor, 1);
DEFINE_INSTANCE_METHOD(Image, resize, 3);
DEFINE_INSTANCE_METHOD(Image, setPixel, 3);
DEFINE_INSTANCE_METHOD(Image, getPixel, 2);
DEFINE_INSTANCE_METHOD(Image, bind, 0);
DEFINE_INSTANCE_METHOD(Image, getTexCoords, 1);
DEFINE_INSTANCE_METHOD2(Image, getPixel, [], 2);
DEFINE_INSTANCE_METHOD2(Image, setPixel, []=, 2);
}

View File

@ -1,105 +0,0 @@
////////////////////////////////////////////////////////////
//
// RubySFML - Ruby extension for the SFML library
// Copyright (C) 2007 Sean O'Neil and Laurent Gomila
// (sean.p.oneil@gmail.com and laurent.gom@gmail.com)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
// you must not claim that you wrote the original software.
// If you use this software in a product, an acknowledgment
// in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
// and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
////////////////////////////////////////////////////////////
#include <SFML/Window.hpp>
#include "RubySFML.h"
using namespace sf;
VALUE g_cInput;
void Input_free(void *p) { delete (Input *)p; }
VALUE Input_new(int argc, VALUE *argv, VALUE vClass) {
Input *ptr = new Input();
VALUE tData = Data_Wrap_Struct(vClass, 0, Input_free, ptr);
rb_obj_call_init(tData, argc, argv);
return tData;
}
static VALUE Input_initialize(int argc, VALUE *argv, VALUE vSelf) {
// Get C++ object pointer from vSelf
Input *pSelf;
Data_Get_Struct(vSelf, Input, pSelf);
if(argc == 0) {
// Nothing to initialize
} else
rb_raise(rb_eTypeError, "wrong argument type(s)");
return vSelf;
}
static VALUE Input_isKeyDown(VALUE vSelf, VALUE vKey) {
// Get C++ object pointer from vSelf
Input *pSelf;
Data_Get_Struct(vSelf, Input, pSelf);
return pSelf->IsKeyDown((Key::Code)NUM2INT(vKey)) ? Qtrue : Qfalse;
}
static VALUE Input_isMouseButtonDown(VALUE vSelf, VALUE vButton) {
// Get C++ object pointer from vSelf
Input *pSelf;
Data_Get_Struct(vSelf, Input, pSelf);
return pSelf->IsMouseButtonDown((Mouse::Button)NUM2INT(vButton)) ? Qtrue : Qfalse;
}
static VALUE Input_isJoystickButtonDown(VALUE vSelf, VALUE vJoy, VALUE vButton) {
// Get C++ object pointer from vSelf
Input *pSelf;
Data_Get_Struct(vSelf, Input, pSelf);
return pSelf->IsJoystickButtonDown(NUM2INT(vJoy), NUM2INT(vButton)) ? Qtrue : Qfalse;
}
static VALUE Input_getMouseX(VALUE vSelf) {
// Get C++ object pointer from vSelf
Input *pSelf;
Data_Get_Struct(vSelf, Input, pSelf);
return INT2FIX(pSelf->GetMouseX());
}
static VALUE Input_getMouseY(VALUE vSelf) {
// Get C++ object pointer from vSelf
Input *pSelf;
Data_Get_Struct(vSelf, Input, pSelf);
return INT2FIX(pSelf->GetMouseY());
}
static VALUE Input_getJoystickAxis(VALUE vSelf, VALUE vJoy, VALUE vAxis) {
// Get C++ object pointer from vSelf
Input *pSelf;
Data_Get_Struct(vSelf, Input, pSelf);
return INT2FIX(pSelf->GetJoystickAxis(NUM2INT(vJoy), (Joy::Axis)NUM2INT(vAxis)));
}
void Init_Input()
{
g_cInput = rb_define_class_under(g_vModule, "Input", rb_cObject);
DEFINE_CLASS_METHOD(Input, new, -1);
DEFINE_INSTANCE_METHOD(Input, initialize, -1);
DEFINE_INSTANCE_METHOD(Input, isKeyDown, 1);
DEFINE_INSTANCE_METHOD(Input, isMouseButtonDown, 1);
DEFINE_INSTANCE_METHOD(Input, isJoystickButtonDown, 2);
DEFINE_INSTANCE_METHOD(Input, getMouseX, 0);
DEFINE_INSTANCE_METHOD(Input, getMouseY, 0);
DEFINE_INSTANCE_METHOD(Input, getJoystickAxis, 2);
}

View File

@ -1,157 +0,0 @@
////////////////////////////////////////////////////////////
//
// RubySFML - Ruby extension for the SFML library
// Copyright (C) 2007 Sean O'Neil and Laurent Gomila
// (sean.p.oneil@gmail.com and laurent.gom@gmail.com)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
// you must not claim that you wrote the original software.
// If you use this software in a product, an acknowledgment
// in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
// and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
////////////////////////////////////////////////////////////
#include <SFML/Graphics.hpp>
#include "RubySFML.h"
using namespace sf;
VALUE g_cIntRect;
DECLARE_INT_RW(IntRect, Left);
DECLARE_INT_RW(IntRect, Top);
DECLARE_INT_RW(IntRect, Right);
DECLARE_INT_RW(IntRect, Bottom);
void IntRect_free(void *p) { delete (IntRect *)p; }
VALUE IntRect_new(int argc, VALUE *argv, VALUE vClass) {
// For each version of this method, convert Ruby args to C++ types (applying default values)
IntRect *ptr = new IntRect();
VALUE tData = Data_Wrap_Struct(vClass, 0, IntRect_free, ptr);
rb_obj_call_init(tData, argc, argv);
return tData;
}
static VALUE IntRect_initialize(int argc, VALUE *argv, VALUE vSelf) {
// Get C++ object pointer from vSelf
IntRect *pSelf;
Data_Get_Struct(vSelf, IntRect, pSelf);
if(argc == 0) {
// Nothing to initialize
} else if(argc == 4 &&
ISNUM(argv[0]) &&
ISNUM(argv[1]) &&
ISNUM(argv[2]) &&
ISNUM(argv[3])) {
pSelf->Left = NUM2INT(argv[0]);
pSelf->Top = NUM2INT(argv[1]);
pSelf->Right = NUM2INT(argv[2]);
pSelf->Bottom = NUM2INT(argv[3]);
} else
rb_raise(rb_eTypeError, "wrong argument type(s)");
return vSelf;
}
static VALUE IntRect_to_s(VALUE vSelf)
{
// Get C++ object pointer from vSelf
IntRect *pSelf;
Data_Get_Struct(vSelf, IntRect, pSelf);
char szBuffer[256];
sprintf(szBuffer, "Left=%d, Top=%d, Right=%d, Bottom=%d", pSelf->Left, pSelf->Top, pSelf->Right, pSelf->Bottom);
return rb_str_new2(szBuffer);
}
static VALUE IntRect_get_Width(VALUE vSelf)
{
// Get C++ object pointer from vSelf
IntRect *pSelf;
Data_Get_Struct(vSelf, IntRect, pSelf);
return INT2NUM(pSelf->GetWidth());
}
static VALUE IntRect_set_Width(VALUE vSelf, VALUE vWidth)
{
// Get C++ object pointer from vSelf
IntRect *pSelf;
Data_Get_Struct(vSelf, IntRect, pSelf);
int nWidth = NUM2INT(vWidth);
pSelf->Right = pSelf->Left + nWidth;
return vWidth;
}
static VALUE IntRect_get_Height(VALUE vSelf)
{
// Get C++ object pointer from vSelf
IntRect *pSelf;
Data_Get_Struct(vSelf, IntRect, pSelf);
return INT2NUM(pSelf->GetHeight());
}
static VALUE IntRect_set_Height(VALUE vSelf, VALUE vHeight)
{
// Get C++ object pointer from vSelf
IntRect *pSelf;
Data_Get_Struct(vSelf, IntRect, pSelf);
int nHeight = NUM2INT(vHeight);
pSelf->Bottom = pSelf->Top + nHeight;
return vHeight;
}
static VALUE IntRect_contains(VALUE vSelf, VALUE x, VALUE y)
{
// Get C++ object pointer from vSelf
IntRect *pSelf;
Data_Get_Struct(vSelf, IntRect, pSelf);
return pSelf->Contains(NUM2INT(x), NUM2INT(y)) ? Qtrue : Qfalse;
}
static VALUE IntRect_intersects(VALUE vSelf, VALUE vRect)
{
// Get C++ object pointer from vSelf
IntRect *pSelf = NULL, *pRect = NULL;
IntRect r;
Data_Get_Struct(vSelf, IntRect, pSelf);
Data_Get_Struct(vRect, IntRect, pRect);
if(!pSelf->Intersects(*pRect, &r))
return Qnil;
DECLARE_OBJ_VAR(IntRect, Result, r);
return vResult;
}
void Init_IntRect()
{
g_cIntRect = rb_define_class_under(g_vModule, "IntRect", rb_cObject);
DEFINE_CLASS_METHOD(IntRect, new, -1);
DEFINE_INSTANCE_METHOD(IntRect, initialize, -1);
DEFINE_RW2(IntRect, Left, left);
DEFINE_RW2(IntRect, Left, l);
DEFINE_RW2(IntRect, Top, top);
DEFINE_RW2(IntRect, Top, t);
DEFINE_RW2(IntRect, Right, right);
DEFINE_RW2(IntRect, Right, r);
DEFINE_RW2(IntRect, Bottom, bottom);
DEFINE_RW2(IntRect, Bottom, b);
DEFINE_RW2(IntRect, Width, width);
DEFINE_RW2(IntRect, Width, w);
DEFINE_RW2(IntRect, Height, height);
DEFINE_RW2(IntRect, Height, h);
DEFINE_INSTANCE_METHOD(IntRect, to_s, 0);
DEFINE_INSTANCE_METHOD(IntRect, contains, 2);
DEFINE_INSTANCE_METHOD(IntRect, intersects, 1);
}

View File

@ -1,153 +0,0 @@
////////////////////////////////////////////////////////////
//
// RubySFML - Ruby extension for the SFML library
// Copyright (C) 2007 Sean O'Neil and Laurent Gomila
// (sean.p.oneil@gmail.com and laurent.gom@gmail.com)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
// you must not claim that you wrote the original software.
// If you use this software in a product, an acknowledgment
// in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
// and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
////////////////////////////////////////////////////////////
#include <SFML/Audio.hpp>
#include "RubySFML.h"
using namespace sf;
VALUE g_cMusic;
void Music_free(void *p) { delete (Music *)p; }
VALUE Music_new(int argc, VALUE *argv, VALUE vClass) {
Music *ptr = NULL;
if(argc == 1 && ISNUM(argv[0]))
ptr = new Music(NUM2INT(argv[0]));
else
ptr = new Music();
VALUE tData = Data_Wrap_Struct(vClass, 0, Music_free, ptr);
rb_obj_call_init(tData, argc, argv);
return tData;
}
static VALUE Music_initialize(int argc, VALUE *argv, VALUE vSelf) {
// Get C++ object pointer from vSelf
Music *pSelf;
Data_Get_Struct(vSelf, Music, pSelf);
if(argc == 0) {
// Nothing to initialize
} else if(argc == 1 && ISNUM(argv[0])) {
// Was forced to set this above in Music_new()
} else if(argc == 1 && ISSTR(argv[0])) {
if(!pSelf->Open(STR2CSTR(argv[0])))
rb_raise(rb_eRuntimeError, "Failed to load specified music file");
} else
rb_raise(rb_eTypeError, "wrong argument type(s)");
return vSelf;
}
static VALUE Music_to_s(VALUE vSelf) {
// Get C++ object pointer from vSelf
Music *pSelf;
Data_Get_Struct(vSelf, Music, pSelf);
char szBuffer[256];
sprintf(szBuffer, "Channels=%d, SampleRate=%d, Duration=%f, Status=%s", pSelf->GetChannelsCount(), pSelf->GetSampleRate(), pSelf->GetDuration(), pSelf->GetStatus() == Sound::Playing ? "playing" : pSelf->GetStatus() == Sound::Paused ? "paused" : "stopped");
return rb_str_new2(szBuffer);
}
static VALUE Music_open(VALUE vSelf, VALUE vFile) {
// Get C++ object pointer from vSelf
Music *pSelf;
Data_Get_Struct(vSelf, Music, pSelf);
return pSelf->Open(STR2CSTR(vFile)) ? Qtrue : Qfalse;
}
static VALUE Music_play(VALUE vSelf) {
// Get C++ object pointer from vSelf
Music *pSelf;
Data_Get_Struct(vSelf, Music, pSelf);
pSelf->Play();
return Qnil;
}
static VALUE Music_stop(VALUE vSelf) {
// Get C++ object pointer from vSelf
Music *pSelf;
Data_Get_Struct(vSelf, Music, pSelf);
pSelf->Stop();
return Qnil;
}
static VALUE Music_set_loop(VALUE vSelf, VALUE vLoop) {
// Get C++ object pointer from vSelf
Music *pSelf;
Data_Get_Struct(vSelf, Music, pSelf);
pSelf->SetLoop(RTEST(vLoop));
return Qnil;
}
static VALUE Music_get_loop(VALUE vSelf) {
// Get C++ object pointer from vSelf
Music *pSelf;
Data_Get_Struct(vSelf, Music, pSelf);
return pSelf->GetLoop() ? Qtrue : Qfalse;
}
static VALUE Music_get_duration(VALUE vSelf) {
// Get C++ object pointer from vSelf
Music *pSelf;
Data_Get_Struct(vSelf, Music, pSelf);
return rb_float_new(pSelf->GetDuration());
}
static VALUE Music_get_channels(VALUE vSelf) {
// Get C++ object pointer from vSelf
Music *pSelf;
Data_Get_Struct(vSelf, Music, pSelf);
return INT2FIX(pSelf->GetChannelsCount());
}
static VALUE Music_get_sampleRate(VALUE vSelf) {
// Get C++ object pointer from vSelf
Music *pSelf;
Data_Get_Struct(vSelf, Music, pSelf);
return INT2FIX(pSelf->GetSampleRate());
}
static VALUE Music_get_status(VALUE vSelf) {
// Get C++ object pointer from vSelf
Music *pSelf;
Data_Get_Struct(vSelf, Music, pSelf);
return INT2FIX(pSelf->GetStatus());
}
void Init_Music()
{
g_cMusic = rb_define_class_under(g_vModule, "Music", rb_cObject);
DEFINE_CLASS_METHOD(Music, new, -1);
DEFINE_INSTANCE_METHOD(Music, initialize, -1);
DEFINE_RW(Music, loop);
DEFINE_GETTER(Music, duration);
DEFINE_GETTER(Music, status);
DEFINE_GETTER(Music, channels);
DEFINE_GETTER(Music, sampleRate);
DEFINE_INSTANCE_METHOD(Music, to_s, 0);
DEFINE_INSTANCE_METHOD(Music, open, 1);
DEFINE_INSTANCE_METHOD(Music, play, 0);
DEFINE_INSTANCE_METHOD(Music, stop, 0);
}

View File

@ -1,147 +0,0 @@
////////////////////////////////////////////////////////////
//
// RubySFML - Ruby extension for the SFML library
// Copyright (C) 2007 Sean O'Neil and Laurent Gomila
// (sean.p.oneil@gmail.com and laurent.gom@gmail.com)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
// you must not claim that you wrote the original software.
// If you use this software in a product, an acknowledgment
// in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
// and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
////////////////////////////////////////////////////////////
#include <SFML/Graphics.hpp>
#include "RubySFML.h"
using namespace sf;
// Wrapper for PostFX that calls the Ruby version of virtual methods in case a Ruby class derives from this one
class rPostFX : public PostFX {
protected:
VALUE m_vSelf, m_vClass;
ID m_idRender;
bool m_bRender, m_bInRender;
virtual void Render(const RenderWindow &Window) const {
// If this method is overridden in Ruby, call it
if(m_bRender) {
VALUE vWindow = Data_Wrap_Struct(g_cRenderWindow, 0, 0, (void*)&Window);
VALUE vRet = rb_funcall(m_vSelf, m_idRender, 1, vWindow);
} else // else call parent
PostFX::Render(Window);
}
public:
// Damn constructors should be inherited from base class
rPostFX() : PostFX() {}
rPostFX(const PostFX &Copy) : PostFX(Copy) {}
// Call as soon as you get a Ruby VALUE pointing to this object
void rInit(VALUE vSelf) {
// Need these for rb_funcall
m_vSelf = vSelf;
m_vClass = CLASS_OF(m_vSelf);
// Initialize members for Render() virtual method
m_idRender = rb_intern("render");
m_bRender = rb_method_boundp(m_vClass, m_idRender, 0) == Qtrue;
}
// When an overridden method in Ruby calls super(), it is called this way
VALUE Render(VALUE vWindow) {
PostFX::Render(*(RenderWindow *)DATA_PTR(vWindow));
return Qnil;
}
};
VALUE g_cPostFX;
void PostFX_free(void *p) { delete (PostFX *)p; }
VALUE PostFX_new(int argc, VALUE *argv, VALUE vClass) {
// For each version of this method, convert Ruby args to C++ types (applying default values)
rPostFX *ptr = new rPostFX();
VALUE tData = Data_Wrap_Struct(vClass, 0, PostFX_free, ptr);
ptr->rInit(tData);
rb_obj_call_init(tData, argc, argv);
return tData;
}
static VALUE PostFX_initialize(int argc, VALUE *argv, VALUE vSelf) {
// Get C++ object pointer from vSelf
PostFX *pSelf;
Data_Get_Struct(vSelf, PostFX, pSelf);
if(argc == 0) {
// Nothing to initialize
} else if(argc == 1 && ISSTR(argv[0])) {
pSelf->LoadFromFile(STR2CSTR(argv[0]));
} else if(argc == 1 && IS(argv[0], g_cPostFX)) {
*pSelf = *(PostFX *)DATA_PTR(argv[0]);
} else
rb_raise(rb_eTypeError, "wrong argument type(s)");
return vSelf;
}
static VALUE PostFX_loadFromFile(VALUE vSelf, VALUE vFile) {
// Get C++ object pointer from vSelf
PostFX *pSelf;
Data_Get_Struct(vSelf, PostFX, pSelf);
return pSelf->LoadFromFile(STR2CSTR(vFile)) ? Qtrue : Qfalse;
}
static VALUE PostFX_setParameter(int argc, VALUE *argv, VALUE vSelf) {
PostFX *pSelf;
Data_Get_Struct(vSelf, PostFX, pSelf);
if(argc == 2 && ISSTR(argv[0]) && ISNUM(argv[1])) {
pSelf->SetParameter(STR2CSTR(argv[0]), (float)NUM2DBL(argv[1]));
} else if(argc == 3 && ISSTR(argv[0]) && ISNUM(argv[1]) && ISNUM(argv[2])) {
pSelf->SetParameter(STR2CSTR(argv[0]), (float)NUM2DBL(argv[1]), (float)NUM2DBL(argv[2]));
} else if(argc == 4 && ISSTR(argv[0]) && ISNUM(argv[1]) && ISNUM(argv[2]) && ISNUM(argv[3])) {
pSelf->SetParameter(STR2CSTR(argv[0]), (float)NUM2DBL(argv[1]), (float)NUM2DBL(argv[2]), (float)NUM2DBL(argv[3]));
} else
rb_raise(rb_eTypeError, "wrong argument type(s)");
return Qnil;
}
static VALUE PostFX_setTexture(VALUE vSelf, VALUE vName, VALUE vImage) {
// Get C++ object pointer from vSelf
PostFX *pSelf;
Data_Get_Struct(vSelf, PostFX, pSelf);
if(!IS(vImage, g_cImage))
rb_raise(rb_eTypeError, "wrong argument type(s)");
pSelf->SetTexture(STR2CSTR(vName), (Image *)DATA_PTR(vImage));
return Qnil;
}
static VALUE PostFX_render(VALUE vSelf, VALUE vWindow) {
// Get C++ object pointer from vSelf
rPostFX *pSelf;
Data_Get_Struct(vSelf, rPostFX, pSelf);
return pSelf->Render(vWindow);
}
void Init_PostFX()
{
g_cPostFX = rb_define_class_under(g_vModule, "PostFX", g_cDrawable);
DEFINE_CLASS_METHOD(PostFX, new, -1);
DEFINE_INSTANCE_METHOD(PostFX, initialize, -1);
DEFINE_INSTANCE_METHOD(PostFX, setParameter, -1);
DEFINE_INSTANCE_METHOD(PostFX, loadFromFile, 1);
DEFINE_INSTANCE_METHOD(PostFX, setTexture, 2);
// Virtual method
DEFINE_INSTANCE_METHOD(PostFX, render, 1);
}

View File

@ -1,237 +0,0 @@
////////////////////////////////////////////////////////////
//
// RubySFML - Ruby extension for the SFML library
// Copyright (C) 2007 Sean O'Neil and Laurent Gomila
// (sean.p.oneil@gmail.com and laurent.gom@gmail.com)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
// you must not claim that you wrote the original software.
// If you use this software in a product, an acknowledgment
// in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
// and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
////////////////////////////////////////////////////////////
#include <SFML/Graphics.hpp>
#include "RubySFML.h"
using namespace sf;
VALUE g_cRenderWindow;
void RenderWindow_free(void *p) { delete (RenderWindow *)p; }
VALUE RenderWindow_new(int argc, VALUE *argv, VALUE vClass) {
// For each version of this method, convert Ruby args to C++ types (applying default values)
RenderWindow *ptr = new RenderWindow();
VALUE tData = Data_Wrap_Struct(vClass, 0, RenderWindow_free, ptr);
rb_obj_call_init(tData, argc, argv);
return tData;
}
static VALUE RenderWindow_initialize(int argc, VALUE *argv, VALUE vSelf) {
// Get C++ object pointer from vSelf
RenderWindow *pSelf;
Data_Get_Struct(vSelf, RenderWindow, pSelf);
if(argc >= 2 && argc <= 4 &&
IS(argv[0], g_cVideoMode) &&
ISSTR(argv[1]) &&
(argc < 3 || true) &&
(argc < 4 || ISNUM(argv[3]))) {
pSelf->Create(
*(VideoMode *)DATA_PTR(argv[0]),
STR2CSTR(argv[1]),
argc < 3 ? (Style::Resize | Style::Close) : NUM2INT(argv[2]),
argc < 4 ? 0 : NUM2INT(argv[3]));
} else
rb_raise(rb_eTypeError, "wrong argument type(s)");
return vSelf;
}
static VALUE RenderWindow_to_s(VALUE vSelf) {
// Get C++ object pointer from vSelf
RenderWindow *pSelf;
Data_Get_Struct(vSelf, RenderWindow, pSelf);
char szBuffer[256];
sprintf(szBuffer, "Height: %d, Width: %d, Depth Bits: %d, Stencil Bits: %d", pSelf->GetWidth(), pSelf->GetHeight(), pSelf->GetDepthBits(), pSelf->GetStencilBits());
return rb_str_new2(szBuffer);
}
static VALUE RenderWindow_get_width(VALUE vSelf) {
// Get C++ object pointer from vSelf
RenderWindow *pSelf;
Data_Get_Struct(vSelf, RenderWindow, pSelf);
return INT2FIX(pSelf->GetWidth());
}
static VALUE RenderWindow_get_height(VALUE vSelf) {
// Get C++ object pointer from vSelf
RenderWindow *pSelf;
Data_Get_Struct(vSelf, RenderWindow, pSelf);
return INT2FIX(pSelf->GetHeight());
}
static VALUE RenderWindow_get_depthBits(VALUE vSelf) {
// Get C++ object pointer from vSelf
RenderWindow *pSelf;
Data_Get_Struct(vSelf, RenderWindow, pSelf);
return INT2FIX(pSelf->GetDepthBits());
}
static VALUE RenderWindow_get_stencilBits(VALUE vSelf) {
// Get C++ object pointer from vSelf
RenderWindow *pSelf;
Data_Get_Struct(vSelf, RenderWindow, pSelf);
return INT2FIX(pSelf->GetStencilBits());
}
static VALUE RenderWindow_get_frameTime(VALUE vSelf) {
// Get C++ object pointer from vSelf
RenderWindow *pSelf;
Data_Get_Struct(vSelf, RenderWindow, pSelf);
return rb_float_new(pSelf->GetFrameTime());
}
static VALUE RenderWindow_get_input(VALUE vSelf) {
// Get C++ object pointer from vSelf
RenderWindow *pSelf;
Data_Get_Struct(vSelf, RenderWindow, pSelf);
DECLARE_PTR_VAR(Input, Input, (Input *)&pSelf->GetInput());
return vInput;
}
static VALUE RenderWindow_getEvent(VALUE vSelf) {
// Get C++ object pointer from vSelf
RenderWindow *pSelf;
Data_Get_Struct(vSelf, RenderWindow, pSelf);
Event ePoll;
if(!pSelf->GetEvent(ePoll))
return Qnil;
DECLARE_OBJ_VAR(Event, Event, ePoll);
return vEvent;
}
static VALUE RenderWindow_useVerticalSync(VALUE vSelf, VALUE vEnabled) {
// Get C++ object pointer from vSelf
RenderWindow *pSelf;
Data_Get_Struct(vSelf, RenderWindow, pSelf);
pSelf->UseVerticalSync(RTEST(vEnabled) != 0);
return Qnil;
}
static VALUE RenderWindow_showMouseCursor(VALUE vSelf, VALUE vShow) {
// Get C++ object pointer from vSelf
RenderWindow *pSelf;
Data_Get_Struct(vSelf, RenderWindow, pSelf);
pSelf->ShowMouseCursor(RTEST(vShow) != 0);
return Qnil;
}
static VALUE RenderWindow_display(VALUE vSelf) {
// Get C++ object pointer from vSelf
RenderWindow *pSelf;
Data_Get_Struct(vSelf, RenderWindow, pSelf);
pSelf->Display();
return Qnil;
}
static VALUE RenderWindow_optimize(VALUE vSelf, VALUE vBool) {
// Get C++ object pointer from vSelf
RenderWindow *pSelf;
Data_Get_Struct(vSelf, RenderWindow, pSelf);
pSelf->OptimizeForNonOpenGL(RTEST(vBool));
return Qnil;
}
static VALUE RenderWindow_capture(VALUE vSelf) {
// Get C++ object pointer from vSelf
RenderWindow *pSelf;
Data_Get_Struct(vSelf, RenderWindow, pSelf);
DECLARE_OBJ_VAR(Image, Image, pSelf->Capture());
return vImage;
}
static VALUE RenderWindow_get_view(VALUE vSelf) {
// Get C++ object pointer from vSelf
RenderWindow *pSelf;
Data_Get_Struct(vSelf, RenderWindow, pSelf);
DECLARE_OBJ_VAR(FloatRect, Rect, pSelf->GetViewRect());
return vRect;
}
static VALUE RenderWindow_set_view(VALUE vSelf, VALUE vView) {
// Get C++ object pointer from vSelf
RenderWindow *pSelf;
Data_Get_Struct(vSelf, RenderWindow, pSelf);
View *pView;
Data_Get_Struct(vView, View, pView);
pSelf->SetView(pView);
return Qnil;
}
static VALUE RenderWindow_set_backgroundColor(VALUE vSelf, VALUE vColor) {
// Get C++ object pointer from vSelf
RenderWindow *pSelf;
Data_Get_Struct(vSelf, RenderWindow, pSelf);
Color *pColor;
Data_Get_Struct(vColor, Color, pColor);
pSelf->SetBackgroundColor(*pColor);
return Qnil;
}
static VALUE RenderWindow_draw(VALUE vSelf, VALUE vObject) {
if(!ISKO(vObject, g_cDrawable))
rb_raise(rb_eTypeError, "wrong argument type(s)");
// Get C++ object pointer from vSelf
RenderWindow *pSelf;
Data_Get_Struct(vSelf, RenderWindow, pSelf);
Drawable *pObject;
Data_Get_Struct(vObject, Drawable, pObject);
pSelf->Draw(*pObject);
return Qnil;
}
static VALUE RenderWindow_setFramerateLimit(VALUE vSelf, VALUE vLimit) {
// Get C++ object pointer from vSelf
RenderWindow *pSelf;
Data_Get_Struct(vSelf, RenderWindow, pSelf);
pSelf->SetFramerateLimit((unsigned int)NUM2INT(vLimit));
return Qnil;
}
void Init_RenderWindow()
{
g_cRenderWindow = rb_define_class_under(g_vModule, "RenderWindow", rb_cObject);
DEFINE_CLASS_METHOD(RenderWindow, new, -1);
DEFINE_INSTANCE_METHOD(RenderWindow, initialize, -1);
DEFINE_GETTER(RenderWindow, width);
DEFINE_GETTER2(RenderWindow, width, w);
DEFINE_GETTER(RenderWindow, height);
DEFINE_GETTER2(RenderWindow, height, h);
DEFINE_GETTER(RenderWindow, input);
DEFINE_GETTER(RenderWindow, frameTime);
DEFINE_GETTER(RenderWindow, stencilBits);
DEFINE_GETTER(RenderWindow, depthBits);
DEFINE_RW(RenderWindow, view);
DEFINE_SETTER(RenderWindow, backgroundColor);
DEFINE_INSTANCE_METHOD(RenderWindow, to_s, 0);
DEFINE_INSTANCE_METHOD(RenderWindow, getEvent, 0); // Don't use GETTER
DEFINE_INSTANCE_METHOD(RenderWindow, useVerticalSync, 1);
DEFINE_INSTANCE_METHOD(RenderWindow, showMouseCursor, 1);
DEFINE_INSTANCE_METHOD(RenderWindow, display, 0);
DEFINE_INSTANCE_METHOD(RenderWindow, optimize, 1);
DEFINE_INSTANCE_METHOD(RenderWindow, capture, 0);
DEFINE_INSTANCE_METHOD(RenderWindow, draw, 1);
DEFINE_INSTANCE_METHOD(RenderWindow, setFramerateLimit, 1);
}

View File

@ -1,219 +0,0 @@
////////////////////////////////////////////////////////////
//
// RubySFML - Ruby extension for the SFML library
// Copyright (C) 2007 Sean O'Neil and Laurent Gomila
// (sean.p.oneil@gmail.com and laurent.gom@gmail.com)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
// you must not claim that you wrote the original software.
// If you use this software in a product, an acknowledgment
// in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
// and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
////////////////////////////////////////////////////////////
#include <SFML/Audio.hpp>
#include "RubySFML.h"
using namespace sf;
VALUE g_cSound;
void Sound_free(void *p) { delete (Sound *)p; }
VALUE Sound_new(int argc, VALUE *argv, VALUE vClass) {
Sound *ptr = new Sound();
VALUE tData = Data_Wrap_Struct(vClass, 0, Sound_free, ptr);
rb_obj_call_init(tData, argc, argv);
return tData;
}
static VALUE Sound_initialize(int argc, VALUE *argv, VALUE vSelf) {
// Get C++ object pointer from vSelf
Sound *pSelf;
Data_Get_Struct(vSelf, Sound, pSelf);
if(argc == 1 && IS(argv[0], g_cSound)) {
*pSelf = *(Sound *)DATA_PTR(argv[0]);
} else if(argc >= 0 && argc <= 7 &&
(argc < 1 || IS(argv[0], g_cSoundBuffer))) {
if(argc >= 1)
pSelf->SetBuffer(*(SoundBuffer *)DATA_PTR(argv[0]));
if(argc >= 2)
pSelf->SetLoop(RTEST(argv[1]) != 0);
if(argc >= 3)
pSelf->SetPitch((float)NUM2DBL(argv[2]));
if(argc >= 4)
pSelf->SetVolume((float)NUM2DBL(argv[3]));
if(argc >= 5) {
float x = argc < 5 ? 0.0f : (float)NUM2DBL(argv[4]);
float y = argc < 6 ? 0.0f : (float)NUM2DBL(argv[5]);
float z = argc < 7 ? 0.0f : (float)NUM2DBL(argv[6]);
pSelf->SetPosition(x, y, z);
}
} else
rb_raise(rb_eTypeError, "wrong argument type(s)");
return vSelf;
}
static VALUE Sound_to_s(VALUE vSelf) {
// Get C++ object pointer from vSelf
Sound *pSelf;
Data_Get_Struct(vSelf, Sound, pSelf);
char szBuffer[256];
float x, y, z;
pSelf->GetPosition(x, y, z);
sprintf(szBuffer, "Loop=%s, Pitch=%2.2f, Volume=%2.2f, Position=(%2.2f,%2.2f,%2.2f), Status=%s", pSelf->GetLoop() ? "true":"false", pSelf->GetPitch(), pSelf->GetVolume(), x, y, z, pSelf->GetStatus() == Sound::Playing ? "playing" : pSelf->GetStatus() == Sound::Paused ? "paused" : "stopped");
return rb_str_new2(szBuffer);
}
static VALUE Sound_play(VALUE vSelf) {
// Get C++ object pointer from vSelf
Sound *pSelf;
Data_Get_Struct(vSelf, Sound, pSelf);
pSelf->Play();
return Qnil;
}
static VALUE Sound_pause(VALUE vSelf) {
// Get C++ object pointer from vSelf
Sound *pSelf;
Data_Get_Struct(vSelf, Sound, pSelf);
pSelf->Pause();
return Qnil;
}
static VALUE Sound_stop(VALUE vSelf) {
// Get C++ object pointer from vSelf
Sound *pSelf;
Data_Get_Struct(vSelf, Sound, pSelf);
pSelf->Stop();
return Qnil;
}
static VALUE Sound_set_buffer(VALUE vSelf, VALUE vBuffer) {
// Get C++ object pointer from vSelf
Sound *pSelf;
Data_Get_Struct(vSelf, Sound, pSelf);
if(!IS(vBuffer, g_cSoundBuffer))
rb_raise(rb_eTypeError, "wrong argument type(s)");
pSelf->SetBuffer(*(SoundBuffer *)DATA_PTR(vBuffer));
return Qnil;
}
static VALUE Sound_set_loop(VALUE vSelf, VALUE vLoop) {
// Get C++ object pointer from vSelf
Sound *pSelf;
Data_Get_Struct(vSelf, Sound, pSelf);
pSelf->SetLoop(RTEST(vLoop));
return Qnil;
}
static VALUE Sound_set_pitch(VALUE vSelf, VALUE vPitch) {
// Get C++ object pointer from vSelf
Sound *pSelf;
Data_Get_Struct(vSelf, Sound, pSelf);
pSelf->SetLoop((float)NUM2DBL(vPitch));
return Qnil;
}
static VALUE Sound_set_volume(VALUE vSelf, VALUE vVolume) {
// Get C++ object pointer from vSelf
Sound *pSelf;
Data_Get_Struct(vSelf, Sound, pSelf);
pSelf->SetVolume((float)NUM2DBL(vVolume));
return Qnil;
}
static VALUE Sound_set_position(VALUE vSelf, VALUE vX, VALUE vY, VALUE vZ) {
// Get C++ object pointer from vSelf
Sound *pSelf;
Data_Get_Struct(vSelf, Sound, pSelf);
pSelf->SetPosition((float)NUM2DBL(vX), (float)NUM2DBL(vY), (float)NUM2DBL(vZ));
return Qnil;
}
static VALUE Sound_get_buffer(VALUE vSelf) {
// Get C++ object pointer from vSelf
Sound *pSelf;
Data_Get_Struct(vSelf, Sound, pSelf);
DECLARE_PTR_VAR(SoundBuffer, SoundBuffer, (SoundBuffer *)pSelf->GetBuffer());
return vSoundBuffer;
}
static VALUE Sound_get_loop(VALUE vSelf) {
// Get C++ object pointer from vSelf
Sound *pSelf;
Data_Get_Struct(vSelf, Sound, pSelf);
return pSelf->GetLoop() ? Qtrue : Qfalse;
}
static VALUE Sound_get_pitch(VALUE vSelf) {
// Get C++ object pointer from vSelf
Sound *pSelf;
Data_Get_Struct(vSelf, Sound, pSelf);
return rb_float_new(pSelf->GetPitch());
}
static VALUE Sound_get_volume(VALUE vSelf) {
// Get C++ object pointer from vSelf
Sound *pSelf;
Data_Get_Struct(vSelf, Sound, pSelf);
return rb_float_new(pSelf->GetVolume());
}
static VALUE Sound_get_position(VALUE vSelf) {
// Get C++ object pointer from vSelf
Sound *pSelf;
Data_Get_Struct(vSelf, Sound, pSelf);
float x, y, z;
pSelf->GetPosition(x, y, z);
VALUE vArray = rb_ary_new();
rb_ary_push(vArray, rb_float_new(x));
rb_ary_push(vArray, rb_float_new(y));
rb_ary_push(vArray, rb_float_new(z));
return vArray;
}
static VALUE Sound_get_status(VALUE vSelf) {
// Get C++ object pointer from vSelf
Sound *pSelf;
Data_Get_Struct(vSelf, Sound, pSelf);
return INT2FIX(pSelf->GetStatus());
}
static VALUE Sound_get_playingOffset(VALUE vSelf) {
// Get C++ object pointer from vSelf
Sound *pSelf;
Data_Get_Struct(vSelf, Sound, pSelf);
return rb_float_new(pSelf->GetPlayingOffset());
}
void Init_Sound()
{
g_cSound = rb_define_class_under(g_vModule, "Sound", rb_cObject);
DEFINE_CLASS_METHOD(Sound, new, -1);
DEFINE_INSTANCE_METHOD(Sound, initialize, -1);
DEFINE_RW(Sound, buffer);
DEFINE_RW(Sound, loop);
DEFINE_RW(Sound, pitch);
DEFINE_RW(Sound, volume);
DEFINE_RW(Sound, position);
DEFINE_GETTER(Sound, status);
DEFINE_GETTER(Sound, playingOffset);
DEFINE_INSTANCE_METHOD(Sound, to_s, 0);
DEFINE_INSTANCE_METHOD(Sound, play, 0);
DEFINE_INSTANCE_METHOD(Sound, pause, 0);
DEFINE_INSTANCE_METHOD(Sound, stop, 0);
}

View File

@ -1,137 +0,0 @@
////////////////////////////////////////////////////////////
//
// RubySFML - Ruby extension for the SFML library
// Copyright (C) 2007 Sean O'Neil and Laurent Gomila
// (sean.p.oneil@gmail.com and laurent.gom@gmail.com)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
// you must not claim that you wrote the original software.
// If you use this software in a product, an acknowledgment
// in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
// and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
////////////////////////////////////////////////////////////
#include <SFML/Audio.hpp>
#include "RubySFML.h"
using namespace sf;
VALUE g_cSoundBuffer;
void SoundBuffer_free(void *p) { delete (SoundBuffer *)p; }
VALUE SoundBuffer_new(int argc, VALUE *argv, VALUE vClass) {
SoundBuffer *ptr = new SoundBuffer();
VALUE tData = Data_Wrap_Struct(vClass, 0, SoundBuffer_free, ptr);
rb_obj_call_init(tData, argc, argv);
return tData;
}
static VALUE SoundBuffer_initialize(int argc, VALUE *argv, VALUE vSelf) {
// Get C++ object pointer from vSelf
SoundBuffer *pSelf;
Data_Get_Struct(vSelf, SoundBuffer, pSelf);
if(argc == 0) {
// Nothing to initialize
} else if(argc == 1 && IS(argv[0], g_cSoundBuffer)) {
*pSelf = *(SoundBuffer *)DATA_PTR(argv[0]);
} else if(argc == 1 && ISSTR(argv[0])) {
if(!pSelf->LoadFromFile(STR2CSTR(argv[0])))
rb_raise(rb_eRuntimeError, "Failed to load specified sound file");
} else
rb_raise(rb_eTypeError, "wrong argument type(s)");
return vSelf;
}
static VALUE SoundBuffer_to_s(VALUE vSelf) {
// Get C++ object pointer from vSelf
SoundBuffer *pSelf;
Data_Get_Struct(vSelf, SoundBuffer, pSelf);
char szBuffer[256];
sprintf(szBuffer, "Samples=%d, SampleRate=%d, Channels=%d, Duration=%f", pSelf->GetSamplesCount(), pSelf->GetSampleRate(), pSelf->GetChannelsCount(), pSelf->GetDuration());
return rb_str_new2(szBuffer);
}
static VALUE SoundBuffer_loadFromFile(VALUE vSelf, VALUE vPath) {
// Get C++ object pointer from vSelf
SoundBuffer *pSelf;
Data_Get_Struct(vSelf, SoundBuffer, pSelf);
return pSelf->LoadFromFile(STR2CSTR(vPath)) ? Qtrue : Qfalse;
}
static VALUE SoundBuffer_saveToFile(VALUE vSelf, VALUE vPath) {
// Get C++ object pointer from vSelf
SoundBuffer *pSelf;
Data_Get_Struct(vSelf, SoundBuffer, pSelf);
return pSelf->SaveToFile(STR2CSTR(vPath)) ? Qtrue : Qfalse;
}
static VALUE SoundBuffer_loadFromMemory(VALUE vSelf, VALUE vSamples, VALUE vSize) {
// Get C++ object pointer from vSelf
SoundBuffer *pSelf;
Data_Get_Struct(vSelf, SoundBuffer, pSelf);
return pSelf->LoadFromMemory(STR2CSTR(vSamples), NUM2INT(vSize)) ? Qtrue : Qfalse;
}
static VALUE SoundBuffer_get_samples(VALUE vSelf) {
// Get C++ object pointer from vSelf
SoundBuffer *pSelf;
Data_Get_Struct(vSelf, SoundBuffer, pSelf);
return rb_str_new((const char *)pSelf->GetSamples(), pSelf->GetSamplesCount()*2);
}
static VALUE SoundBuffer_get_samplesCount(VALUE vSelf) {
// Get C++ object pointer from vSelf
SoundBuffer *pSelf;
Data_Get_Struct(vSelf, SoundBuffer, pSelf);
return INT2FIX(pSelf->GetSamplesCount());
}
static VALUE SoundBuffer_get_sampleRate(VALUE vSelf) {
// Get C++ object pointer from vSelf
SoundBuffer *pSelf;
Data_Get_Struct(vSelf, SoundBuffer, pSelf);
return INT2FIX(pSelf->GetSampleRate());
}
static VALUE SoundBuffer_get_channels(VALUE vSelf) {
// Get C++ object pointer from vSelf
SoundBuffer *pSelf;
Data_Get_Struct(vSelf, SoundBuffer, pSelf);
return INT2FIX(pSelf->GetChannelsCount());
}
static VALUE SoundBuffer_get_duration(VALUE vSelf) {
// Get C++ object pointer from vSelf
SoundBuffer *pSelf;
Data_Get_Struct(vSelf, SoundBuffer, pSelf);
return rb_float_new(pSelf->GetDuration());
}
void Init_SoundBuffer()
{
g_cSoundBuffer = rb_define_class_under(g_vModule, "SoundBuffer", rb_cObject);
DEFINE_CLASS_METHOD(SoundBuffer, new, -1);
DEFINE_INSTANCE_METHOD(SoundBuffer, initialize, -1);
DEFINE_GETTER(SoundBuffer, samples);
DEFINE_GETTER(SoundBuffer, samplesCount);
DEFINE_GETTER(SoundBuffer, sampleRate);
DEFINE_GETTER(SoundBuffer, channels);
DEFINE_GETTER(SoundBuffer, duration);
DEFINE_INSTANCE_METHOD(SoundBuffer, to_s, 0);
DEFINE_INSTANCE_METHOD(SoundBuffer, loadFromFile, 1);
DEFINE_INSTANCE_METHOD(SoundBuffer, saveToFile, 1);
DEFINE_INSTANCE_METHOD(SoundBuffer, loadFromMemory, 2);
}

View File

@ -1,101 +0,0 @@
////////////////////////////////////////////////////////////
//
// RubySFML - Ruby extension for the SFML library
// Copyright (C) 2007 Sean O'Neil and Laurent Gomila
// (sean.p.oneil@gmail.com and laurent.gom@gmail.com)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
// you must not claim that you wrote the original software.
// If you use this software in a product, an acknowledgment
// in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
// and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
////////////////////////////////////////////////////////////
#include <SFML/Audio.hpp>
#include "RubySFML.h"
using namespace sf;
VALUE g_cSoundBufferRecorder;
void SoundBufferRecorder_free(void *p) { delete (SoundBufferRecorder *)p; }
VALUE SoundBufferRecorder_new(int argc, VALUE *argv, VALUE vClass) {
SoundBufferRecorder *ptr = new SoundBufferRecorder();
VALUE tData = Data_Wrap_Struct(vClass, 0, SoundBufferRecorder_free, ptr);
rb_obj_call_init(tData, argc, argv);
return tData;
}
static VALUE SoundBufferRecorder_initialize(int argc, VALUE *argv, VALUE vSelf) {
if(argc == 0) {
// Nothing to initialize
} else
rb_raise(rb_eTypeError, "wrong argument type(s)");
return vSelf;
}
VALUE SoundBufferRecorder_canCapture(VALUE vClass) {
return SoundBufferRecorder::CanCapture() ? Qtrue : Qfalse;
}
VALUE SoundBufferRecorder_get_buffer(VALUE vSelf) {
// Get C++ object pointer from vSelf
SoundBufferRecorder *pSelf;
Data_Get_Struct(vSelf, SoundBufferRecorder, pSelf);
DECLARE_PTR_VAR(SoundBuffer, SoundBuffer, (SoundBuffer *)&pSelf->GetBuffer());
return vSoundBuffer;
}
VALUE SoundBufferRecorder_start(int argc, VALUE *argv, VALUE vSelf) {
// Get C++ object pointer from vSelf
SoundBufferRecorder *pSelf;
Data_Get_Struct(vSelf, SoundBufferRecorder, pSelf);
if(argc == 0) {
pSelf->Start();
} else if(argc == 1) {
pSelf->Start(NUM2INT(argv[0]));
} else
rb_raise(rb_eTypeError, "wrong argument type(s)");
return Qnil;
}
VALUE SoundBufferRecorder_stop(VALUE vSelf) {
// Get C++ object pointer from vSelf
SoundBufferRecorder *pSelf;
Data_Get_Struct(vSelf, SoundBufferRecorder, pSelf);
pSelf->Stop();
return Qnil;
}
VALUE SoundBufferRecorder_get_sampleRate(VALUE vSelf) {
// Get C++ object pointer from vSelf
SoundBufferRecorder *pSelf;
Data_Get_Struct(vSelf, SoundBufferRecorder, pSelf);
return INT2FIX(pSelf->GetSampleRate());
}
void Init_SoundBufferRecorder()
{
g_cSoundBufferRecorder = rb_define_class_under(g_vModule, "SoundBufferRecorder", rb_cObject);
DEFINE_CLASS_METHOD(SoundBufferRecorder, new, -1);
DEFINE_INSTANCE_METHOD(SoundBufferRecorder, initialize, -1);
DEFINE_CLASS_METHOD(SoundBufferRecorder, canCapture, 0);
DEFINE_GETTER(SoundBufferRecorder, sampleRate);
DEFINE_GETTER(SoundBufferRecorder, buffer);
DEFINE_INSTANCE_METHOD(SoundBufferRecorder, start, -1);
DEFINE_INSTANCE_METHOD(SoundBufferRecorder, stop, 0);
}

View File

@ -1,319 +0,0 @@
////////////////////////////////////////////////////////////
//
// RubySFML - Ruby extension for the SFML library
// Copyright (C) 2007 Sean O'Neil and Laurent Gomila
// (sean.p.oneil@gmail.com and laurent.gom@gmail.com)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
// you must not claim that you wrote the original software.
// If you use this software in a product, an acknowledgment
// in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
// and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
////////////////////////////////////////////////////////////
#include <SFML/Graphics.hpp>
#include "RubySFML.h"
#include <math.h>
using namespace sf;
#ifdef _MSC_VER
#define SQRTF sqrtf
#else
#define SQRTF sqrt
#endif
// Wrapper for Sprite that calls the Ruby version of virtual methods in case a Ruby class derives from this one
class rSprite : public Sprite {
protected:
VALUE m_vSelf, m_vClass;
ID m_idRender;
bool m_bRender, m_bInRender;
virtual void Render(const RenderWindow &Window) const {
// If this method is overridden in Ruby, call it
if(m_bRender) {
VALUE vWindow = Data_Wrap_Struct(g_cRenderWindow, 0, 0, (void*)&Window);
VALUE vRet = rb_funcall(m_vSelf, m_idRender, 1, vWindow);
} else // else call parent
Sprite::Render(Window);
}
public:
// Call as soon as you get a Ruby VALUE pointing to this object
void rInit(VALUE vSelf) {
// Need these for rb_funcall
m_vSelf = vSelf;
m_vClass = CLASS_OF(m_vSelf);
// Initialize members for Render() virtual method
m_idRender = rb_intern("render");
m_bRender = rb_method_boundp(m_vClass, m_idRender, 0) == Qtrue;
}
// When an overridden method in Ruby calls super(), it is called this way
VALUE Render(VALUE vWindow) {
Sprite::Render(*(RenderWindow *)DATA_PTR(vWindow));
return Qnil;
}
};
VALUE g_cSprite;
void Sprite_free(void *p) { delete (Sprite *)p; }
VALUE Sprite_new(int argc, VALUE *argv, VALUE vClass) {
rSprite *ptr = new rSprite();
VALUE tData = Data_Wrap_Struct(vClass, 0, Sprite_free, ptr);
ptr->rInit(tData);
rb_obj_call_init(tData, argc, argv);
return tData;
}
static VALUE Sprite_initialize(int argc, VALUE *argv, VALUE vSelf) {
Sprite *pSelf;
Data_Get_Struct(vSelf, Sprite, pSelf);
if(argc == 0) {
// Nothing to initialize
} else if(argc >= 1 && argc <= 6 && IS(argv[0], g_cImage) && (argc < 6 || IS(argv[5], g_cColor))) {
pSelf->SetImage(*(Image *)DATA_PTR(argv[0]));
if(argc >= 2)
pSelf->SetLeft((float)NUM2DBL(argv[1]));
if(argc >= 3)
pSelf->SetTop((float)NUM2DBL(argv[2]));
if(argc >= 4) {
if(ISNUM(argv[3])) {
float f = (float)NUM2DBL(argv[3]);
pSelf->SetScale(f, f);
} else if(IS(argv[3], rb_cArray)) {
float x = (float)NUM2DBL(rb_ary_entry(argv[3], 0));
float y = (float)NUM2DBL(rb_ary_entry(argv[3], 1));
pSelf->SetScale(x, y);
}
}
if(argc >= 5)
pSelf->SetRotation((float)NUM2DBL(argv[4]));
if(argc >= 6)
pSelf->SetColor(*(Color *)DATA_PTR(argv[5]));
} else
rb_raise(rb_eTypeError, "wrong argument type(s)");
pSelf->SetRotationCenter(pSelf->GetWidth()/2, pSelf->GetHeight()/2);
return vSelf;
}
static VALUE Sprite_to_s(VALUE vSelf) {
// Get C++ object pointer from vSelf
Sprite *pSelf;
Data_Get_Struct(vSelf, Sprite, pSelf);
char szBuffer[256];
sprintf(szBuffer, "Left=%f, Top=%f, Width=%f, Height=%f, Scale=[%f,%f]", pSelf->GetLeft(), pSelf->GetTop(), pSelf->GetWidth(), pSelf->GetHeight(), pSelf->GetScaleX(), pSelf->GetScaleY());
return rb_str_new2(szBuffer);
}
static VALUE Sprite_set_image(VALUE vSelf, VALUE vImage) {
// Get C++ object pointer from vSelf
Sprite *pSelf;
Data_Get_Struct(vSelf, Sprite, pSelf);
if(!IS(vImage, g_cImage))
rb_raise(rb_eTypeError, "wrong argument type(s)");
pSelf->SetImage(*(Image *)DATA_PTR(vImage));
return Qnil;
}
static VALUE Sprite_set_subRect(VALUE vSelf, VALUE vRect) {
// Get C++ object pointer from vSelf
Sprite *pSelf;
Data_Get_Struct(vSelf, Sprite, pSelf);
if(!IS(vRect, g_cIntRect))
rb_raise(rb_eTypeError, "wrong argument type(s)");
pSelf->SetSubRect(*(IntRect *)DATA_PTR(vRect));
return Qnil;
}
static VALUE Sprite_get_image(VALUE vSelf) {
// Get C++ object pointer from vSelf
Sprite *pSelf;
Data_Get_Struct(vSelf, Sprite, pSelf);
DECLARE_PTR_VAR(Image, Image, (Image *)pSelf->GetImage());
return vImage;
}
static VALUE Sprite_get_subRect(VALUE vSelf) {
// Get C++ object pointer from vSelf
Sprite *pSelf;
Data_Get_Struct(vSelf, Sprite, pSelf);
DECLARE_OBJ_VAR(IntRect, Rect, pSelf->GetSubRect());
return vRect;
}
static VALUE Sprite_get_width(VALUE vSelf) {
// Get C++ object pointer from vSelf
Sprite *pSelf;
Data_Get_Struct(vSelf, Sprite, pSelf);
return rb_float_new(pSelf->GetWidth());
}
static VALUE Sprite_get_height(VALUE vSelf) {
// Get C++ object pointer from vSelf
Sprite *pSelf;
Data_Get_Struct(vSelf, Sprite, pSelf);
return rb_float_new(pSelf->GetHeight());
}
static VALUE Sprite_getPixel(VALUE vSelf, VALUE vX, VALUE vY) {
// Get C++ object pointer from vSelf
Sprite *pSelf;
Data_Get_Struct(vSelf, Sprite, pSelf);
DECLARE_OBJ_VAR(Color, Color, pSelf->GetPixel(NUM2INT(vX), NUM2INT(vY)));
return vColor;
}
static VALUE Sprite_set_right(VALUE vSelf, VALUE v) {
// Get C++ object pointer from vSelf
Sprite *pSelf;
Data_Get_Struct(vSelf, Sprite, pSelf);
pSelf->SetLeft((float)NUM2DBL(v) - pSelf->GetWidth());
return Qnil;
}
static VALUE Sprite_set_bottom(VALUE vSelf, VALUE v) {
// Get C++ object pointer from vSelf
Sprite *pSelf;
Data_Get_Struct(vSelf, Sprite, pSelf);
pSelf->SetTop((float)NUM2DBL(v) - pSelf->GetHeight());
return Qnil;
}
static VALUE Sprite_set_x(VALUE vSelf, VALUE v) {
// Get C++ object pointer from vSelf
Sprite *pSelf;
Data_Get_Struct(vSelf, Sprite, pSelf);
pSelf->SetLeft((float)NUM2DBL(v) - pSelf->GetWidth()*0.5f);
return Qnil;
}
static VALUE Sprite_set_y(VALUE vSelf, VALUE v) {
// Get C++ object pointer from vSelf
Sprite *pSelf;
Data_Get_Struct(vSelf, Sprite, pSelf);
pSelf->SetTop((float)NUM2DBL(v) - pSelf->GetHeight()*0.5f);
return Qnil;
}
static VALUE Sprite_get_right(VALUE vSelf) {
// Get C++ object pointer from vSelf
Sprite *pSelf;
Data_Get_Struct(vSelf, Sprite, pSelf);
return rb_float_new(pSelf->GetLeft() + pSelf->GetWidth());
}
static VALUE Sprite_get_bottom(VALUE vSelf) {
// Get C++ object pointer from vSelf
Sprite *pSelf;
Data_Get_Struct(vSelf, Sprite, pSelf);
return rb_float_new(pSelf->GetTop() + pSelf->GetHeight());
}
static VALUE Sprite_get_x(VALUE vSelf) {
// Get C++ object pointer from vSelf
Sprite *pSelf;
Data_Get_Struct(vSelf, Sprite, pSelf);
return rb_float_new(pSelf->GetLeft() + pSelf->GetWidth()*0.5f);
}
static VALUE Sprite_get_y(VALUE vSelf) {
// Get C++ object pointer from vSelf
Sprite *pSelf;
Data_Get_Struct(vSelf, Sprite, pSelf);
return rb_float_new(pSelf->GetTop() + pSelf->GetHeight()*0.5f);
}
static VALUE Sprite_get_radius(VALUE vSelf) {
// Get C++ object pointer from vSelf
Sprite *pSelf;
Data_Get_Struct(vSelf, Sprite, pSelf);
float w = pSelf->GetWidth() * 0.5f;
float h = pSelf->GetHeight() * 0.5f;
return rb_float_new(SQRTF(w*w + h*h));
}
static VALUE Sprite_flipX(VALUE vSelf, VALUE vBool) {
// Get C++ object pointer from vSelf
Sprite *pSelf;
Data_Get_Struct(vSelf, Sprite, pSelf);
pSelf->FlipX(RTEST(vBool));
return Qnil;
}
static VALUE Sprite_flipY(VALUE vSelf, VALUE vBool) {
// Get C++ object pointer from vSelf
Sprite *pSelf;
Data_Get_Struct(vSelf, Sprite, pSelf);
pSelf->FlipY(RTEST(vBool));
return Qnil;
}
static VALUE Sprite_distance(VALUE vSelf, VALUE vOther) {
if(!ISKO(vOther, g_cSprite))
rb_raise(rb_eTypeError, "wrong argument type(s)");
// Get C++ object pointer from vSelf
Sprite *pSelf;
Data_Get_Struct(vSelf, Sprite, pSelf);
Sprite *pOther;
Data_Get_Struct(vOther, Sprite, pOther);
// Get distance from center positions
float dx = (pSelf->GetLeft() + pSelf->GetWidth()*0.5f) -
(pOther->GetLeft() + pOther->GetWidth()*0.5f);
float dy = (pSelf->GetTop() + pSelf->GetHeight()*0.5f) -
(pOther->GetTop() + pOther->GetHeight()*0.5f);
return rb_float_new(SQRTF(dx*dx + dy*dy));
}
static VALUE Sprite_render(VALUE vSelf, VALUE vWindow) {
// Get C++ object pointer from vSelf
rSprite *pSelf;
Data_Get_Struct(vSelf, rSprite, pSelf);
return pSelf->Render(vWindow);
}
void Init_Sprite()
{
g_cSprite = rb_define_class_under(g_vModule, "Sprite", g_cDrawable);
DEFINE_CLASS_METHOD(Sprite, new, -1);
DEFINE_INSTANCE_METHOD(Sprite, initialize, -1);
DEFINE_RW(Sprite, right); // Right x position
DEFINE_RW(Sprite, bottom); // Bottom x position
DEFINE_RW(Sprite, x); // Center x postion
DEFINE_RW(Sprite, y); // Center y position
DEFINE_RW(Sprite, image);
DEFINE_RW(Sprite, subRect);
DEFINE_GETTER(Sprite, width);
DEFINE_GETTER2(Sprite, width, w);
DEFINE_GETTER(Sprite, height);
DEFINE_GETTER2(Sprite, height, h);
DEFINE_GETTER(Sprite, radius);
DEFINE_INSTANCE_METHOD(Sprite, to_s, 0);
DEFINE_INSTANCE_METHOD(Sprite, getPixel, 2);
DEFINE_INSTANCE_METHOD2(Sprite, getPixel, [], 2);
DEFINE_INSTANCE_METHOD(Sprite, distance, 1);
DEFINE_INSTANCE_METHOD2(Sprite, distance, getDistance, 1);
DEFINE_INSTANCE_METHOD(Sprite, flipX, 0);
DEFINE_INSTANCE_METHOD(Sprite, flipY, 0);
// Virtual method
DEFINE_INSTANCE_METHOD(Sprite, render, 1);
}

View File

@ -1,190 +0,0 @@
////////////////////////////////////////////////////////////
//
// RubySFML - Ruby extension for the SFML library
// Copyright (C) 2007 Sean O'Neil and Laurent Gomila
// (sean.p.oneil@gmail.com and laurent.gom@gmail.com)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
// you must not claim that you wrote the original software.
// If you use this software in a product, an acknowledgment
// in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
// and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
////////////////////////////////////////////////////////////
#include <SFML/Graphics.hpp>
#include "RubySFML.h"
using namespace sf;
// Wrapper for String that calls the Ruby version of virtual methods in case a Ruby class derives from this one
class rString : public String {
protected:
VALUE m_vSelf, m_vClass;
ID m_idRender;
bool m_bRender;
virtual void Render(const RenderWindow &Window) const {
// If this method is overridden in Ruby, call it
if(m_bRender) {
VALUE vWindow = Data_Wrap_Struct(g_cRenderWindow, 0, 0, (void*)&Window);
VALUE vRet = rb_funcall(m_vSelf, m_idRender, 1, vWindow);
} else // else call parent
String::Render(Window);
}
public:
// Damn constructors should be inherited from base class
rString(const std::string &Text="", const std::string &Font="", float Size=32.f) :String(Text, Font, Size) {}
// Call as soon as you get a Ruby VALUE pointing to this object
void rInit(VALUE vSelf) {
// Need these for rb_funcall
m_vSelf = vSelf;
m_vClass = CLASS_OF(m_vSelf);
// Initialize members for Render() virtual method
m_idRender = rb_intern("render");
m_bRender = rb_method_boundp(m_vClass, m_idRender, 0) == Qtrue;
}
// When an overridden method in Ruby calls super(), it is called this way
VALUE Render(VALUE vWindow) {
String::Render(*(RenderWindow *)DATA_PTR(vWindow));
return Qnil;
}
};
VALUE g_cString;
void String_free(void *p) { delete (String *)p; }
VALUE String_new(int argc, VALUE *argv, VALUE vClass) {
// For each version of this method, convert Ruby args to C++ types (applying default values)
rString *ptr = new rString();
VALUE tData = Data_Wrap_Struct(vClass, 0, String_free, ptr);
rb_obj_call_init(tData, argc, argv);
ptr->rInit(tData);
return tData;
}
static VALUE String_initialize(int argc, VALUE *argv, VALUE vSelf) {
// Get C++ object pointer from vSelf
String *pSelf;
Data_Get_Struct(vSelf, String, pSelf);
if(argc >= 0 && argc <= 3 &&
(argc < 1 || ISSTR(argv[0])) &&
(argc < 2 || ISSTR(argv[1])) &&
(argc < 3 || ISNUM(argv[2]))) {
if(argc >= 1)
pSelf->SetText(STR2CSTR(argv[0]));
if(argc >= 2)
pSelf->SetFont(STR2CSTR(argv[1]));
if(argc >= 3)
pSelf->SetSize((float)NUM2DBL(argv[2]));
} else
rb_raise(rb_eTypeError, "wrong argument type(s)");
return vSelf;
}
static VALUE String_preloadFont(int argc, VALUE *argv, VALUE vClass) {
if(argc >= 2 && argc <= 2)
String::PreloadFont(STR2CSTR(argv[0]), NUM2INT(argv[1]));
else
rb_raise(rb_eTypeError, "wrong argument type(s)");
return Qnil;
}
static VALUE String_set_text(VALUE vSelf, VALUE vText) {
// Get C++ object pointer from vSelf
String *pSelf;
Data_Get_Struct(vSelf, String, pSelf);
if(!ISSTR(vText))
rb_raise(rb_eTypeError, "wrong argument type(s)");
pSelf->SetText(STR2CSTR(vText));
return Qnil;
}
static VALUE String_set_font(VALUE vSelf, VALUE vFont) {
// Get C++ object pointer from vSelf
String *pSelf;
Data_Get_Struct(vSelf, String, pSelf);
if(!ISSTR(vFont))
rb_raise(rb_eTypeError, "wrong argument type(s)");
pSelf->SetText(STR2CSTR(vFont));
return Qnil;
}
static VALUE String_set_size(VALUE vSelf, VALUE vSize) {
// Get C++ object pointer from vSelf
String *pSelf;
Data_Get_Struct(vSelf, String, pSelf);
if(!ISNUM(vSize))
rb_raise(rb_eTypeError, "wrong argument type(s)");
pSelf->SetSize((float)NUM2DBL(vSize));
return Qnil;
}
static VALUE String_get_text(VALUE vSelf) {
// Get C++ object pointer from vSelf
String *pSelf;
Data_Get_Struct(vSelf, String, pSelf);
return rb_str_new2(pSelf->GetText().c_str());
}
static VALUE String_get_font(VALUE vSelf) {
// Get C++ object pointer from vSelf
String *pSelf;
Data_Get_Struct(vSelf, String, pSelf);
return rb_str_new2(pSelf->GetFont().c_str());
}
static VALUE String_get_size(VALUE vSelf) {
// Get C++ object pointer from vSelf
String *pSelf;
Data_Get_Struct(vSelf, String, pSelf);
return rb_float_new(pSelf->GetSize());
}
static VALUE String_getRect(VALUE vSelf) {
// Get C++ object pointer from vSelf
String *pSelf;
Data_Get_Struct(vSelf, String, pSelf);
DECLARE_OBJ_VAR(FloatRect, Rect, pSelf->GetRect());
return vRect;
}
static VALUE String_render(VALUE vSelf, VALUE vWindow) {
// Get C++ object pointer from vSelf
rString *pSelf;
Data_Get_Struct(vSelf, rString, pSelf);
return pSelf->Render(vWindow);
}
void Init_String()
{
g_cString = rb_define_class_under(g_vModule, "Text", g_cDrawable);
DEFINE_CLASS_METHOD(String, new, -1);
DEFINE_INSTANCE_METHOD(String, initialize, -1);
DEFINE_CLASS_METHOD(String, preloadFont, -1);
DEFINE_RW(String, text);
DEFINE_RW(String, font);
DEFINE_RW(String, size);
DEFINE_INSTANCE_METHOD(String, getRect, 0);
// Virtual method
DEFINE_INSTANCE_METHOD(String, render, 1);
}

View File

@ -1,114 +0,0 @@
////////////////////////////////////////////////////////////
//
// RubySFML - Ruby extension for the SFML library
// Copyright (C) 2007 Sean O'Neil and Laurent Gomila
// (sean.p.oneil@gmail.com and laurent.gom@gmail.com)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
// you must not claim that you wrote the original software.
// If you use this software in a product, an acknowledgment
// in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
// and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
////////////////////////////////////////////////////////////
#include <SFML/Window.hpp>
#include "RubySFML.h"
using namespace sf;
VALUE g_cVideoMode;
DECLARE_INT_RW(VideoMode, Width);
DECLARE_INT_RW(VideoMode, Height);
DECLARE_INT_RW(VideoMode, BitsPerPixel);
void VideoMode_free(void *p) { delete (VideoMode *)p; }
VALUE VideoMode_new(int argc, VALUE *argv, VALUE vClass) {
VideoMode *ptr = new VideoMode();
VALUE tData = Data_Wrap_Struct(vClass, 0, VideoMode_free, ptr);
rb_obj_call_init(tData, argc, argv);
return tData;
}
static VALUE VideoMode_initialize(int argc, VALUE *argv, VALUE vSelf) {
// Get C++ object pointer from vSelf
VideoMode *pSelf;
Data_Get_Struct(vSelf, VideoMode, pSelf);
if(argc == 0) {
// Nothing to initialize
} else if(argc >= 2 && argc <= 3 &&
ISNUM(argv[0]) &&
ISNUM(argv[1]) &&
(argc < 3 || ISNUM(argv[2]))) {
*pSelf = VideoMode(NUM2INT(argv[0]), NUM2INT(argv[1]), argc < 3 ? 32 : NUM2INT(argv[2]));
} else
rb_raise(rb_eTypeError, "wrong argument type(s)");
return vSelf;
}
static VALUE VideoMode_desktop(VALUE vClass)
{
DECLARE_OBJ_VAR(VideoMode, Desktop, VideoMode::GetDesktopMode());
return vDesktop;
}
// Ruby each iterator
static VALUE VideoMode_each(VALUE vClass)
{
int nLength = VideoMode::GetModesCount();
for(int i=0; i<nLength; i++) {
VideoMode mode = VideoMode::GetMode(i);
DECLARE_PTR_VAR(VideoMode, Element, &mode);
rb_yield(vElement);
}
return Qnil;
}
static VALUE VideoMode_isValid(VALUE vSelf)
{
// Get C++ object pointer from vSelf
VideoMode *pSelf;
Data_Get_Struct(vSelf, VideoMode, pSelf);
return pSelf->IsValid() ? Qtrue : Qfalse;
}
static VALUE VideoMode_to_s(VALUE vSelf)
{
// Get C++ object pointer from vSelf
VideoMode *pSelf;
Data_Get_Struct(vSelf, VideoMode, pSelf);
char szBuffer[256];
sprintf(szBuffer, "Width: %d, Height: %d, BPP: %d", pSelf->Width, pSelf->Height, pSelf->BitsPerPixel);
return rb_str_new2(szBuffer);
}
void Init_VideoMode()
{
g_cVideoMode = rb_define_class_under(g_vModule, "VideoMode", rb_cObject);
DEFINE_CLASS_METHOD(VideoMode, new, -1);
DEFINE_INSTANCE_METHOD(VideoMode, initialize, -1);
DEFINE_RW2(VideoMode, Width, width);
DEFINE_RW2(VideoMode, Width, w);
DEFINE_RW2(VideoMode, Height, height);
DEFINE_RW2(VideoMode, Height, h);
DEFINE_RW2(VideoMode, BitsPerPixel, bitsPerPixel);
DEFINE_RW2(VideoMode, BitsPerPixel, bpp);
DEFINE_CLASS_METHOD(VideoMode, each, 0);
DEFINE_CLASS_METHOD(VideoMode, desktop, 0);
DEFINE_INSTANCE_METHOD(VideoMode, isValid, 0);
DEFINE_INSTANCE_METHOD(VideoMode, to_s, 0);
}

View File

@ -1,93 +0,0 @@
////////////////////////////////////////////////////////////
//
// RubySFML - Ruby extension for the SFML library
// Copyright (C) 2007 Sean O'Neil and Laurent Gomila
// (sean.p.oneil@gmail.com and laurent.gom@gmail.com)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
// you must not claim that you wrote the original software.
// If you use this software in a product, an acknowledgment
// in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
// and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
////////////////////////////////////////////////////////////
#include <SFML/Graphics.hpp>
#include "RubySFML.h"
using namespace sf;
VALUE g_cView;
//DECLARE_DOUBLE_RW(View, Left);
//DECLARE_DOUBLE_RW(View, Top);
//DECLARE_DOUBLE_RW(View, Width);
//DECLARE_DOUBLE_RW(View, Height);
DECLARE_OBJ_RW(View, Rect, FloatRect);
DECLARE_DOUBLE_RW(View, Zoom);
void View_free(void *p) { delete (View *)p; }
VALUE View_new(int argc, VALUE *argv, VALUE vClass) {
View *ptr = new View();
VALUE tData = Data_Wrap_Struct(vClass, 0, View_free, ptr);
rb_obj_call_init(tData, argc, argv);
return tData;
}
static VALUE View_initialize(int argc, VALUE *argv, VALUE vSelf) {
// Get C++ object pointer from vSelf
View *pSelf;
Data_Get_Struct(vSelf, View, pSelf);
if(argc == 0) {
// Nothing to initialize
} else if(argc >= 1 && argc <= 2 &&
IS(argv[0], g_cFloatRect) &&
(argc < 2 || ISNUM(argv[1]))) {
pSelf->Rect = *(FloatRect *)DATA_PTR(argv[0]);
if(argc >= 2)
pSelf->Zoom = (float)NUM2DBL(argv[1]);
} else
rb_raise(rb_eTypeError, "wrong argument type(s)");
return vSelf;
}
static VALUE View_to_s(VALUE vSelf)
{
// Get C++ object pointer from vSelf
View *pSelf;
Data_Get_Struct(vSelf, View, pSelf);
char szBuffer[256];
sprintf(szBuffer, "Left=%f, Top=%f, Width=%f, Height=%f, Zoom=%f", pSelf->Rect.Left, pSelf->Rect.Top, pSelf->Rect.GetHeight(), pSelf->Rect.GetWidth(), pSelf->Zoom);
return rb_str_new2(szBuffer);
}
void Init_View()
{
g_cView = rb_define_class_under(g_vModule, "View", rb_cObject);
DEFINE_CLASS_METHOD(View, new, -1);
DEFINE_INSTANCE_METHOD(View, initialize, -1);
//DEFINE_RW2(View, Left, l);
//DEFINE_RW2(View, Top, top);
//DEFINE_RW2(View, Top, t);
//DEFINE_RW2(View, Width, width);
//DEFINE_RW2(View, Width, w);
//DEFINE_RW2(View, Height, height);
//DEFINE_RW2(View, Height, h);
DEFINE_RW2(View, Rect, rect);
DEFINE_RW2(View, Zoom, zoom);
DEFINE_INSTANCE_METHOD(View, to_s, 0);
}

View File

@ -1,181 +0,0 @@
////////////////////////////////////////////////////////////
//
// RubySFML - Ruby extension for the SFML library
// Copyright (C) 2007 Sean O'Neil and Laurent Gomila
// (sean.p.oneil@gmail.com and laurent.gom@gmail.com)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
// you must not claim that you wrote the original software.
// If you use this software in a product, an acknowledgment
// in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
// and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
////////////////////////////////////////////////////////////
#include <SFML/Window.hpp>
#include "RubySFML.h"
using namespace sf;
VALUE g_cWindow;
void Window_free(void *p) { delete (Window *)p; }
VALUE Window_new(int argc, VALUE *argv, VALUE vClass) {
Window *ptr = new Window();
VALUE tData = Data_Wrap_Struct(vClass, 0, Window_free, ptr);
rb_obj_call_init(tData, argc, argv);
return tData;
}
static VALUE Window_initialize(int argc, VALUE *argv, VALUE vSelf) {
// Get C++ object pointer from vSelf
Window *pSelf;
Data_Get_Struct(vSelf, Window, pSelf);
if(argc >= 2 && argc <= 3 &&
IS(argv[0], g_cVideoMode) &&
ISSTR(argv[1]) &&
(argc < 3 || true) &&
(argc < 4 || ISNUM(argv[3]))) {
pSelf->Create(*(VideoMode *)DATA_PTR(argv[0]), STR2CSTR(argv[1]),
argc < 3 ? (Style::Resize|Style::Close) : NUM2INT(argv[2]),
argc < 4 ? 0 : NUM2INT(argv[3]));
} else
rb_raise(rb_eTypeError, "wrong argument type(s)");
return vSelf;
}
static VALUE Window_to_s(VALUE vSelf) {
// Get C++ object pointer from vSelf
Window *pSelf;
Data_Get_Struct(vSelf, Window, pSelf);
char szBuffer[256];
sprintf(szBuffer, "Height: %d, Width: %d, Depth Bits: %d, Stencil Bits: %d", pSelf->GetWidth(), pSelf->GetHeight(), pSelf->GetDepthBits(), pSelf->GetStencilBits());
return rb_str_new2(szBuffer);
}
static VALUE Window_get_width(VALUE vSelf) {
// Get C++ object pointer from vSelf
Window *pSelf;
Data_Get_Struct(vSelf, Window, pSelf);
return INT2FIX(pSelf->GetWidth());
}
static VALUE Window_get_height(VALUE vSelf) {
// Get C++ object pointer from vSelf
Window *pSelf;
Data_Get_Struct(vSelf, Window, pSelf);
return INT2FIX(pSelf->GetHeight());
}
static VALUE Window_get_depthBits(VALUE vSelf) {
// Get C++ object pointer from vSelf
Window *pSelf;
Data_Get_Struct(vSelf, Window, pSelf);
return INT2FIX(pSelf->GetDepthBits());
}
static VALUE Window_get_stencilBits(VALUE vSelf) {
// Get C++ object pointer from vSelf
Window *pSelf;
Data_Get_Struct(vSelf, Window, pSelf);
return INT2FIX(pSelf->GetStencilBits());
}
static VALUE Window_get_frameTime(VALUE vSelf) {
// Get C++ object pointer from vSelf
Window *pSelf;
Data_Get_Struct(vSelf, Window, pSelf);
return rb_float_new(pSelf->GetFrameTime());
}
static VALUE Window_get_input(VALUE vSelf) {
// Get C++ object pointer from vSelf
Window *pSelf;
Data_Get_Struct(vSelf, Window, pSelf);
DECLARE_PTR_VAR(Input, Input, (Input *)&pSelf->GetInput());
return vInput;
}
static VALUE Window_getEvent(VALUE vSelf) {
// Get C++ object pointer from vSelf
Window *pSelf;
Data_Get_Struct(vSelf, Window, pSelf);
Event ePoll;
if(!pSelf->GetEvent(ePoll))
return Qnil;
DECLARE_OBJ_VAR(Event, Event, ePoll);
return vEvent;
}
static VALUE Window_useVerticalSync(VALUE vSelf, VALUE vEnabled) {
// Get C++ object pointer from vSelf
Window *pSelf;
Data_Get_Struct(vSelf, Window, pSelf);
pSelf->UseVerticalSync(RTEST(vEnabled) != 0);
return Qnil;
}
static VALUE Window_showMouseCursor(VALUE vSelf, VALUE vShow) {
// Get C++ object pointer from vSelf
Window *pSelf;
Data_Get_Struct(vSelf, Window, pSelf);
pSelf->ShowMouseCursor(RTEST(vShow) != 0);
return Qnil;
}
static VALUE Window_setFramerateLimit(VALUE vSelf, VALUE vLimit) {
// Get C++ object pointer from vSelf
Window *pSelf;
Data_Get_Struct(vSelf, Window, pSelf);
pSelf->SetFramerateLimit((unsigned int)NUM2INT(vLimit));
return Qnil;
}
static VALUE Window_display(VALUE vSelf) {
// Get C++ object pointer from vSelf
Window *pSelf;
Data_Get_Struct(vSelf, Window, pSelf);
pSelf->Display();
return Qnil;
}
static VALUE Window_setCurrent(VALUE vSelf) {
// Get C++ object pointer from vSelf
Window *pSelf;
Data_Get_Struct(vSelf, Window, pSelf);
return pSelf->SetCurrent() ? Qtrue : Qfalse;
}
void Init_Window()
{
g_cWindow = rb_define_class_under(g_vModule, "Window", rb_cObject);
DEFINE_CLASS_METHOD(Window, new, -1);
DEFINE_INSTANCE_METHOD(Window, initialize, -1);
DEFINE_GETTER(Window, width);
DEFINE_GETTER2(Window, width, w);
DEFINE_GETTER(Window, height);
DEFINE_GETTER2(Window, height, h);
DEFINE_GETTER(Window, input);
DEFINE_GETTER(Window, frameTime);
DEFINE_GETTER(Window, stencilBits);
DEFINE_GETTER(Window, depthBits);
DEFINE_INSTANCE_METHOD(Window, to_s, 0);
DEFINE_INSTANCE_METHOD(Window, getEvent, 0); // Don't use GETTER
DEFINE_INSTANCE_METHOD(Window, useVerticalSync, 1);
DEFINE_INSTANCE_METHOD(Window, showMouseCursor, 1);
DEFINE_INSTANCE_METHOD(Window, setFramerateLimit, 1);
DEFINE_INSTANCE_METHOD(Window, display, 0);
DEFINE_INSTANCE_METHOD(Window, setCurrent, 0); // Dont use SETTER
}

View File

@ -1,431 +0,0 @@
<html>
<title>RubySFML Documentation</title>
<style type="text/css">
h4,h5,ul {margin: 5px}
pre {background: #F0F0F0}
.comment {color: #8080FF}
.text {color: green}
.keyword {color: purple}
</style>
<head>
</head>
<body>
<h1>Introduction</h1>
<p>I apologize for how limited this documentation is, but as this extension is primarily a simple wrapper around SFML's C++ classes, I will rely on SFML's documentation to explain more detail about the classes and methods. This documentation is simply meant to explain which classes and methods are available in Ruby, as well as what changes have been made during the translation from C++ to Ruby.</p>
<p>As Ruby doesn't support native threading and has its own networking classes, I only exposed certain classes in the system, window, graphics, and audio libraries. For most exposed classes, the only changes I made were to make the methods start with a lower-case letter. For classes with simple Get/Set methods, I often drop the Get and Set to allow you to use sprite.left and sprite.left=. I also added a few to_i, to_f, and to_s methods where it seemed appropriate. Last but not least, I added an each iterator to VideoMode.</p>
<p>In addition to the C++ classes I exposed, I also added two helper classes in RubySFML.rb, one for rendering tiled sprites, and the other for dealing with sprites that use 2D velocity/accelerate calculations (TSprite and VSprite respectively).</p>
<h3>Tips for Windows Users</h3>
<p>For the Windows users out there, I apologize for not being compatible with the one-click installer, but it's being built with Visual Studio 6.0, which is ridiculously old and not compatible with any of the SFML libraries. There's a free version of Visual Studio 2005 available, and the Ruby source compiles very smoothly with it, so I can't think of a good excuse for the one-click installer to still be using 6.0.</p>
<p>On the bright side, you can distribute your game in a self-sufficient package by zipping it up with the bin and lib folders that come with the Windows binary version of this extension. Add a simple installer that creates a program group icon that runs "%install_path%\bin\ruby.exe %install_path%\my_game.rb", and you're all set. Oh yeah, OpenAL needs to be installed on any machine running this. Fortunately it is a very small/simple install, and it should be easy for you to either bundle it with your distribution or provide a link for your users to download it. All of this keeps your users from having to download/run the one-click installer, install all the necessary extensions, worry about compatibility issues, etc. It is likely that very few Windows users will ever play your game if you don't provide them everything they need to run it, so it's probably better this way.</p>
<p><b>Note:</b> This custom build of Ruby does have gems and zlib (which is required by gems), but no other extensions are installed. Feel free to install any other gems/extensions you need (native mswin32 gems compiled with Visual Studio 6.0 may not work). Keep in mind that many gems often have large doc, examples, and test folders. Deleting these unnecessary folders, along with the gem cache folder, can significantly shrink the size of the file you're distributing.</p>
<h3>RubySFML Sample Code</h3>
<pre>
<span class="comment"># Include the RubySFML extension</span>
<span class="keyword">require</span> "<span class="text">RubySFML</span>"
<span class="keyword">include</span> SFML
<span class="comment"># Create the main window</span>
mode = VideoMode.new 800, 600, 32
window = RenderWindow.new mode, "<span class="text">RubySFML Test</span>", false
<span class="comment"># Load a sprite to display</span>
image = Image.new "<span class="text">cute_image.jpg</span>"
sprite = Sprite.new image
<span class="comment"># Create a graphical string to display</span>
text = Text.new "<span class="text">Hello SFML</span>", "<span class="text">arial.ttf</span>", 50
<span class="comment"># Load a music and start playing it</span>
music = Music.new "<span class="text">nice_music.ogg</span>"
music.play
<span class="comment"># Start the game loop</span>
running = true
<span class="keyword">while</span> running
<span class="keyword">while</span> event = window.getEvent
running = false <span class="keyword">if</span> event.type == Event::Close
<span class="keyword">end</span>
<span class="comment"># Draw the sprite, then the text, and update the window</span>
window.draw sprite
window.draw text
window.display
<span class="keyword">end</span>
</pre>
<h3>RubySFML Modules</h3>
<ul>
<li><b><a href="#global">SFML</a</b> - Contains all SFML classes, modules, and global methods.</li>
<li><b>SFML::Event</b> - Contains constants for all of the SFML enumerated event types.</li>
<li><b>SFML::Key</b> - Contains constants for all of the SFML enumerated key codes.</li>
<li><b>SFML::Mouse</b> - Contains constants for all of the SFML enumerated mouse button codes.</li>
</ul>
<h3>RubySFML Classes</h3>
<ul>
<li><a href="#clock">SFML::Clock</a> - A system clock using high-performance timers where available</li>
<li><a href="#color">SFML::Color</a> - A simple RGBA color class</li>
<li><a href="#drawable">SFML::Drawable</a> - A pure virtual class representing 2D objects to use with RenderWindow</li>
<li><a href="#event">SFML::Event</a> - A class representing various system events (like keyboard and mouse events)</li>
<li><a href="#floatrect">SFML::FloatRect</a> - A simple rectangle made of 4 floats</li>
<li><a href="#image">SFML::Image</a> - A class for managing image files and textures</li>
<li><a href="#input">SFML::Input</a> - A class for checking the current state of various input devices</li>
<li><a href="#intrect">SFML::IntRect</a> - A simple rectangle made of 4 ints</li>
<li><a href="#music">SFML::Music</a> - A class for playing streaming music files</li>
<li><a href="#postfx">SFML::PostFX</a> - A class for mananging post-rendering shaders</li>
<li><a href="#renderwindow">SFML::RenderWindow</a> - A sub-class of Window which makes it easy to draw 2D sprites and text</li>
<li><a href="#sound">SFML::Sound</a> - A class for playing sound clips</li>
<li><a href="#soundbuffer">SFML::SoundBuffer</a> - A class for managing sound clips and sound files</li>
<li><a href="#soundbufferrecorder">SFML::SoundBufferRecorder</a> - A class for recording sound from a capture device, like a microphone</li>
<li><a href="#sprite">SFML::Sprite</a> - A class for managing/drawing 2D sprites</li>
<li><a href="#text">SFML::Text</a> - A class for managing/drawing 2D text (using ttf fonts)</li>
<li><a href="#videomode">SFML::VideoMode</a> - A class for managing video modes and window sizes</li>
<li><a href="#view">SFML::View</a> - A class for managing the 2D camera in RenderWindow</li>
<li><a href="#window">SFML::Window</a> - A class for creating/managing a suitable window for custom OpenGL rendering (also handles all input and events)</li>
</ul>
<h3>RubySFML Methods (by module/class)</h3>
<hr/>
<h4><a name="global">SFML</a></h4>
<ul>
<li><b>checkExtension(str)</b> - Returns true if the specifed OpenGL extension is supported.</li>
<li><b>getMaxTextureSize</b> - Returns the max texture size for the current display hardware.</li>
<li><b>getMaxTextureUnits</b> - Returns the max number of texture units for the current display hardware.</li>
</ul>
<hr/>
<h4><a name="clock">SFML::Clock</a></h4>
<ul>
<li><b>initialize()</b> - Default constructor</li>
<li><b>to_s</b> - Returns a formatted string representing this object (for debugging purposes)</li>
<li><b>reset</b> - Resets the clock</li>
<li><b>elapsedTime,to_f</b> - Returns the elapsed time since the last reset</li>
</ul>
<hr/>
<h4><a name="color">SFML::Color</a></h4>
<ul>
<li><b>initialize()</b> - Default constructor</li>
<li><b>initialize(n)</b> - Builds the color from a 32-bit unsigned RGBA value (0x12345678 is r=0x78, g=0x56, b=0x34, a=0x12)</li>
<li><b>initialize(r, g, b, a=255)</b> - Builds the color from its separate components</li>
<li><b>to_s</b> - Returns a formatted string representing this object (for debugging purposes)</li>
<li><b>r, g, b, a</b> - Returns the r, g, b, and a values (respectively)</li>
<li><b>r=, g=, b=, a=</b> - Sets the r, g, b, and a values (respectively)</li>
<li><b>toRGBA</b> - Returns the 4 components as a 32-bit unsigned value (0x12345678 is r=0x78, g=0x56, b=0x34, a=0x12)</li>
<li><b>to_i</b> - Alias for toRGBA</li>
</ul>
<hr/>
<h4><a name="drawable">SFML::Drawable</a></h4>
<ul>
<li><b>initialize(left=0, top=0, scale=1, rotation=0, color=Color.White)</b> - Initializes various members (scale can be a number or an array of two numbers)</li>
<li><b>to_s</b> - Returns a formatted string representing this object (for debugging purposes)</li>
<li><b>left, left=</b> - Gets/sets the left x position</li>
<li><b>top, top=</b> - Gets/sets the top y position</li>
<li><b>scale, scale=</b> - Gets/sets the scale of this object (get returns an array, set takes a num or an array</li>
<li><b>color, color=</b> - Gets/sets the base color of this object</li>
<li><b>rotation, rotation=</b> - Gets/sets the angle of rotation (in degrees)</li>
<li><b>upVector</b> - Gets this object's up vector (based on its angle of rotation)</li>
<li><b>rightVector</b> - Gets this object's right vector (based on its angle of rotation)</li>
<li><b>setRotationCenter(x, y)</b> - Sets the center of rotation for this object</li>
<li><b>move(x, y)</b> - Adds an offset to the left and top members</li>
<li><b>rotate(a)</b> - Adds an offset to the rotation member</li>
<li><b>render(window)</b> - (virtual) Override to add custom rendering code</li>
</ul>
<hr/>
<h4><a name="event">SFML::Event</a></h4>
<h5>For all event types</h5>
<ul>
<li><b>initialize</b> - Takes no parameters</li>
<li><b>to_s</b> - Returns a formatted string representing this object (for debugging purposes)</li>
<li><b>type</b> - Returns the event type</li>
</ul>
<h5>For the Event::TextEntered event type</h5>
<ul>
<li><b>char</b> - Returns the character typed (only for Event::TextEntered events)</li>
</ul>
<h5>For Event::KeyPressed and Event::KeyReleased event types</h5>
<ul>
<li><b>code</b> - Returns the character code (only for Event::KeyPressed and Event::KeyReleased events)</li>
<li><b>alt</b> - Returns true if an Alt key is down (only for Event::KeyPressed and Event::KeyReleased events)</li>
<li><b>control</b> - Returns true if a Ctrl key is down (only for Event::KeyPressed and Event::KeyReleased events)</li>
<li><b>shift</b> - Returns true if a Shift key is down (only for Event::KeyPressed and Event::KeyReleased events)</li>
</ul>
<h5>For mouse and joystick event types</h5>
<ul>
<li><b>delta</b> - Returns the scroll wheel offset (only for Event::MouseWheelMoved events)</li>
<li><b>buttons</b> - Returns the state of the mouse buttons (only for mouse events)</li>
<li><b>button</b> - Returns the state of the joystick buttons (only for joystick events)</li>
<li><b>x</b> - Returns the x position (for mouse and joystick events)</li>
<li><b>y</b> - Returns the y position (for mouse and joystick events)</li>
<li><b>z</b> - Returns the z position (for joystick events)</li>
</ul>
<h5>For the Event::Resize event type</h5>
<ul>
<li><b>width</b> - Returns the new window width (only for Event::Resize events)</li>
<li><b>height</b> - Returns the new window height (only for Event::Resize events)</li>
</ul>
<hr/>
<h4><a name="floatrect">SFML::FloatRect</a></h4>
<ul>
<li><b>initialize()</b> - Default constructor</li>
<li><b>initialize(left, top, right, bottom)</b> - Initialize the rectangle's members</li>
<li><b>to_s</b> - Returns a formatted string representing this object (for debugging purposes)</li>
<li><b>left, l</b> - Gets the left x position</li>
<li><b>left=, l=</b> - Sets the left x position</li>
<li><b>top, t</b> - Gets the top y position</li>
<li><b>top=, t=</b> - Sets the top y position</li>
<li><b>right, r</b> - Gets the right x position</li>
<li><b>right=, r=</b> - Sets the right x position</li>
<li><b>bottom, b</b> - Gets the bottom y position</li>
<li><b>bottom=, b=</b> - Sets the bottom y position</li>
<li><b>width, w</b> - Gets the rectangle width</li>
<li><b>height, h</b> - Gets the rectangle height</li>
<li><b>contains(x, y)</b> - Returns true if the x, y position is inside the rectangle</li>
<li><b>intersects(rect)</b> - Returns the intersection of two rectangles (nil if there is no intersection)</li>
</ul>
<hr/>
<h4><a name="image">SFML::Image</a></h4>
<ul>
<li><b>initialize</b> - Creates an empty image</li>
<li><b>initialize(image)</b> - Creates a copy of an image</li>
<li><b>initialize(path)</b> - Loads an image file using the specified path (raises a RuntimeError on failure)</li>
<li><b>initialize(w, h, c=Color.Black)</b> - Creates a blank image using the specified width, height, and color</li>
<li><b>to_s</b> - Returns a formatted string representing this object (for debugging purposes)</li>
<li><b>getValidTextureSize(s)</b> - (static) Returns the valid nearest texture size &gt;= s</li>
<li><b>width, w</b> - Gets the image width</li>
<li><b>height, h</b> - Gets the image height</li>
<li><b>smooth=, setSmooth(bool)</b> - Sets the OpenGL texture parameter to linear interpolation for true or nearest for false</li>
<li><b>repeat=, setRepeat(bool)</b> - Sets the OpenGL texture parameter to repeat for true or clip for false</li>
<li><b>loadFromFile(path)</b> - Loads a file image using the specified path</li>
<li><b>saveToFile(path)</b> - Saves the image to a file using the specified path</li>
<li><b>create(w, h, c=Color.Black)</b> - Creates an empty image with the specified width, height, and color</li>
<li><b>createMaskFromColor(color, a=0)</b> - Scans the image for pixels of the specified color, and sets the alpha value of those pixels to a.</li>
<li><b>resize(w, h, c=Color.Black)</b> - Resizes the image. If the image grows, sets new pixels to the specified color.</li>
<li><b>getPixel(x, y), [x,y]</b> - Returns the color of the specified pixel.</li>
<li><b>setPixel(x, y, c), [x,y]=</b> - Sets the color of the specified pixel to c.</li>
<li><b>update</b> - Updates the image in video memory (call after manually setting pixels).</li>
<li><b>bind</b> - Bind the image for rendering (call if you're using this image with raw OpenGL calls).</li>
<li><b>getTexCoords(rect)</b> - Converts an IntRect representing pixel positions to a FloatRect representing texture coordinates.</li>
</ul>
<hr/>
<h4><a name="input">SFML::Input</a></h4>
<ul>
<li><b>initialize</b> - Default constructor</li>
<li><b>isKeyDown(key)</b> - Returns true if the specified key is down</li>
<li><b>isMouseButtonDown(button)</b> - Returns true if the specified mouse button is down</li>
<li><b>isJoystickButtonDown(n, button)</b> - Returns true if the specified button on joystick n is down</li>
<li><b>getMouseX</b> - Returns the current x position of the mouse</li>
<li><b>getMouseY</b> - Returns the current y position of the mouse</li>
<li><b>getJoystickX(n)</b> - Returns the current x position of joystick n</li>
<li><b>getJoystickY(n)</b> - Returns the current y position of joystick n</li>
<li><b>getJoystickZ(n)</b> - Returns the current z position of joystick n</li>
</ul>
<hr/>
<h4><a name="intrect">SFML::IntRect</a></h4>
<ul>
<li><b>initialize()</b> - Default constructor</li>
<li><b>initialize(left, top, right, bottom)</b> - Initialize the rectangle's members</li>
<li><b>to_s</b> - Returns a formatted string representing this object (for debugging purposes)</li>
<li><b>left, l</b> - Gets the left x position</li>
<li><b>left=, l=</b> - Sets the left x position</li>
<li><b>top, t</b> - Gets the top y position</li>
<li><b>top=, t=</b> - Sets the top y position</li>
<li><b>right, r</b> - Gets the right x position</li>
<li><b>right=, r=</b> - Sets the right x position</li>
<li><b>bottom, b</b> - Gets the bottom y position</li>
<li><b>bottom=, b=</b> - Sets the bottom y position</li>
<li><b>width, w</b> - Gets the rectangle width</li>
<li><b>height, h</b> - Gets the rectangle height</li>
<li><b>contains(x, y)</b> - Returns true if the x, y position is inside the rectangle</li>
<li><b>intersects(rect)</b> - Returns the intersection of two rectangles (nil if there is no intersection)</li>
</ul>
<hr/>
<h4><a name="music">SFML::Music</a></h4>
<ul>
<li><b>initialize(bufSize=44100)</b> - Allows you to specify the buffer size.</li>
<li><b>initialize(path)</b> - Opens a music file using the specified path (raises a RuntimeError on failure).</li>
<li><b>to_s</b> - Returns a formatted string representing this object (for debugging purposes)</li>
<li><b>loop, loop=</b> - Gets/sets a boolean indicating whether the music should loop back to the beginning when it's finished playing.</li>
<li><b>duration</b> - Gets the duration of the sound stream.</li>
<li><b>channels</b> - Gets the number of channels in the sound stream (1=mono, 2=stereo).</li>
<li><b>sampleRate</b> - Gets the sample rate of the sound stream (44100 = CD quality).</li>
<li><b>status</b> - Gets the status of the music object (Sound::Stopped, Sound::Paused, Sound::Playing).</li>
<li><b>open(path)</b> - Opens a music file using the specified path (returns false on failure).</li>
<li><b>play</b> - Start the music.</li>
<li><b>stop</b> - Stop the music.</li>
</ul>
<hr/>
<h4><a name="postfx">SFML::PostFX</a></h4>
<ul>
<li>(Inherits all methods from <a href="#drawable">SFML::Drawable</a>)</li>
<li><b>initialize()</b> - Default constructor</li>
<li><b>initialize(path)</b> - Loads an effect file using the specified path.</li>
<li><b>initialize(postFX)</b> - Makes a copy of a PostFX object.</li>
<li><b>loadFromFile(path)</b> - Loads an effect file using the specified path (returns false on failure).</li>
<li><b>setParameter(name, x, y=nil, z=nil, w=nil)</b> - Sets the named parameter to an array of 1, 2, 3, or 4 floats.</li>
<li><b>setTexture(name, image)</b> - Sets a named texture parameter.</li>
</ul>
<hr/>
<h4><a name="renderwindow">SFML::RenderWindow</a></h4>
<ul>
<li><b>initialize(mode, title, style=Window::Resizable, antialias=0)</b> - Creates a 2D render window using the specified VideoMode, title, and style</li>
<li><b>to_s</b> - Returns a formatted string representing this object (for debugging purposes)</li>
<li><b>width, w</b> - Gets the width of the window</li>
<li><b>height, h</b> - Gets the height of the window</li>
<li><b>input</b> - Gets the <a href="#input">SFML::Input</a> object for this window</li>
<li><b>frameTime</b> - Gets the amount of time it took to render the previous frame</li>
<li><b>stencilBits</b> - Gets the number of bits used in the stencil buffer</li>
<li><b>depthBits</b> - Gets the number of bits used in the back buffer</li>
<li><b>view, view=</b> - Gets/sets the <a href="#view">SFML::View</a> into the 2D world (2D camera position)</li>
<li><b>backgroundColor=</b> - Sets the background color for the whole window</li>
<li><b>getEvent</b> - Returns the next event in the window's event queue (or nil if the queue is empty)</li>
<li><b>useVerticalSync(bool)</b> - Use to enable/disable vsync</li>
<li><b>showMouseCursor(bool)</b> - Use to show/hide the operating system's mouse cursor</li>
<li><b>display</b> - Call to swap the front and back buffers to display the frame</li>
<li><b>beginOpenGL</b> - Call to save the OpenGL state before you call raw OpenGL methods</li>
<li><b>endOpenGL</b> - Call to restore the OpenGL state after you call raw OpenGL methods</li>
<li><b>capture</b> - Take a screenshot and return it as an image</li>
<li><b>draw(obj)</b> - Call to draw any object derived from <a href="#drawable">SFML::Drawable</a></li>
<li><b>setFramerateLimit</b> - Set a fixed framerate (use 0 to disable it)</li>
</ul>
<hr/>
<h4><a name="sound">SFML::Sound</a></h4>
<ul>
<li><b>initialize(sound)</b> - Creates a copy of a Sound object</li>
<li><b>initialize(buffer=nil, loop=false, pitch=1, volume=100, x=0, y=0, z=0)</b> - Creates a Sound object using the specified sound buffer and other parameters</li>
<li><b>to_s</b> - Returns a formatted string representing this object (for debugging purposes)</li>
<li><b>buffer, buffer=</b> - Gets/sets this sound object's <a href="#soundbuffer">SFML::SoundBuffer</a>.</li>
<li><b>loop, loop=</b> - Gets/sets the loop flag for this sound object.</li>
<li><b>pitch, pitch=</b> - Gets/sets the pitch for this sound object.</li>
<li><b>volume, volume=</b> - Gets/sets the volume for this sound object.</li>
<li><b>position, position=</b> - Gets/sets the position for this sound object (using an array of 3 numbers).</li>
<li><b>status</b> - Gets the status of this sound object (Sound::Stopped, Sound::Paused, Sound::Playing).</li>
<li><b>playingOffset</b> - Gets the current playing position of the sound (in seconds).</li>
<li><b>play</b> - Starts playing the sound.</li>
<li><b>pause</b> - Pauses the sound.</li>
<li><b>stop</b> - Stops playing the sound.</li>
</ul>
<hr/>
<h4><a name="soundbuffer">SFML::SoundBuffer</a></h4>
<ul>
<li><b>initialize()</b> - Default constructor</li>
<li><b>initialize(soundBuffer)</b> - Creates a copy of a SoundBuffer object.</li>
<li><b>initialize(path)</b> - Loads a sound file using the specified path (raises a RuntimeError on failure).</li>
<li><b>to_s</b> - Returns a formatted string representing this object (for debugging purposes)</li>
<li><b>samples</b> - Gets the raw (binary) samples as a Ruby string.</li>
<li><b>samplesCount</b> - Gets the total number of samples (shorts) returned by the samples call.</li>
<li><b>samplesRate</b> - Gets the sample rate (or number of samples per second for each channel).</li>
<li><b>channels</b> - Gets the number of channels (1=mono, 2=stereo).</li>
<li><b>duration</b> - Gets the duration of the sound buffer (in seconds).</li>
<li><b>loadFromFile(path)</b> - Loads a sound file using the specified path (returns false on failure).</li>
<li><b>saveToFile(path)</b> - Saves a sound file to the specified path (returns false on failure).</li>
<li><b>loadFromMemory(samples, samplesCount, channels, sampleRate)</b> - Builds a SoundBuffer from raw (binary) samples.</li>
</ul>
<hr/>
<h4><a name="soundbufferrecorder">SFML::SoundBufferRecorder</a></h4>
<ul>
<li><b>initialize()</b> - Default constructor</li>
<li><b>canCapture</b> - (static) Returns true if the current system is capable of sound capture</li>
<li><b>start(sampleRate=44100)</b> - Starts the sound capture</li>
<li><b>stop</b> - Stops the sound capture</li>
<li><b>buffer</b> - Gets the SoundBuffer object containing the captured audio</li>
<li><b>sampleRate</b> - Gets the current sample rate</li>
</ul>
<hr/>
<h4><a name="sprite">SFML::Sprite</a></h4>
<ul>
<li>(Inherits all methods from <a href="#drawable">SFML::Drawable</a>)</li>
<li><b>initialize()</b> - Default constructor</li>
<li><b>initialize(image, left=0, top=0, scale=1, rotation=0, c=Color.White)</b> - Builds a Sprite object with the specified image and other options (scale can take one number or an array of two numbers)</li>
<li><b>to_s</b> - Returns a formatted string representing this object (for debugging purposes)</li>
<li><b>width, w</b> - Gets the sprite's width (affected by subRect and scale)</li>
<li><b>height, h</b> - Gets the sprite's height (affected by subRect and scale)</li>
<li><b>right, right=</b> - Gets/sets the right x position</li>
<li><b>bottom, bottom=</b> - Gets/sets the bottom y position</li>
<li><b>x, x=</b> - Gets/sets the center x position</li>
<li><b>y, y=</b> - Gets/sets the center y position</li>
<li><b>image, image=</b> - Gets/sets the image to use for this sprite</li>
<li><b>subRect, subRect=</b> - Gets/sets a rectangle within the image to use (generally used for tiled images)</li>
<li><b>getPixel(x,y), [x,y]</b> - Gets the color of a pixel within the sprite's subRect of the sprite's image ([0,0] would be the top-left pixel of the subRect)</li>
<li><b>radius</b> - Gets the bounding radius of the sprite (based on height and width)</li>
<li><b>distance(sprite)</b> - Gets the distance between the center positions of two sprites</li>
<li><b>render(window)</b> - (virtual) Override to add custom rendering code</li>
</ul>
<hr/>
<h4><a name="text">SFML::Text</a></h4>
<ul>
<li>(Inherits all methods from <a href="#drawable">SFML::Drawable</a>)</li>
<li><b>initialize(str="", font="", size=32)</b> - Initialize the Text object to the specified string, font, and font size.</li>
<li><b>preloadFont(font, size)</b> - (static) Call this to force the font to be loaded before the first time it gets rendered.</li>
<li><b>text, text=</b> - Gets/sets the current text string.</li>
<li><b>font, font=</b> - Gets/sets the current font.</li>
<li><b>size, size=</b> - Gets/sets the current font size.</li>
<li><b>getRect</b> - Gets the current screen rectangle.</li>
<li><b>render(window)</b> - (virtual) Override to add custom rendering code</li>
</ul>
<hr/>
<h4><a name="videomode">SFML::VideoMode</a></h4>
<ul>
<li><b>initialize()</b> - Default constructor</li>
<li><b>initialize(w, h, bpp=32)</b> - Creates a VideoMode with the specified width, height, and bits-per-pixel.</li>
<li><b>desktop</b> - (static) Returns the VideoMode for the current desktop.</li>
<li><b>each</b> - (static) Iterates through all valid full-screen video modes.</li>
<li><b>to_s</b> - Returns a formatted string representing this object (for debugging purposes)</li>
<li><b>width, w, width=, w=</b> - Gets/sets the current width of this VideoMode.</li>
<li><b>height, h, height=, h=</b> - Gets/sets the current height of this VideoMode.</li>
<li><b>bitsPerPixel, bpp, bitsPerPixel=, bpp=</b> - Gets/sets the current bits-per-pixel of this VideoMode.</li>
<li><b>isValid</b> - Returns true if the current VideoMode is a valid full-screen mode.</li>
</ul>
<hr/>
<h4><a name="view">SFML::View</a></h4>
<ul>
<li><b>initialize()</b> - Default constructor</li>
<li><b>initialize(left, top, width, height, zoom=1)</b> - Initializes all View members</li>
<li><b>to_s</b> - Returns a formatted string representing this object (for debugging purposes)</li>
<li><b>left, l, left=, l=</b> - Gets/sets the left x position for the view</li>
<li><b>top, t, top=, t=</b> - Gets/sets the top y position for the view</li>
<li><b>width, w, width=, w=</b> - Gets/sets the width for the view</li>
<li><b>height, h, height=, h=</b> - Gets/sets the height for the view</li>
<li><b>zoom, zoom=</b> - Gets/sets the zoom factor for the view</li>
</ul>
<hr/>
<h4><a name="window">SFML::Window</a></h4>
<ul>
<li><b>initialize(mode, title, style=Window::Resizable, antialias=0)</b> - Creates a window using the specified VideoMode, title, and style</li>
<li><b>to_s</b> - Returns a formatted string representing this object (for debugging purposes)</li>
<li><b>width, w</b> - Gets the width of the window</li>
<li><b>height, h</b> - Gets the height of the window</li>
<li><b>input</b> - Gets the <a href="#input">SFML::Input</a> object for this window</li>
<li><b>frameTime</b> - Gets the amount of time it took to render the previous frame</li>
<li><b>stencilBits</b> - Gets the number of bits used in the stencil buffer</li>
<li><b>depthBits</b> - Gets the number of bits used in the back buffer</li>
<li><b>getEvent</b> - Returns the next event in the window's event queue (or nil if the queue is empty)</li>
<li><b>useVerticalSync(bool)</b> - Use to enable/disable vsync</li>
<li><b>showMouseCursor(bool)</b> - Use to show/hide the operating system's mouse cursor</li>
<li><b>display</b> - Call to swap the front and back buffers to display the frame</li>
<li><b>setCurrent</b> - Sets this window as the current target for rendering</li>
<li><b>setFramerateLimit</b> - Set a fixed framerate (use 0 to disable it)</li>
</ul>
</body>
</html>

View File

@ -1,430 +0,0 @@
<html>
<title>RubySFML Documentation</title>
<style type="text/css">
h4,h5,ul {margin: 5px}
pre {background: #F0F0F0}
.comment {color: #8080FF}
.text {color: green}
.keyword {color: purple}
</style>
<head>
</head>
<body>
<h1>Introduction</h1>
<p>Cette documentation est assez courte, mais étant donné que cette extension n'est qu'une simple encapsulation des classes C++ de SFML, il est conseillé de se baser sur la documentation SFML pour obtenir plus de détails sur les classes et les fonctions. Cette documentation a simplement pour but de détailler les classes et fonctions qui sont présentes dans l'extension RubySFML, ainsi que de décrire les changements qui ont été effectués durant la traduction C++ vers Ruby.</p>
<p>Etant donné que Ruby ne supporte pas les threads et possède ses propres classes pour le réseau, seules certaines classes des modules système, fenêtrage, graphisme et audio sont exposées. Pour la plupart des classes, les seuls changements effectués ont été de faire débuter les noms des fonctions par une minuscule. Pour les classes possédant des accesseurs simples, ceux-ci ont souvent été abandonnés pour utiliser une syntaxe plus simple (par exemple sprite.left = ...). Quelques fonctions to_i, to_f et to_s ont étalement été ajoutées là où cela semblait pertinent. Enfin, un itérateur "each" a été ajouté à VideoMode.</p>
<p>En plus des classes C++ exposées, deux classes utiles ont également été ajoutées à RubySFML.rb, l'une pour afficher des sprites à base de tuiles, et l'autre pour gérer les sprites utilisant des calculs de vitesse / acceleration (respectivement TSprite et VSprite).</p>
<h3>Astuces pour les utilisateurs Windows</h3>
<p>Pour les utilisateurs Windows, nous regrettons de ne pas pouvoir être compatibles avec l'installeur "one-click", mais celui-ci est compilé avec Visual Studio 6.0, qui est ridiculeusement vieux et incompatible avec les bibliothèques SFML. Il existe une version gratuite de Visual Studio 2005, et les sources de Ruby compilent parfaitement avec celle-ci, on ne peut donc trouver aucune bonne excuse à l'installeur pour toujours utiliser Visual C++ 6.0.</p>
<p>La bonne nouvelle est que vous pouvez distribuer vos applications dans une archive qui se suffit à elle-même, en incluant les répertoires "bin" et "lib" qui sont inclus dans la version Windows de cette extension. Ajoutez un installeur simple qui crée une icône du menu démarrer exécutant "%install_path%\bin\ruby.exe %install_path%\my_game.rb", et tout sera parfait. Oh, encore une chose, OpenAL doit être installé pour exécuter les programmes utilisant RubySFML. Heureusement, il s'agit d'un installeur extrêmement petit et simple, et vous pourrez sans problème le fournir dans vos installations ou donner un lien pour le télécharger. Tout ceci évite à vos utilisateurs d'avoir à télécharger / exécuter l'installeur "one-click", installer toutes les extensions nécessaires, s'occuper des problèmes de compatibilité, etc. Il est probable que très peu d'utilisateurs Windows utilisent vos applications si vous ne leur fournissez pas tout ce dont ils ont besoin, c'est donc probablement mieux de cette manière.</p>
<p><b>Note :</b> cette compilation perso de Ruby ne contient pas gems et zlib (qui est recquis par gems), mais aucune autre extension n'est installée. N'hésitez pas à installer n'importe quelle autre gems / extension dont vous auriez besoin (les gems mswin32 compilés avec Visual Studio 6.0 ne fonctionneront probablement pas). Gardez en tête que beaucoup de gems ont une documentation conséquente, des exemples et des répertoires de test. Supprimer ces répertoires innutiles, ainsi que le répertoire cache des gems, peut réduire de manière significative la taille des fichiers que vous distribuez.</p>
<h3>Exemple de code RubySFML</h3>
<pre>
<span class="comment"># On inclut l'extension RubySFML</span>
<span class="keyword">require</span> "<span class="text">RubySFML</span>"
<span class="keyword">include</span> SFML
<span class="comment"># On crée la fenêtre principale</span>
mode = VideoMode.new 800, 600, 32
window = RenderWindow.new mode, "<span class="text">RubySFML Test</span>", false
<span class="comment"># On charge un sprite à afficher</span>
image = Image.new "<span class="text">cute_image.jpg</span>"
sprite = Sprite.new image
<span class="comment"># On crée une chaîne graphique à afficher</span>
text = Text.new "<span class="text">Hello SFML</span>", "<span class="text">arial.ttf</span>", 50
<span class="comment"># On charge une musique et on commence à la jouer</span>
music = Music.new "<span class="text">nice_music.ogg</span>"
music.play
<span class="comment"># On démarre la boucle principale</span>
running = true
<span class="keyword">while</span> running
<span class="keyword">while</span> event = window.getEvent
running = false <span class="keyword">if</span> event.type == Event::Close
<span class="keyword">end</span>
<span class="comment"># On dessine le sprite, le texte, puis on met à jour la fenêtre</span>
window.draw sprite
window.draw text
window.display
<span class="keyword">end</span>
</pre>
<h3>Modules RubySFML</h3>
<ul>
<li><b><a href="#global">SFML</a</b> - Contient toutes les classes, modules et fonctions globales SFML</li>
<li><b>SFML::Event</b> - Contient les constantes associées aux évènements SFML.</li>
<li><b>SFML::Key</b> - Contient les constantes pour tous les codes de touches clavier SFML.</li>
<li><b>SFML::Mouse</b> - Contient les constantes pour tous les codes de boutons souris SFML.</li>
</ul>
<h3>Classes RubySFML</h3>
<ul>
<li><a href="#clock">SFML::Clock</a> - Une horloge système utilisant les timers haute performance lorsqu'ils sont accessibles</li>
<li><a href="#color">SFML::Color</a> - Une classe de couleurs RGBA très simple</li>
<li><a href="#drawable">SFML::Drawable</a> - Une classe abstraite représentant les objets 2D utilisés dans une Renderwindow </li>
<li><a href="#event">SFML::Event</a> - Une classe représentant les différents évènements système (clavier, souris, etc.)</li>
<li><a href="#floatrect">SFML::FloatRect</a> - Un simple rectangle composé de 4 coordonnées flottantes</li>
<li><a href="#image">SFML::Image</a> - Une classe pour gérer les fichiers images et les textures</li>
<li><a href="#input">SFML::Input</a> - Une classe pour récupérer l'état des périphériques d'entrée (clavier, souris, joystick)</li>
<li><a href="#intrect">SFML::IntRect</a> - Un simple rectangle composé de 4 coordonnées entières</li>
<li><a href="#music">SFML::Music</a> - Une classe pour jouer des musiques en streaming</li>
<li><a href="#postfx">SFML::PostFX</a> - Une classe pour gérer les shaders post-rendu</li>
<li><a href="#renderwindow">SFML::RenderWindow</a> - Une sous-classe de Window wui permet d'afficher les objets 2D tels que sprites et texte</li>
<li><a href="#sound">SFML::Sound</a> - Une classe pour jouer des sons</li>
<li><a href="#soundbuffer">SFML::SoundBuffer</a> - Une classe pour stocker des échantillons audio</li>
<li><a href="#soundbufferrecorder">SFML::SoundBufferRecorder</a> - Une classe pour enregistrer du son à partir d'un périphérique de capture audio, comme un microphone</li>
<li><a href="#sprite">SFML::Sprite</a> - Une classe pour gérer et afficher des sprites 2D</li>
<li><a href="#text">SFML::Text</a> - Une classe pour gérer et afficher du texte 2D</li>
<li><a href="#videomode">SFML::VideoMode</a> - Une classe pour gérer les différents modes vidéo</li>
<li><a href="#view">SFML::View</a> - Une classe pour gérer la caméra 2D dans une RenderWindow</li>
<li><a href="#window">SFML::Window</a> - Une classe pour créer et gérer une fenêtre capable d'afficher un rendu OpenGL (gère également les entrées et les évènements)</li>
</ul>
<h3>Fonctions RubySFML (par module / classe)</h3>
<hr/>
<h4><a name="global">SFML</a></h4>
<ul>
<li><b>checkExtension(str)</b> - Renvoie vrai si l'extension OpenGL donnée est supportée.</li>
<li><b>getMaxTextureSize</b> - Renvoie la taille maximum de texture.</li>
<li><b>getMaxTextureUnits</b> - Renvoie le nombre maximum d'unités de textures utilisables.</li>
</ul>
<hr/>
<h4><a name="clock">SFML::Clock</a></h4>
<ul>
<li><b>initialize()</b> - Constructeur par défaut</li>
<li><b>to_s</b> - Renvoie une chaîne formatée décrivant l'objet (pour déboguage)</li>
<li><b>reset</b> - Remet à zéro l'horloge</li>
<li><b>elapsedTime,to_f</b> - Renvoie le nombre de secondes écoulées depuis le dernier appel à reset</li>
</ul>
<hr/>
<h4><a name="color">SFML::Color</a></h4>
<ul>
<li><b>initialize()</b> - Constructeur par défaut</li>
<li><b>initialize(n)</b> - Construit l'objet à partir d'une couleur 32 bits entière non signée (0x12345678 donne r=0x78, g=0x56, b=0x34, a=0x12)</li>
<li><b>initialize(r, g, b, a=255)</b> - Construit la couleur à partir de ses composantes</li>
<li><b>to_s</b> - Renvoie une chaîne formatée décrivant l'objet (pour déboguage)</li>
<li><b>r, g, b, a</b> - Renvoie les composantes r, g, b et a (respectivement)</li>
<li><b>r=, g=, b=, a=</b> - Affecte les composantes r, g, b et a (respectivement)</li>
<li><b>toRGBA</b> -Renvoie les 4 composantes de la couleur sous forme d'entier RGBA 32 bits non signé (0x12345678 donne r=0x78, g=0x56, b=0x34, a=0x12)</li>
<li><b>to_i</b> - Alias pour toRGBA</li>
</ul>
<hr/>
<h4><a name="drawable">SFML::Drawable</a></h4>
<ul>
<li><b>initialize(left=0, top=0, scale=1, rotation=0, color=Color.White)</b> - Initialise les différents membres (scale peut être un nombre ou un tableau de deux nombres)</li>
<li><b>to_s</b> - Renvoie une chaîne formatée décrivant l'objet (pour déboguage)</li>
<li><b>left, left=</b> - Modifie / récupère la position x de l'objet</li>
<li><b>top, top=</b> - Modifie / récupère la position y de l'objet</li>
<li><b>scale, scale=</b> - Modifie / récupère le facteur d'échelle de l'objet (renvoie un tableau, mais peut être initialisé à partir d'un tableau ou d'un seul nombre)</li>
<li><b>color, color=</b> - Modifie / récupère la couleur de l'objet</li>
<li><b>rotation, rotation=</b> - Modifie / récupère l'angle de rotation (en degrés)</li>
<li><b>upVector</b> - Récupère le vecteur "haut" de l'objet (basé sur son angle de rotation)</li>
<li><b>rightVector</b> - Récupère le vecteur "droite" de l'objet (basé sur son angle de rotation)</li>
<li><b>setRotationCenter(x, y)</b> - Change le centre de rotation de l'objet</li>
<li><b>move(x, y)</b> - Déplace l'objet horizontalement et verticalement</li>
<li><b>rotate(a)</b> - Fait tourner l'objet</li>
<li><b>render(window)</b> - (virtuelle) à redéfinir pour personnaliser le rendu de l'objet</li>
</ul>
<hr/>
<h4><a name="event">SFML::Event</a></h4>
<h5>Pour tous les types d'évènements</h5>
<ul>
<li><b>initialize</b> - Ne prend aucun paramètre</li>
<li><b>to_s</b> - Renvoie une chaîne formatée décrivant l'objet (pour déboguage)</li>
<li><b>type</b> - Renvoie le type de l'évènement</li>
</ul>
<h5>Pour les évènements de type Event::TextEntered</h5>
<ul>
<li><b>char</b> - Renvoie le caractère entré (uniquement pour les évènements Event::TextEntered)</li>
</ul>
<h5>Pour les évènements de type Event::KeyPressed et Event::KeyReleased</h5>
<ul>
<li><b>code</b> - Renvoie le code de la touche (uniquement pour les évènements Event::KeyPressed et Event::KeyReleased)</li>
<li><b>alt</b> - Renvoie vrai si la touche Alt est enfoncée (uniquement pour les évènements Event::KeyPressed et Event::KeyReleased)</li>
<li><b>control</b> - Renvoie vrai si la touche Control est enfoncée (uniquement pour les évènements Event::KeyPressed et Event::KeyReleased)</li>
<li><b>shift</b> - Renvoie vrai si la touche Shift est enfoncée (uniquement pour les évènements Event::KeyPressed et Event::KeyReleased)</li>
</ul>
<h5>Pour les évènements de type souris et joystick</h5>
<ul>
<li><b>delta</b> - Renvoie le déplacement de la molette souris (uniquement pour les évènements Event::MouseWheelMoved)</li>
<li><b>buttons</b> - Renvoie l'état des boutons de la souris (uniquement pour les évènements souris)</li>
<li><b>button</b> - Renvoie l'état des boutons du joystick (uniquement pour les évènements joystick)</li>
<li><b>x</b> - Renvoie la position x (uniquement pour les évènements souris et joystick)</li>
<li><b>y</b> - Renvoie la position y (uniquement pour les évènements souris et joystick)</li>
<li><b>z</b> - Renvoie la position z (uniquement pour les évènements joystick)</li>
</ul>
<h5>Pour les évènements de type Event::Resize</h5>
<ul>
<li><b>width</b> - Renvoie la nouvelle largeur de la fenêtre (uniquement pour les évènements Event::Resize)</li>
<li><b>height</b> - Renvoie la nouvelle hauteur de la fenêtre (uniquement pour les évènements Event::Resize)</li>
</ul>
<hr/>
<h4><a name="floatrect">SFML::FloatRect</a></h4>
<ul>
<li><b>initialize()</b> - Constructeur par défaut</li>
<li><b>initialize(left, top, right, bottom)</b> - Initialise les coordonnées du rectangle (gauche, haut, droite, bas)</li>
<li><b>to_s</b> - Renvoie une chaîne formatée décrivant l'objet (pour déboguage)</li>
<li><b>left, l</b> - Renvoie la position x gauche</li>
<li><b>left=, l=</b> - Modifie la position x gauche</li>
<li><b>top, t</b> - Renvoie la position y haute</li>
<li><b>top=, t=</b> - Modifie la position y haute</li>
<li><b>right, r</b> - Renvoie la position x droite</li>
<li><b>right=, r=</b> - Modifie la position x droite</li>
<li><b>bottom, b</b> - Renvoie la position y basse</li>
<li><b>bottom=, b=</b> - Modifie la position y basse</li>
<li><b>width, w</b> - Renvoie la largeur du rectangle</li>
<li><b>height, h</b> - Renvoie la hauteur du rectangle</li>
<li><b>contains(x, y)</b> - Renvoie vrai si le point (x, y) est à l'intérieur du rectangle</li>
<li><b>intersects(rect)</b> - Renvoie l'intersection de deux rectangles (nil s'il n'y a aucune intersection)</li>
</ul>
<hr/>
<h4><a name="image">SFML::Image</a></h4>
<ul>
<li><b>initialize</b> - Crée une image vide</li>
<li><b>initialize(image)</b> - Crée une copie d'une image</li>
<li><b>initialize(path)</b> - Charge une image à partir du fichier spécifié (lève une erreur RuntimeError si échoue)</li>
<li><b>initialize(w, h, c=Color.Black)</b> - Crée une image vide avec les dimensions et la couleur données</li>
<li><b>to_s</b> - Renvoie une chaîne formatée décrivant l'objet (pour déboguage)</li>
<li><b>getValidTextureSize(s)</b> - (statique) Renvoie la taille de texture valide la plus proche &gt;= s</li>
<li><b>width, w</b> - Renvoie la largeur de l'image</li>
<li><b>height, h</b> - Renvoie la hauteur de l'image</li>
<li><b>smooth=, setSmooth(bool)</b> - Modifie les paramètres de lissage de l'image (true pour activer, false pour désactiver)</li>
<li><b>repeat=, setRepeat(bool)</b> - Modifie les paramètres de répétition de l'image (true pour activer, false pour désactiver)</li>
<li><b>loadFromFile(path)</b> - Charge l'image à partir du fichier spécifié (renvoie faux si échoue)</li>
<li><b>saveToFile(path)</b> - Sauvegarde l'image dans le fichier spécifié</li>
<li><b>create(w, h, c=Color.Black)</b> - Crée une image vide avec les dimensions et la couleur données</li>
<li><b>createMaskFromColor(color, a=0)</b> - Remplace la valeur alpha (transparence) de tous les pixels ayant la couleur spécifiée, par la valeur de transparence donnée</li>
<li><b>resize(w, h, c=Color.Black)</b> - Redimensionne l'image. Si celle-ci est agrandie, les nouveaux pixels ont la couleur spécifiée</li>
<li><b>getPixel(x, y), [x,y]</b> - Renvoie la couleur du pixel (x, y)</li>
<li><b>setPixel(x, y, c), [x,y]=</b> - Change la couleur du pixel (x, y) par la couleur spécifiée</li>
<li><b>update</b> - Met à jour l'image en mémoire vidéo (à appeler après toute modification manuelle des pixels)</li>
<li><b>bind</b> - Utilise l'image pour le rendu (à appeler si vous utiliser l'image en tant que texture pour un rendu OpenGL)</li>
<li><b>getTexCoords(rect)</b> - Convertit des coordonnées entières en pixel, en coordonnées flottantes de texture</li>
</ul>
<hr/>
<h4><a name="input">SFML::Input</a></h4>
<ul>
<li><b>initialize</b> - Constructeur par défaut</li>
<li><b>isKeyDown(key)</b> - Renvoie vrai si la touche spécifiée est enfoncée</li>
<li><b>isMouseButtonDown(button)</b> - Renvoie vrai si le bouton souris spécifié est enfoncé</li>
<li><b>isJoystickButtonDown(n, button)</b> - Renvoie vrai si le bouton du joystick n spécifié est enfoncé</li>
<li><b>getMouseX</b> - Renvoie la position x actuelle de la souris</li>
<li><b>getMouseY</b> - Renvoie la position y actuelle de la souris</li>
<li><b>getJoystickX(n)</b> - Renvoie la position x actuelle du joystick n</li>
<li><b>getJoystickY(n)</b> - Renvoie la position y actuelle du joystick n</li>
<li><b>getJoystickZ(n)</b> - Renvoie la position z actuelle du joystick n</li>
</ul>
<hr/>
<h4><a name="intrect">SFML::IntRect</a></h4>
<ul>
<li><b>initialize()</b> - Constructeur par défaut</li>
<li><b>initialize(left, top, right, bottom)</b> - Initialise les coordonnées du rectangle (gauche, haut, droite, bas)</li>
<li><b>to_s</b> - Renvoie une chaîne formatée décrivant l'objet (pour déboguage)</li>
<li><b>left, l</b> - Renvoie la position x gauche</li>
<li><b>left=, l=</b> - Modifie la position x gauche</li>
<li><b>top, t</b> - Renvoie la position y haute</li>
<li><b>top=, t=</b> - Modifie la position y haute</li>
<li><b>right, r</b> - Renvoie la position x droite</li>
<li><b>right=, r=</b> - Modifie la position x droite</li>
<li><b>bottom, b</b> - Renvoie la position y basse</li>
<li><b>bottom=, b=</b> - Modifie la position y basse</li>
<li><b>width, w</b> - Renvoie la largeur du rectangle</li>
<li><b>height, h</b> - Renvoie la hauteur du rectangle</li>
<li><b>contains(x, y)</b> - Renvoie vrai si le point (x, y) est à l'intérieur du rectangle</li>
<li><b>intersects(rect)</b> - Renvoie l'intersection de deux rectangles (nil s'il n'y a aucune intersection)</li>
</ul>
<hr/>
<h4><a name="music">SFML::Music</a></h4>
<ul>
<li><b>initialize(bufSize=44100)</b> - Permet de spécifier la taille du tampon interne (à modifier si vous rencontrez des problèmes de performances ou de saccades)</li>
<li><b>initialize(path)</b> - Ouvre la musique à partir du fichier spécifié (lève une erreur RuntimeError si échoue).</li>
<li><b>to_s</b> - Renvoie une chaîne formatée décrivant l'objet (pour déboguage)</li>
<li><b>loop, loop=</b> - Renvoie / modifie un booléen indiquant si la musique doit boucler lorsqu'elle est terminée</li>
<li><b>duration</b> - Renvoie la durée totale de la musique, en secondes</li>
<li><b>channels</b> - Renvoie le nombre de canaux de la musique (1 = mono, 2 = stereo).</li>
<li><b>sampleRate</b> - Renvoie le taux d'échantillonnage de la musique (44100 = qualité CD).</li>
<li><b>status</b> - Renvoie l'état de lecture de la musique (Sound::Stopped, Sound::Paused, Sound::Playing).</li>
<li><b>open(path)</b> - Ouvre la musique à partir du fichier spécifié (renvoie faux si échoue).</li>
<li><b>play</b> - Démarre la lecture de la musique</li>
<li><b>stop</b> - Stoppe la lecture de la musique</li>
</ul>
<hr/>
<h4><a name="postfx">SFML::PostFX</a></h4>
<ul>
<li>(Hérite de toutes les fonctions de <a href="#drawable">SFML::Drawable</a>)</li>
<li><b>initialize()</b> - Constructeur par défaut</li>
<li><b>initialize(path)</b> - Charge le fichier effet spécifié</li>
<li><b>initialize(postFX)</b> - Crée une copie d'un objet PostFX</li>
<li><b>loadFromFile(path)</b> - Charge le fichier effet spécifié (renvoie faux si échoue)</li>
<li><b>setParameter(name, x, y=nil, z=nil, w=nil)</b> - Change la valeur d'un paramètre de l'effet</li>
<li><b>setTexture(name, image)</b> - Change une texture de l'effet</li>
</ul>
<hr/>
<h4><a name="renderwindow">SFML::RenderWindow</a></h4>
<ul>
<li><b>initialize(mode, title, style=Window::Resizable, antialias=0)</b> - Crée une fenêtre de rendu 2D en utilisant le mode vidéo, le titre et le style spécifiés</li>
<li><b>to_s</b> - Renvoie une chaîne formatée décrivant l'objet (pour déboguage)</li>
<li><b>width, w</b> - Renvoie la largeur de la fenêtre</li>
<li><b>height, h</b> - Renvoie la hauteur de la fenêtre</li>
<li><b>input</b> - Renvoie l'objet <a href="#input">SFML::Input</a> associé à cette fenêtre</li>
<li><b>frameTime</b> - Renvoie le temps écoulé depuis le dernier rafraîchissement</li>
<li><b>stencilBits</b> - Renvoie le nombre de bits alloués au tampon stencil</li>
<li><b>depthBits</b> - Renvoie le nombre de bits alloués au tampon de profondeur</li>
<li><b>view, view=</b> - Renvoie / modifie l'objet <a href="#view">SFML::View</a> courant (camera 2D)</li>
<li><b>backgroundColor=</b> - Modifie la couleur de fond de la fenêtre</li>
<li><b>getEvent</b> - Renvoie le prochain évènement en attente dans la file d'évènements (ou nil s'il n'y en a aucun)</li>
<li><b>useVerticalSync(bool)</b> - Active / désactive la synchronisation verticale</li>
<li><b>showMouseCursor(bool)</b> - Affiche / cache le curseur souris sur la fenêtre</li>
<li><b>display</b> - Met à jour la fenêtre à l'écran</li>
<li><b>beginOpenGL</b> - Sauvegarde les états OpenGL internes avant que vous ne placiez des appels OpenGL</li>
<li><b>endOpenGL</b> - Restaure les états OpenGL internes après que vous ayiez placé des appels OpenGL</li>
<li><b>capture</b> - Prend une capture d'écran et la renvoie sous forme d'image</li>
<li><b>draw(obj)</b> - Affiche dans la fenêtre tout objet dérivant de <a href="#drawable">SFML::Drawable</a></li>
<li><b>setFramerateLimit</b> - Fixe une limite de rafraîchissement, en images par seconde (0 pour désactiver)</li>
</ul>
<hr/>
<h4><a name="sound">SFML::Sound</a></h4>
<ul>
<li><b>initialize(sound)</b> - Crée une copie d'un objet son</li>
<li><b>initialize(buffer=nil, loop=false, pitch=1, volume=100, x=0, y=0, z=0)</b> - Crée un objet son en utilisant le tampon audio et les autres paramètres spécifiés</li>
<li><b>to_s</b> - Renvoie une chaîne formatée décrivant l'objet (pour déboguage)</li>
<li><b>buffer, buffer=</b> - Renvoie / modifie le <a href="#soundbuffer">SFML::SoundBuffer</a> de cet objet</li>
<li><b>loop, loop=</b> - Renvoie / modifie l'état de bouclage du son</li>
<li><b>pitch, pitch=</b> - Renvoie / modifie le pitch du son</li>
<li><b>volume, volume=</b> - Renvoie / modifie le volume du son</li>
<li><b>position, position=</b> -Renvoie / modifie la position du son (utilise un tableau de 3 valeurs)</li>
<li><b>status</b> - Renvoie l'état de lecture du son (Sound::Stopped, Sound::Paused, Sound::Playing).</li>
<li><b>playingOffset</b> - Renvoie la position de lecture courante du son (en secondes).</li>
<li><b>play</b> - Démarre la lecture du son</li>
<li><b>pause</b> - Met ne pause le son</li>
<li><b>stop</b> - Stoppe la lecture du son</li>
</ul>
<hr/>
<h4><a name="soundbuffer">SFML::SoundBuffer</a></h4>
<ul>
<li><b>initialize()</b> - Constructeur par défaut</li>
<li><b>initialize(soundBuffer)</b> - Crée une copie d'un objet SoundBuffer</li>
<li><b>initialize(path)</b> - Charge le tampon sonore à partir du fichier spécifié (lève une erreur RuntimeError si échoue).</li>
<li><b>to_s</b> - Renvoie une chaîne formatée décrivant l'objet (pour déboguage)</li>
<li><b>samples</b> - Renvoie les échantillons sonores bruts sous forme de chaîne Ruby</li>
<li><b>samplesCount</b> - Renvoie le nombre d'échantillons sonores du tampon</li>
<li><b>samplesRate</b> - Renvoie le taux d'échantillonnage (nombre d'échantillons par seconde pour chaque canal)</li>
<li><b>channels</b> - Renvoie le nombre de canaux (1 = mono, 2 = stereo)</li>
<li><b>duration</b> - Renvoie la durée du tampon sonore (en secondes)</li>
<li><b>loadFromFile(path)</b> - Charge le tampon sonore à partir du fichier spécifié (renvoie faux si échoue)</li>
<li><b>saveToFile(path)</b> - Sauvegarde le tampon sonore dans le fichier spécifié (renvoie faux si échoue)</li>
<li><b>loadFromMemory(samples, samplesCount, channels, sampleRate)</b> - Construit le tampon sonore à partir d'échantillons bruts en mémoire</li>
</ul>
<hr/>
<h4><a name="soundbufferrecorder">SFML::SoundBufferRecorder</a></h4>
<ul>
<li><b>initialize()</b> - Constructeur par défaut</li>
<li><b>canCapture</b> - (statique) Renvoie vrai si le système est capable d'effectuer les captures audio</li>
<li><b>start(sampleRate=44100)</b> - Démarre la capture audio</li>
<li><b>stop</b> - Stoppe la capture audio</li>
<li><b>buffer</b> - Renvoie l'objet SoundBuffer contenant le son capturé</li>
<li><b>sampleRate</b> - Renvoie le taux d'échantillonnage utilisé pour la capture</li>
</ul>
<hr/>
<h4><a name="sprite">SFML::Sprite</a></h4>
<ul>
<li>(Hérite de toutes les fonctions de <a href="#drawable">SFML::Drawable</a>)</li>
<li><b>initialize()</b> - Constructeur par défaut</li>
<li><b>initialize(image, left=0, top=0, scale=1, rotation=0, c=Color.White)</b> - Construit le sprite à partir de l'image et des autres paramètres donnés (le paramètre scale peut être un nombre simple ou un tableau de deux nombres)</li>
<li><b>to_s</b> - Renvoie une chaîne formatée décrivant l'objet (pour déboguage)</li>
<li><b>width, w</b> - Renvoie la largeur du sprite (affectée par subRect et scale)</li>
<li><b>height, h</b> - Renvoie la hauteur du sprite (affectée par subRect et scale)</li>
<li><b>right, right=</b> - Renvoie / modifie la position x droite du sprite</li>
<li><b>bottom, bottom=</b> - Renvoie / modifie la position y basse du sprite</li>
<li><b>x, x=</b> - Renvoie / modifie la position x centrale du sprite</li>
<li><b>y, y=</b> - Renvoie / modifie la position y centrale du sprite</li>
<li><b>image, image=</b> - Renvoie / modifie l'image utilisée par le sprite</li>
<li><b>subRect, subRect=</b> - Renvoie / modifie le sous-rectangle de l'image source utilisé pour le sprite</li>
<li><b>getPixel(x,y), [x,y]</b> - Renvoie la couleur d'un pixel du sprite relativement à son sous-rectangle ([0, 0] serait le pixel haut-gauche du sous-rectangle)</li>
<li><b>radius</b> - Renvoie le rayon du cercle englobant du sprite (basé sur sa hauteur et sa largeur)</li>
<li><b>distance(sprite)</b> - Renvoie la distance entre les centres de deux sprites</li>
<li><b>render(window)</b> - (virtuelle) A redéfinir pour effectuer un rendu personnalisé</li>
</ul>
<hr/>
<h4><a name="text">SFML::Text</a></h4>
<ul>
<li>(Hérite de toutes les fonctions de <a href="#drawable">SFML::Drawable</a>)</li>
<li><b>initialize(str="", font="", size=32)</b> - Initialise l'objet Text avec le texte, la police et la taille spécifiés</li>
<li><b>preloadFont(font, size)</b> - (statique) Force le chargement de la police avant sa première utilisation</li>
<li><b>text, text=</b> - Renvoie / modifie la chaîne à afficher</li>
<li><b>font, font=</b> - Renvoie / modifie la police de caractères à utiliser</li>
<li><b>size, size=</b> - Renvoie / modifie la taille du texte</li>
<li><b>getRect</b> - Renvoie le rectangle englobant de la chaîne graphique</li>
<li><b>render(window)</b> - (virtuelle) A redéfinir pour effectuer un rendu personnalisé</li>
</ul>
<hr/>
<h4><a name="videomode">SFML::VideoMode</a></h4>
<ul>
<li><b>initialize()</b> - Constructeur par défaut</li>
<li><b>initialize(w, h, bpp=32)</b> - Crée un mode vidéo avec les dimensions et la profondeur (bits par pixel) spécifiées</li>
<li><b>desktop</b> - (statique) Renvoie le mode vidéo actuel du bureau</li>
<li><b>each</b> - (statique) Itère sur tous les modes vidéo plein écran valides</li>
<li><b>to_s</b> - Renvoie une chaîne formatée décrivant l'objet (pour déboguage)</li>
<li><b>width, w, width=, w=</b> - Renvoie / modifie la largeur du mode vidéo</li>
<li><b>height, h, height=, h=</b> - Renvoie / modifie la hauteur du mode vidéo</li>
<li><b>bitsPerPixel, bpp, bitsPerPixel=, bpp=</b> - Renvoie / modifie la profondeur (bits par pixels) du mode vidéo</li>
<li><b>isValid</b> - Renvoie vrai si le mode est un mode plein écran valide</li>
</ul>
<hr/>
<h4><a name="view">SFML::View</a></h4>
<ul>
<li><b>initialize()</b> - Constructeur par défaut</li>
<li><b>initialize(left, top, width, height, zoom=1)</b> - Initialise la vue avec la position, taille et le zomm spécifiés</li>
<li><b>to_s</b> - Renvoie une chaîne formatée décrivant l'objet (pour déboguage)</li>
<li><b>left, l, left=, l=</b> - Renvoie / modifie la position x gauche de la vue</li>
<li><b>top, t, top=, t=</b> - Renvoie / modifie la position y haute de la vue</li>
<li><b>width, w, width=, w=</b> - Renvoie / modifie la largeur de la vue</li>
<li><b>height, h, height=, h=</b> - Renvoie / modifie la hauteur de la vue</li>
<li><b>zoom, zoom=</b> - Renvoie / modifie le facteur de zoom de la vue</li>
</ul>
<hr/>
<h4><a name="window">SFML::Window</a></h4>
<ul>
<li><b>initialize(mode, title, style=Window::Resizable, antialias=0)</b> - Crée une fenêtre en utilisant le mode vidéo, le titre et le style spécifiés</li>
<li><b>to_s</b> - Renvoie une chaîne formatée décrivant l'objet (pour déboguage)</li>
<li><b>width, w</b> - Renvoie la largeur de la fenêtre</li>
<li><b>height, h</b> - Renvoie la hauteur de la fenêtre</li>
<li><b>input</b> - Renvoie l'objet <a href="#input">SFML::Input</a> associé à cette fenêtre</li>
<li><b>frameTime</b> - Renvoie le temps écoulé depuis le dernier rafraîchissement</li>
<li><b>stencilBits</b> - Renvoie le nombre de bits alloués au tampon stencil</li>
<li><b>depthBits</b> - Renvoie le nombre de bits alloués au tampon de profondeur</li>
<li><b>getEvent</b> - Renvoie le prochain évènement en attente dans la file d'évènements (ou nil s'il n'y en a aucun)</li>
<li><b>useVerticalSync(bool)</b> - Active / désactive la synchronisation verticale</li>
<li><b>showMouseCursor(bool)</b> - Affiche / cache le curseur souris sur la fenêtre</li>
<li><b>display</b> - Met à jour la fenêtre à l'écran</li>
<li><b>setCurrent</b> - Rend la fenêtre courante active pour le rendu</li>
<li><b>setFramerateLimit</b> - Fixe une limite de rafraîchissement, en images par seconde (0 pour désactiver)</li>
</ul>
</body>
</html>

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -1 +0,0 @@
..\bin\ruby.exe SideScroller.rb

View File

@ -1,240 +0,0 @@
require 'RubySFML'
include SFML
module Tiles
Grass = 0
Earth = 1
end
# Collectible item.
class Gem2 < Sprite
def initialize(image, x, y)
super(image)
self.x = x
self.y = y
end
def update
self.rotation = 25 * Math.sin($clock.to_f*6)
end
end
class Player < VSprite
attr_reader :score
def initialize(image, w, h)
super(image, w, h)
@sb = SoundBuffer.new("media/Beep.wav")
@sound = Sound.new(@sb)
@score = 0
end
def update(window, map)
time = window.frameTime
input = window.input
# If there's no ground beneath my feet, increase speed downward
if !map.solid?(self.x, self.bottom)
@vy += 1
# If there is ground beneath my feet, and the user presses up,
# boost speed upwards to jump
elsif input.isKeyDown(Key::Up)
@vy = -20
end
super(1) # Update position based on velocity
# If we just moved down, see it we landed
if @vy > 0
if map.solid?(self.x, self.bottom)
@vy = 0
self.top -= self.top % 50
end
# If we just moved up, see if we hit our head
elsif @vy < 0
if map.solid?(self.x, self.top)
@vy = 0
self.top += 50 - self.top % 50
end
end
moved = false
if input.isKeyDown(Key::Left)
moved = true
self.x -= 10
# If we just moved left, see if we hit a wall
if map.solid?(self.left, self.y)
self.left += 50 - self.left % 50
end
end
if input.isKeyDown(Key::Right)
moved = true
self.x += 10
# If we just moved right, see if we hit a wall
if map.solid?(self.right, self.y)
self.left -= self.left % 50
end
end
if @vy < 0
@tx = 3
elsif moved
@tx = (@tx + 1) % 3
else
@tx = 0
end
# Same as in the tutorial game.
map.gems.reject! do |c|
if (c.x - self.x).abs < 50 and (c.y - self.y).abs < 50
@sound.play
@score += 10
true
else
false
end
end
end
end
# Map class holds and draws tiles and gems.
class Map < Drawable
attr_reader :width, :height, :gems
def initialize(filename, player)
@start = Time.now
@tileset_image = Image.new("media/Tileset.png")
@tileset = TSprite.new(@tileset_image, 50, 50)
@gem_image = Image.new("media/Gem.png")
@gems = []
@exit_image = Image.new("media/Star.png")
@exit = TSprite.new(@exit_image, 25, 25)
lines = File.readlines(filename).map { |line| line.chop }
@height = lines.size
@width = lines[0].size
@tiles = Array.new(@width) do |x|
Array.new(@height) do |y|
case lines[y][x, 1]
when '"' then Tiles::Grass
when '#' then Tiles::Earth
when 'S' then player.x, player.y = x*50, y*50; nil
when 'E' then @exit.left, @exit.top = x*50+25, y*50+25; nil
when 'x' then @gems << Gem2.new(@gem_image, x * 50 + 25, y * 50 + 25); nil
else nil
end
end
end
end
def done?(player)
player.x.to_i/50 == @exit.x.to_i/50 and player.y.to_i/50 == @exit.y.to_i/50
end
def render(window)
# Very primitive drawing function:
# Draws all the tiles, some off-screen, some on-screen.
@height.times do |y|
@width.times do |x|
tile = @tiles[x][y]
if tile
@tileset.tx = tile
@tileset.left = x * 50
@tileset.top = y * 50
window.draw(@tileset) if
@tileset.right > window.view.left and
@tileset.left < window.view.right and
@tileset.bottom > window.view.top and
@tileset.top < window.view.bottom
end
end
end
@gems.each { |c|
c.update
window.draw(c) if
c.right > window.view.left and
c.left < window.view.right and
c.bottom > window.view.top and
c.top < window.view.bottom
}
window.draw(@exit)
end
# Solid at a given pixel position?
def solid?(x, y)
x < 0 or y < 0 or x >= @width*50 or y >= @height*50 or @tiles[x / 50][y / 50]
end
end
$clock = Clock.new
mode = VideoMode.new(640, 480, 32)
win = RenderWindow.new(mode, "RubySFML Test", 0)
view = View.new(FloatRect.new(0, 0, 640, 480))
win.showMouseCursor(false)
win.useVerticalSync(true)
sky_image = Image.new("media/Space.png")
sky = Sprite.new(sky_image)
player_image = Image.new("media/CptnRuby.png")
player = Player.new(player_image, 50, 50)
levels = Dir["media/Level*.txt"].sort
level = 1
level_start = Time.now
map = Map.new(levels.shift, player)
# Simple game loop
done = false
game_over = false
while !done
if map.done?(player)
if levels.empty?
game_over = true
else
level += 1
level_start = Time.now
map = Map.new(levels.shift, player)
end
end
while e = win.getEvent()
done = true if e.type == Event::Closed or
(e.type == Event::KeyReleased and e.code == Key::Escape)
end
player.update(win, map)
left = player.x - 640/2
left = 0 if left < 0
left = map.width*50-640 if left > map.width*50-640
top = player.y - 480/2
top = 0 if top < 0
top = map.height*50-480 if top > map.height*50-480
view.rect = FloatRect.new(left, top, left+640, top+480)
win.setView(view)
sky.left = view.rect.left
sky.top = view.rect.top
win.draw(sky)
win.draw(map)
win.draw(player)
score = Text.new("Score: #{player.score}", "", 20)
score.left, score.top = sky.left, sky.top
win.draw(score)
if game_over
text = Text.new("Game Over!", "", 60)
text.left, text.top = sky.left+200, sky.top+200
win.draw(text)
elsif Time.now - level_start < 3
text = Text.new("Level #{level}!", "", 60)
text.left, text.top = sky.left+200, sky.top+200
win.draw(text)
text = Text.new("(Collect the gems and find the exit)", "", 25)
text.left, text.top = sky.left+125, sky.top+260
win.draw(text)
end
win.display()
sleep(0.01)
end

View File

@ -1 +0,0 @@
..\bin\ruby.exe tetris.rb

View File

@ -1 +0,0 @@
..\bin\ruby.exe Tutorial.rb

View File

@ -1,102 +0,0 @@
require 'RubySFML'
include SFML
TURN = 180
THRUST = 200
class Player < VSprite
attr_reader :score
def initialize(image)
super(image, image.w, image.h)
@sb = SoundBuffer.new("media/Beep.wav")
@beep = Sound.new(@sb)
@score = 0
end
def warp(x, y)
self.x = x
self.y = y
end
def turn_left(time) super(TURN*time); end
def turn_right(time) super(TURN*time); end
def accelerate(time) super(upVector, THRUST*time); end
def update(time)
super(time)
self.x %= 640
self.y %= 480
scale_speed(1.0 - 0.5*time)
end
def collect(stars)
stars.reject! { |star|
if distance(star) < 35 then
@score += 10
@beep.play
true
else
false
end
}
end
end
class Star < TSprite
def initialize(image)
super(image, image.h, image.h)
self.color = Color.new(rand(255 - 40) + 40, rand(255 - 40) + 40, rand(255 - 40) + 40, 255)
self.x = rand * 640
self.y = rand * 480
self.subRect = IntRect.new(0, 0, image.h, image.h)
@last_change = $clock.to_f
end
def update(time)
if $clock.to_f - @last_change >= 0.1 # Change every 10th of a second
@tx = (@tx+1) % 10
@last_change = $clock.to_f
end
end
end
$clock = Clock.new
mode = VideoMode.new(640, 480, 32)
win = RenderWindow.new(mode, "RubySFML Test", Window::Fullscreen)
win.showMouseCursor(false)
win.useVerticalSync(true)
background_image = Image.new("media/Space.png")
player_image = Image.new("media/Starfighter.png")
star_image = Image.new("media/Star.png")
background = Sprite.new(background_image)
player_image.createMaskFromColor(Color.new(255, 0, 255, 255))
player = Player.new(player_image)
player.warp(320, 240)
stars = []
10.times { stars << Star.new(star_image) }
# Simple game loop
done = false
while !done
while e = win.getEvent()
done = true if e.type == Event::Closed or
(e.type == Event::KeyReleased and e.code == Key::Escape)
end
time = win.frameTime
input = win.input
player.turn_left(time) if input.isKeyDown(Key::Left)
player.turn_right(time) if input.isKeyDown(Key::Right)
player.accelerate(time) if input.isKeyDown(Key::Up)
player.update(time)
player.collect(stars)
stars << Star.new(star_image) if rand(100) < 1 and stars.size < 10
stars.each {|star| star.update(time) }
win.draw(background)
stars.each {|star| win.draw(star) }
win.draw(player)
win.draw(Text.new("Score: #{player.score}", "", 20))
win.display()
end

View File

@ -1 +0,0 @@
..\bin\ruby.exe fps.rb

View File

@ -1,313 +0,0 @@
require 'RubySFML'
include SFML
require 'gl'
include Gl
require 'glu'
include Glu
class Array
def magnitude
return Math::sqrt(self[0]**2 + self[1]**2 + self[2]**2)
end
def normalize
mag = self.magnitude
return [self[0]/mag, self[1]/mag, self[2]/mag]
end
def normalize!
mag = self.magnitude
self[0] /= mag
self[1] /= mag
self[2] /= mag
end
def vec(pos)
return [pos[0]-self[0], pos[1]-self[1], pos[2]-self[2]]
end
def dot(vec)
return self[0]*vec[0] + self[1]*vec[1] + self[2]*vec[2]
end
def cross(vec)
return [
self[1]*vec[2] - self[2]*vec[1],
self[2]*vec[0] - self[0]*vec[2],
self[0]*vec[1] - self[1]*vec[0]
]
end
end
class Player
attr_accessor :pos, :view, :score
def initialize(x, y)
@score = 0
@pos = [x+0.5, 10, y+0.5]
@view = [0, 0, -1]
end
def turn_left(time)
angle = -2.0 * time
@view[0], @view[2] = @view[0]*Math::cos(angle) - @view[2]*Math::sin(angle), @view[0]*Math::sin(angle) + @view[2]*Math::cos(angle)
@view.normalize!
end
def turn_right(time)
angle = 2.0 * time
@view[0], @view[2] = @view[0]*Math::cos(angle) - @view[2]*Math::sin(angle), @view[0]*Math::sin(angle) + @view[2]*Math::cos(angle)
@view.normalize!
end
def move_right(time)
angle = 0.5*Math::PI
right = [@view[0]*Math::cos(angle) - @view[2]*Math::sin(angle), 0, @view[0]*Math::sin(angle) + @view[2]*Math::cos(angle)]
d = 5*time
@pos = [@pos[0]+right[0]*d, @pos[1], @pos[2]+right[2]*d]
end
def move_left(time)
angle = 0.5*Math::PI
right = [@view[0]*Math::cos(angle) - @view[2]*Math::sin(angle), 0, @view[0]*Math::sin(angle) + @view[2]*Math::cos(angle)]
d = 5*time
@pos = [@pos[0]-right[0]*d, @pos[1], @pos[2]-right[2]*d]
end
def move_forward(time)
d = 5*time
@pos = [@pos[0]+@view[0]*d, @pos[1], @pos[2]+@view[2]*d]
end
def move_backward(time)
d = 5*time
@pos = [@pos[0]-@view[0]*d, @pos[1], @pos[2]-@view[2]*d]
end
def init_view
glLoadIdentity()
gluLookAt(@pos[0], @pos[1], @pos[2], @pos[0]+@view[0], @pos[1]+@view[1], @pos[2]+@view[2], 0, 1, 0)
end
def update(win, map)
pos = @pos
input, time = win.input, win.frameTime
turn_left(time) if input.isKeyDown(Key::Left)
turn_right(time) if input.isKeyDown(Key::Right)
move_forward(time) if input.isKeyDown(Key::W)
move_backward(time) if input.isKeyDown(Key::S)
move_left(time) if input.isKeyDown(Key::A)
move_right(time) if input.isKeyDown(Key::D)
@pos = pos if map.solid?(@pos[0], @pos[2])
end
end
class Block
attr_accessor :pos
def initialize(x, y)
@pos = [x.to_i+0.5, 0, y.to_i+0.5]
end
def draw()
glPushMatrix()
glTranslatef(@pos[0], @pos[1], @pos[2])
glColor4f(1, 0, 0, 1)
glBegin(GL_QUADS)
# Facing +z
glNormal3d(0, 0, 1)
glVertex3f(0.5, 0.5, 0.5)
glVertex3f(-0.5, 0.5, 0.5)
glVertex3f(-0.5, -0.5, 0.5)
glVertex3f(0.5, -0.5, 0.5)
# Facing -z
glNormal3d(0, 0, -1)
glVertex3f(-0.5, 0.5, -0.5)
glVertex3f(0.5, 0.5, -0.5)
glVertex3f(0.5, -0.5, -0.5)
glVertex3f(-0.5, -0.5, -0.5)
# Facing +x
glNormal3d(1, 0, 0)
glVertex3f(0.5, 0.5, 0.5)
glVertex3f(0.5, -0.5, 0.5)
glVertex3f(0.5, -0.5, -0.5)
glVertex3f(0.5, 0.5, -0.5)
# Facing -x
glNormal3d(-1, 0, 0)
glVertex3f(-0.5, 0.5, 0.5)
glVertex3f(-0.5, 0.5, -0.5)
glVertex3f(-0.5, -0.5, -0.5)
glVertex3f(-0.5, -0.5, 0.5)
glEnd()
glPopMatrix()
end
end
class Billboard
attr_accessor :pos
def initialize(x, y, size=0.25)
@size = size
@pos = [x.to_i+0.5, 0, y.to_i+0.5]
end
def draw(camera)
normal = @pos.vec(camera.pos).normalize
up = [0, 1, 0]
right = up.cross(normal).normalize
glPushMatrix()
glTranslatef(@pos[0], @pos[1], @pos[2])
glColor4f(1, 1, 1, 1)
glBegin(GL_QUADS)
# Facing camera
glNormal3d(normal[0], normal[1], normal[2])
glTexCoord2f(1, 0)
glVertex3f((right[0]+up[0])*@size, (right[1]+up[1])*@size, (right[2]+up[2])*@size)
glTexCoord2f(0, 0)
glVertex3f((-right[0]+up[0])*@size, (-right[1]+up[1])*@size, (-right[2]+up[2])*@size)
glTexCoord2f(0, 1)
glVertex3f(-(right[0]+up[0])*@size, -(right[1]+up[1])*@size, -(right[2]+up[2])*@size)
glTexCoord2f(1, 1)
glVertex3f((right[0]-up[0])*@size, (right[1]-up[1])*@size, (right[2]-up[2])*@size)
glEnd()
glPopMatrix()
end
end
# Map class holds and draws tiles and gems.
class Map
attr_reader :width, :height, :blocks, :gems
def initialize(filename, player)
@start = Time.now
@sb = SoundBuffer.new("media/Beep.wav")
@sound = Sound.new(@sb)
@gem_image = Image.new("media/Gem.png")
@exit_image = Image.new("media/Star.png")
@exit_image.resize(25, 25, Color.Black)
@exit = nil
@blocks = []
@gems = []
lines = File.readlines(filename).map { |line| line.chop }
@height = lines.size
@width = lines[0].size
@tiles = Array.new(@width) do |x|
Array.new(@height) do |y|
case lines[y][x, 1]
when '"', '#' then @blocks << Block.new(x, y); @blocks[-1]
when 'S' then player.pos = [x+0.5, 0, y+0.5]; nil
when 'E' then @exit = Billboard.new(x, y); nil
when 'x' then @gems << Billboard.new(x, y); nil
else nil
end
end
end
end
def draw(player)
@blocks.each {|b| b.draw()}
glEnable(GL_TEXTURE_2D)
@gem_image.bind
@gems.each {|g| g.draw(player)}
@exit_image.bind
@exit.draw(player)
glDisable(GL_TEXTURE_2D)
end
def exit?(player)
player.pos[0].to_i == @exit.pos[0].to_i and player.pos[2].to_i == @exit.pos[2].to_i
end
# Solid at a given pixel position?
def solid?(x, y)
y < 0 or x < 0 or x >= @width or y >= @width or @tiles[x.to_i][y.to_i]
end
def collect_gems(player)
@gems.reject! {|g|
if player.pos.vec(g.pos).magnitude <= 0.5
@sound.play
player.score += 10
true
else
false
end
}
end
end
$clock = Clock.new
mode = VideoMode.new(640, 480, 32)
win = RenderWindow.new(mode, "RubySFML Test", 0)
win.showMouseCursor(false)
win.useVerticalSync(true)
sky_image = Image.new("media/Space.png")
player = Player.new(0, 5)
levels = Dir["media/Level*.txt"].sort
level = 1
level_start = Time.now
map = Map.new(levels.shift, player)
# Simple game loop
done = false
while !done
if map.exit?(player)
if levels.empty?
game_over = true
else
level += 1
level_start = Time.now
map = Map.new(levels.shift, player)
end
end
while e = win.getEvent()
done = true if e.type == Event::Closed or
(e.type == Event::KeyReleased and e.code == Key::Escape)
end
time = win.frameTime
player.update(win, map)
#win.beginOpenGL()
glEnable(GL_DEPTH_TEST)
glEnable(GL_CULL_FACE)
glEnable(GL_BLEND)
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
glMatrixMode(GL_PROJECTION)
glPushMatrix()
glLoadIdentity()
gluPerspective(45.0, 640.0/480.0, 0.1, 100.0)
glMatrixMode(GL_MODELVIEW)
glPushMatrix()
player.init_view()
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT)
glEnable(GL_COLOR_MATERIAL)
glEnable(GL_LIGHTING)
glEnable(GL_LIGHT0)
glEnable(GL_NORMALIZE)
glDisable(GL_TEXTURE_2D)
glLightfv(GL_LIGHT0, GL_POSITION, player.pos + [1])
glLightfv(GL_LIGHT0, GL_DIFFUSE, [1, 1, 1, 1])
glLightf(GL_LIGHT0, GL_LINEAR_ATTENUATION, 0.25)
glLightModelfv(GL_LIGHT_MODEL_AMBIENT, [0, 0, 0, 1])
map.collect_gems(player)
map.draw(player)
glPopMatrix()
glMatrixMode(GL_PROJECTION)
glPopMatrix()
#win.endOpenGL()
text = Text.new("Score: #{player.score}", "", 20)
win.draw(text)
if game_over
text = Text.new("Game Over!", "", 60)
text.left, text.top = 200, 200
win.draw(text)
elsif Time.now - level_start < 3
text = Text.new("Level #{level}!", "", 60)
text.left, text.top = 200, 200
win.draw(text)
text = Text.new("(Collect the gems and find the exit)", "", 25)
text.left, text.top = 125, 260
win.draw(text)
end
win.display()
sleep(0.01)
end

Binary file not shown.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.5 KiB

View File

@ -1,29 +0,0 @@
NOTE: The Tutorial.rb and SideScroller.rb demos were ported from the gosu
Ruby extension. As the Ruby code does not use the gosu extension, I doubt
the code will be considered a derivative work. However, some of the
media files are theirs, so we've included their copyright notice and license.
Copyright (C) 2004-2007 Julian Raschke, Jan Lücker and all contributors.
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
Julian Raschke julian@raschke.de
Jan Lücker jan.luecker@gmx.de
http://code.google.com/p/gosu/

View File

@ -1,10 +0,0 @@
##############
#............#
#...........##
#...#....S...#
#.....""""...#
#.....#......E
#"""""#.....##
#.xxxx......##
#.xxxx...#####
######"""#####

View File

@ -1,26 +0,0 @@
######################################################
S....x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x...#
#....................................................#
#""""""""""""""""""""""""""""""""""""""""""""""""""..#
#....................................................#
#....................................................#
#..""""""""""""""""""""""""""""""""""""""""""""""""""#
#..##x#x#x#x#x#x#x#x#x#x#x#x#x#x#x#x#x#x#x#x#x#x#x####
#....................................................#
#.........###...........###...........###............#
#.......#.....#.......#.....#.......#.....#..........#
#.....#.........#...#.........#...#.........#...#....#
#...#x.x.x.x.x.x.x#x.x.x.x.x.x.x#x.x.x.x.x.x.x#x.x...#
#....................................................#
#..""""""""""""""""""""""""""""""""""""""""""""""""""#
#..###################################################
#....x#x#x#x#x#x#x#x#x#x#x#x#x#x#x#x#x#x#x#x#x#x#x...#
#....x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x...#
#""""""""""""""""""""""""""""""""""""""""""""""""""..#
###################################################..#
#....x..x..x..x..x..x..x..x..x..x..x..x..x..x..x..x..#
#....................................................#
#....................................................#
#..###################################################
#....x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x...#
####################################################E#

View File

@ -1,25 +0,0 @@
######################################################
#........S...........................................#
#.............xx......x.x............................#
#............x..x....................................#
#x....x...x..x.......#####..xxx....................x.#
#.x.........................xxx.........##.........x.#
#...............""..........###...##..........##.....#
#..##..###..##..##...................................#
#........................................xx........###
#.............................###....................#
##....##.............................................#
#....................##....##......##....##....##....#
#.................................................x..#
#...x....##....##.......x...x.....................x..#
#.....x...............x...x...x...................x..#
#......x...##.....##.................................#
#.......x.........................................#..#
#...........##........#...#...#..#.......x...........#
#...#................................................#
#....."""".................x.......#..#####...###....#
#x....#......................##......................#
#"""""#.....#.....x..................#...............#
##xxxx......#........................................#
##xxxx...#####............."...""""".................E
######"""#############################################

Binary file not shown.

Before

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.5 KiB

Binary file not shown.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 214 B

View File

@ -1 +0,0 @@
..\bin\ruby.exe test.rb

View File

@ -1,99 +0,0 @@
require "RubySFML"
include SFML
require "gl"
include Gl
class TextTest < Text
# Test overriding a virtual C++ method
def render(win)
self.color = Color.new(color.r+1, color.g+2, color.b+3, 255)
super # Call base class's version of render (in C++)
# Custom OpenGL calls
rect = getRect()
#win.beginOpenGL()
glColor4f(1, 1, 1, 1)
glLineWidth(5)
glBegin(GL_LINES)
glVertex2f(0, 0)
glVertex2f(rect.width, rect.height)
glVertex2f(rect.width, 0)
glVertex2f(0, rect.height)
glEnd()
#win.endOpenGL()
end
end
# Test Clock class
clock = Clock.new
10.times { sleep 0.01; puts "Clock - #{clock}" }
puts
# Test VideoMode class
puts "Current desktop mode - #{VideoMode::desktop}"
puts "32-bit video modes:"
VideoMode::each {|mode| puts mode.to_s if mode.bpp == 32 }
puts
# Test RenderWindow class
mode = VideoMode.new(800, 600, 32)
win = RenderWindow.new(mode, "RubySFML Test")
win.useVerticalSync(false)
win.showMouseCursor(false)
win.setBackgroundColor(Color.Red)
puts "Window - #{win}"
puts "View Rect - #{win.view}"
puts
# Test Color, Image, and Sprite classes
puts format("Red = 0x%X", Color.Red.toRGBA)
puts format("Green = 0x%X", Color.Green.toRGBA)
puts format("Blue = 0x%X", Color.Blue.toRGBA)
puts format("Black = 0x%X", Color.Black.toRGBA)
image = Image.new("media/cursor.png")
sprite = Sprite.new(image)
image.width.times {|x| puts "image[#{x},#{x}] = #{image[x,x]}" }
image.createMaskFromColor(Color.Black) # Set black to transparent
sprite.x = mode.w/2 - sprite.w/2
sprite.y = mode.h/2 - sprite.h/2
puts "Image - #{image}"
puts "Sprite - #{sprite}"
puts
# Test Text (sfString) class
text = TextTest.new("This is a test!")
# Test Sound and SoundBuffer classes
sb = SoundBuffer.new("media/cannon.wav")
sound = Sound.new(sb)
sound.volume = 100
puts "SoundBuffer - #{sound.buffer}"
puts "Sound - #{sound}"
# Simple game loop
done = false
while !done
while e = win.getEvent()
puts "Event - #{e.to_s}" # Dump events to stdout
done = true if
e.type == Event::Closed or
(e.type == Event::KeyReleased and e.code == Key::Escape)
sound.play if
(e.type == Event::KeyPressed and e.code == Key::Space) or
(e.type == Event::MouseButtonPressed and e.buttons == Mouse::Left)
sprite.x, sprite.y = e.x-sprite.w/2, e.y-sprite.h/2 if
e.type == Event::MouseMoved
end
text.left = 0 if (text.left += 1) >= 800
text.top = 0 if (text.top += 1) >= 600
win.draw(text)
win.draw(sprite)
win.display()
end

View File

@ -1,196 +0,0 @@
require 'RubySFML'
include SFML
# A simple class to handle a single puzzle piece
class Piece
# Each shape is made up of 4 blocks:
# * * * * ** ** **
# * ** ** ** * * **
# * * * * * *
# *
SHAPES = [ # Negative y is down
[[0, 0], [0, 1], [0, -1], [0, -2]],
[[0, 0], [0, 1], [1, 0], [0, -1]],
[[0, 0], [0, 1], [1, 0], [1, -1]],
[[1, 0], [1, 1], [0, 0], [0, -1]],
[[0, 0], [0, 1], [1, 1], [0, -1]],
[[1, 0], [1, 1], [0, 1], [1, -1]],
[[0, 0], [0, 1], [1, 1], [1, 0]],
]
# Each shape has its own color
COLORS = [Color.Red, Color.Yellow, Color.Cyan, Color.Magenta, Color.Green, Color.Blue, Color.new(255, 128, 64)]
attr_accessor :x, :y, :r
def initialize(n, x, y)
@n, @x, @y = n, x, y
@r = 0
end
def shape(); SHAPES[@n]; end
def color(); COLORS[@n]; end
def rleft(); @r = (@r+1) % 4; end
def rright(); @r = (@r-1) % 4; end
def each() # Iterate each block coordinate (corrected for rotation)
case @r
when 0 then shape.each {|c| yield([c[0], c[1]])}
when 1 then shape.each {|c| yield([-c[1], c[0]])}
when 2 then shape.each {|c| yield([-c[0], -c[1]])}
when 3 then shape.each {|c| yield([c[1], -c[0]])}
end
end
end
class Grid
HEIGHT = 20
WIDTH = 10
BLOCK = 18
BORDER = 1
BSIZE = BLOCK + BORDER
def initialize()
@rows = []
HEIGHT.times { @rows.push Array.new(WIDTH) }
@background_image = Image.new(WIDTH*(BSIZE)+BORDER, HEIGHT*BSIZE+BORDER, Color.White)
@background = Sprite.new(@background_image, (640-WIDTH*BSIZE)/2-BORDER, (480-HEIGHT*BSIZE)/2-BORDER)
@block_image = Image.new(BLOCK, BLOCK, Color.White)
@block = Sprite.new(@block_image)
@score = 0
@last_down = $clock.to_f
@piece = Piece.new(rand(7), WIDTH/2-1, HEIGHT-1)
@next_piece = Piece.new(rand(7), WIDTH/2-1, HEIGHT-1)
end
def [](y)
return @rows[y]
end
def draw_block(win, x, y, color)
@block.left = x*BSIZE + @background.left+BORDER
@block.top = ((HEIGHT-1)-y)*BSIZE + @background.top+BORDER
@block.color = color
win.draw(@block)
end
def solid?(x, y)
return true if x < 0 or y < 0 or x >= WIDTH or y >= HEIGHT
return @rows[y][x]
end
def left
x = @piece.x
@piece.x -= 1
@piece.each {|c| @piece.x = x if solid?(@piece.x+c[0], @piece.y+c[1])}
end
def right
x = @piece.x
@piece.x += 1
@piece.each {|c| @piece.x = x if solid?(@piece.x+c[0], @piece.y+c[1])}
end
def up
r = @piece.r
@piece.rright
@piece.each {|c| @piece.r = r if solid?(@piece.x+c[0], @piece.y+c[1])}
end
def down
@last_down = $clock.to_f
y = @piece.y
@piece.y -= 1
done = false
@piece.each {|c| done = true if solid?(@piece.x+c[0], @piece.y+c[1])}
if done
@piece.y = y
@piece.each {|c| @rows[@piece.y+c[1]][@piece.x+c[0]] = @piece.color}
@piece = @next_piece
@next_piece = Piece.new(rand(7), WIDTH/2-1, HEIGHT-1)
end
end
def update(win)
speed = 0.5 - 0.1 * (@score/1000)
down if $clock.to_f - @last_down >= speed
collapsed = 0
while y = find_full_row()
collapse_row(y)
collapsed += 1
end
@score += 5 * 2**collapsed if collapsed > 0
end
def render(win)
win.draw(@background)
HEIGHT.times {|y|
WIDTH.times {|x|
c = @rows[y][x] || Color.Black
draw_block(win, x, y, c)
}
}
@piece.each {|c|
x, y, c = @piece.x+c[0], @piece.y+c[1], @piece.color
next if y < 0 or y > HEIGHT-1
draw_block(win, x, y, c)
}
score = Text.new("Score: #{@score}", "", 20)
#score.left, score.top = 10, 10
win.draw(score)
text = Text.new("Coming Next:", "", 20)
text.left, text.top = 450, 50
win.draw(text)
@next_piece.each {|c|
x, y, c = 14+c[0], 16+c[1], @next_piece.color
next if y < 0 or y > HEIGHT-1
draw_block(win, x, y, c)
}
end
def collapse_row(i)
while i < HEIGHT-1
@rows[i] = @rows[i+1]
i += 1
end
@rows[HEIGHT-1] = Array.new(WIDTH, nil)
end
def find_full_row()
HEIGHT.times {|y| return y unless @rows[y].index(nil) }
return nil
end
end
$clock = Clock.new
mode = VideoMode.new(640, 480, 32)
win = RenderWindow.new(mode, "RubySFML Test", 0)
win.showMouseCursor(false)
win.useVerticalSync(true)
grid = Grid.new()
# Simple game loop
done = false
while !done
while e = win.getEvent()
case e.type
when Event::Closed then done = true
when Event::KeyReleased then done = true if e.code == Key::Escape
when Event::KeyPressed
case e.code
when Key::Up then grid.up
when Key::Left then grid.left
when Key::Right then grid.right
when Key::Down then grid.down
end
end
end
grid.update(win)
grid.render(win)
win.display()
sleep(0.01)
end

Binary file not shown.

Binary file not shown.

View File

@ -1,332 +0,0 @@
/* zconf.h -- configuration of the zlib compression library
* Copyright (C) 1995-2005 Jean-loup Gailly.
* For conditions of distribution and use, see copyright notice in zlib.h
*/
/* @(#) $Id$ */
#ifndef ZCONF_H
#define ZCONF_H
/*
* If you *really* need a unique prefix for all types and library functions,
* compile with -DZ_PREFIX. The "standard" zlib should be compiled without it.
*/
#ifdef Z_PREFIX
# define deflateInit_ z_deflateInit_
# define deflate z_deflate
# define deflateEnd z_deflateEnd
# define inflateInit_ z_inflateInit_
# define inflate z_inflate
# define inflateEnd z_inflateEnd
# define deflateInit2_ z_deflateInit2_
# define deflateSetDictionary z_deflateSetDictionary
# define deflateCopy z_deflateCopy
# define deflateReset z_deflateReset
# define deflateParams z_deflateParams
# define deflateBound z_deflateBound
# define deflatePrime z_deflatePrime
# define inflateInit2_ z_inflateInit2_
# define inflateSetDictionary z_inflateSetDictionary
# define inflateSync z_inflateSync
# define inflateSyncPoint z_inflateSyncPoint
# define inflateCopy z_inflateCopy
# define inflateReset z_inflateReset
# define inflateBack z_inflateBack
# define inflateBackEnd z_inflateBackEnd
# define compress z_compress
# define compress2 z_compress2
# define compressBound z_compressBound
# define uncompress z_uncompress
# define adler32 z_adler32
# define crc32 z_crc32
# define get_crc_table z_get_crc_table
# define zError z_zError
# define alloc_func z_alloc_func
# define free_func z_free_func
# define in_func z_in_func
# define out_func z_out_func
# define Byte z_Byte
# define uInt z_uInt
# define uLong z_uLong
# define Bytef z_Bytef
# define charf z_charf
# define intf z_intf
# define uIntf z_uIntf
# define uLongf z_uLongf
# define voidpf z_voidpf
# define voidp z_voidp
#endif
#if defined(__MSDOS__) && !defined(MSDOS)
# define MSDOS
#endif
#if (defined(OS_2) || defined(__OS2__)) && !defined(OS2)
# define OS2
#endif
#if defined(_WINDOWS) && !defined(WINDOWS)
# define WINDOWS
#endif
#if defined(_WIN32) || defined(_WIN32_WCE) || defined(__WIN32__)
# ifndef WIN32
# define WIN32
# endif
#endif
#if (defined(MSDOS) || defined(OS2) || defined(WINDOWS)) && !defined(WIN32)
# if !defined(__GNUC__) && !defined(__FLAT__) && !defined(__386__)
# ifndef SYS16BIT
# define SYS16BIT
# endif
# endif
#endif
/*
* Compile with -DMAXSEG_64K if the alloc function cannot allocate more
* than 64k bytes at a time (needed on systems with 16-bit int).
*/
#ifdef SYS16BIT
# define MAXSEG_64K
#endif
#ifdef MSDOS
# define UNALIGNED_OK
#endif
#ifdef __STDC_VERSION__
# ifndef STDC
# define STDC
# endif
# if __STDC_VERSION__ >= 199901L
# ifndef STDC99
# define STDC99
# endif
# endif
#endif
#if !defined(STDC) && (defined(__STDC__) || defined(__cplusplus))
# define STDC
#endif
#if !defined(STDC) && (defined(__GNUC__) || defined(__BORLANDC__))
# define STDC
#endif
#if !defined(STDC) && (defined(MSDOS) || defined(WINDOWS) || defined(WIN32))
# define STDC
#endif
#if !defined(STDC) && (defined(OS2) || defined(__HOS_AIX__))
# define STDC
#endif
#if defined(__OS400__) && !defined(STDC) /* iSeries (formerly AS/400). */
# define STDC
#endif
#ifndef STDC
# ifndef const /* cannot use !defined(STDC) && !defined(const) on Mac */
# define const /* note: need a more gentle solution here */
# endif
#endif
/* Some Mac compilers merge all .h files incorrectly: */
#if defined(__MWERKS__)||defined(applec)||defined(THINK_C)||defined(__SC__)
# define NO_DUMMY_DECL
#endif
/* Maximum value for memLevel in deflateInit2 */
#ifndef MAX_MEM_LEVEL
# ifdef MAXSEG_64K
# define MAX_MEM_LEVEL 8
# else
# define MAX_MEM_LEVEL 9
# endif
#endif
/* Maximum value for windowBits in deflateInit2 and inflateInit2.
* WARNING: reducing MAX_WBITS makes minigzip unable to extract .gz files
* created by gzip. (Files created by minigzip can still be extracted by
* gzip.)
*/
#ifndef MAX_WBITS
# define MAX_WBITS 15 /* 32K LZ77 window */
#endif
/* The memory requirements for deflate are (in bytes):
(1 << (windowBits+2)) + (1 << (memLevel+9))
that is: 128K for windowBits=15 + 128K for memLevel = 8 (default values)
plus a few kilobytes for small objects. For example, if you want to reduce
the default memory requirements from 256K to 128K, compile with
make CFLAGS="-O -DMAX_WBITS=14 -DMAX_MEM_LEVEL=7"
Of course this will generally degrade compression (there's no free lunch).
The memory requirements for inflate are (in bytes) 1 << windowBits
that is, 32K for windowBits=15 (default value) plus a few kilobytes
for small objects.
*/
/* Type declarations */
#ifndef OF /* function prototypes */
# ifdef STDC
# define OF(args) args
# else
# define OF(args) ()
# endif
#endif
/* The following definitions for FAR are needed only for MSDOS mixed
* model programming (small or medium model with some far allocations).
* This was tested only with MSC; for other MSDOS compilers you may have
* to define NO_MEMCPY in zutil.h. If you don't need the mixed model,
* just define FAR to be empty.
*/
#ifdef SYS16BIT
# if defined(M_I86SM) || defined(M_I86MM)
/* MSC small or medium model */
# define SMALL_MEDIUM
# ifdef _MSC_VER
# define FAR _far
# else
# define FAR far
# endif
# endif
# if (defined(__SMALL__) || defined(__MEDIUM__))
/* Turbo C small or medium model */
# define SMALL_MEDIUM
# ifdef __BORLANDC__
# define FAR _far
# else
# define FAR far
# endif
# endif
#endif
#if defined(WINDOWS) || defined(WIN32)
/* If building or using zlib as a DLL, define ZLIB_DLL.
* This is not mandatory, but it offers a little performance increase.
*/
# ifdef ZLIB_DLL
# if defined(WIN32) && (!defined(__BORLANDC__) || (__BORLANDC__ >= 0x500))
# ifdef ZLIB_INTERNAL
# define ZEXTERN extern __declspec(dllexport)
# else
# define ZEXTERN extern __declspec(dllimport)
# endif
# endif
# endif /* ZLIB_DLL */
/* If building or using zlib with the WINAPI/WINAPIV calling convention,
* define ZLIB_WINAPI.
* Caution: the standard ZLIB1.DLL is NOT compiled using ZLIB_WINAPI.
*/
# ifdef ZLIB_WINAPI
# ifdef FAR
# undef FAR
# endif
# include <windows.h>
/* No need for _export, use ZLIB.DEF instead. */
/* For complete Windows compatibility, use WINAPI, not __stdcall. */
# define ZEXPORT WINAPI
# ifdef WIN32
# define ZEXPORTVA WINAPIV
# else
# define ZEXPORTVA FAR CDECL
# endif
# endif
#endif
#if defined (__BEOS__)
# ifdef ZLIB_DLL
# ifdef ZLIB_INTERNAL
# define ZEXPORT __declspec(dllexport)
# define ZEXPORTVA __declspec(dllexport)
# else
# define ZEXPORT __declspec(dllimport)
# define ZEXPORTVA __declspec(dllimport)
# endif
# endif
#endif
#ifndef ZEXTERN
# define ZEXTERN extern
#endif
#ifndef ZEXPORT
# define ZEXPORT
#endif
#ifndef ZEXPORTVA
# define ZEXPORTVA
#endif
#ifndef FAR
# define FAR
#endif
#if !defined(__MACTYPES__)
typedef unsigned char Byte; /* 8 bits */
#endif
typedef unsigned int uInt; /* 16 bits or more */
typedef unsigned long uLong; /* 32 bits or more */
#ifdef SMALL_MEDIUM
/* Borland C/C++ and some old MSC versions ignore FAR inside typedef */
# define Bytef Byte FAR
#else
typedef Byte FAR Bytef;
#endif
typedef char FAR charf;
typedef int FAR intf;
typedef uInt FAR uIntf;
typedef uLong FAR uLongf;
#ifdef STDC
typedef void const *voidpc;
typedef void FAR *voidpf;
typedef void *voidp;
#else
typedef Byte const *voidpc;
typedef Byte FAR *voidpf;
typedef Byte *voidp;
#endif
#if 0 /* HAVE_UNISTD_H -- this line is updated by ./configure */
# include <sys/types.h> /* for off_t */
# include <unistd.h> /* for SEEK_* and off_t */
# ifdef VMS
# include <unixio.h> /* for off_t */
# endif
# define z_off_t off_t
#endif
#ifndef SEEK_SET
# define SEEK_SET 0 /* Seek from beginning of file. */
# define SEEK_CUR 1 /* Seek from current position. */
# define SEEK_END 2 /* Set file pointer to EOF plus "offset" */
#endif
#ifndef z_off_t
# define z_off_t long
#endif
#if defined(__OS400__)
# define NO_vsnprintf
#endif
#if defined(__MVS__)
# define NO_vsnprintf
# ifdef FAR
# undef FAR
# endif
#endif
/* MVS linker does not support external names larger than 8 bytes */
#if defined(__MVS__)
# pragma map(deflateInit_,"DEIN")
# pragma map(deflateInit2_,"DEIN2")
# pragma map(deflateEnd,"DEEND")
# pragma map(deflateBound,"DEBND")
# pragma map(inflateInit_,"ININ")
# pragma map(inflateInit2_,"ININ2")
# pragma map(inflateEnd,"INEND")
# pragma map(inflateSync,"INSY")
# pragma map(inflateSetDictionary,"INSEDI")
# pragma map(compressBound,"CMBND")
# pragma map(inflate_table,"INTABL")
# pragma map(inflate_fast,"INFA")
# pragma map(inflate_copyright,"INCOPY")
#endif
#endif /* ZCONF_H */

File diff suppressed because it is too large Load Diff

Binary file not shown.

Binary file not shown.

Binary file not shown.