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.
Files changed (103) hide show
  1. data/Rakefile +42 -15
  2. data/doc/build_install.txt +70 -25
  3. data/doc/history.txt +4 -0
  4. data/doc/requirements_and_design.txt +2 -3
  5. data/doc/roadmap.txt +15 -2
  6. data/doc/screenshots.txt +23 -0
  7. data/doc/supplies/page_template.html +2 -1
  8. data/doc/thanks.txt +3 -0
  9. data/doc/tutorial.txt +5 -3
  10. data/examples/README +57 -7
  11. data/examples/legacy/COPYRIGHT +8 -0
  12. data/examples/{aaindex.rb → legacy/aaindex.rb} +6 -5
  13. data/examples/legacy/aapoly.rb +153 -0
  14. data/examples/legacy/aargb.rb +139 -0
  15. data/examples/legacy/accanti.rb +159 -0
  16. data/examples/legacy/accpersp.rb +216 -0
  17. data/examples/legacy/alpha.rb +133 -0
  18. data/examples/legacy/alpha3D.rb +165 -0
  19. data/examples/legacy/bezcurve.rb +107 -0
  20. data/examples/legacy/bezmesh.rb +131 -0
  21. data/examples/legacy/checker.rb +121 -0
  22. data/examples/legacy/clip.rb +104 -0
  23. data/examples/legacy/colormat.rb +145 -0
  24. data/examples/legacy/cube.rb +73 -0
  25. data/examples/legacy/depthcue.rb +101 -0
  26. data/examples/legacy/dof.rb +212 -0
  27. data/examples/legacy/double.rb +104 -0
  28. data/examples/legacy/drawf.rb +98 -0
  29. data/examples/legacy/feedback.rb +152 -0
  30. data/examples/legacy/fog.rb +172 -0
  31. data/examples/legacy/font-glut.rb +41 -0
  32. data/examples/legacy/font.rb +158 -0
  33. data/examples/legacy/hello.rb +75 -0
  34. data/examples/legacy/image.rb +145 -0
  35. data/examples/legacy/jitter.rb +209 -0
  36. data/examples/legacy/lines.rb +135 -0
  37. data/examples/legacy/list.rb +120 -0
  38. data/examples/legacy/material.rb +290 -0
  39. data/examples/legacy/mipmap.rb +159 -0
  40. data/examples/legacy/model.rb +119 -0
  41. data/examples/legacy/movelight.rb +140 -0
  42. data/examples/legacy/pickdepth.rb +180 -0
  43. data/examples/legacy/planet.rb +112 -0
  44. data/examples/legacy/quadric.rb +180 -0
  45. data/examples/legacy/readpixel.rb +59 -0
  46. data/examples/legacy/robot.rb +120 -0
  47. data/examples/legacy/select.rb +207 -0
  48. data/examples/{smooth_prev.rb → legacy/smooth.rb} +3 -2
  49. data/examples/legacy/stencil.rb +154 -0
  50. data/examples/legacy/stroke.rb +170 -0
  51. data/examples/legacy/surface.rb +170 -0
  52. data/examples/legacy/teaambient.rb +132 -0
  53. data/examples/legacy/teapots.rb +188 -0
  54. data/examples/legacy/tess.rb +222 -0
  55. data/examples/legacy/texbind.rb +157 -0
  56. data/examples/legacy/texgen.rb +171 -0
  57. data/examples/legacy/texturesurf.rb +128 -0
  58. data/examples/legacy/varray.rb +167 -0
  59. data/examples/legacy/wrap.rb +158 -0
  60. data/examples/nehe_lesson02.rb +117 -0
  61. data/examples/nehe_lesson03.rb +122 -0
  62. data/examples/nehe_lesson04.rb +133 -0
  63. data/examples/nehe_lesson05.rb +186 -0
  64. data/examples/plane.rb +1 -1
  65. data/examples/smooth.rb +4 -2
  66. data/examples/test.rb +3 -2
  67. data/ext/common/{rbogl.c → common.h} +99 -32
  68. data/ext/common/gl-enums.h +39 -1
  69. data/ext/gl/gl-1.0-1.1.c +350 -305
  70. data/ext/gl/gl-1.2.c +933 -38
  71. data/ext/gl/gl-1.3.c +725 -0
  72. data/ext/gl/gl-1.4.c +647 -0
  73. data/ext/gl/gl-1.5.c +362 -0
  74. data/ext/gl/gl-2.0.c +1632 -0
  75. data/ext/gl/gl-2.1.c +154 -0
  76. data/ext/gl/gl-enums.c +1 -2
  77. data/ext/gl/gl.c +58 -2
  78. data/ext/gl/mkrf_conf.rb +4 -1
  79. data/ext/glu/glu.c +5 -4
  80. data/ext/glu/mkrf_conf.rb +4 -1
  81. data/ext/glut/glut.c +7 -1
  82. data/ext/glut/mkrf_conf.rb +5 -0
  83. data/lib/gl_prev.rb +4 -3
  84. data/lib/glu_prev.rb +4 -3
  85. data/lib/glut_prev.rb +3 -3
  86. data/{examples/all_tests.rb → lib/opengl.rb} +9 -12
  87. data/test/README +5 -18
  88. data/test/tc_common.rb +79 -0
  89. data/test/tc_func_10_11.rb +1255 -0
  90. data/test/tc_func_12.rb +186 -0
  91. data/test/tc_func_13.rb +203 -0
  92. data/test/tc_func_14.rb +197 -0
  93. data/test/tc_func_15.rb +82 -0
  94. data/test/tc_func_20.rb +320 -0
  95. data/test/tc_func_21.rb +67 -0
  96. data/test/tc_include_gl.rb +1 -1
  97. data/test/{tc_opengl_namespace.rb → tc_misc.rb} +20 -20
  98. data/test/tc_require_gl.rb +1 -1
  99. metadata +99 -27
  100. data/ext/common/Rakefile +0 -39
  101. data/ext/common/rbogl.h +0 -52
  102. data/test/runtests.sh +0 -7
  103. data/test/tc_gl_vertex.rb +0 -180
@@ -0,0 +1,222 @@
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
+ # * tess.c
40
+ # * This program demonstrates polygon tessellation.
41
+ # * Two tesselated objects are drawn. The first is a
42
+ # * rectangle with a triangular hole. The second is a
43
+ # * smooth shaded, self-intersecting star.
44
+ # *
45
+ # * Note the exterior rectangle is drawn with its vertices
46
+ # * in counter-clockwise order, but its interior clockwise.
47
+ # * Note the combineCallback is needed for the self-intersecting
48
+ # * star. Also note that removing the TessProperty for the
49
+ # * star will make the interior unshaded (WINDING_ODD).
50
+ # */
51
+
52
+ require "gl_prev"
53
+ require "glu_prev"
54
+ require "glut_prev"
55
+
56
+ $startList = nil;
57
+
58
+ display = proc {
59
+ GL::Clear(GL::COLOR_BUFFER_BIT);
60
+ GL::Color(1.0, 1.0, 1.0);
61
+ GL::CallList($startList);
62
+ GL::CallList($startList + 1);
63
+ GL::Flush();
64
+ }
65
+
66
+ $beginCallback = proc {|which|
67
+ GL::Begin(which);
68
+ }
69
+
70
+ $errorCallback = proc {|errorCode|
71
+ print "Tessellation Error: #{GLU::ErrorString(errorCode)}";
72
+ exit(0);
73
+ }
74
+
75
+ $endCallback = proc {
76
+ GL::End();
77
+ }
78
+
79
+ $vertexCallback = proc {|vertex|
80
+ GL::Color(vertex[3], vertex[4], vertex[5]);
81
+ GL::Vertex(vertex[0], vertex[1], vertex[2]);
82
+ }
83
+
84
+ #/* combineCallback is used to create a new vertex when edges
85
+ # * intersect. coordinate location is trivial to calculate,
86
+ # * but weight[4] may be used to average color, normal, or texture
87
+ # * coordinate data. In this program, color is weighted.
88
+ # */
89
+ $combineCallback = proc {|coords, vertex_data, weight|
90
+ vertex = []
91
+ vertex[0] = coords[0];
92
+ vertex[1] = coords[1];
93
+ vertex[2] = coords[2];
94
+ for i in 3...6
95
+ vertex[i] = weight[0] * vertex_data[0][i] + weight[1] * vertex_data[1][i] + weight[2] * vertex_data[2][i] + weight[3] * vertex_data[3][i];
96
+ end
97
+ vertex
98
+ }
99
+
100
+ def init
101
+ rect = [[50.0, 50.0, 0.0],
102
+ [200.0, 50.0, 0.0],
103
+ [200.0, 200.0, 0.0],
104
+ [50.0, 200.0, 0.0]];
105
+ tri = [[75.0, 75.0, 0.0],
106
+ [125.0, 175.0, 0.0],
107
+ [175.0, 75.0, 0.0]];
108
+ star= [[250.0, 50.0, 0.0, 1.0, 0.0, 1.0],
109
+ [325.0, 200.0, 0.0, 1.0, 1.0, 0.0],
110
+ [400.0, 50.0, 0.0, 0.0, 1.0, 1.0],
111
+ [250.0, 150.0, 0.0, 1.0, 0.0, 0.0],
112
+ [400.0, 150.0, 0.0, 0.0, 1.0, 0.0]];
113
+
114
+ GL::ClearColor(0.0, 0.0, 0.0, 0.0);
115
+
116
+ $startList = GL::GenLists(2);
117
+
118
+ tobj = GLU::NewTess();
119
+ p "1"
120
+ GLU::TessCallback(tobj, GLU::TESS_VERTEX,
121
+ proc {|v| GL::Vertex(v)})
122
+ p "2"
123
+ GLU::TessCallback(tobj, GLU::TESS_BEGIN,
124
+ $beginCallback);
125
+ p "3"
126
+ GLU::TessCallback(tobj, GLU::TESS_END,
127
+ $endCallback);
128
+ p "4"
129
+ GLU::TessCallback(tobj, GLU::TESS_ERROR,
130
+ $errorCallback);
131
+
132
+ # /* rectangle with triangular hole inside */
133
+ p "5"
134
+ GL::NewList($startList, GL::COMPILE);
135
+ GL::ShadeModel(GL::FLAT);
136
+ GLU::TessBeginPolygon(tobj, nil);
137
+ p "5.1"
138
+ GLU::TessBeginContour(tobj);
139
+ GLU::TessVertex(tobj, rect[0], rect[0]);
140
+ GLU::TessVertex(tobj, rect[1], rect[1]);
141
+ GLU::TessVertex(tobj, rect[2], rect[2]);
142
+ GLU::TessVertex(tobj, rect[3], rect[3]);
143
+ GLU::TessEndContour(tobj);
144
+ GLU::TessEndPolygon(tobj);
145
+ p "5.2"
146
+ GLU::TessBeginPolygon(tobj, nil);
147
+ GLU::TessBeginContour(tobj);
148
+ GLU::TessVertex(tobj, tri[0], tri[0]);
149
+ GLU::TessVertex(tobj, tri[1], tri[1]);
150
+ GLU::TessVertex(tobj, tri[2], tri[2]);
151
+ GLU::TessEndContour(tobj);
152
+ p "5.3"
153
+ GLU::TessEndPolygon(tobj);
154
+ p "5.4"
155
+ GL::EndList();
156
+ p "6"
157
+
158
+ GLU::TessCallback(tobj, GLU::TESS_VERTEX,
159
+ $vertexCallback);
160
+ p "7"
161
+ GLU::TessCallback(tobj, GLU::TESS_BEGIN,
162
+ $beginCallback);
163
+ p "8"
164
+ GLU::TessCallback(tobj, GLU::TESS_END,
165
+ $endCallback);
166
+ p "9"
167
+ GLU::TessCallback(tobj, GLU::TESS_ERROR,
168
+ $errorCallback);
169
+ p "10"
170
+ GLU::TessCallback(tobj, GLU::TESS_COMBINE,
171
+ $combineCallback);
172
+ p "11"
173
+
174
+ # /* smooth shaded, self-intersecting star */
175
+ GL::NewList($startList + 1, GL::COMPILE);
176
+ GL::ShadeModel(GL::SMOOTH);
177
+ p "12"
178
+ GLU::TessProperty(tobj, GLU::TESS_WINDING_RULE,
179
+ GLU::TESS_WINDING_POSITIVE);
180
+ p "13"
181
+ GLU::TessBeginPolygon(tobj, nil);
182
+ p "13.1"
183
+ GLU::TessBeginContour(tobj);
184
+ GLU::TessVertex(tobj, star[0], star[0]);
185
+ GLU::TessVertex(tobj, star[1], star[1]);
186
+ GLU::TessVertex(tobj, star[2], star[2]);
187
+ GLU::TessVertex(tobj, star[3], star[3]);
188
+ GLU::TessVertex(tobj, star[4], star[4]);
189
+ GLU::TessEndContour(tobj);
190
+ p "13.2"
191
+ #GLU::TessEndPolygon(tobj);
192
+ p "14"
193
+ GL::EndList();
194
+ p "15"
195
+ GLU::DeleteTess(tobj);
196
+ p "16"
197
+ end
198
+
199
+ reshape = proc {|w, h|
200
+ GL::Viewport(0, 0, w, h);
201
+ GL::MatrixMode(GL::PROJECTION);
202
+ GL::LoadIdentity();
203
+ GLU::Ortho2D(0.0, w, 0.0, h);
204
+ }
205
+
206
+ #/* ARGSUSED1 */
207
+ keyboard = proc {|key, x, y|
208
+ case (key)
209
+ when 27
210
+ exit(0);
211
+ end
212
+ }
213
+
214
+ GLUT::Init();
215
+ GLUT::InitDisplayMode(GLUT::SINGLE | GLUT::RGB);
216
+ GLUT::InitWindowSize(500, 500);
217
+ GLUT::CreateWindow();
218
+ init();
219
+ GLUT::DisplayFunc(display);
220
+ GLUT::ReshapeFunc(reshape);
221
+ GLUT::KeyboardFunc(keyboard);
222
+ GLUT::MainLoop();
@@ -0,0 +1,157 @@
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
+ # texbind.c
39
+ # This program demonstrates using glBindTexture() by
40
+ # creating and managing two textures.
41
+ #/
42
+
43
+ #define checkImageWidth 64
44
+ #define checkImageHeight 64
45
+
46
+ require "gl_prev"
47
+ require "glu_prev"
48
+ require "glut_prev"
49
+ require "mathn"
50
+
51
+ CheckImageWidth = 64
52
+ CheckImageHeight = 64
53
+ #$checkImage = MDArray.new(CheckImageHeight, CheckImageWidth, 4)
54
+ #$otherImage = MDArray.new(CheckImageHeight, CheckImageWidth, 4)
55
+ $checkImage = []
56
+ $otherImage = []
57
+
58
+ $texName = [];
59
+
60
+ def makeCheckImages
61
+ for i in (0..CheckImageHeight-1)
62
+ for j in (0..CheckImageWidth-1)
63
+ if ((i&0x8==0)!=(j&0x8==0)) then tmp = 1; else tmp=0; end
64
+ #c = ((((i&0x8)==0)^((j&0x8))==0))*255;
65
+ c = tmp * 255;
66
+ $checkImage[i*CheckImageWidth*4+j*4+0] = c;
67
+ $checkImage[i*CheckImageWidth*4+j*4+1] = c;
68
+ $checkImage[i*CheckImageWidth*4+j*4+2] = c;
69
+ $checkImage[i*CheckImageWidth*4+j*4+3] = 255;
70
+ #c = ((((i&0x10)==0)^((j&0x10))==0))*255;
71
+ if ((i&0x10==0)!=(j&0x10==0)) then tmp = 1; else tmp=0; end
72
+ c = tmp * 255;
73
+ $otherImage[i*CheckImageWidth*4+j*4+0] = c;
74
+ $otherImage[i*CheckImageWidth*4+j*4+1] = 0;
75
+ $otherImage[i*CheckImageWidth*4+j*4+2] = 0;
76
+ $otherImage[i*CheckImageWidth*4+j*4+3] = 255;
77
+ end
78
+ end
79
+ end
80
+
81
+ def init
82
+ GL.ClearColor(0.0, 0.0, 0.0, 0.0);
83
+ GL.ShadeModel(GL::FLAT);
84
+ GL.Enable(GL::DEPTH_TEST);
85
+
86
+ makeCheckImages();
87
+ GL.PixelStorei(GL::UNPACK_ALIGNMENT, 1);
88
+
89
+ $texName = GL.GenTextures(2);
90
+ GL.BindTexture(GL::TEXTURE_2D, $texName[0]);
91
+ GL.TexParameteri(GL::TEXTURE_2D, GL::TEXTURE_WRAP_S, GL::CLAMP);
92
+ GL.TexParameteri(GL::TEXTURE_2D, GL::TEXTURE_WRAP_T, GL::CLAMP);
93
+ GL.TexParameteri(GL::TEXTURE_2D, GL::TEXTURE_MAG_FILTER,GL::NEAREST);
94
+ GL.TexParameteri(GL::TEXTURE_2D, GL::TEXTURE_MIN_FILTER,GL::NEAREST);
95
+ GL.TexImage2D(GL::TEXTURE_2D, 0, GL::RGBA, CheckImageWidth,
96
+ CheckImageHeight, 0, GL::RGBA, GL::UNSIGNED_BYTE,
97
+ $checkImage.pack("C*"));
98
+
99
+ GL.BindTexture(GL::TEXTURE_2D, $texName[1]);
100
+ GL.TexParameteri(GL::TEXTURE_2D, GL::TEXTURE_WRAP_S, GL::CLAMP);
101
+ GL.TexParameteri(GL::TEXTURE_2D, GL::TEXTURE_WRAP_T, GL::CLAMP);
102
+ GL.TexParameteri(GL::TEXTURE_2D, GL::TEXTURE_MAG_FILTER, GL::NEAREST);
103
+ GL.TexParameteri(GL::TEXTURE_2D, GL::TEXTURE_MIN_FILTER, GL::NEAREST);
104
+ GL.TexEnvf(GL::TEXTURE_ENV, GL::TEXTURE_ENV_MODE, GL::DECAL);
105
+ GL.TexImage2D(GL::TEXTURE_2D, 0, GL::RGBA, CheckImageWidth,
106
+ CheckImageHeight, 0, GL::RGBA, GL::UNSIGNED_BYTE,
107
+ $otherImage.pack("C*"));
108
+ GL.Enable(GL::TEXTURE_2D);
109
+ end
110
+
111
+ display = Proc.new {
112
+ GL.Clear(GL::COLOR_BUFFER_BIT | GL::DEPTH_BUFFER_BIT);
113
+ GL.BindTexture(GL::TEXTURE_2D, $texName[0]);
114
+ GL.Begin(GL::QUADS);
115
+ GL.TexCoord(0.0, 0.0); GL.Vertex(-2.0, -1.0, 0.0);
116
+ GL.TexCoord(0.0, 1.0); GL.Vertex(-2.0, 1.0, 0.0);
117
+ GL.TexCoord(1.0, 1.0); GL.Vertex(0.0, 1.0, 0.0);
118
+ GL.TexCoord(1.0, 0.0); GL.Vertex(0.0, -1.0, 0.0);
119
+ GL.End();
120
+ GL.BindTexture(GL::TEXTURE_2D, $texName[1]);
121
+ GL.Begin(GL::QUADS);
122
+ GL.TexCoord(0.0, 0.0); GL.Vertex(1.0, -1.0, 0.0);
123
+ GL.TexCoord(0.0, 1.0); GL.Vertex(1.0, 1.0, 0.0);
124
+ GL.TexCoord(1.0, 1.0); GL.Vertex(2.41421, 1.0, -1.41421);
125
+ GL.TexCoord(1.0, 0.0); GL.Vertex(2.41421, -1.0, -1.41421);
126
+ GL.End();
127
+ GL.Flush();
128
+ }
129
+
130
+ reshape = Proc.new {|w, h|
131
+ GL.Viewport(0, 0, w, h);
132
+ GL.MatrixMode(GL::PROJECTION);
133
+ GL.LoadIdentity();
134
+ GLU.Perspective(60.0, w/h, 1.0, 30.0);
135
+ GL.MatrixMode(GL::MODELVIEW);
136
+ GL.LoadIdentity();
137
+ GL.Translate(0.0, 0.0, -3.6);
138
+ }
139
+
140
+ #* ARGSUSED1 */
141
+ keyboard = Proc.new {|key, x, y|
142
+ case (key)
143
+ when 27
144
+ exit(0);
145
+ end
146
+ }
147
+
148
+ GLUT.Init
149
+ GLUT.InitDisplayMode(GLUT::SINGLE | GLUT::RGB | GLUT::DEPTH);
150
+ GLUT.InitWindowSize(250, 250);
151
+ GLUT.InitWindowPosition(100, 100);
152
+ GLUT.CreateWindow($0);
153
+ init();
154
+ GLUT.ReshapeFunc(reshape);
155
+ GLUT.DisplayFunc(display);
156
+ GLUT.KeyboardFunc(keyboard);
157
+ GLUT.MainLoop();
@@ -0,0 +1,171 @@
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
+ # texgen.c
39
+ # This program draws a texture mapped teapot with
40
+ # automatically generated texture coordinates. The
41
+ # texture is rendered as stripes on the teapot.
42
+ # Initially, the object is drawn with texture coordinates
43
+ # based upon the object coordinates of the vertex
44
+ # and distance from the plane x = 0. Pressing the 'e'
45
+ # key changes the coordinate generation to eye coordinates
46
+ # of the vertex. Pressing the 'o' key switches it back
47
+ # to the object coordinates. Pressing the 's' key
48
+ # changes the plane to a slanted one (x + y + z = 0).
49
+ # Pressing the 'x' key switches it back to x = 0.
50
+ #/
51
+
52
+ require "gl_prev"
53
+ require "glu_prev"
54
+ require "glut_prev"
55
+ require "mathn"
56
+ StripeImageWidth = 32
57
+ $stripeImage = []
58
+
59
+ $texName;
60
+
61
+ def makeStripeImage
62
+ for j in (0..StripeImageWidth-1)
63
+ $stripeImage[4*j] = if (j<=4) then 255; else 0; end;
64
+ $stripeImage[4*j+1] = if (j>4) then 255 else 0; end;
65
+ $stripeImage[4*j+2] = 0;
66
+ $stripeImage[4*j+3] = 255;
67
+ end
68
+ end
69
+
70
+ #* planes for texture coordinate generation */
71
+ $xequalzero = [1.0, 0.0, 0.0, 0.0];
72
+ $slanted = [1.0, 1.0, 1.0, 0.0];
73
+ $currentCoeff = nil;
74
+ $currentPlane = nil;
75
+ $currentGenMode = nil;
76
+
77
+ def init
78
+ GL.ClearColor(0.0, 0.0, 0.0, 0.0);
79
+ GL.Enable(GL::DEPTH_TEST);
80
+ GL.ShadeModel(GL::SMOOTH);
81
+
82
+ makeStripeImage();
83
+ GL.PixelStorei(GL::UNPACK_ALIGNMENT, 1);
84
+
85
+ $texName = GL.GenTextures(1);
86
+ GL.BindTexture(GL::TEXTURE_2D, $texName[0]);
87
+ GL.TexParameteri(GL::TEXTURE_2D, GL::TEXTURE_WRAP_S, GL::REPEAT);
88
+ GL.TexParameteri(GL::TEXTURE_2D, GL::TEXTURE_MAG_FILTER, GL::LINEAR);
89
+ GL.TexParameteri(GL::TEXTURE_2D, GL::TEXTURE_MIN_FILTER, GL::LINEAR);
90
+ GL.TexImage2D(GL::TEXTURE_2D, 0, GL::RGBA, StripeImageWidth, 1, 0,
91
+ GL::RGBA, GL::UNSIGNED_BYTE, $stripeImage.pack("C*"));
92
+ GL.TexEnvf(GL::TEXTURE_ENV, GL::TEXTURE_ENV_MODE, GL::MODULATE);
93
+ $currentCoeff = $xequalzero;
94
+ $currentGenMode = GL::OBJECT_LINEAR;
95
+ $currentPlane = GL::OBJECT_PLANE;
96
+ GL.TexGen(GL::S, GL::TEXTURE_GEN_MODE, $currentGenMode);
97
+ GL.TexGen(GL::S, $currentPlane, $currentCoeff);
98
+
99
+ GL.Enable(GL::TEXTURE_GEN_S);
100
+ GL.Enable(GL::TEXTURE_2D);
101
+ GL.Enable(GL::CULL_FACE);
102
+ GL.Enable(GL::LIGHTING);
103
+ GL.Enable(GL::LIGHT0);
104
+ GL.Enable(GL::AUTO_NORMAL);
105
+ GL.Enable(GL::NORMALIZE);
106
+ GL.FrontFace(GL::CW);
107
+ GL.CullFace(GL::BACK);
108
+ GL.Material(GL::FRONT, GL::SHININESS, 64.0);
109
+ end
110
+
111
+ display = Proc.new {
112
+ GL.Clear(GL::COLOR_BUFFER_BIT | GL::DEPTH_BUFFER_BIT);
113
+ GL.PushMatrix();
114
+ GL.Rotate(45.0, 0.0, 0.0, 1.0);
115
+ GL.BindTexture(GL::TEXTURE_2D, $texName[0]);
116
+ GLUT.SolidTeapot(2.0);
117
+ GL.PopMatrix();
118
+ GL.Flush();
119
+ }
120
+
121
+ reshape = Proc.new {|w, h|
122
+ GL.Viewport(0, 0, w, h);
123
+ GL.MatrixMode(GL::PROJECTION);
124
+ GL.LoadIdentity();
125
+ if (w <= h)
126
+ GL.Ortho(-3.5, 3.5, -3.5*h/w,3.5*h/w, -3.5, 3.5);
127
+ else
128
+ GL.Ortho(-3.5*w/h, 3.5*w/h, -3.5, 3.5, -3.5, 3.5);
129
+ end
130
+ GL.MatrixMode(GL::MODELVIEW);
131
+ GL.LoadIdentity();
132
+ }
133
+
134
+ #* ARGSUSED1 */
135
+ keyboard = Proc.new {|key, x, y|
136
+ case (key)
137
+ when 'e'[0],'E'[0]
138
+ $currentGenMode = GL::EYE_LINEAR;
139
+ $currentPlane = GL::EYE_PLANE;
140
+ GL.TexGen(GL::S, GL::TEXTURE_GEN_MODE, $currentGenMode);
141
+ GL.TexGen(GL::S, $currentPlane, $currentCoeff);
142
+ GLUT.PostRedisplay();
143
+ when 'o'[0], 'O'[0]
144
+ $currentGenMode = GL::OBJECT_LINEAR;
145
+ $currentPlane = GL::OBJECT_PLANE;
146
+ GL.TexGen(GL::S, GL::TEXTURE_GEN_MODE, $currentGenMode);
147
+ GL.TexGen(GL::S, $currentPlane, $currentCoeff);
148
+ GLUT.PostRedisplay();
149
+ when 's'[0],'S'[0]
150
+ $currentCoeff = $slanted;
151
+ GL.TexGen(GL::S, $currentPlane, $currentCoeff);
152
+ GLUT.PostRedisplay();
153
+ when 'x'[0],'X'[0]
154
+ $currentCoeff = $xequalzero;
155
+ GL.TexGen(GL::S, $currentPlane, $currentCoeff);
156
+ GLUT.PostRedisplay();
157
+ when 27
158
+ exit(0);
159
+ end
160
+ }
161
+
162
+ GLUT.Init
163
+ GLUT.InitDisplayMode (GLUT::SINGLE | GLUT::RGB | GLUT::DEPTH);
164
+ GLUT.InitWindowSize(256, 256);
165
+ GLUT.InitWindowPosition(100, 100);
166
+ GLUT.CreateWindow ($0);
167
+ init();
168
+ GLUT.DisplayFunc(display);
169
+ GLUT.ReshapeFunc(reshape);
170
+ GLUT.KeyboardFunc(keyboard);
171
+ GLUT.MainLoop();