ruby-opengl 0.40.1 → 0.50.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 (154) hide show
  1. data/Rakefile +2 -2
  2. data/doc/build_install.txt +48 -28
  3. data/doc/extensions.txt +361 -0
  4. data/doc/history.txt +8 -2
  5. data/doc/requirements_and_design.txt +0 -13
  6. data/doc/roadmap.txt +11 -13
  7. data/doc/supplies/page_template.html +11 -5
  8. data/doc/thanks.txt +2 -4
  9. data/doc/tutorial.txt +1 -4
  10. data/examples/{nehe_lesson02.rb → NeHe/nehe_lesson02.rb} +0 -0
  11. data/examples/{nehe_lesson03.rb → NeHe/nehe_lesson03.rb} +0 -0
  12. data/examples/{nehe_lesson04.rb → NeHe/nehe_lesson04.rb} +0 -0
  13. data/examples/{nehe_lesson05.rb → NeHe/nehe_lesson05.rb} +0 -0
  14. data/examples/NeHe/nehe_lesson36.rb +303 -0
  15. data/examples/OrangeBook/3Dlabs-License.txt +33 -0
  16. data/examples/OrangeBook/brick.frag +36 -0
  17. data/examples/OrangeBook/brick.rb +388 -0
  18. data/examples/OrangeBook/brick.vert +41 -0
  19. data/examples/OrangeBook/particle.frag +17 -0
  20. data/examples/OrangeBook/particle.rb +424 -0
  21. data/examples/OrangeBook/particle.vert +38 -0
  22. data/examples/README +13 -83
  23. data/examples/RedBook/aaindex.rb +97 -0
  24. data/examples/RedBook/aapoly.rb +142 -0
  25. data/examples/RedBook/aargb.rb +119 -0
  26. data/examples/RedBook/accanti.rb +162 -0
  27. data/examples/RedBook/accpersp.rb +215 -0
  28. data/examples/RedBook/alpha.rb +123 -0
  29. data/examples/RedBook/alpha3D.rb +158 -0
  30. data/examples/RedBook/bezcurve.rb +105 -0
  31. data/examples/RedBook/bezmesh.rb +137 -0
  32. data/examples/RedBook/checker.rb +124 -0
  33. data/examples/RedBook/clip.rb +95 -0
  34. data/examples/RedBook/colormat.rb +135 -0
  35. data/examples/RedBook/cube.rb +69 -0
  36. data/examples/RedBook/depthcue.rb +99 -0
  37. data/examples/RedBook/dof.rb +205 -0
  38. data/examples/{legacy → RedBook}/double.rb +59 -58
  39. data/examples/{legacy → RedBook}/drawf.rb +47 -54
  40. data/examples/RedBook/feedback.rb +145 -0
  41. data/examples/RedBook/fog.rb +167 -0
  42. data/examples/RedBook/font.rb +151 -0
  43. data/examples/RedBook/hello.rb +79 -0
  44. data/examples/RedBook/image.rb +137 -0
  45. data/examples/{legacy → RedBook}/jitter.rb +60 -62
  46. data/examples/RedBook/lines.rb +128 -0
  47. data/examples/RedBook/list.rb +111 -0
  48. data/examples/RedBook/material.rb +275 -0
  49. data/examples/RedBook/mipmap.rb +156 -0
  50. data/examples/{legacy → RedBook}/model.rb +66 -72
  51. data/examples/{legacy → RedBook}/movelight.rb +67 -75
  52. data/examples/RedBook/pickdepth.rb +179 -0
  53. data/examples/{legacy → RedBook}/planet.rb +62 -66
  54. data/examples/RedBook/quadric.rb +158 -0
  55. data/examples/RedBook/robot.rb +115 -0
  56. data/examples/RedBook/select.rb +196 -0
  57. data/examples/RedBook/smooth.rb +95 -0
  58. data/examples/RedBook/stencil.rb +163 -0
  59. data/examples/RedBook/stroke.rb +167 -0
  60. data/examples/RedBook/surface.rb +166 -0
  61. data/examples/RedBook/teaambient.rb +132 -0
  62. data/examples/RedBook/teapots.rb +182 -0
  63. data/examples/RedBook/tess.rb +183 -0
  64. data/examples/RedBook/texbind.rb +147 -0
  65. data/examples/RedBook/texgen.rb +169 -0
  66. data/examples/RedBook/texturesurf.rb +128 -0
  67. data/examples/RedBook/varray.rb +159 -0
  68. data/examples/RedBook/wrap.rb +148 -0
  69. data/examples/misc/anisotropic.rb +194 -0
  70. data/examples/misc/font-glut.rb +46 -0
  71. data/examples/{plane.rb → misc/plane.rb} +0 -0
  72. data/examples/misc/readpixel.rb +65 -0
  73. data/examples/{smooth.rb → misc/smooth.rb} +0 -0
  74. data/examples/{test.rb → misc/test.rb} +0 -0
  75. data/ext/common/common.h +252 -70
  76. data/ext/common/gl-enums.h +6102 -7334
  77. data/ext/common/gl-types.h +47 -0
  78. data/ext/common/glu-enums.h +469 -0
  79. data/ext/gl/gl-1.0-1.1.c +842 -2464
  80. data/ext/gl/gl-1.2.c +217 -281
  81. data/ext/gl/gl-1.3.c +113 -133
  82. data/ext/gl/gl-1.4.c +98 -334
  83. data/ext/gl/gl-1.5.c +28 -34
  84. data/ext/gl/gl-2.0.c +26 -235
  85. data/ext/gl/gl-2.1.c +31 -124
  86. data/ext/gl/gl-enums.c +786 -631
  87. data/ext/gl/gl-ext-arb.c +66 -0
  88. data/ext/gl/gl-ext-ext.c +218 -0
  89. data/ext/gl/gl.c +138 -31
  90. data/ext/gl/mkrf_conf.rb +1 -0
  91. data/ext/glu/glu-enums.c +163 -0
  92. data/ext/glu/glu.c +1003 -1205
  93. data/ext/glu/mkrf_conf.rb +1 -0
  94. data/ext/glut/glut.c +1056 -1175
  95. data/lib/opengl.rb +90 -3
  96. data/test/tc_common.rb +26 -13
  97. data/test/tc_ext_arb.rb +73 -0
  98. data/test/tc_ext_ext.rb +74 -0
  99. data/test/tc_func_12.rb +8 -8
  100. data/test/tc_func_13.rb +17 -11
  101. data/test/tc_func_14.rb +8 -8
  102. data/test/tc_func_15.rb +190 -2
  103. data/test/tc_func_20.rb +36 -10
  104. data/test/tc_func_21.rb +445 -2
  105. data/test/tc_glu.rb +305 -0
  106. data/test/tc_misc.rb +1 -0
  107. metadata +84 -68
  108. data/doc/screenshots.txt +0 -23
  109. data/examples/legacy/COPYRIGHT +0 -8
  110. data/examples/legacy/aaindex.rb +0 -98
  111. data/examples/legacy/aapoly.rb +0 -153
  112. data/examples/legacy/aargb.rb +0 -139
  113. data/examples/legacy/accanti.rb +0 -159
  114. data/examples/legacy/accpersp.rb +0 -216
  115. data/examples/legacy/alpha.rb +0 -133
  116. data/examples/legacy/alpha3D.rb +0 -165
  117. data/examples/legacy/bezcurve.rb +0 -107
  118. data/examples/legacy/bezmesh.rb +0 -131
  119. data/examples/legacy/checker.rb +0 -121
  120. data/examples/legacy/clip.rb +0 -104
  121. data/examples/legacy/colormat.rb +0 -145
  122. data/examples/legacy/cube.rb +0 -73
  123. data/examples/legacy/depthcue.rb +0 -101
  124. data/examples/legacy/dof.rb +0 -212
  125. data/examples/legacy/feedback.rb +0 -152
  126. data/examples/legacy/fog.rb +0 -172
  127. data/examples/legacy/font-glut.rb +0 -41
  128. data/examples/legacy/font.rb +0 -158
  129. data/examples/legacy/hello.rb +0 -75
  130. data/examples/legacy/image.rb +0 -145
  131. data/examples/legacy/lines.rb +0 -135
  132. data/examples/legacy/list.rb +0 -120
  133. data/examples/legacy/material.rb +0 -290
  134. data/examples/legacy/mipmap.rb +0 -159
  135. data/examples/legacy/pickdepth.rb +0 -180
  136. data/examples/legacy/quadric.rb +0 -180
  137. data/examples/legacy/readpixel.rb +0 -59
  138. data/examples/legacy/robot.rb +0 -120
  139. data/examples/legacy/select.rb +0 -207
  140. data/examples/legacy/smooth.rb +0 -41
  141. data/examples/legacy/stencil.rb +0 -154
  142. data/examples/legacy/stroke.rb +0 -170
  143. data/examples/legacy/surface.rb +0 -170
  144. data/examples/legacy/teaambient.rb +0 -132
  145. data/examples/legacy/teapots.rb +0 -188
  146. data/examples/legacy/tess.rb +0 -222
  147. data/examples/legacy/texbind.rb +0 -157
  148. data/examples/legacy/texgen.rb +0 -171
  149. data/examples/legacy/texturesurf.rb +0 -128
  150. data/examples/legacy/varray.rb +0 -167
  151. data/examples/legacy/wrap.rb +0 -158
  152. data/lib/gl_prev.rb +0 -46
  153. data/lib/glu_prev.rb +0 -46
  154. data/lib/glut_prev.rb +0 -45
@@ -0,0 +1,38 @@
1
+ //
2
+ // Vertex shader for rendering a "confetti cannon"
3
+ // via a partcle system
4
+ //
5
+ // Author: Randi Rost
6
+ //
7
+ // Copyright (c) 2003-2004: 3Dlabs, Inc.
8
+ //
9
+ // See 3Dlabs-License.txt for license information
10
+ //
11
+
12
+ uniform float Time; // updated each frame by the application
13
+ uniform vec4 Background; // constant color equal to background
14
+
15
+ attribute vec3 Velocity; // initial velocity
16
+ attribute float StartTime; // time at which particle is activated
17
+
18
+ varying vec4 Color;
19
+
20
+ void main(void)
21
+ {
22
+ vec4 vert;
23
+ float t = Time - StartTime;
24
+
25
+ if (t >= 0.0)
26
+ {
27
+ vert = gl_Vertex + vec4 (Velocity * t, 0.0);
28
+ vert.y -= 4.9 * t * t;
29
+ Color = gl_Color;
30
+ }
31
+ else
32
+ {
33
+ vert = gl_Vertex; // Initial position
34
+ Color = Background; // "pre-birth" color
35
+ }
36
+
37
+ gl_Position = gl_ModelViewProjectionMatrix * vert;
38
+ }
data/examples/README CHANGED
@@ -1,86 +1,16 @@
1
1
  Examples
2
2
  ========
3
3
 
4
- Just some quick notes on which examples work and which don't.
5
-
6
-
7
- Running legacy ruby-opengl code
8
- -------------------------------
9
-
10
- Note that the filenames ending with `_prev.rb` contain code that is compatible
11
- with the previous version of ruby-opengl (i.e. Yoshi's version). If you have
12
- code that runs with the previous version, to make it run with this current
13
- version, either see the tutorial about the simple changes you can make to the
14
- code, or else just use
15
-
16
- require "gl_prev"
17
- require "glu_prev"
18
- require "glut_prev"
19
-
20
- at the top of your files instead of
21
-
22
- require 'opengl'
23
- require 'glut'
24
-
25
- For examples of using the legacy code look at the directory legacy/ for
26
- lots of example code that was borrowed from Yoshi's examples
27
-
28
-
29
- Status of examples
30
- ------------------
31
-
32
- * plane.rb -- works (Should show a picture of a planar surface)
33
- * smooth.rb -- works
34
- * test.rb -- works
35
-
36
- Status of legacy examples
37
- -------------------------
38
-
39
- * aaindex.rb -- does not seem to work
40
- * aapoly.rb -- works
41
- * aargb.rb -- works
42
- * accanti.rb -- does not seem to work
43
- * accpersp.rb -- does not seem to work
44
- * alpha3D.rb -- works
45
- * alpha.rb -- works
46
- * bezcurve.rb -- works
47
- * bezmesh.rb -- works
48
- * checker.rb -- works
49
- * clip.rb -- works
50
- * colormat.rb -- works
51
- * cube.rb -- works
52
- * depthcue.rb -- works
53
- * smooth.rb -- works
54
- * dof.rb -- works
55
- * double.rb -- works
56
- * drawf.rb -- works
57
- * feedback.rb -- seems to work
58
- * fog.rb -- works
59
- * font-glut.rb -- works
60
- * font.rb -- works
61
- * hello.rb -- works
62
- * image.rb -- works
63
- * lines.rb -- works
64
- * list.rb -- works
65
- * material.rb -- works
66
- * mipmap.rb -- works
67
- * model.rb -- works
68
- * movelight.rb -- works
69
- * pickdepth.rb -- works
70
- * planet.rb -- works
71
- * quadric.rb -- works
72
- * readpixel.rb -- does not seem to work
73
- * robot.rb -- seems to work
74
- * select.rb -- works
75
- * smooth.rb -- works
76
- * stencil.rb -- works
77
- * stroke.rb -- works
78
- * surface.rb -- works
79
- * teaambient.rb -- works
80
- * teapots.rb -- works
81
- * tess.rb -- does not seem to work
82
- * texbind.rb -- works
83
- * texgen.rb -- works
84
- * texturesurf.rb -- works
85
- * varray.rb -- works
86
- * wrap.rb -- works
4
+ This directory contains OpenGL examples converted to ruby from various sources.
5
+ As such, they are distributed under various terms - see each file for licensing info.
6
+
7
+ RedBook/
8
+ Examples from OpenGL Red Book and SGI's example code in general, licensed under
9
+ SGI open-source license.
10
+ OrangeBook/
11
+ Examples from OpenGL Orange Book (GLSL), distributed under BSD license
12
+ NeHe/
13
+ NeHe's opengl tutorials (http://nehe.gamedev.net), licensed under free license.
14
+ Misc/
15
+ Other examples. If license is not given, MIT is assumed.
16
+
@@ -0,0 +1,97 @@
1
+ #!/usr/bin/env ruby -rubygems
2
+ require 'opengl'
3
+ require 'rational'
4
+ include Gl,Glu,Glut
5
+
6
+
7
+ RAMPSIZE=16
8
+ RAMP1START=32
9
+ RAMP2START=48
10
+
11
+ STDOUT.sync = TRUE
12
+ $rotAngle = 0
13
+
14
+ # Initialize antialiasing for color index mode,
15
+ # including loading a green color ramp starting
16
+ # at RAMP1START, and a blue color ramp starting
17
+ # at RAMP2START. The ramps must be a multiple of 16.
18
+ def myinit
19
+ for i in (0..RAMPSIZE)
20
+ shade = i.to_f/RAMPSIZE.to_f
21
+ glutSetColor(RAMP1START+i, 0, shade, 0.0)
22
+ glutSetColor(RAMP2START+i, 0, 0, shade)
23
+ end
24
+
25
+ glEnable(GL_LINE_SMOOTH)
26
+ glHint(GL_LINE_SMOOTH_HINT, GL_DONT_CARE)
27
+ glLineWidth(1.5)
28
+
29
+ glClearIndex(RAMP1START)
30
+ end
31
+
32
+ display = Proc.new do
33
+ glClear(GL_COLOR_BUFFER_BIT)
34
+
35
+ glIndexi(RAMP1START)
36
+ glPushMatrix()
37
+ glRotate(-$rotAngle, 0.0, 0.0, 0.1)
38
+ glBegin(GL_LINES)
39
+ glVertex(-0.5, 0.5)
40
+ glVertex(0.5, -0.5)
41
+ glEnd
42
+ glPopMatrix()
43
+
44
+ # glIndexi(RAMP2START)
45
+ glPushMatrix()
46
+ glRotate($rotAngle, 0.0, 0.0, 0.1)
47
+ glBegin(GL_LINES)
48
+ glVertex(0.5, 0.5)
49
+ glVertex(-0.5, -0.5)
50
+ glEnd
51
+ glPopMatrix()
52
+
53
+ glutSwapBuffers()
54
+ end
55
+
56
+ reshape = Proc.new do |w, h|
57
+ glViewport(0, 0, w, h)
58
+ glMatrixMode(GL_PROJECTION)
59
+ glLoadIdentity()
60
+ if (w <= h)
61
+ gluOrtho2D(-1.0, 1.0, -h.to_f/w.to_f, h.to_f/w.to_f)
62
+ else
63
+ gluOrtho2D(w.to_f/h.to_f, w.to_f/h.to_f, -1.0, 1.0)
64
+ end
65
+ glMatrixMode(GL_MODELVIEW)
66
+ glLoadIdentity()
67
+ end
68
+
69
+ keyboard = Proc.new do |key, x, y|
70
+ case (key)
71
+ when 'r'[0]
72
+ $rotAngle += 20
73
+ $rotAngle = 0 if ($rotAngle >= 360)
74
+ glutPostRedisplay()
75
+ when 'R'[0]
76
+ $rotAngle -= 20
77
+ $rotAngle = 360 if ($rotAngle <= 0)
78
+ glutPostRedisplay()
79
+ when 27
80
+ exit(0)
81
+ end
82
+ end
83
+
84
+ # Main Loop
85
+ # Open window with initial window size, title bar,
86
+ # color index display mode, and handle input events.
87
+ #
88
+ glutInit
89
+ glutInitDisplayMode(GLUT_DOUBLE | GLUT_INDEX)
90
+ glutInitWindowSize(500, 500)
91
+ glutInitWindowPosition(100, 100)
92
+ glutCreateWindow($0)
93
+ myinit
94
+ glutReshapeFunc(reshape)
95
+ glutKeyboardFunc(keyboard)
96
+ glutDisplayFunc(display)
97
+ glutMainLoop
@@ -0,0 +1,142 @@
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
+ # aapoly.c
38
+ # This program draws filled polygons with antialiased
39
+ # edges. The special GL_SRC_ALPHA_SATURATE blending
40
+ # function is used.
41
+ # Pressing the 't' key turns the antialiasing on and off.
42
+ require 'opengl'
43
+ include Gl,Glu,Glut
44
+
45
+ $polySmooth = true
46
+
47
+ def init
48
+ glCullFace(GL_BACK)
49
+ glEnable(GL_CULL_FACE)
50
+ glBlendFunc(GL_SRC_ALPHA_SATURATE, GL_ONE)
51
+ glClearColor(0.0, 0.0, 0.0, 0.0)
52
+ end
53
+
54
+ NFACE=6
55
+ NVERT=8
56
+ $indices = [
57
+ [4, 5, 6, 7], [2, 3, 7, 6], [0, 4, 7, 3],
58
+ [0, 1, 5, 4], [1, 5, 6, 2], [0, 3, 2, 1]
59
+ ]
60
+
61
+ def drawCube(x0, x1, y0, y1, z0, z1)
62
+ v = [[],[],[],[],[],[],[],[]]
63
+ c = [
64
+ [0.0, 0.0, 0.0, 1.0], [1.0, 0.0, 0.0, 1.0],
65
+ [0.0, 1.0, 0.0, 1.0], [1.0, 1.0, 0.0, 1.0],
66
+ [0.0, 0.0, 1.0, 1.0], [1.0, 0.0, 1.0, 1.0],
67
+ [0.0, 1.0, 1.0, 1.0], [1.0, 1.0, 1.0, 1.0]
68
+ ]
69
+
70
+ # indices of front, top, left, bottom, right, back faces
71
+
72
+ v[0][0] = v[3][0] = v[4][0] = v[7][0] = x0
73
+ v[1][0] = v[2][0] = v[5][0] = v[6][0] = x1
74
+ v[0][1] = v[1][1] = v[4][1] = v[5][1] = y0
75
+ v[2][1] = v[3][1] = v[6][1] = v[7][1] = y1
76
+ v[0][2] = v[1][2] = v[2][2] = v[3][2] = z0
77
+ v[4][2] = v[5][2] = v[6][2] = v[7][2] = z1
78
+
79
+ glEnableClientState(GL_VERTEX_ARRAY)
80
+ glEnableClientState(GL_COLOR_ARRAY)
81
+ glVertexPointer(3, GL_FLOAT, 0, v.flatten!.pack("f*"))
82
+ glColorPointer(4, GL_FLOAT, 0, c.flatten!.pack("f*"))
83
+ glDrawElements(GL_QUADS, NFACE*4, GL_UNSIGNED_BYTE, $indices.flatten.pack("C*"))
84
+ glDisableClientState(GL_VERTEX_ARRAY)
85
+ glDisableClientState(GL_COLOR_ARRAY)
86
+ end
87
+
88
+ # Note: polygons must be drawn from front to back
89
+ # for proper blending.
90
+ display = proc do
91
+ if ($polySmooth)
92
+ glClear(GL_COLOR_BUFFER_BIT)
93
+ glEnable(GL_BLEND)
94
+ glEnable(GL_POLYGON_SMOOTH)
95
+ glDisable(GL_DEPTH_TEST)
96
+ else
97
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
98
+ glDisable(GL_BLEND)
99
+ glDisable(GL_POLYGON_SMOOTH)
100
+ glEnable(GL_DEPTH_TEST)
101
+ end
102
+
103
+ glPushMatrix()
104
+ glTranslate(0.0, 0.0, -8.0)
105
+ glRotate(30.0, 1.0, 0.0, 0.0)
106
+ glRotate(60.0, 0.0, 1.0, 0.0)
107
+ drawCube(-0.5, 0.5, -0.5, 0.5, -0.5, 0.5)
108
+ glPopMatrix()
109
+ glutSwapBuffers()
110
+ end
111
+
112
+ reshape = proc do |w, h|
113
+ glViewport(0, 0, w, h)
114
+ glMatrixMode(GL_PROJECTION)
115
+ glLoadIdentity()
116
+ gluPerspective(30.0, w.to_f/ h.to_f, 1.0, 20.0)
117
+ glMatrixMode(GL_MODELVIEW)
118
+ glLoadIdentity()
119
+ end
120
+
121
+ keyboard = proc do |key, x, y|
122
+ case (key)
123
+ when ?t ,?T
124
+ $polySmooth = !$polySmooth
125
+ glutPostRedisplay()
126
+ when 27
127
+ exit(0) # Escape key
128
+ end
129
+ end
130
+
131
+ # Main Loop
132
+ glutInit
133
+ glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_ALPHA | GLUT_DEPTH)
134
+ glutInitWindowSize(500, 500)
135
+ glutInitWindowPosition(100, 100)
136
+ glutCreateWindow($0)
137
+ init()
138
+ glutReshapeFunc(reshape)
139
+ glutKeyboardFunc(keyboard)
140
+ glutDisplayFunc(display)
141
+ glutMainLoop()
142
+
@@ -0,0 +1,119 @@
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
+ # aargb.c
38
+ # This program draws shows how to draw anti-aliased lines. It draws
39
+ # two diagonal lines to form an X when 'r' is typed in the window,
40
+ # the lines are rotated in opposite directions.
41
+ require 'opengl'
42
+ require 'mathn'
43
+ include Gl,Glu,Glut
44
+
45
+ $rotAngle = 0.0
46
+
47
+ # Initialize antialiasing for RGBA mode, including alpha
48
+ # blending, hint, and line width. Print out implementation
49
+ # specific info on line width granularity and width.
50
+ def init
51
+ glEnable(GL_LINE_SMOOTH)
52
+ glEnable(GL_BLEND)
53
+ glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
54
+ glHint(GL_LINE_SMOOTH_HINT, GL_DONT_CARE)
55
+ glLineWidth(1.5)
56
+ glClearColor(0.0, 0.0, 0.0, 0.0)
57
+ end
58
+
59
+ # Draw 2 diagonal lines to form an X
60
+ display = Proc.new do
61
+ glClear(GL_COLOR_BUFFER_BIT)
62
+
63
+ glColor(0.0, 1.0, 0.0)
64
+ glPushMatrix()
65
+ glRotate(-$rotAngle, 0.0, 0.0, 0.1)
66
+ glBegin(GL_LINES)
67
+ glVertex(-0.5, 0.5)
68
+ glVertex(0.5, -0.5)
69
+ glEnd()
70
+ glPopMatrix()
71
+
72
+ glColor(0.0, 0.0, 1.0)
73
+ glPushMatrix()
74
+ glRotate($rotAngle, 0.0, 0.0, 0.1)
75
+ glBegin(GL_LINES)
76
+ glVertex(0.5, 0.5)
77
+ glVertex(-0.5, -0.5)
78
+ glEnd()
79
+ glPopMatrix()
80
+ glutSwapBuffers()
81
+ end
82
+
83
+ reshape = Proc.new do |w, h|
84
+ glViewport(0, 0, w, h)
85
+ glMatrixMode(GL_PROJECTION)
86
+ glLoadIdentity()
87
+ if (w <= h)
88
+ gluOrtho2D(-1.0, 1.0, -1.0*h/w, 1.0*h/w)
89
+ else
90
+ gluOrtho2D(-1.0*w/h, 1.0*w/h, -1.0, 1.0)
91
+ end
92
+ glMatrixMode(GL_MODELVIEW)
93
+ glLoadIdentity()
94
+ end
95
+
96
+ keyboard = Proc.new do |key, x, y|
97
+ case (key)
98
+ when 'r'[0],'R'[0]
99
+ $rotAngle = $rotAngle + 20.0
100
+ $rotAngle = 0.0 if ($rotAngle >= 360.0)
101
+ glutPostRedisplay()
102
+ when 27 # Escape Key
103
+ exit(0)
104
+ end
105
+ end
106
+
107
+ # Main Loop
108
+ # Open window with initial window size, title bar,
109
+ # RGBA display mode, and handle input events.
110
+ glutInit
111
+ glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB)
112
+ glutInitWindowSize(500, 500)
113
+ glutInitWindowPosition(100, 100)
114
+ glutCreateWindow($0)
115
+ init()
116
+ glutReshapeFunc(reshape)
117
+ glutKeyboardFunc(keyboard)
118
+ glutDisplayFunc(display)
119
+ glutMainLoop()