ruby-opengl 0.33.0 → 0.40.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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,170 @@
1
+ #/* aux2glut conversion Copyright (c) Mark J. Kilgard, 1994, 1995 */
2
+ #
3
+ #/**
4
+ # * (c) Copyright 1993, Silicon Graphics, Inc.
5
+ # * ALL RIGHTS RESERVED
6
+ # * Permission to use, copy, modify, and distribute this software for
7
+ # * any purpose and without fee is hereby granted, provided that the above
8
+ # * copyright notice appear in all copies and that both the copyright notice
9
+ # * and this permission notice appear in supporting documentation, and that
10
+ # * the name of Silicon Graphics, Inc. not be used in advertising
11
+ # * or publicity pertaining to distribution of the software without specific,
12
+ # * written prior permission.
13
+ # *
14
+ # * THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS"
15
+ # * AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE,
16
+ # * INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR
17
+ # * FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
18
+ # * GRAPHICS, INC. BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT,
19
+ # * SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY
20
+ # * KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION,
21
+ # * LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF
22
+ # * THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC. HAS BEEN
23
+ # * ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON
24
+ # * ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE
25
+ # * POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE.
26
+ # *
27
+ # * US Government Users Restricted Rights
28
+ # * Use, duplication, or disclosure by the Government is subject to
29
+ # * restrictions set forth in FAR 52.227.19(c)(2) or subparagraph
30
+ # * (c)(1)(ii) of the Rights in Technical Data and Computer Software
31
+ # * clause at DFARS 252.227-7013 and/or in similar or successor
32
+ # * clauses in the FAR or the DOD or NASA FAR Supplement.
33
+ # * Unpublished-- rights reserved under the copyright laws of the
34
+ # * United States. Contractor/manufacturer is Silicon Graphics,
35
+ # * Inc., 2011 N. Shoreline Blvd., Mountain View, CA 94039-7311.
36
+ # *
37
+ # * OpenGL(TM) is a trademark of Silicon Graphics, Inc.
38
+ # */
39
+ #/**
40
+ # * surface.c
41
+ # * This program draws a NURBS surface in the shape of a
42
+ # * symmetrical hill.
43
+ # */
44
+
45
+ require "gl_prev"
46
+ require "glu_prev"
47
+ require "glut_prev"
48
+ require "mathn"
49
+
50
+ $ctlpoints = [];
51
+ $showPoints = 0;
52
+
53
+ $theNurb = nil;
54
+
55
+ #/*
56
+ # * Initializes the control points of the surface to a small hill.
57
+ # * The control points range from -3 to +3 in x, y, and z
58
+ # */
59
+ def init_surface
60
+ for u in 0..3
61
+ for v in 0..3
62
+ $ctlpoints[u*4*3+v*3+0] = 2.0*(u - 1.5);
63
+ $ctlpoints[u*4*3+v*3+1] = 2.0*(v - 1.5);
64
+
65
+ if ( (u == 1 || u == 2) && (v == 1 || v == 2))
66
+ $ctlpoints[u*4*3+v*3+2] = 7.0;
67
+ else
68
+ $ctlpoints[u*4*3+v*3+2] = -3.0;
69
+ end
70
+ end
71
+ end
72
+ end
73
+
74
+ #/* Initialize material property and depth buffer.
75
+ # */
76
+ def myinit
77
+ mat_diffuse = [ 0.7, 0.7, 0.7, 1.0 ];
78
+ mat_specular = [ 1.0, 1.0, 1.0, 1.0 ];
79
+ mat_shininess = [ 100.0 ];
80
+
81
+ GL.ClearColor(0.0, 0.0, 0.0, 1.0);
82
+ GL.Material(GL::FRONT, GL::DIFFUSE, mat_diffuse);
83
+ GL.Material(GL::FRONT, GL::SPECULAR, mat_specular);
84
+ GL.Material(GL::FRONT, GL::SHININESS, mat_shininess);
85
+
86
+ GL.Enable(GL::LIGHTING);
87
+ GL.Enable(GL::LIGHT0);
88
+ GL.DepthFunc(GL::LESS);
89
+ GL.Enable(GL::DEPTH_TEST);
90
+ GL.Enable(GL::AUTO_NORMAL);
91
+ GL.Enable(GL::NORMALIZE);
92
+
93
+ init_surface();
94
+
95
+ $theNurb = GLU.NewNurbsRenderer();
96
+ GLU.NurbsProperty($theNurb, GLU::SAMPLING_TOLERANCE, 25.0);
97
+ GLU.NurbsProperty($theNurb, GLU::DISPLAY_MODE, GLU::FILL);
98
+ end
99
+
100
+ display = Proc.new {
101
+ knots = [0.0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0];
102
+
103
+ GL.Clear(GL::COLOR_BUFFER_BIT | GL::DEPTH_BUFFER_BIT);
104
+
105
+ GL.PushMatrix();
106
+ GL.Rotate(330.0, 1.0,0.0,0.0);
107
+ GL.Scale(0.25, 0.25, 0.25);
108
+
109
+ GLU.BeginSurface($theNurb);
110
+ GLU.NurbsSurface($theNurb,
111
+ 8, knots,
112
+ 8, knots,
113
+ 4 * 3,
114
+ 3,
115
+ $ctlpoints,
116
+ 4, 4,
117
+ GL::MAP2_VERTEX_3);
118
+ GLU.EndSurface($theNurb);
119
+
120
+ if($showPoints==1)
121
+ GL.PointSize(5.0);
122
+ GL.Disable(GL::LIGHTING);
123
+ GL.Color(1.0, 1.0, 0.0);
124
+ GL.Begin(GL::POINTS);
125
+ for i in 0..3
126
+ for j in 0..3
127
+ GL.Vertex($ctlpoints[i*4*3+j*3+0], $ctlpoints[i*4*3+j*3+1], $ctlpoints[i*4*3+j*3+2]);
128
+ end
129
+ end
130
+ GL.End();
131
+ GL.Enable(GL::LIGHTING);
132
+ end
133
+
134
+ GL.PopMatrix();
135
+ GL.Flush();
136
+ }
137
+
138
+ reshape = Proc.new {|w, h|
139
+ GL.Viewport(0, 0, w, h);
140
+ GL.MatrixMode(GL::PROJECTION);
141
+ GL.LoadIdentity();
142
+ GLU.Perspective(45.0, w/h, 3.0, 8.0);
143
+
144
+ GL.MatrixMode(GL::MODELVIEW);
145
+ GL.LoadIdentity();
146
+ GL.Translate(0.0, 0.0, -5.0);
147
+ }
148
+
149
+ menu = Proc.new {|value|
150
+ $showPoints = value;
151
+ GLUT.PostRedisplay();
152
+ }
153
+
154
+ #/* Main Loop */
155
+ #int
156
+ #main(int argc, char** argv)
157
+ #{
158
+ GLUT.Init
159
+ GLUT.InitDisplayMode(GLUT::SINGLE | GLUT::RGB);
160
+ GLUT.CreateWindow($0);
161
+ myinit();
162
+ GLUT.ReshapeFunc(reshape);
163
+ GLUT.DisplayFunc(display);
164
+ GLUT.CreateMenu(menu);
165
+ GLUT.AddMenuEntry("Show control points", 1);
166
+ GLUT.AddMenuEntry("Hide control points", 0);
167
+ GLUT.AttachMenu(GLUT::RIGHT_BUTTON);
168
+ GLUT.MainLoop();
169
+ # return 0; /* ANSI C requires main to return int. */
170
+ #}
@@ -0,0 +1,132 @@
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
+ #/**
41
+ # * teaambient.c
42
+ # * This program renders three lighted, shaded teapots, with
43
+ # * different ambient values.
44
+ # */
45
+
46
+ require "gl_prev"
47
+ require "glu_prev"
48
+ require "glut_prev"
49
+
50
+ #/* Initialize light source and lighting model.
51
+ # */
52
+ def myinit
53
+ light_ambient = [0.0, 0.0, 0.0, 1.0];
54
+ light_diffuse = [1.0, 1.0, 1.0, 1.0];
55
+ light_specular = [1.0, 1.0, 1.0, 1.0];
56
+ #/* light_position is NOT default value */
57
+ light_position = [1.0, 0.0, 0.0, 0.0];
58
+ global_ambient = [0.75, 0.75, 0.75, 1.0];
59
+
60
+ GL::Light(GL::LIGHT0, GL::AMBIENT, light_ambient);
61
+ GL::Light(GL::LIGHT0, GL::DIFFUSE, light_diffuse);
62
+ GL::Light(GL::LIGHT0, GL::SPECULAR, light_specular);
63
+ GL::Light(GL::LIGHT0, GL::POSITION, light_position);
64
+
65
+ GL::LightModel(GL::LIGHT_MODEL_AMBIENT, global_ambient);
66
+
67
+ GL::FrontFace(GL::CW);
68
+ GL::Enable(GL::LIGHTING);
69
+ GL::Enable(GL::LIGHT0);
70
+ GL::Enable(GL::AUTO_NORMAL);
71
+ GL::Enable(GL::NORMALIZE);
72
+ GL::DepthFunc(GL::LESS);
73
+ GL::Enable(GL::DEPTH_TEST);
74
+ end
75
+
76
+ display = proc {
77
+ low_ambient = [0.1, 0.1, 0.1, 1.0];
78
+ more_ambient = [0.4, 0.4, 0.4, 1.0];
79
+ most_ambient = [1.0, 1.0, 1.0, 1.0];
80
+
81
+ GL::Clear(GL::COLOR_BUFFER_BIT | GL::DEPTH_BUFFER_BIT);
82
+
83
+ # /* material has small ambient reflection */
84
+ GL::Material(GL::FRONT, GL::AMBIENT, low_ambient);
85
+ GL::Material(GL::FRONT, GL::SHININESS, 40.0);
86
+ GL::PushMatrix();
87
+ GL::Translate(0.0, 2.0, 0.0);
88
+ GLUT::SolidTeapot(1.0);
89
+ GL::PopMatrix();
90
+
91
+ # /* material has moderate ambient reflection */
92
+ GL::Material(GL::FRONT, GL::AMBIENT, more_ambient);
93
+ GL::PushMatrix();
94
+ GL::Translate(0.0, 0.0, 0.0);
95
+ GLUT::SolidTeapot(1.0);
96
+ GL::PopMatrix();
97
+
98
+ # /* material has large ambient reflection */
99
+ GL::Material(GL::FRONT, GL::AMBIENT, most_ambient);
100
+ GL::PushMatrix();
101
+ GL::Translate(0.0, -2.0, 0.0);
102
+ GLUT::SolidTeapot(1.0);
103
+ GL::PopMatrix();
104
+ GL::Flush();
105
+ }
106
+
107
+ myReshape = proc {|w, h|
108
+ GL::Viewport(0, 0, w, h);
109
+ GL::MatrixMode(GL::PROJECTION);
110
+ GL::LoadIdentity();
111
+ if (w <= h)
112
+ GL::Ortho(-4.0, 4.0, -4.0 * h / w,
113
+ 4.0 * h / w, -10.0, 10.0);
114
+ else
115
+ GL::Ortho(-4.0 * w / h,
116
+ 4.0 * w / h, -4.0, 4.0, -10.0, 10.0);
117
+ end
118
+ GL::MatrixMode(GL::MODELVIEW);
119
+ }
120
+
121
+ #/* Main Loop
122
+ # * Open window with initial window size, title bar,
123
+ # * RGBA display mode, and handle input events.
124
+ # */
125
+ GLUT::Init();
126
+ GLUT::InitDisplayMode(GLUT::SINGLE | GLUT::RGB | GLUT::DEPTH);
127
+ GLUT::InitWindowSize(500, 500);
128
+ GLUT::CreateWindow();
129
+ myinit();
130
+ GLUT::ReshapeFunc(myReshape);
131
+ GLUT::DisplayFunc(display);
132
+ GLUT::MainLoop();
@@ -0,0 +1,188 @@
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
+ #/**
41
+ # * teapots.c
42
+ # * This program demonstrates lots of material properties.
43
+ # * A single light source illuminates the objects.
44
+ # */
45
+ require "gl_prev"
46
+ require "glu_prev"
47
+ require "glut_prev"
48
+
49
+ #/*
50
+ # * Initialize depth buffer, projection matrix, light source, and lighting
51
+ # * model. Do not specify a material property here.
52
+ # */
53
+ def myinit
54
+ ambient = [0.0, 0.0, 0.0, 1.0];
55
+ diffuse = [1.0, 1.0, 1.0, 1.0];
56
+ position = [0.0, 3.0, 3.0, 0.0];
57
+
58
+ lmodel_ambient = [0.2, 0.2, 0.2, 1.0];
59
+ local_view = [0.0];
60
+
61
+ GL::Light(GL::LIGHT0, GL::AMBIENT, ambient);
62
+ GL::Light(GL::LIGHT0, GL::DIFFUSE, diffuse);
63
+ GL::Light(GL::LIGHT0, GL::POSITION, position);
64
+ GL::LightModel(GL::LIGHT_MODEL_AMBIENT, lmodel_ambient);
65
+ GL::LightModel(GL::LIGHT_MODEL_LOCAL_VIEWER, local_view);
66
+
67
+ GL::FrontFace(GL::CW);
68
+ GL::Enable(GL::LIGHTING);
69
+ GL::Enable(GL::LIGHT0);
70
+ GL::Enable(GL::AUTO_NORMAL);
71
+ GL::Enable(GL::NORMALIZE);
72
+ GL::Enable(GL::DEPTH_TEST);
73
+ GL::DepthFunc(GL::LESS);
74
+ end
75
+
76
+ #/*
77
+ # * Move object into position. Use 3rd through 12th parameters to specify the
78
+ # * material property. Draw a teapot.
79
+ # */
80
+ def renderTeapot(x, y, ambr, ambg, ambb, difr, difg, difb, specr, specg, specb, shine)
81
+ mat = [];
82
+
83
+ GL::PushMatrix();
84
+ GL::Translate(x, y, 0.0);
85
+ mat[0] = ambr;
86
+ mat[1] = ambg;
87
+ mat[2] = ambb;
88
+ mat[3] = 1.0;
89
+ GL::Material(GL::FRONT, GL::AMBIENT, mat);
90
+ mat[0] = difr;
91
+ mat[1] = difg;
92
+ mat[2] = difb;
93
+ GL::Material(GL::FRONT, GL::DIFFUSE, mat);
94
+ mat[0] = specr;
95
+ mat[1] = specg;
96
+ mat[2] = specb;
97
+ GL::Material(GL::FRONT, GL::SPECULAR, mat);
98
+ GL::Material(GL::FRONT, GL::SHININESS, shine * 128.0);
99
+ GLUT::SolidTeapot(1.0);
100
+ GL::PopMatrix();
101
+ end
102
+
103
+ #/**
104
+ # * First column: emerald, jade, obsidian, pearl, ruby, turquoise
105
+ # * 2nd column: brass, bronze, chrome, copper, gold, silver
106
+ # * 3rd column: black, cyan, green, red, white, yellow plastic
107
+ # * 4th column: black, cyan, green, red, white, yellow rubber
108
+ # */
109
+ display = proc {
110
+ GL::Clear(GL::COLOR_BUFFER_BIT | GL::DEPTH_BUFFER_BIT);
111
+ renderTeapot(2.0, 17.0, 0.0215, 0.1745, 0.0215,
112
+ 0.07568, 0.61424, 0.07568, 0.633, 0.727811, 0.633, 0.6);
113
+ renderTeapot(2.0, 14.0, 0.135, 0.2225, 0.1575,
114
+ 0.54, 0.89, 0.63, 0.316228, 0.316228, 0.316228, 0.1);
115
+ renderTeapot(2.0, 11.0, 0.05375, 0.05, 0.06625,
116
+ 0.18275, 0.17, 0.22525, 0.332741, 0.328634, 0.346435, 0.3);
117
+ renderTeapot(2.0, 8.0, 0.25, 0.20725, 0.20725,
118
+ 1, 0.829, 0.829, 0.296648, 0.296648, 0.296648, 0.088);
119
+ renderTeapot(2.0, 5.0, 0.1745, 0.01175, 0.01175,
120
+ 0.61424, 0.04136, 0.04136, 0.727811, 0.626959, 0.626959, 0.6);
121
+ renderTeapot(2.0, 2.0, 0.1, 0.18725, 0.1745,
122
+ 0.396, 0.74151, 0.69102, 0.297254, 0.30829, 0.306678, 0.1);
123
+ renderTeapot(6.0, 17.0, 0.329412, 0.223529, 0.027451,
124
+ 0.780392, 0.568627, 0.113725, 0.992157, 0.941176, 0.807843,
125
+ 0.21794872);
126
+ renderTeapot(6.0, 14.0, 0.2125, 0.1275, 0.054,
127
+ 0.714, 0.4284, 0.18144, 0.393548, 0.271906, 0.166721, 0.2);
128
+ renderTeapot(6.0, 11.0, 0.25, 0.25, 0.25,
129
+ 0.4, 0.4, 0.4, 0.774597, 0.774597, 0.774597, 0.6);
130
+ renderTeapot(6.0, 8.0, 0.19125, 0.0735, 0.0225,
131
+ 0.7038, 0.27048, 0.0828, 0.256777, 0.137622, 0.086014, 0.1);
132
+ renderTeapot(6.0, 5.0, 0.24725, 0.1995, 0.0745,
133
+ 0.75164, 0.60648, 0.22648, 0.628281, 0.555802, 0.366065, 0.4);
134
+ renderTeapot(6.0, 2.0, 0.19225, 0.19225, 0.19225,
135
+ 0.50754, 0.50754, 0.50754, 0.508273, 0.508273, 0.508273, 0.4);
136
+ renderTeapot(10.0, 17.0, 0.0, 0.0, 0.0, 0.01, 0.01, 0.01,
137
+ 0.50, 0.50, 0.50, 0.25);
138
+ renderTeapot(10.0, 14.0, 0.0, 0.1, 0.06, 0.0, 0.50980392, 0.50980392,
139
+ 0.50196078, 0.50196078, 0.50196078, 0.25);
140
+ renderTeapot(10.0, 11.0, 0.0, 0.0, 0.0,
141
+ 0.1, 0.35, 0.1, 0.45, 0.55, 0.45, 0.25);
142
+ renderTeapot(10.0, 8.0, 0.0, 0.0, 0.0, 0.5, 0.0, 0.0,
143
+ 0.7, 0.6, 0.6, 0.25);
144
+ renderTeapot(10.0, 5.0, 0.0, 0.0, 0.0, 0.55, 0.55, 0.55,
145
+ 0.70, 0.70, 0.70, 0.25);
146
+ renderTeapot(10.0, 2.0, 0.0, 0.0, 0.0, 0.5, 0.5, 0.0,
147
+ 0.60, 0.60, 0.50, 0.25);
148
+ renderTeapot(14.0, 17.0, 0.02, 0.02, 0.02, 0.01, 0.01, 0.01,
149
+ 0.4, 0.4, 0.4, 0.078125);
150
+ renderTeapot(14.0, 14.0, 0.0, 0.05, 0.05, 0.4, 0.5, 0.5,
151
+ 0.04, 0.7, 0.7, 0.078125);
152
+ renderTeapot(14.0, 11.0, 0.0, 0.05, 0.0, 0.4, 0.5, 0.4,
153
+ 0.04, 0.7, 0.04, 0.078125);
154
+ renderTeapot(14.0, 8.0, 0.05, 0.0, 0.0, 0.5, 0.4, 0.4,
155
+ 0.7, 0.04, 0.04, 0.078125);
156
+ renderTeapot(14.0, 5.0, 0.05, 0.05, 0.05, 0.5, 0.5, 0.5,
157
+ 0.7, 0.7, 0.7, 0.078125);
158
+ renderTeapot(14.0, 2.0, 0.05, 0.05, 0.0, 0.5, 0.5, 0.4,
159
+ 0.7, 0.7, 0.04, 0.078125);
160
+ GL::Flush();
161
+ }
162
+
163
+ myReshape = proc {|w, h|
164
+ GL::Viewport(0, 0, w, h);
165
+ GL::MatrixMode(GL::PROJECTION);
166
+ GL::LoadIdentity();
167
+ if (w <= h)
168
+ GL::Ortho(0.0, 16.0, 0.0, 16.0 * h.to_f / w,
169
+ -10.0, 10.0);
170
+ else
171
+ GL::Ortho(0.0, 16.0 * w.to_f / h, 0.0, 16.0,
172
+ -10.0, 10.0);
173
+ end
174
+ GL::MatrixMode(GL::MODELVIEW);
175
+ }
176
+
177
+ #/*
178
+ # * Main Loop Open window with initial window size, title bar, RGBA display
179
+ # * mode, and handle input events.
180
+ # */
181
+ GLUT::Init()
182
+ GLUT::InitDisplayMode(GLUT::SINGLE | GLUT::RGB | GLUT::DEPTH);
183
+ GLUT::CreateWindow()
184
+ myinit();
185
+ GLUT::ReshapeFunc(myReshape);
186
+ GLUT::DisplayFunc(display);
187
+ GLUT::MainLoop();
188
+