danabr75-opengl 0.10.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.autotest +29 -0
- data/.gemtest +0 -0
- data/.gitignore +6 -0
- data/.travis.yml +19 -0
- data/Gemfile +8 -0
- data/History.md +101 -0
- data/MIT-LICENSE +18 -0
- data/Manifest.txt +142 -0
- data/README.rdoc +105 -0
- data/Rakefile +170 -0
- data/danabr75-opengl.gemspec +32 -0
- data/examples/NeHe/NeHe.png +0 -0
- data/examples/NeHe/crate.png +0 -0
- data/examples/NeHe/glass.png +0 -0
- data/examples/NeHe/nehe_lesson02.rb +117 -0
- data/examples/NeHe/nehe_lesson03.rb +123 -0
- data/examples/NeHe/nehe_lesson04.rb +132 -0
- data/examples/NeHe/nehe_lesson05.rb +182 -0
- data/examples/NeHe/nehe_lesson06.rb +186 -0
- data/examples/NeHe/nehe_lesson07.rb +240 -0
- data/examples/NeHe/nehe_lesson08.rb +255 -0
- data/examples/NeHe/nehe_lesson09.rb +203 -0
- data/examples/NeHe/nehe_lesson11.rb +176 -0
- data/examples/NeHe/nehe_lesson12.rb +203 -0
- data/examples/NeHe/nehe_lesson16.rb +211 -0
- data/examples/NeHe/nehe_lesson19.rb +209 -0
- data/examples/NeHe/nehe_lesson36.rb +308 -0
- data/examples/NeHe/particle.png +0 -0
- data/examples/NeHe/star.png +0 -0
- data/examples/NeHe/tim.png +0 -0
- data/examples/OrangeBook/3Dlabs-License.txt +33 -0
- data/examples/OrangeBook/brick.frag +36 -0
- data/examples/OrangeBook/brick.rb +378 -0
- data/examples/OrangeBook/brick.vert +41 -0
- data/examples/OrangeBook/particle.frag +17 -0
- data/examples/OrangeBook/particle.rb +408 -0
- data/examples/OrangeBook/particle.vert +38 -0
- data/examples/README +16 -0
- data/examples/RedBook/aapoly.rb +143 -0
- data/examples/RedBook/aargb.rb +121 -0
- data/examples/RedBook/accanti.rb +164 -0
- data/examples/RedBook/accpersp.rb +217 -0
- data/examples/RedBook/alpha.rb +125 -0
- data/examples/RedBook/alpha3D.rb +160 -0
- data/examples/RedBook/bezcurve.rb +107 -0
- data/examples/RedBook/bezmesh.rb +139 -0
- data/examples/RedBook/checker.rb +126 -0
- data/examples/RedBook/clip.rb +97 -0
- data/examples/RedBook/colormat.rb +137 -0
- data/examples/RedBook/cube.rb +71 -0
- data/examples/RedBook/depthcue.rb +101 -0
- data/examples/RedBook/dof.rb +206 -0
- data/examples/RedBook/double.rb +107 -0
- data/examples/RedBook/drawf.rb +93 -0
- data/examples/RedBook/feedback.rb +147 -0
- data/examples/RedBook/fog.rb +168 -0
- data/examples/RedBook/font.rb +153 -0
- data/examples/RedBook/hello.rb +81 -0
- data/examples/RedBook/image.rb +139 -0
- data/examples/RedBook/jitter.rb +207 -0
- data/examples/RedBook/light.rb +157 -0
- data/examples/RedBook/lines.rb +130 -0
- data/examples/RedBook/list.rb +113 -0
- data/examples/RedBook/material.rb +276 -0
- data/examples/RedBook/mipmap.rb +158 -0
- data/examples/RedBook/model.rb +115 -0
- data/examples/RedBook/movelight.rb +134 -0
- data/examples/RedBook/pickdepth.rb +181 -0
- data/examples/RedBook/planet.rb +110 -0
- data/examples/RedBook/quadric.rb +160 -0
- data/examples/RedBook/robot.rb +117 -0
- data/examples/RedBook/select.rb +198 -0
- data/examples/RedBook/smooth.rb +97 -0
- data/examples/RedBook/stencil.rb +165 -0
- data/examples/RedBook/stroke.rb +169 -0
- data/examples/RedBook/surface.rb +168 -0
- data/examples/RedBook/teaambient.rb +134 -0
- data/examples/RedBook/teapots.rb +184 -0
- data/examples/RedBook/tess.rb +185 -0
- data/examples/RedBook/texbind.rb +149 -0
- data/examples/RedBook/texgen.rb +171 -0
- data/examples/RedBook/texturesurf.rb +130 -0
- data/examples/RedBook/varray.rb +161 -0
- data/examples/RedBook/wrap.rb +150 -0
- data/examples/misc/OGLBench.rb +338 -0
- data/examples/misc/anisotropic.rb +196 -0
- data/examples/misc/fbo_test.rb +357 -0
- data/examples/misc/font-glut.rb +47 -0
- data/examples/misc/glfwtest.rb +30 -0
- data/examples/misc/plane.rb +161 -0
- data/examples/misc/readpixel.rb +66 -0
- data/examples/misc/sdltest.rb +36 -0
- data/examples/misc/trislam.rb +829 -0
- data/ext/opengl/GL/gl.h +2115 -0
- data/ext/opengl/GL/glext.h +11770 -0
- data/ext/opengl/common.h +372 -0
- data/ext/opengl/conv.h +247 -0
- data/ext/opengl/extconf.rb +19 -0
- data/ext/opengl/fptr_struct.h +912 -0
- data/ext/opengl/funcdef.h +279 -0
- data/ext/opengl/gl-1.0-1.1.c +3345 -0
- data/ext/opengl/gl-1.2.c +155 -0
- data/ext/opengl/gl-1.3.c +447 -0
- data/ext/opengl/gl-1.4.c +346 -0
- data/ext/opengl/gl-1.5.c +225 -0
- data/ext/opengl/gl-2.0.c +665 -0
- data/ext/opengl/gl-2.1.c +57 -0
- data/ext/opengl/gl-3.0.c +502 -0
- data/ext/opengl/gl-enums.c +4853 -0
- data/ext/opengl/gl-enums.h +14528 -0
- data/ext/opengl/gl-error.c +110 -0
- data/ext/opengl/gl-error.h +25 -0
- data/ext/opengl/gl-ext-3dfx.c +27 -0
- data/ext/opengl/gl-ext-arb.c +880 -0
- data/ext/opengl/gl-ext-ati.c +41 -0
- data/ext/opengl/gl-ext-ext.c +885 -0
- data/ext/opengl/gl-ext-gremedy.c +41 -0
- data/ext/opengl/gl-ext-nv.c +679 -0
- data/ext/opengl/gl.c +265 -0
- data/ext/opengl/gl_buffer.c +202 -0
- data/ext/opengl/glimpl.c +187 -0
- data/ext/opengl/glimpl.h +47 -0
- data/ext/opengl/opengl.c +9 -0
- data/lib/gl.rb +1 -0
- data/lib/opengl.rb +79 -0
- data/lib/opengl/bindings_version.rb +4 -0
- data/lib/opengl/implementation.rb +38 -0
- data/lib/opengl/test_case.rb +86 -0
- data/test/dummy.xorg.conf +140 -0
- data/test/test_gl.rb +45 -0
- data/test/test_gl_10_11.rb +1363 -0
- data/test/test_gl_12.rb +71 -0
- data/test/test_gl_13.rb +221 -0
- data/test/test_gl_14.rb +218 -0
- data/test/test_gl_15.rb +258 -0
- data/test/test_gl_20.rb +417 -0
- data/test/test_gl_21.rb +436 -0
- data/test/test_gl_ext_arb.rb +508 -0
- data/test/test_gl_ext_ati.rb +28 -0
- data/test/test_gl_ext_ext.rb +608 -0
- data/test/test_gl_ext_gremedy.rb +29 -0
- data/test/test_gl_ext_nv.rb +349 -0
- data/test/test_glimpl.rb +23 -0
- data/test/test_opengl_buffer.rb +122 -0
- data/utils/README +6 -0
- data/utils/enumgen.rb +108 -0
- data/utils/extlistgen.rb +90 -0
- metadata +326 -0
data/ext/opengl/glimpl.c
ADDED
@@ -0,0 +1,187 @@
|
|
1
|
+
#include "common.h"
|
2
|
+
|
3
|
+
#ifdef HAVE_DLFCN_H
|
4
|
+
#include <dlfcn.h>
|
5
|
+
#endif
|
6
|
+
#ifdef HAVE_WINDOWS_H
|
7
|
+
#include <windows.h>
|
8
|
+
#endif
|
9
|
+
|
10
|
+
VALUE rb_cGlimpl;
|
11
|
+
|
12
|
+
static void *gl_load_library(const char *name)
|
13
|
+
{
|
14
|
+
void *dl = NULL;
|
15
|
+
|
16
|
+
#if defined(HAVE_DLFCN_H)
|
17
|
+
dl = dlopen(name, RTLD_LAZY | RTLD_LOCAL
|
18
|
+
#if defined(RTLD_FIRST)
|
19
|
+
| RTLD_FIRST
|
20
|
+
#endif
|
21
|
+
);
|
22
|
+
if (dl == NULL)
|
23
|
+
rb_raise(rb_eLoadError,"Can't load OpenGL library %s: %s", name, dlerror());
|
24
|
+
|
25
|
+
#elif defined(HAVE_WINDOWS_H)
|
26
|
+
dl = LoadLibrary(name);
|
27
|
+
if (dl == NULL) {
|
28
|
+
char error_text[999] = "LoadLibrary() error";
|
29
|
+
FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_MAX_WIDTH_MASK,
|
30
|
+
NULL, GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
|
31
|
+
(LPTSTR)&error_text, sizeof(error_text), NULL);
|
32
|
+
rb_raise(rb_eLoadError,"Can't load OpenGL library %s: %s", name, error_text);
|
33
|
+
}
|
34
|
+
#else
|
35
|
+
#error No loading mechanism available
|
36
|
+
#endif
|
37
|
+
|
38
|
+
return dl;
|
39
|
+
}
|
40
|
+
|
41
|
+
static void *gl_load_symbol(void *dl, const char *name, int raise)
|
42
|
+
{
|
43
|
+
void *fptr = NULL;
|
44
|
+
|
45
|
+
#if defined(HAVE_DLFCN_H)
|
46
|
+
fptr = dlsym(dl, name);
|
47
|
+
if (fptr == NULL && raise)
|
48
|
+
rb_raise(rb_eNotImpError,"Function %s is not available on this system: %s",name, dlerror());
|
49
|
+
|
50
|
+
#elif defined(HAVE_WINDOWS_H)
|
51
|
+
fptr = GetProcAddress(dl, name);
|
52
|
+
if (fptr == NULL && raise){
|
53
|
+
char error_text[999] = "GetProcAddress() error";
|
54
|
+
FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_MAX_WIDTH_MASK,
|
55
|
+
NULL, GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
|
56
|
+
(LPTSTR)&error_text, sizeof(error_text), NULL);
|
57
|
+
rb_raise(rb_eNotImpError,"Function %s is not available on this system: %s",name, error_text);
|
58
|
+
}
|
59
|
+
#else
|
60
|
+
#error No loading mechanism available
|
61
|
+
#endif
|
62
|
+
|
63
|
+
return fptr;
|
64
|
+
}
|
65
|
+
|
66
|
+
static void gl_close_library(void *dl)
|
67
|
+
{
|
68
|
+
#if defined(HAVE_DLFCN_H)
|
69
|
+
dlclose(dl);
|
70
|
+
#elif defined(HAVE_WINDOWS_H)
|
71
|
+
FreeLibrary(dl);
|
72
|
+
#else
|
73
|
+
#error No loading mechanism available
|
74
|
+
#endif
|
75
|
+
}
|
76
|
+
|
77
|
+
|
78
|
+
static struct glimpl *
|
79
|
+
rb_glimpl_struct( VALUE self )
|
80
|
+
{
|
81
|
+
return DATA_PTR(self);
|
82
|
+
}
|
83
|
+
|
84
|
+
static void *load_gl_function(VALUE self, const char *name, int raise)
|
85
|
+
{
|
86
|
+
struct glimpl *this = rb_glimpl_struct(self);
|
87
|
+
void *func_ptr = NULL;
|
88
|
+
|
89
|
+
if(this->fptr_GetProcAddress){
|
90
|
+
func_ptr = this->fptr_GetProcAddress(name);
|
91
|
+
}
|
92
|
+
|
93
|
+
if(func_ptr == NULL){
|
94
|
+
func_ptr = gl_load_symbol(this->dl, name, 0);
|
95
|
+
}
|
96
|
+
|
97
|
+
if(func_ptr == NULL)
|
98
|
+
{
|
99
|
+
/* prepend a '_' for the Unix C symbol mangling convention */
|
100
|
+
char *symbol_name = ALLOC_N(char, strlen(name) + 2);
|
101
|
+
symbol_name[0] = '_';
|
102
|
+
strcpy(symbol_name + 1, name);
|
103
|
+
func_ptr = gl_load_symbol(this->dl, symbol_name, 0);
|
104
|
+
xfree(symbol_name);
|
105
|
+
}
|
106
|
+
|
107
|
+
if(func_ptr == NULL && raise == 1)
|
108
|
+
rb_raise(rb_eNotImpError,"Function %s is not available on this system",name);
|
109
|
+
|
110
|
+
return func_ptr;
|
111
|
+
}
|
112
|
+
|
113
|
+
static void
|
114
|
+
rb_glimpl_mark( struct glimpl *this )
|
115
|
+
{
|
116
|
+
int i;
|
117
|
+
rb_gc_mark(this->current_sel_buffer);
|
118
|
+
rb_gc_mark(this->current_feed_buffer);
|
119
|
+
rb_gc_mark(this->Vertex_ptr);
|
120
|
+
rb_gc_mark(this->Normal_ptr);
|
121
|
+
rb_gc_mark(this->Color_ptr);
|
122
|
+
rb_gc_mark(this->Index_ptr);
|
123
|
+
rb_gc_mark(this->TexCoord_ptr);
|
124
|
+
rb_gc_mark(this->EdgeFlag_ptr);
|
125
|
+
rb_gc_mark(this->FogCoord_ptr);
|
126
|
+
rb_gc_mark(this->SecondaryColor_ptr);
|
127
|
+
rb_gc_mark(this->error_checking);
|
128
|
+
rb_gc_mark(this->inside_begin_end);
|
129
|
+
|
130
|
+
for (i=0;i<_MAX_VERTEX_ATTRIBS;i++){
|
131
|
+
rb_gc_mark(this->VertexAttrib_ptr[i]);
|
132
|
+
}
|
133
|
+
}
|
134
|
+
|
135
|
+
static void rb_glimpl_free( struct glimpl *this )
|
136
|
+
{
|
137
|
+
if(this->dl) gl_close_library(this->dl);
|
138
|
+
this->dl = NULL;
|
139
|
+
xfree(this);
|
140
|
+
}
|
141
|
+
|
142
|
+
static VALUE
|
143
|
+
rb_glimpl_s_open(int argc, VALUE *argv, VALUE klass)
|
144
|
+
{
|
145
|
+
VALUE self;
|
146
|
+
struct glimpl *this;
|
147
|
+
VALUE dl_name;
|
148
|
+
VALUE proc_address_function;
|
149
|
+
char *p_dl_name;
|
150
|
+
|
151
|
+
rb_scan_args(argc, argv, "11", &dl_name, &proc_address_function);
|
152
|
+
|
153
|
+
p_dl_name = StringValueCStr(dl_name);
|
154
|
+
|
155
|
+
self = Data_Make_Struct( klass, struct glimpl, rb_glimpl_mark, rb_glimpl_free, this );
|
156
|
+
|
157
|
+
this->error_checking = Qtrue;
|
158
|
+
this->inside_begin_end = Qfalse;
|
159
|
+
this->load_gl_function = load_gl_function;
|
160
|
+
this->dl = gl_load_library(p_dl_name);
|
161
|
+
|
162
|
+
if( NIL_P(proc_address_function) ){
|
163
|
+
this->fptr_GetProcAddress = NULL;
|
164
|
+
} else {
|
165
|
+
char *p_proc_address_function = StringValueCStr(proc_address_function);
|
166
|
+
this->fptr_GetProcAddress = gl_load_symbol(this->dl, p_proc_address_function, 1);
|
167
|
+
}
|
168
|
+
|
169
|
+
return self;
|
170
|
+
}
|
171
|
+
|
172
|
+
static VALUE rb_glimpl_close(VALUE self)
|
173
|
+
{
|
174
|
+
struct glimpl *this = rb_glimpl_struct(self);
|
175
|
+
if(this->dl) gl_close_library(this->dl);
|
176
|
+
this->dl = NULL;
|
177
|
+
return Qnil;
|
178
|
+
}
|
179
|
+
|
180
|
+
void gl_init_glimpl(VALUE module)
|
181
|
+
{
|
182
|
+
rb_cGlimpl = rb_define_class_under(module, "Implementation", rb_cObject);
|
183
|
+
|
184
|
+
rb_undef_alloc_func(rb_cGlimpl);
|
185
|
+
rb_define_singleton_method(rb_cGlimpl, "open", rb_glimpl_s_open, -1);
|
186
|
+
rb_define_method(rb_cGlimpl, "close", rb_glimpl_close, 0);
|
187
|
+
}
|
data/ext/opengl/glimpl.h
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
#ifndef _GLIMPL_H_
|
2
|
+
#define _GLIMPL_H_
|
3
|
+
|
4
|
+
#ifndef GLFUNC_MAGIC_START
|
5
|
+
#include "fptr_struct.h"
|
6
|
+
#endif
|
7
|
+
|
8
|
+
#define GET_GLIMPL_VARIABLE(_name_) \
|
9
|
+
(((struct glimpl *)DATA_PTR(obj))->_name_)
|
10
|
+
|
11
|
+
#define SET_GLIMPL_VARIABLE(_name_,_val_) \
|
12
|
+
((struct glimpl *)DATA_PTR(obj))->_name_ = (_val_)
|
13
|
+
|
14
|
+
/* at least GL_MAX_VERTEX_ATTRIBS - usually 16 or 32 on today's high-end cards */
|
15
|
+
#define _MAX_VERTEX_ATTRIBS 64
|
16
|
+
|
17
|
+
extern VALUE g_default_glimpl;
|
18
|
+
|
19
|
+
struct glimpl {
|
20
|
+
struct glfunc_ptrs glfuncs;
|
21
|
+
|
22
|
+
int opengl_version[2]; /* major, minor */
|
23
|
+
char *opengl_extensions;
|
24
|
+
|
25
|
+
void * (* load_gl_function)(VALUE self, const char *name,int raise);
|
26
|
+
|
27
|
+
VALUE current_feed_buffer;
|
28
|
+
VALUE current_sel_buffer;
|
29
|
+
VALUE Vertex_ptr;
|
30
|
+
VALUE Normal_ptr;
|
31
|
+
VALUE Color_ptr;
|
32
|
+
VALUE Index_ptr;
|
33
|
+
VALUE TexCoord_ptr;
|
34
|
+
VALUE EdgeFlag_ptr;
|
35
|
+
VALUE FogCoord_ptr; /* OpenGL 1.4 */
|
36
|
+
VALUE SecondaryColor_ptr; /* OpenGL 1.4 */
|
37
|
+
VALUE VertexAttrib_ptr[_MAX_VERTEX_ATTRIBS];
|
38
|
+
|
39
|
+
VALUE error_checking;
|
40
|
+
VALUE inside_begin_end;
|
41
|
+
|
42
|
+
void *dl;
|
43
|
+
void * (APIENTRY * fptr_GetProcAddress)(const char *name);
|
44
|
+
};
|
45
|
+
|
46
|
+
|
47
|
+
#endif /* _GLIMPL_H_ */
|
data/ext/opengl/opengl.c
ADDED
data/lib/gl.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'opengl'
|
data/lib/opengl.rb
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (C) 2006 Peter McLain <peter.mclain@gmail.com>
|
3
|
+
# Copyright (C) 2007 Jan Dvorak <jan.dvorak@kraxnet.cz>
|
4
|
+
#
|
5
|
+
# This program is distributed under the terms of the MIT license.
|
6
|
+
# See the included MIT-LICENSE file for the terms of this license.
|
7
|
+
#
|
8
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
9
|
+
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
10
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
11
|
+
# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
12
|
+
# CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
13
|
+
# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
14
|
+
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
15
|
+
#
|
16
|
+
|
17
|
+
# This module provides access to the GL,GLU and GLUT methods and constants
|
18
|
+
# in the way that they were available in previous versions of ruby-opengl.
|
19
|
+
#
|
20
|
+
# Thanks to Ilmari Heikkinen for a previous "reversed" version of this code,
|
21
|
+
# and to Bill Kelly for a version before that one.
|
22
|
+
|
23
|
+
begin
|
24
|
+
RUBY_VERSION =~ /(\d+.\d+)/
|
25
|
+
require "opengl/#{$1}/opengl"
|
26
|
+
rescue LoadError
|
27
|
+
require 'opengl/opengl'
|
28
|
+
end
|
29
|
+
|
30
|
+
require 'opengl/implementation'
|
31
|
+
require 'opengl/bindings_version'
|
32
|
+
|
33
|
+
module Gl
|
34
|
+
meths = Gl::Implementation.instance_methods.select{|mn| mn=~/^gl/ }
|
35
|
+
meths += %w[is_available? is_supported?
|
36
|
+
extension_available? extension_supported?
|
37
|
+
version_available? version_supported?
|
38
|
+
enable_error_checking disable_error_checking is_error_checking_enabled?
|
39
|
+
]
|
40
|
+
|
41
|
+
meths.each do |mn|
|
42
|
+
define_singleton_method(mn) do |*args,&block|
|
43
|
+
begin
|
44
|
+
implementation.send(mn, *args, &block)
|
45
|
+
rescue
|
46
|
+
end
|
47
|
+
end
|
48
|
+
define_method(mn) do |*args,&block|
|
49
|
+
begin
|
50
|
+
implementation.send(mn, *args, &block)
|
51
|
+
rescue
|
52
|
+
end
|
53
|
+
end
|
54
|
+
private mn
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
# (Gl.)glVertex -> GL.Vertex
|
59
|
+
# (Gl::)GL_TRUE -> GL::TRUE
|
60
|
+
module GL
|
61
|
+
extend self
|
62
|
+
include Gl
|
63
|
+
|
64
|
+
Gl.constants.each do |cn|
|
65
|
+
n = cn.to_s.sub(/^GL_/,'')
|
66
|
+
# due to ruby naming scheme, we can't export constants with leading decimal,
|
67
|
+
# e.g. (Gl::)GL_2D would under old syntax become (GL::)2D which is illegal
|
68
|
+
next if n =~ /^[0-9]/
|
69
|
+
const_set( n, Gl.const_get( cn ) )
|
70
|
+
end
|
71
|
+
|
72
|
+
Gl.methods( false ).each do |mn|
|
73
|
+
n = mn.to_s.sub(/^gl/,'')
|
74
|
+
alias_method( n, mn )
|
75
|
+
public( n )
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
OpenGL = Gl
|
@@ -0,0 +1,38 @@
|
|
1
|
+
|
2
|
+
module Gl
|
3
|
+
if RUBY_PLATFORM =~ /mingw|mswin/i
|
4
|
+
class ImplementationWindows < Implementation
|
5
|
+
DLPATH = "opengl32.dll"
|
6
|
+
def self.open
|
7
|
+
super(DLPATH, "wglGetProcAddress")
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
Gl::DefaultImplementation = ImplementationWindows
|
12
|
+
|
13
|
+
elsif RUBY_PLATFORM =~ /darwin/i
|
14
|
+
class ImplementationOSX < Implementation
|
15
|
+
DLPATH = "/System/Library/Frameworks/OpenGL.framework/Versions/Current/OpenGL"
|
16
|
+
def self.open
|
17
|
+
super(DLPATH)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
Gl::DefaultImplementation = ImplementationOSX
|
22
|
+
|
23
|
+
else
|
24
|
+
class ImplementationGLX < Implementation
|
25
|
+
DLPATH = "libGL.so"
|
26
|
+
def self.open
|
27
|
+
begin
|
28
|
+
super(DLPATH, "glXGetProcAddress")
|
29
|
+
rescue NotImplementedError
|
30
|
+
super(DLPATH, "glXGetProcAddressARB")
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
Gl::DefaultImplementation = ImplementationGLX
|
36
|
+
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,86 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (C) 2007 Jan Dvorak <jan.dvorak@kraxnet.cz>
|
3
|
+
#
|
4
|
+
# This program is distributed under the terms of the MIT license.
|
5
|
+
# See the included MIT-LICENSE file for the terms of this license.
|
6
|
+
#
|
7
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
8
|
+
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
9
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
10
|
+
# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
11
|
+
# CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
12
|
+
# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
13
|
+
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
14
|
+
#
|
15
|
+
|
16
|
+
require 'rubygems'
|
17
|
+
begin
|
18
|
+
gem 'minitest'
|
19
|
+
rescue Gem::LoadError
|
20
|
+
end
|
21
|
+
|
22
|
+
require 'minitest/autorun'
|
23
|
+
require 'gl'
|
24
|
+
require 'glu'
|
25
|
+
require 'glut'
|
26
|
+
require 'matrix'
|
27
|
+
|
28
|
+
include Gl
|
29
|
+
include Glu
|
30
|
+
include Glut
|
31
|
+
|
32
|
+
Gl.enable_error_checking
|
33
|
+
|
34
|
+
module OpenGL; end
|
35
|
+
|
36
|
+
class OpenGL::TestCase < MiniTest::Unit::TestCase
|
37
|
+
|
38
|
+
WINDOW_SIZE = 512
|
39
|
+
|
40
|
+
glutInit
|
41
|
+
glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA | GLUT_STENCIL |
|
42
|
+
GLUT_ACCUM | GLUT_ALPHA)
|
43
|
+
|
44
|
+
def setup
|
45
|
+
glutInitWindowPosition 1, 1
|
46
|
+
glutInitWindowSize WINDOW_SIZE, WINDOW_SIZE
|
47
|
+
@window = glutCreateWindow "test"
|
48
|
+
|
49
|
+
glPushAttrib GL_ALL_ATTRIB_BITS
|
50
|
+
glPushClientAttrib GL_CLIENT_ALL_ATTRIB_BITS
|
51
|
+
glMatrixMode GL_MODELVIEW
|
52
|
+
glLoadIdentity
|
53
|
+
glMatrixMode GL_PROJECTION
|
54
|
+
glLoadIdentity
|
55
|
+
|
56
|
+
glClearColor 0, 0, 0, 0
|
57
|
+
glClear GL_COLOR_BUFFER_BIT
|
58
|
+
end
|
59
|
+
|
60
|
+
def teardown
|
61
|
+
glPopAttrib
|
62
|
+
glPopClientAttrib
|
63
|
+
glRenderMode GL_RENDER
|
64
|
+
|
65
|
+
# in case there is an GL error that escaped error checking routines ...
|
66
|
+
error = glGetError
|
67
|
+
assert_equal 0, error, gluErrorString(error)
|
68
|
+
|
69
|
+
glutDestroyWindow @window
|
70
|
+
end
|
71
|
+
|
72
|
+
def assert_each_in_delta expected, actual, epsilon = 0.01
|
73
|
+
assert_equal expected.length, actual.length, 'array lengths do not match'
|
74
|
+
|
75
|
+
expected.flatten.zip(actual.flatten).each_with_index do |(e, a), i|
|
76
|
+
assert_in_delta e, a, epsilon, "element #{i}"
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
def supported? funcs
|
81
|
+
Array(funcs).each do |name| # convert to array if it isn't already
|
82
|
+
skip "#{name} is not supported" unless Gl.is_available? name
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
end
|