ruby-opengl 0.33.0 → 0.40.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +42 -15
- data/doc/build_install.txt +70 -25
- data/doc/history.txt +4 -0
- data/doc/requirements_and_design.txt +2 -3
- data/doc/roadmap.txt +15 -2
- data/doc/screenshots.txt +23 -0
- data/doc/supplies/page_template.html +2 -1
- data/doc/thanks.txt +3 -0
- data/doc/tutorial.txt +5 -3
- data/examples/README +57 -7
- data/examples/legacy/COPYRIGHT +8 -0
- data/examples/{aaindex.rb → legacy/aaindex.rb} +6 -5
- data/examples/legacy/aapoly.rb +153 -0
- data/examples/legacy/aargb.rb +139 -0
- data/examples/legacy/accanti.rb +159 -0
- data/examples/legacy/accpersp.rb +216 -0
- data/examples/legacy/alpha.rb +133 -0
- data/examples/legacy/alpha3D.rb +165 -0
- data/examples/legacy/bezcurve.rb +107 -0
- data/examples/legacy/bezmesh.rb +131 -0
- data/examples/legacy/checker.rb +121 -0
- data/examples/legacy/clip.rb +104 -0
- data/examples/legacy/colormat.rb +145 -0
- data/examples/legacy/cube.rb +73 -0
- data/examples/legacy/depthcue.rb +101 -0
- data/examples/legacy/dof.rb +212 -0
- data/examples/legacy/double.rb +104 -0
- data/examples/legacy/drawf.rb +98 -0
- data/examples/legacy/feedback.rb +152 -0
- data/examples/legacy/fog.rb +172 -0
- data/examples/legacy/font-glut.rb +41 -0
- data/examples/legacy/font.rb +158 -0
- data/examples/legacy/hello.rb +75 -0
- data/examples/legacy/image.rb +145 -0
- data/examples/legacy/jitter.rb +209 -0
- data/examples/legacy/lines.rb +135 -0
- data/examples/legacy/list.rb +120 -0
- data/examples/legacy/material.rb +290 -0
- data/examples/legacy/mipmap.rb +159 -0
- data/examples/legacy/model.rb +119 -0
- data/examples/legacy/movelight.rb +140 -0
- data/examples/legacy/pickdepth.rb +180 -0
- data/examples/legacy/planet.rb +112 -0
- data/examples/legacy/quadric.rb +180 -0
- data/examples/legacy/readpixel.rb +59 -0
- data/examples/legacy/robot.rb +120 -0
- data/examples/legacy/select.rb +207 -0
- data/examples/{smooth_prev.rb → legacy/smooth.rb} +3 -2
- data/examples/legacy/stencil.rb +154 -0
- data/examples/legacy/stroke.rb +170 -0
- data/examples/legacy/surface.rb +170 -0
- data/examples/legacy/teaambient.rb +132 -0
- data/examples/legacy/teapots.rb +188 -0
- data/examples/legacy/tess.rb +222 -0
- data/examples/legacy/texbind.rb +157 -0
- data/examples/legacy/texgen.rb +171 -0
- data/examples/legacy/texturesurf.rb +128 -0
- data/examples/legacy/varray.rb +167 -0
- data/examples/legacy/wrap.rb +158 -0
- data/examples/nehe_lesson02.rb +117 -0
- data/examples/nehe_lesson03.rb +122 -0
- data/examples/nehe_lesson04.rb +133 -0
- data/examples/nehe_lesson05.rb +186 -0
- data/examples/plane.rb +1 -1
- data/examples/smooth.rb +4 -2
- data/examples/test.rb +3 -2
- data/ext/common/{rbogl.c → common.h} +99 -32
- data/ext/common/gl-enums.h +39 -1
- data/ext/gl/gl-1.0-1.1.c +350 -305
- data/ext/gl/gl-1.2.c +933 -38
- data/ext/gl/gl-1.3.c +725 -0
- data/ext/gl/gl-1.4.c +647 -0
- data/ext/gl/gl-1.5.c +362 -0
- data/ext/gl/gl-2.0.c +1632 -0
- data/ext/gl/gl-2.1.c +154 -0
- data/ext/gl/gl-enums.c +1 -2
- data/ext/gl/gl.c +58 -2
- data/ext/gl/mkrf_conf.rb +4 -1
- data/ext/glu/glu.c +5 -4
- data/ext/glu/mkrf_conf.rb +4 -1
- data/ext/glut/glut.c +7 -1
- data/ext/glut/mkrf_conf.rb +5 -0
- data/lib/gl_prev.rb +4 -3
- data/lib/glu_prev.rb +4 -3
- data/lib/glut_prev.rb +3 -3
- data/{examples/all_tests.rb → lib/opengl.rb} +9 -12
- data/test/README +5 -18
- data/test/tc_common.rb +79 -0
- data/test/tc_func_10_11.rb +1255 -0
- data/test/tc_func_12.rb +186 -0
- data/test/tc_func_13.rb +203 -0
- data/test/tc_func_14.rb +197 -0
- data/test/tc_func_15.rb +82 -0
- data/test/tc_func_20.rb +320 -0
- data/test/tc_func_21.rb +67 -0
- data/test/tc_include_gl.rb +1 -1
- data/test/{tc_opengl_namespace.rb → tc_misc.rb} +20 -20
- data/test/tc_require_gl.rb +1 -1
- metadata +99 -27
- data/ext/common/Rakefile +0 -39
- data/ext/common/rbogl.h +0 -52
- data/test/runtests.sh +0 -7
- data/test/tc_gl_vertex.rb +0 -180
@@ -0,0 +1,112 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (c) 1993-1997, Silicon Graphics, Inc.
|
3
|
+
# ALL RIGHTS RESERVED
|
4
|
+
# Permission to use, copy, modify, and distribute this software for
|
5
|
+
# any purpose and without fee is hereby granted, provided that the above
|
6
|
+
# copyright notice appear in all copies and that both the copyright notice
|
7
|
+
# and this permission notice appear in supporting documentation, and that
|
8
|
+
# the name of Silicon Graphics, Inc. not be used in advertising
|
9
|
+
# or publicity pertaining to distribution of the software without specific,
|
10
|
+
# written prior permission.
|
11
|
+
#
|
12
|
+
# THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS"
|
13
|
+
# AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE,
|
14
|
+
# INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR
|
15
|
+
# FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
|
16
|
+
# GRAPHICS, INC. BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT,
|
17
|
+
# SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY
|
18
|
+
# KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION,
|
19
|
+
# LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF
|
20
|
+
# THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC. HAS BEEN
|
21
|
+
# ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON
|
22
|
+
# ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE
|
23
|
+
# POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE.
|
24
|
+
#
|
25
|
+
# US Government Users Restricted Rights
|
26
|
+
# Use, duplication, or disclosure by the Government is subject to
|
27
|
+
# restrictions set forth in FAR 52.227.19(c)(2) or subparagraph
|
28
|
+
# (c)(1)(ii) of the Rights in Technical Data and Computer Software
|
29
|
+
# clause at DFARS 252.227-7013 and/or in similar or successor
|
30
|
+
# clauses in the FAR or the DOD or NASA FAR Supplement.
|
31
|
+
# Unpublished-- rights reserved under the copyright laws of the
|
32
|
+
# United States. Contractor/manufacturer is Silicon Graphics,
|
33
|
+
# Inc., 2011 N. Shoreline Blvd., Mountain View, CA 94039-7311.
|
34
|
+
#
|
35
|
+
# OpenGL(R) is a registered trademark of Silicon Graphics, Inc.
|
36
|
+
#/
|
37
|
+
|
38
|
+
#
|
39
|
+
# planet.c
|
40
|
+
# This program shows how to composite modeling transformations
|
41
|
+
# to draw translated and rotated models.
|
42
|
+
# Interaction: pressing the d and y keys (day and year)
|
43
|
+
# alters the rotation of the planet around the sun.
|
44
|
+
#/
|
45
|
+
require "gl_prev"
|
46
|
+
require "glu_prev"
|
47
|
+
require "glut_prev"
|
48
|
+
require "rational"
|
49
|
+
|
50
|
+
STDOUT.sync = TRUE
|
51
|
+
|
52
|
+
$year = 0; $day = 0;
|
53
|
+
|
54
|
+
def init
|
55
|
+
GL.ClearColor(0.0, 0.0, 0.0, 0.0);
|
56
|
+
GL.ShadeModel(GL::FLAT);
|
57
|
+
end
|
58
|
+
|
59
|
+
display = Proc.new {
|
60
|
+
GL.Clear(GL::COLOR_BUFFER_BIT);
|
61
|
+
GL.Color(1.0, 1.0, 1.0);
|
62
|
+
|
63
|
+
GL.PushMatrix();
|
64
|
+
GLUT.WireSphere(1.0, 20, 16); # draw sun */
|
65
|
+
GL.Rotate($year, 0.0, 1.0, 0.0);
|
66
|
+
GL.Translate(2.0, 0.0, 0.0);
|
67
|
+
GL.Rotate($day, 0.0, 1.0, 0.0);
|
68
|
+
GLUT.WireSphere(0.2, 10, 8); # draw smaller planet */
|
69
|
+
GL.PopMatrix();
|
70
|
+
GLUT.SwapBuffers();
|
71
|
+
}
|
72
|
+
|
73
|
+
reshape = Proc.new { |w, h|
|
74
|
+
GL.Viewport(0, 0, w, h);
|
75
|
+
GL.MatrixMode(GL::PROJECTION);
|
76
|
+
GL.LoadIdentity();
|
77
|
+
GLU.Perspective(60.0, w.to_f/h.to_f, 1.0, 20.0);
|
78
|
+
GL.MatrixMode(GL::MODELVIEW);
|
79
|
+
GL.LoadIdentity();
|
80
|
+
GLU.LookAt(0.0, 0.0, 5.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
|
81
|
+
}
|
82
|
+
|
83
|
+
# ARGSUSED1 */
|
84
|
+
keyboard = Proc.new {|key, x, y|
|
85
|
+
case (key)
|
86
|
+
when 'd'[0]
|
87
|
+
$day = ($day + 10) % 360;
|
88
|
+
GLUT.PostRedisplay();
|
89
|
+
when 'D'[0]
|
90
|
+
$day = ($day - 10) % 360;
|
91
|
+
GLUT.PostRedisplay();
|
92
|
+
when 'y'[0]
|
93
|
+
$year = ($year + 5) % 360;
|
94
|
+
GLUT.PostRedisplay();
|
95
|
+
when 'Y'[0]
|
96
|
+
$year = ($year - 5) % 360;
|
97
|
+
GLUT.PostRedisplay();
|
98
|
+
when 27
|
99
|
+
exit(0);
|
100
|
+
end
|
101
|
+
}
|
102
|
+
|
103
|
+
GLUT.Init
|
104
|
+
GLUT.InitDisplayMode(GLUT::DOUBLE | GLUT::RGB);
|
105
|
+
GLUT.InitWindowSize(500, 500);
|
106
|
+
GLUT.InitWindowPosition(100, 100);
|
107
|
+
GLUT.CreateWindow($0);
|
108
|
+
init();
|
109
|
+
GLUT.DisplayFunc(display);
|
110
|
+
GLUT.ReshapeFunc(reshape);
|
111
|
+
GLUT.KeyboardFunc(keyboard);
|
112
|
+
GLUT.MainLoop();
|
@@ -0,0 +1,180 @@
|
|
1
|
+
#/*
|
2
|
+
# * Copyright (c) 1993-1997, Silicon Graphics, Inc.
|
3
|
+
# * ALL RIGHTS RESERVED
|
4
|
+
# * Permission to use, copy, modify, and distribute this software for
|
5
|
+
# * any purpose and without fee is hereby granted, provided that the above
|
6
|
+
# * copyright notice appear in all copies and that both the copyright notice
|
7
|
+
# * and this permission notice appear in supporting documentation, and that
|
8
|
+
# * the name of Silicon Graphics, Inc. not be used in advertising
|
9
|
+
# * or publicity pertaining to distribution of the software without specific,
|
10
|
+
# * written prior permission.
|
11
|
+
# *
|
12
|
+
# * THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS"
|
13
|
+
# * AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE,
|
14
|
+
# * INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR
|
15
|
+
# * FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
|
16
|
+
# * GRAPHICS, INC. BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT,
|
17
|
+
# * SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY
|
18
|
+
# * KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION,
|
19
|
+
# * LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF
|
20
|
+
# * THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC. HAS BEEN
|
21
|
+
# * ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON
|
22
|
+
# * ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE
|
23
|
+
# * POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE.
|
24
|
+
# *
|
25
|
+
# * US Government Users Restricted Rights
|
26
|
+
# * Use, duplication, or disclosure by the Government is subject to
|
27
|
+
# * restrictions set forth in FAR 52.227.19(c)(2) or subparagraph
|
28
|
+
# * (c)(1)(ii) of the Rights in Technical Data and Computer Software
|
29
|
+
# * clause at DFARS 252.227-7013 and/or in similar or successor
|
30
|
+
# * clauses in the FAR or the DOD or NASA FAR Supplement.
|
31
|
+
# * Unpublished-- rights reserved under the copyright laws of the
|
32
|
+
# * United States. Contractor/manufacturer is Silicon Graphics,
|
33
|
+
# * Inc., 2011 N. Shoreline Blvd., Mountain View, CA 94039-7311.
|
34
|
+
# *
|
35
|
+
# * OpenGL(R) is a registered trademark of Silicon Graphics, Inc.
|
36
|
+
# */
|
37
|
+
#
|
38
|
+
#/*
|
39
|
+
# * quadric.c
|
40
|
+
# * This program demonstrates the use of some of the gluQuadric*
|
41
|
+
# * routines. Quadric objects are created with some quadric
|
42
|
+
# * properties and the callback routine to handle errors.
|
43
|
+
# * Note that the cylinder has no top or bottom and the circle
|
44
|
+
# * has a hole in it.
|
45
|
+
# */
|
46
|
+
require "gl_prev"
|
47
|
+
require "glu_prev"
|
48
|
+
require "glut_prev"
|
49
|
+
require "mathn"
|
50
|
+
|
51
|
+
$startList = nil;
|
52
|
+
|
53
|
+
#void CALLBACK errorCallback(GLenum errorCode)
|
54
|
+
#{
|
55
|
+
# const GLubyte *estring;
|
56
|
+
#
|
57
|
+
# estring = gluErrorString(errorCode);
|
58
|
+
# fprintf(stderr, "Quadric Error: %s\n", estring);
|
59
|
+
# exit(0);
|
60
|
+
#}
|
61
|
+
|
62
|
+
def init
|
63
|
+
mat_ambient = [ 0.5, 0.5, 0.5, 1.0 ];
|
64
|
+
mat_specular = [ 1.0, 1.0, 1.0, 1.0 ];
|
65
|
+
mat_shininess = [ 50.0 ];
|
66
|
+
light_position = [ 1.0, 1.0, 1.0, 0.0 ];
|
67
|
+
model_ambient = [ 0.5, 0.5, 0.5, 1.0 ];
|
68
|
+
|
69
|
+
GL.ClearColor(0.0, 0.0, 0.0, 0.0);
|
70
|
+
|
71
|
+
GL.Material(GL::FRONT, GL::AMBIENT, mat_ambient);
|
72
|
+
GL.Material(GL::FRONT, GL::SPECULAR, mat_specular);
|
73
|
+
GL.Material(GL::FRONT, GL::SHININESS, mat_shininess);
|
74
|
+
GL.Light(GL::LIGHT0, GL::POSITION, light_position);
|
75
|
+
GL.LightModel(GL::LIGHT_MODEL_AMBIENT, model_ambient);
|
76
|
+
|
77
|
+
GL.Enable(GL::LIGHTING);
|
78
|
+
GL.Enable(GL::LIGHT0);
|
79
|
+
GL.Enable(GL::DEPTH_TEST);
|
80
|
+
|
81
|
+
#/* Create 4 display lists, each with a different quadric object.
|
82
|
+
# * Different drawing styles and surface normal specifications
|
83
|
+
# * are demonstrated.
|
84
|
+
# */
|
85
|
+
$startList = GL.GenLists(4);
|
86
|
+
qobj = GLU.NewQuadric();
|
87
|
+
# gluQuadricCallback(qobj, GLU_ERROR,
|
88
|
+
# (GLvoid (CALLBACK*) ()) errorCallback);
|
89
|
+
|
90
|
+
GLU.QuadricDrawStyle(qobj, GLU::FILL); #/* smooth shaded */
|
91
|
+
GLU.QuadricNormals(qobj, GLU::SMOOTH);
|
92
|
+
GL.NewList($startList, GL::COMPILE);
|
93
|
+
GLU.Sphere(qobj, 0.75, 15, 10);
|
94
|
+
GL.EndList();
|
95
|
+
|
96
|
+
GLU.QuadricDrawStyle(qobj, GLU::FILL); #/* flat shaded */
|
97
|
+
GLU.QuadricNormals(qobj, GLU::FLAT);
|
98
|
+
GL.NewList($startList+1, GL::COMPILE);
|
99
|
+
GLU.Cylinder(qobj, 0.5, 0.3, 1.0, 15, 5);
|
100
|
+
GL.EndList();
|
101
|
+
|
102
|
+
GLU.QuadricDrawStyle(qobj, GLU::LINE); #/* all polygons wireframe */
|
103
|
+
GLU.QuadricNormals(qobj, GLU::NONE);
|
104
|
+
GL.NewList($startList+2, GL::COMPILE);
|
105
|
+
GLU.Disk(qobj, 0.25, 1.0, 20, 4);
|
106
|
+
GL.EndList();
|
107
|
+
|
108
|
+
GLU.QuadricDrawStyle(qobj, GLU::SILHOUETTE); #/* boundary only */
|
109
|
+
GLU.QuadricNormals(qobj, GLU::NONE);
|
110
|
+
GL.NewList($startList+3, GL::COMPILE);
|
111
|
+
GLU.PartialDisk(qobj, 0.0, 1.0, 20, 4, 0.0, 225.0);
|
112
|
+
GL.EndList();
|
113
|
+
end
|
114
|
+
|
115
|
+
display = Proc.new {
|
116
|
+
GL.Clear(GL::COLOR_BUFFER_BIT | GL::DEPTH_BUFFER_BIT);
|
117
|
+
GL.PushMatrix();
|
118
|
+
|
119
|
+
GL.Enable(GL::LIGHTING);
|
120
|
+
GL.ShadeModel(GL::SMOOTH);
|
121
|
+
GL.Translate(-1.0, -1.0, 0.0);
|
122
|
+
GL.CallList($startList);
|
123
|
+
|
124
|
+
GL.ShadeModel(GL::FLAT);
|
125
|
+
GL.Translate(0.0, 2.0, 0.0);
|
126
|
+
GL.PushMatrix();
|
127
|
+
GL.Rotate(300.0, 1.0, 0.0, 0.0);
|
128
|
+
GL.CallList($startList+1);
|
129
|
+
GL.PopMatrix();
|
130
|
+
|
131
|
+
GL.Disable(GL::LIGHTING);
|
132
|
+
GL.Color(0.0, 1.0, 1.0);
|
133
|
+
GL.Translate(2.0, -2.0, 0.0);
|
134
|
+
GL.CallList($startList+2);
|
135
|
+
|
136
|
+
GL.Color(1.0, 1.0, 0.0);
|
137
|
+
GL.Translate(0.0, 2.0, 0.0);
|
138
|
+
GL.CallList($startList+3);
|
139
|
+
|
140
|
+
GL.PopMatrix();
|
141
|
+
GL.Flush();
|
142
|
+
}
|
143
|
+
|
144
|
+
reshape = Proc.new {|w, h|
|
145
|
+
GL.Viewport(0, 0, w, h);
|
146
|
+
GL.MatrixMode(GL::PROJECTION);
|
147
|
+
GL.LoadIdentity();
|
148
|
+
if (w <= h)
|
149
|
+
GL.Ortho(-2.5, 2.5, -2.5*h/w,
|
150
|
+
2.5*h/w, -10.0, 10.0);
|
151
|
+
else
|
152
|
+
GL.Ortho(-2.5*w/h,
|
153
|
+
2.5*w/h, -2.5, 2.5, -10.0, 10.0);
|
154
|
+
end
|
155
|
+
GL.MatrixMode(GL::MODELVIEW);
|
156
|
+
GL.LoadIdentity();
|
157
|
+
}
|
158
|
+
|
159
|
+
#/* ARGSUSED1 */
|
160
|
+
keyboard = Proc.new {|key, x, y|
|
161
|
+
case (key)
|
162
|
+
when 27
|
163
|
+
exit(0);
|
164
|
+
end
|
165
|
+
}
|
166
|
+
|
167
|
+
#int main(int argc, char** argv)
|
168
|
+
#{
|
169
|
+
GLUT.Init
|
170
|
+
GLUT.InitDisplayMode(GLUT::SINGLE | GLUT::RGB | GLUT::DEPTH);
|
171
|
+
GLUT.InitWindowSize(500, 500);
|
172
|
+
GLUT.InitWindowPosition(100, 100);
|
173
|
+
GLUT.CreateWindow($0);
|
174
|
+
init();
|
175
|
+
GLUT.DisplayFunc(display);
|
176
|
+
GLUT.ReshapeFunc(reshape);
|
177
|
+
GLUT.KeyboardFunc(keyboard);
|
178
|
+
GLUT.MainLoop();
|
179
|
+
# return 0;
|
180
|
+
#}
|
@@ -0,0 +1,59 @@
|
|
1
|
+
require "gl_prev"
|
2
|
+
require "glu_prev"
|
3
|
+
require "glut_prev"
|
4
|
+
|
5
|
+
begin
|
6
|
+
require "RMagick"
|
7
|
+
rescue Exception
|
8
|
+
print "This sample needs RMagick Module.\n"
|
9
|
+
exit
|
10
|
+
end
|
11
|
+
|
12
|
+
WIDTH = 200
|
13
|
+
HEIGHT = 200
|
14
|
+
|
15
|
+
display = Proc.new {
|
16
|
+
GL.Clear(GL::COLOR_BUFFER_BIT);
|
17
|
+
|
18
|
+
GL.Begin(GL::LINES);
|
19
|
+
GL.Vertex(0.5, 0.5);
|
20
|
+
GL.Vertex(-0.5, -0.5);
|
21
|
+
GL.End
|
22
|
+
|
23
|
+
GL.Flush();
|
24
|
+
|
25
|
+
pixel_str = GL.ReadPixels(0, 0, WIDTH, HEIGHT, GL::RGBA, GL::SHORT)
|
26
|
+
pixels = pixel_str.unpack("s*")
|
27
|
+
|
28
|
+
image = Magick::Image.new(WIDTH, HEIGHT)
|
29
|
+
image.import_pixels(0, 0, WIDTH, HEIGHT, "RGBA", pixels)
|
30
|
+
image.flip!
|
31
|
+
# image.write("opengl_window.gif")
|
32
|
+
}
|
33
|
+
|
34
|
+
reshape = Proc.new {|w, h|
|
35
|
+
GL.Viewport(0, 0, w, h);
|
36
|
+
GL.MatrixMode(GL::PROJECTION);
|
37
|
+
GL.LoadIdentity();
|
38
|
+
if (w <= h)
|
39
|
+
GLU.Ortho2D(-1.0, 1.0, -h.to_f/w.to_f, h.to_f/w.to_f);
|
40
|
+
else
|
41
|
+
GLU.Ortho2D(w.to_f/h.to_f, w.to_f/h.to_f, -1.0, 1.0);
|
42
|
+
end
|
43
|
+
GL.MatrixMode(GL::MODELVIEW);
|
44
|
+
GL.LoadIdentity();
|
45
|
+
}
|
46
|
+
|
47
|
+
|
48
|
+
# Main Loop
|
49
|
+
# Open window with initial window size, title bar,
|
50
|
+
# color index display mode, and handle input events.
|
51
|
+
#
|
52
|
+
GLUT.Init
|
53
|
+
GLUT.InitDisplayMode(GLUT::SINGLE | GLUT::RGB | GLUT::ALPHA);
|
54
|
+
GLUT.InitWindowSize(WIDTH, HEIGHT);
|
55
|
+
GLUT.CreateWindow($0);
|
56
|
+
GLUT.ReshapeFunc(reshape);
|
57
|
+
GLUT.DisplayFunc(display);
|
58
|
+
GLUT.MainLoop
|
59
|
+
|
@@ -0,0 +1,120 @@
|
|
1
|
+
#/*
|
2
|
+
# * Copyright (c) 1993-1997, Silicon Graphics, Inc.
|
3
|
+
# * ALL RIGHTS RESERVED
|
4
|
+
# * Permission to use, copy, modify, and distribute this software for
|
5
|
+
# * any purpose and without fee is hereby granted, provided that the above
|
6
|
+
# * copyright notice appear in all copies and that both the copyright notice
|
7
|
+
# * and this permission notice appear in supporting documentation, and that
|
8
|
+
# * the name of Silicon Graphics, Inc. not be used in advertising
|
9
|
+
# * or publicity pertaining to distribution of the software without specific,
|
10
|
+
# * written prior permission.
|
11
|
+
# *
|
12
|
+
# * THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS"
|
13
|
+
# * AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE,
|
14
|
+
# * INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR
|
15
|
+
# * FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
|
16
|
+
# * GRAPHICS, INC. BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT,
|
17
|
+
# * SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY
|
18
|
+
# * KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION,
|
19
|
+
# * LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF
|
20
|
+
# * THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC. HAS BEEN
|
21
|
+
# * ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON
|
22
|
+
# * ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE
|
23
|
+
# * POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE.
|
24
|
+
# *
|
25
|
+
# * US Government Users Restricted Rights
|
26
|
+
# * Use, duplication, or disclosure by the Government is subject to
|
27
|
+
# * restrictions set forth in FAR 52.227.19(c)(2) or subparagraph
|
28
|
+
# * (c)(1)(ii) of the Rights in Technical Data and Computer Software
|
29
|
+
# * clause at DFARS 252.227-7013 and/or in similar or successor
|
30
|
+
# * clauses in the FAR or the DOD or NASA FAR Supplement.
|
31
|
+
# * Unpublished-- rights reserved under the copyright laws of the
|
32
|
+
# * United States. Contractor/manufacturer is Silicon Graphics,
|
33
|
+
# * Inc., 2011 N. Shoreline Blvd., Mountain View, CA 94039-7311.
|
34
|
+
# *
|
35
|
+
# * OpenGL(R) is a registered trademark of Silicon Graphics, Inc.
|
36
|
+
# */
|
37
|
+
#
|
38
|
+
#/*
|
39
|
+
# * robot.c
|
40
|
+
# * This program shows how to composite modeling transformations
|
41
|
+
# * to draw translated and rotated hierarchical models.
|
42
|
+
# * Interaction: pressing the s and e keys (shoulder and elbow)
|
43
|
+
# * alters the rotation of the robot arm.
|
44
|
+
# */
|
45
|
+
require "gl_prev"
|
46
|
+
require "glu_prev"
|
47
|
+
require "glut_prev"
|
48
|
+
require "mathn"
|
49
|
+
|
50
|
+
$shoulder = 0;
|
51
|
+
$elbow = 0;
|
52
|
+
|
53
|
+
def init
|
54
|
+
GL.ClearColor(0.0, 0.0, 0.0, 0.0);
|
55
|
+
GL.ShadeModel(GL::FLAT);
|
56
|
+
end
|
57
|
+
|
58
|
+
display = Proc.new {
|
59
|
+
GL.Clear(GL::COLOR_BUFFER_BIT);
|
60
|
+
GL.PushMatrix();
|
61
|
+
GL.Translate(-1.0, 0.0, 0.0);
|
62
|
+
GL.Rotate($shoulder, 0.0, 0.0, 1.0);
|
63
|
+
GL.Translate(1.0, 0.0, 0.0);
|
64
|
+
GL.PushMatrix();
|
65
|
+
GL.Scale(2.0, 0.4, 1.0);
|
66
|
+
GLUT.WireCube (1.0);
|
67
|
+
GL.PopMatrix();
|
68
|
+
|
69
|
+
GL.Translate(1.0, 0.0, 0.0);
|
70
|
+
GL.Rotate($elbow, 0.0, 0.0, 1.0);
|
71
|
+
GL.Translate(1.0, 0.0, 0.0);
|
72
|
+
GL.PushMatrix();
|
73
|
+
GL.Scale(2.0, 0.4, 1.0);
|
74
|
+
GLUT.WireCube(1.0);
|
75
|
+
GL.PopMatrix();
|
76
|
+
|
77
|
+
GL.PopMatrix();
|
78
|
+
GLUT.SwapBuffers();
|
79
|
+
}
|
80
|
+
|
81
|
+
reshape = Proc.new {|w, h|
|
82
|
+
GL.Viewport(0, 0, w, h);
|
83
|
+
GL.MatrixMode(GL::PROJECTION);
|
84
|
+
GL.LoadIdentity();
|
85
|
+
GLU.Perspective(65.0, w/ h, 1.0, 20.0);
|
86
|
+
GL.MatrixMode(GL::MODELVIEW);
|
87
|
+
GL.LoadIdentity();
|
88
|
+
GL.Translate(0.0, 0.0, -5.0);
|
89
|
+
}
|
90
|
+
|
91
|
+
#/* ARGSUSED1 */
|
92
|
+
keyboard = Proc.new {|key, x, y|
|
93
|
+
case (key)
|
94
|
+
when 's'[0]
|
95
|
+
$shoulder = ($shoulder + 5) % 360;
|
96
|
+
GLUT.PostRedisplay();
|
97
|
+
when 'S'[0]
|
98
|
+
$shoulder = ($shoulder - 5) % 360;
|
99
|
+
GLUT.PostRedisplay();
|
100
|
+
when 'e'[0]
|
101
|
+
$elbow = ($elbow + 5) % 360;
|
102
|
+
GLUT.PostRedisplay();
|
103
|
+
when 'E'[0]
|
104
|
+
$elbow = ($elbow - 5) % 360;
|
105
|
+
GLUT.PostRedisplay();
|
106
|
+
when 27
|
107
|
+
exit(0);
|
108
|
+
end
|
109
|
+
}
|
110
|
+
|
111
|
+
GLUT.Init
|
112
|
+
GLUT.InitDisplayMode(GLUT::DOUBLE | GLUT::RGB);
|
113
|
+
GLUT.InitWindowSize(500, 500);
|
114
|
+
GLUT.InitWindowPosition(100, 100);
|
115
|
+
GLUT.CreateWindow($0);
|
116
|
+
init();
|
117
|
+
GLUT.DisplayFunc(display);
|
118
|
+
GLUT.ReshapeFunc(reshape);
|
119
|
+
GLUT.KeyboardFunc(keyboard);
|
120
|
+
GLUT.MainLoop();
|