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,128 @@
|
|
1
|
+
#
|
2
|
+
#/* Copyright (c) Mark J. Kilgard, 1994. */
|
3
|
+
#
|
4
|
+
#/*
|
5
|
+
# * (c) Copyright 1993, Silicon Graphics, Inc.
|
6
|
+
# * ALL RIGHTS RESERVED
|
7
|
+
# * Permission to use, copy, modify, and distribute this software for
|
8
|
+
# * any purpose and without fee is hereby granted, provided that the above
|
9
|
+
# * copyright notice appear in all copies and that both the copyright notice
|
10
|
+
# * and this permission notice appear in supporting documentation, and that
|
11
|
+
# * the name of Silicon Graphics, Inc. not be used in advertising
|
12
|
+
# * or publicity pertaining to distribution of the software without specific,
|
13
|
+
# * written prior permission.
|
14
|
+
# *
|
15
|
+
# * THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS"
|
16
|
+
# * AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE,
|
17
|
+
# * INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR
|
18
|
+
# * FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
|
19
|
+
# * GRAPHICS, INC. BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT,
|
20
|
+
# * SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY
|
21
|
+
# * KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION,
|
22
|
+
# * LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF
|
23
|
+
# * THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC. HAS BEEN
|
24
|
+
# * ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON
|
25
|
+
# * ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE
|
26
|
+
# * POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE.
|
27
|
+
# *
|
28
|
+
# * US Government Users Restricted Rights
|
29
|
+
# * Use, duplication, or disclosure by the Government is subject to
|
30
|
+
# * restrictions set forth in FAR 52.227.19(c)(2) or subparagraph
|
31
|
+
# * (c)(1)(ii) of the Rights in Technical Data and Computer Software
|
32
|
+
# * clause at DFARS 252.227-7013 and/or in similar or successor
|
33
|
+
# * clauses in the FAR or the DOD or NASA FAR Supplement.
|
34
|
+
# * Unpublished-- rights reserved under the copyright laws of the
|
35
|
+
# * United States. Contractor/manufacturer is Silicon Graphics,
|
36
|
+
# * Inc., 2011 N. Shoreline Blvd., Mountain View, CA 94039-7311.
|
37
|
+
# *
|
38
|
+
# * OpenGL(TM) is a trademark of Silicon Graphics, Inc.
|
39
|
+
# */
|
40
|
+
#/* texturesurf.c
|
41
|
+
# * This program uses evaluators to generate a curved
|
42
|
+
# * surface and automatically generated texture coordinates.
|
43
|
+
# */
|
44
|
+
#
|
45
|
+
require "gl_prev"
|
46
|
+
require "glu_prev"
|
47
|
+
require "glut_prev"
|
48
|
+
|
49
|
+
$ctrlpoints = [
|
50
|
+
[[ -1.5, -1.5, 4.0], [ -0.5, -1.5, 2.0],
|
51
|
+
[0.5, -1.5, -1.0], [1.5, -1.5, 2.0]],
|
52
|
+
[[ -1.5, -0.5, 1.0], [ -0.5, -0.5, 3.0],
|
53
|
+
[0.5, -0.5, 0.0], [1.5, -0.5, -1.0]],
|
54
|
+
[[ -1.5, 0.5, 4.0], [ -0.5, 0.5, 0.0],
|
55
|
+
[0.5, 0.5, 3.0], [1.5, 0.5, 4.0]],
|
56
|
+
[[ -1.5, 1.5, -2.0], [ -0.5, 1.5, -2.0],
|
57
|
+
[0.5, 1.5, 0.0], [1.5, 1.5, -1.0]]
|
58
|
+
].flatten;
|
59
|
+
|
60
|
+
$texpts = [[[0.0, 0.0], [0.0, 1.0]], [[1.0, 0.0], [1.0, 1.0]]].flatten;
|
61
|
+
|
62
|
+
display = proc {
|
63
|
+
GL::Clear(GL::COLOR_BUFFER_BIT | GL::DEPTH_BUFFER_BIT);
|
64
|
+
GL::Color(1.0, 1.0, 1.0);
|
65
|
+
GL::EvalMesh2(GL::FILL, 0, 20, 0, 20);
|
66
|
+
GL::Flush();
|
67
|
+
}
|
68
|
+
|
69
|
+
ImageWidth=64
|
70
|
+
ImageHeight=64
|
71
|
+
$image = []
|
72
|
+
|
73
|
+
def makeImage
|
74
|
+
for i in 0...ImageWidth
|
75
|
+
ti = 2.0*3.14159265*i/ImageWidth.to_f;
|
76
|
+
for j in 0...ImageHeight
|
77
|
+
tj = 2.0*3.14159265*j/ImageHeight.to_f;
|
78
|
+
|
79
|
+
$image[3*(ImageHeight*i+j)] = 127*(1.0+Math::sin(ti));
|
80
|
+
$image[3*(ImageHeight*i+j)+1] = 127*(1.0+Math::cos(2*tj));
|
81
|
+
$image[3*(ImageHeight*i+j)+2] = 127*(1.0+Math::cos(ti+tj));
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
def myinit
|
87
|
+
GL::Map2d(GL::MAP2_VERTEX_3, 0, 1, 3, 4,
|
88
|
+
0, 1, 12, 4, $ctrlpoints);
|
89
|
+
GL::Map2d(GL::MAP2_TEXTURE_COORD_2, 0, 1, 2, 2,
|
90
|
+
0, 1, 4, 2, $texpts);
|
91
|
+
GL::Enable(GL::MAP2_TEXTURE_COORD_2);
|
92
|
+
GL::Enable(GL::MAP2_VERTEX_3);
|
93
|
+
GL::MapGrid2d(20, 0.0, 1.0, 20, 0.0, 1.0);
|
94
|
+
makeImage();
|
95
|
+
GL::TexEnv(GL::TEXTURE_ENV, GL::TEXTURE_ENV_MODE, GL::DECAL);
|
96
|
+
GL::TexParameter(GL::TEXTURE_2D, GL::TEXTURE_WRAP_S, GL::REPEAT);
|
97
|
+
GL::TexParameter(GL::TEXTURE_2D, GL::TEXTURE_WRAP_T, GL::REPEAT);
|
98
|
+
GL::TexParameter(GL::TEXTURE_2D, GL::TEXTURE_MAG_FILTER, GL::NEAREST);
|
99
|
+
GL::TexParameter(GL::TEXTURE_2D, GL::TEXTURE_MIN_FILTER, GL::NEAREST);
|
100
|
+
GL::TexImage2D(GL::TEXTURE_2D, 0, 3, ImageWidth, ImageHeight, 0,
|
101
|
+
GL::RGB, GL::UNSIGNED_BYTE, $image.pack("C*"));
|
102
|
+
GL::Enable(GL::TEXTURE_2D);
|
103
|
+
GL::Enable(GL::DEPTH_TEST);
|
104
|
+
GL::Enable(GL::NORMALIZE);
|
105
|
+
GL::ShadeModel(GL::FLAT);
|
106
|
+
end
|
107
|
+
|
108
|
+
myReshape = proc {|w, h|
|
109
|
+
GL::Viewport(0, 0, w, h);
|
110
|
+
GL::MatrixMode(GL::PROJECTION);
|
111
|
+
GL::LoadIdentity();
|
112
|
+
if (w <= h)
|
113
|
+
GL::Ortho(-4.0, 4.0, -4.0*h.to_f/w, 4.0*h.to_f/w, -4.0, 4.0);
|
114
|
+
else
|
115
|
+
GL::Ortho(-4.0*w.to_f/h, 4.0*w.to_f/h, -4.0, 4.0, -4.0, 4.0);
|
116
|
+
end
|
117
|
+
GL::MatrixMode(GL::MODELVIEW);
|
118
|
+
GL::LoadIdentity();
|
119
|
+
GL::Rotate(85.0, 1.0, 1.0, 1.0);
|
120
|
+
}
|
121
|
+
|
122
|
+
GLUT::Init();
|
123
|
+
GLUT::InitDisplayMode(GLUT::SINGLE | GLUT::RGB | GLUT::DEPTH);
|
124
|
+
GLUT::CreateWindow();
|
125
|
+
myinit();
|
126
|
+
GLUT::ReshapeFunc(myReshape);
|
127
|
+
GLUT::DisplayFunc(display);
|
128
|
+
GLUT::MainLoop();
|
@@ -0,0 +1,167 @@
|
|
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
|
+
# * varray.c
|
40
|
+
# * This program demonstrates vertex arrays.
|
41
|
+
# */
|
42
|
+
|
43
|
+
require "gl_prev"
|
44
|
+
require "glu_prev"
|
45
|
+
require "glut_prev"
|
46
|
+
|
47
|
+
POINTER=1
|
48
|
+
INTERLEAVED=2
|
49
|
+
|
50
|
+
DRAWARRAY=1
|
51
|
+
ARRAYELEMENT=2
|
52
|
+
DRAWELEMENTS=3
|
53
|
+
|
54
|
+
$setupMethod = POINTER;
|
55
|
+
$derefMethod = DRAWARRAY;
|
56
|
+
|
57
|
+
def setupPointers
|
58
|
+
$vertices = [25, 25,
|
59
|
+
100, 325,
|
60
|
+
175, 25,
|
61
|
+
175, 325,
|
62
|
+
250, 25,
|
63
|
+
325, 325].pack("i*");
|
64
|
+
$colors = [1.0, 0.2, 0.2,
|
65
|
+
0.2, 0.2, 1.0,
|
66
|
+
0.8, 1.0, 0.2,
|
67
|
+
0.75, 0.75, 0.75,
|
68
|
+
0.35, 0.35, 0.35,
|
69
|
+
0.5, 0.5, 0.5].pack("f*");
|
70
|
+
|
71
|
+
GL.EnableClientState(GL::VERTEX_ARRAY);
|
72
|
+
GL.EnableClientState(GL::COLOR_ARRAY);
|
73
|
+
|
74
|
+
GL.VertexPointer(2, GL::INT, 0, $vertices);
|
75
|
+
GL.ColorPointer(3, GL::FLOAT, 0, $colors);
|
76
|
+
end
|
77
|
+
|
78
|
+
def setupInterleave
|
79
|
+
$intertwined =
|
80
|
+
[1.0, 0.2, 1.0, 100.0, 100.0, 0.0,
|
81
|
+
1.0, 0.2, 0.2, 0.0, 200.0, 0.0,
|
82
|
+
1.0, 1.0, 0.2, 100.0, 300.0, 0.0,
|
83
|
+
0.2, 1.0, 0.2, 200.0, 300.0, 0.0,
|
84
|
+
0.2, 1.0, 1.0, 300.0, 200.0, 0.0,
|
85
|
+
0.2, 0.2, 1.0, 200.0, 100.0, 0.0].pack("f*");
|
86
|
+
|
87
|
+
GL.InterleavedArrays(GL::C3F_V3F, 0, $intertwined);
|
88
|
+
end
|
89
|
+
|
90
|
+
def init
|
91
|
+
GL.ClearColor(0.0, 0.0, 0.0, 0.0);
|
92
|
+
GL.ShadeModel(GL::SMOOTH);
|
93
|
+
setupPointers();
|
94
|
+
end
|
95
|
+
|
96
|
+
display = proc {
|
97
|
+
GL.Clear(GL::COLOR_BUFFER_BIT);
|
98
|
+
|
99
|
+
if ($derefMethod == DRAWARRAY)
|
100
|
+
GL.DrawArrays(GL::TRIANGLES, 0, 6);
|
101
|
+
elsif ($derefMethod == ARRAYELEMENT)
|
102
|
+
GL.Begin(GL::TRIANGLES);
|
103
|
+
GL.ArrayElement(2);
|
104
|
+
GL.ArrayElement(3);
|
105
|
+
GL.ArrayElement(5);
|
106
|
+
GL.End();
|
107
|
+
elsif ($derefMethod == DRAWELEMENTS)
|
108
|
+
$indices = [0, 1, 3, 4].pack("I*")
|
109
|
+
GL.DrawElements(GL::POLYGON, 4, GL::UNSIGNED_INT, $indices);
|
110
|
+
end
|
111
|
+
GL.Flush();
|
112
|
+
}
|
113
|
+
|
114
|
+
reshape = proc {|w, h|
|
115
|
+
GL.Viewport(0, 0, w, h);
|
116
|
+
GL.MatrixMode(GL::PROJECTION);
|
117
|
+
GL.LoadIdentity();
|
118
|
+
GLU.Ortho2D(0.0, w, 0.0, h);
|
119
|
+
}
|
120
|
+
|
121
|
+
#/* ARGSUSED2 */
|
122
|
+
mouse = proc {|button, state, x, y|
|
123
|
+
case (button)
|
124
|
+
when GLUT::LEFT_BUTTON
|
125
|
+
if (state == GLUT::DOWN)
|
126
|
+
if ($setupMethod == POINTER)
|
127
|
+
$setupMethod = INTERLEAVED;
|
128
|
+
setupInterleave();
|
129
|
+
elsif ($setupMethod == INTERLEAVED)
|
130
|
+
$setupMethod = POINTER;
|
131
|
+
setupPointers();
|
132
|
+
end
|
133
|
+
GLUT.PostRedisplay();
|
134
|
+
end
|
135
|
+
when GLUT::MIDDLE_BUTTON,GLUT::RIGHT_BUTTON
|
136
|
+
if (state == GLUT::DOWN)
|
137
|
+
if ($derefMethod == DRAWARRAY)
|
138
|
+
$derefMethod = ARRAYELEMENT;
|
139
|
+
elsif ($derefMethod == ARRAYELEMENT)
|
140
|
+
$derefMethod = DRAWELEMENTS;
|
141
|
+
elsif ($derefMethod == DRAWELEMENTS)
|
142
|
+
$derefMethod = DRAWARRAY;
|
143
|
+
end
|
144
|
+
GLUT.PostRedisplay();
|
145
|
+
end
|
146
|
+
end
|
147
|
+
}
|
148
|
+
|
149
|
+
#/* ARGSUSED1 */
|
150
|
+
keyboard = proc {|key, x, y|
|
151
|
+
case (key)
|
152
|
+
when 27
|
153
|
+
exit(0);
|
154
|
+
end
|
155
|
+
}
|
156
|
+
|
157
|
+
GLUT.Init();
|
158
|
+
GLUT.InitDisplayMode(GLUT::SINGLE | GLUT::RGB);
|
159
|
+
GLUT.InitWindowSize(350, 350);
|
160
|
+
GLUT.InitWindowPosition(100, 100);
|
161
|
+
GLUT.CreateWindow()
|
162
|
+
init();
|
163
|
+
GLUT.DisplayFunc(display);
|
164
|
+
GLUT.ReshapeFunc(reshape);
|
165
|
+
GLUT.MouseFunc(mouse);
|
166
|
+
GLUT.KeyboardFunc(keyboard);
|
167
|
+
GLUT.MainLoop();
|
@@ -0,0 +1,158 @@
|
|
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
|
+
#/* wrap.c
|
39
|
+
# * This program texture maps a checkerboard image onto
|
40
|
+
# * two rectangles. This program demonstrates the wrapping
|
41
|
+
# * modes, if the texture coordinates fall outside 0.0 and 1.0.
|
42
|
+
# * Interaction: Pressing the 's' and 'S' keys switch the
|
43
|
+
# * wrapping between clamping and repeating for the s parameter.
|
44
|
+
# * The 't' and 'T' keys control the wrapping for the t parameter.
|
45
|
+
# *
|
46
|
+
# * If running this program on OpenGL 1.0, texture objects are
|
47
|
+
# * not used.
|
48
|
+
# */
|
49
|
+
|
50
|
+
require "gl_prev"
|
51
|
+
require "glu_prev"
|
52
|
+
require "glut_prev"
|
53
|
+
require "mathn"
|
54
|
+
|
55
|
+
#/* Create checkerboard texture */
|
56
|
+
CheckImageWidth=64
|
57
|
+
CheckImageHeight=64
|
58
|
+
$checkImage = []
|
59
|
+
|
60
|
+
$texName = 0;
|
61
|
+
|
62
|
+
def makeCheckImage
|
63
|
+
for i in 0..CheckImageHeight-1
|
64
|
+
for j in 0..CheckImageWidth-1
|
65
|
+
c = if (((i&0x8)==0)!=((j&0x8)==0)) then 255; else 0; end;
|
66
|
+
$checkImage[(i*CheckImageWidth+j)*4+0] = c;
|
67
|
+
$checkImage[(i*CheckImageWidth+j)*4+1] = c;
|
68
|
+
$checkImage[(i*CheckImageWidth+j)*4+2] = c;
|
69
|
+
$checkImage[(i*CheckImageWidth+j)*4+3] = 255;
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
def init
|
75
|
+
GL.ClearColor(0.0, 0.0, 0.0, 0.0);
|
76
|
+
GL.ShadeModel(GL::FLAT);
|
77
|
+
GL.Enable(GL::DEPTH_TEST);
|
78
|
+
|
79
|
+
makeCheckImage();
|
80
|
+
GL.PixelStore(GL::UNPACK_ALIGNMENT, 1);
|
81
|
+
|
82
|
+
$texName = GL.GenTextures(1);
|
83
|
+
GL.BindTexture(GL::TEXTURE_2D, $texName[0]);
|
84
|
+
|
85
|
+
GL.TexParameter(GL::TEXTURE_2D, GL::TEXTURE_WRAP_S, GL::REPEAT);
|
86
|
+
GL.TexParameter(GL::TEXTURE_2D, GL::TEXTURE_WRAP_T, GL::REPEAT);
|
87
|
+
GL.TexParameter(GL::TEXTURE_2D, GL::TEXTURE_MAG_FILTER, GL::NEAREST);
|
88
|
+
GL.TexParameter(GL::TEXTURE_2D, GL::TEXTURE_MIN_FILTER, GL::NEAREST);
|
89
|
+
GL.TexImage2D(GL::TEXTURE_2D, 0, GL::RGBA, CheckImageWidth,
|
90
|
+
CheckImageHeight,
|
91
|
+
0, GL::RGBA, GL::UNSIGNED_BYTE, $checkImage.pack("C*"));
|
92
|
+
end
|
93
|
+
|
94
|
+
display = Proc.new {
|
95
|
+
GL.Clear(GL::COLOR_BUFFER_BIT | GL::DEPTH_BUFFER_BIT);
|
96
|
+
GL.Enable(GL::TEXTURE_2D);
|
97
|
+
GL.TexEnvf(GL::TEXTURE_ENV, GL::TEXTURE_ENV_MODE, GL::DECAL);
|
98
|
+
GL.BindTexture(GL::TEXTURE_2D, $texName[0]);
|
99
|
+
|
100
|
+
GL.Begin(GL::QUADS);
|
101
|
+
GL.TexCoord(0.0, 0.0); GL.Vertex(-2.0, -1.0, 0.0);
|
102
|
+
GL.TexCoord(0.0, 3.0); GL.Vertex(-2.0, 1.0, 0.0);
|
103
|
+
GL.TexCoord(3.0, 3.0); GL.Vertex(0.0, 1.0, 0.0);
|
104
|
+
GL.TexCoord(3.0, 0.0); GL.Vertex(0.0, -1.0, 0.0);
|
105
|
+
|
106
|
+
GL.TexCoord(0.0, 0.0); GL.Vertex(1.0, -1.0, 0.0);
|
107
|
+
GL.TexCoord(0.0, 3.0); GL.Vertex(1.0, 1.0, 0.0);
|
108
|
+
GL.TexCoord(3.0, 3.0); GL.Vertex(2.41421, 1.0, -1.41421);
|
109
|
+
GL.TexCoord(3.0, 0.0); GL.Vertex(2.41421, -1.0, -1.41421);
|
110
|
+
GL.End();
|
111
|
+
GL.Flush();
|
112
|
+
GL.Disable(GL::TEXTURE_2D);
|
113
|
+
}
|
114
|
+
|
115
|
+
reshape = Proc.new {|w, h|
|
116
|
+
GL.Viewport(0, 0, w, h);
|
117
|
+
GL.MatrixMode(GL::PROJECTION);
|
118
|
+
GL.LoadIdentity();
|
119
|
+
GLU.Perspective(60.0, w/h, 1.0, 30.0);
|
120
|
+
GL.MatrixMode(GL::MODELVIEW);
|
121
|
+
GL.LoadIdentity();
|
122
|
+
GL.Translate(0.0, 0.0, -3.6);
|
123
|
+
}
|
124
|
+
|
125
|
+
#/* ARGSUSED1 */
|
126
|
+
keyboard = Proc.new {|key, x, y|
|
127
|
+
case (key)
|
128
|
+
when 's'[0]
|
129
|
+
GL.TexParameter(GL::TEXTURE_2D, GL::TEXTURE_WRAP_S, GL::CLAMP);
|
130
|
+
GLUT.PostRedisplay();
|
131
|
+
when 'S'[0]
|
132
|
+
GL.TexParameter(GL::TEXTURE_2D, GL::TEXTURE_WRAP_S, GL::REPEAT);
|
133
|
+
GLUT.PostRedisplay();
|
134
|
+
when 't'[0]
|
135
|
+
GL.TexParameter(GL::TEXTURE_2D, GL::TEXTURE_WRAP_T, GL::CLAMP);
|
136
|
+
GLUT.PostRedisplay();
|
137
|
+
when 'T'[0]
|
138
|
+
GL.TexParameter(GL::TEXTURE_2D, GL::TEXTURE_WRAP_T, GL::REPEAT);
|
139
|
+
GLUT.PostRedisplay();
|
140
|
+
when 27
|
141
|
+
exit(0);
|
142
|
+
end
|
143
|
+
}
|
144
|
+
|
145
|
+
#int main(int argc, char** argv)
|
146
|
+
#{
|
147
|
+
GLUT.Init
|
148
|
+
GLUT.InitDisplayMode(GLUT::SINGLE | GLUT::RGB | GLUT::DEPTH);
|
149
|
+
GLUT.InitWindowSize(250, 250);
|
150
|
+
GLUT.InitWindowPosition(100, 100);
|
151
|
+
GLUT.CreateWindow($0);
|
152
|
+
init();
|
153
|
+
GLUT.DisplayFunc(display);
|
154
|
+
GLUT.ReshapeFunc(reshape);
|
155
|
+
GLUT.KeyboardFunc(keyboard);
|
156
|
+
GLUT.MainLoop();
|
157
|
+
# return 0;
|
158
|
+
#}
|