danabr75-opengl 0.10.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (149) hide show
  1. checksums.yaml +7 -0
  2. data/.autotest +29 -0
  3. data/.gemtest +0 -0
  4. data/.gitignore +6 -0
  5. data/.travis.yml +19 -0
  6. data/Gemfile +8 -0
  7. data/History.md +101 -0
  8. data/MIT-LICENSE +18 -0
  9. data/Manifest.txt +142 -0
  10. data/README.rdoc +105 -0
  11. data/Rakefile +170 -0
  12. data/danabr75-opengl.gemspec +32 -0
  13. data/examples/NeHe/NeHe.png +0 -0
  14. data/examples/NeHe/crate.png +0 -0
  15. data/examples/NeHe/glass.png +0 -0
  16. data/examples/NeHe/nehe_lesson02.rb +117 -0
  17. data/examples/NeHe/nehe_lesson03.rb +123 -0
  18. data/examples/NeHe/nehe_lesson04.rb +132 -0
  19. data/examples/NeHe/nehe_lesson05.rb +182 -0
  20. data/examples/NeHe/nehe_lesson06.rb +186 -0
  21. data/examples/NeHe/nehe_lesson07.rb +240 -0
  22. data/examples/NeHe/nehe_lesson08.rb +255 -0
  23. data/examples/NeHe/nehe_lesson09.rb +203 -0
  24. data/examples/NeHe/nehe_lesson11.rb +176 -0
  25. data/examples/NeHe/nehe_lesson12.rb +203 -0
  26. data/examples/NeHe/nehe_lesson16.rb +211 -0
  27. data/examples/NeHe/nehe_lesson19.rb +209 -0
  28. data/examples/NeHe/nehe_lesson36.rb +308 -0
  29. data/examples/NeHe/particle.png +0 -0
  30. data/examples/NeHe/star.png +0 -0
  31. data/examples/NeHe/tim.png +0 -0
  32. data/examples/OrangeBook/3Dlabs-License.txt +33 -0
  33. data/examples/OrangeBook/brick.frag +36 -0
  34. data/examples/OrangeBook/brick.rb +378 -0
  35. data/examples/OrangeBook/brick.vert +41 -0
  36. data/examples/OrangeBook/particle.frag +17 -0
  37. data/examples/OrangeBook/particle.rb +408 -0
  38. data/examples/OrangeBook/particle.vert +38 -0
  39. data/examples/README +16 -0
  40. data/examples/RedBook/aapoly.rb +143 -0
  41. data/examples/RedBook/aargb.rb +121 -0
  42. data/examples/RedBook/accanti.rb +164 -0
  43. data/examples/RedBook/accpersp.rb +217 -0
  44. data/examples/RedBook/alpha.rb +125 -0
  45. data/examples/RedBook/alpha3D.rb +160 -0
  46. data/examples/RedBook/bezcurve.rb +107 -0
  47. data/examples/RedBook/bezmesh.rb +139 -0
  48. data/examples/RedBook/checker.rb +126 -0
  49. data/examples/RedBook/clip.rb +97 -0
  50. data/examples/RedBook/colormat.rb +137 -0
  51. data/examples/RedBook/cube.rb +71 -0
  52. data/examples/RedBook/depthcue.rb +101 -0
  53. data/examples/RedBook/dof.rb +206 -0
  54. data/examples/RedBook/double.rb +107 -0
  55. data/examples/RedBook/drawf.rb +93 -0
  56. data/examples/RedBook/feedback.rb +147 -0
  57. data/examples/RedBook/fog.rb +168 -0
  58. data/examples/RedBook/font.rb +153 -0
  59. data/examples/RedBook/hello.rb +81 -0
  60. data/examples/RedBook/image.rb +139 -0
  61. data/examples/RedBook/jitter.rb +207 -0
  62. data/examples/RedBook/light.rb +157 -0
  63. data/examples/RedBook/lines.rb +130 -0
  64. data/examples/RedBook/list.rb +113 -0
  65. data/examples/RedBook/material.rb +276 -0
  66. data/examples/RedBook/mipmap.rb +158 -0
  67. data/examples/RedBook/model.rb +115 -0
  68. data/examples/RedBook/movelight.rb +134 -0
  69. data/examples/RedBook/pickdepth.rb +181 -0
  70. data/examples/RedBook/planet.rb +110 -0
  71. data/examples/RedBook/quadric.rb +160 -0
  72. data/examples/RedBook/robot.rb +117 -0
  73. data/examples/RedBook/select.rb +198 -0
  74. data/examples/RedBook/smooth.rb +97 -0
  75. data/examples/RedBook/stencil.rb +165 -0
  76. data/examples/RedBook/stroke.rb +169 -0
  77. data/examples/RedBook/surface.rb +168 -0
  78. data/examples/RedBook/teaambient.rb +134 -0
  79. data/examples/RedBook/teapots.rb +184 -0
  80. data/examples/RedBook/tess.rb +185 -0
  81. data/examples/RedBook/texbind.rb +149 -0
  82. data/examples/RedBook/texgen.rb +171 -0
  83. data/examples/RedBook/texturesurf.rb +130 -0
  84. data/examples/RedBook/varray.rb +161 -0
  85. data/examples/RedBook/wrap.rb +150 -0
  86. data/examples/misc/OGLBench.rb +338 -0
  87. data/examples/misc/anisotropic.rb +196 -0
  88. data/examples/misc/fbo_test.rb +357 -0
  89. data/examples/misc/font-glut.rb +47 -0
  90. data/examples/misc/glfwtest.rb +30 -0
  91. data/examples/misc/plane.rb +161 -0
  92. data/examples/misc/readpixel.rb +66 -0
  93. data/examples/misc/sdltest.rb +36 -0
  94. data/examples/misc/trislam.rb +829 -0
  95. data/ext/opengl/GL/gl.h +2115 -0
  96. data/ext/opengl/GL/glext.h +11770 -0
  97. data/ext/opengl/common.h +372 -0
  98. data/ext/opengl/conv.h +247 -0
  99. data/ext/opengl/extconf.rb +19 -0
  100. data/ext/opengl/fptr_struct.h +912 -0
  101. data/ext/opengl/funcdef.h +279 -0
  102. data/ext/opengl/gl-1.0-1.1.c +3345 -0
  103. data/ext/opengl/gl-1.2.c +155 -0
  104. data/ext/opengl/gl-1.3.c +447 -0
  105. data/ext/opengl/gl-1.4.c +346 -0
  106. data/ext/opengl/gl-1.5.c +225 -0
  107. data/ext/opengl/gl-2.0.c +665 -0
  108. data/ext/opengl/gl-2.1.c +57 -0
  109. data/ext/opengl/gl-3.0.c +502 -0
  110. data/ext/opengl/gl-enums.c +4853 -0
  111. data/ext/opengl/gl-enums.h +14528 -0
  112. data/ext/opengl/gl-error.c +110 -0
  113. data/ext/opengl/gl-error.h +25 -0
  114. data/ext/opengl/gl-ext-3dfx.c +27 -0
  115. data/ext/opengl/gl-ext-arb.c +880 -0
  116. data/ext/opengl/gl-ext-ati.c +41 -0
  117. data/ext/opengl/gl-ext-ext.c +885 -0
  118. data/ext/opengl/gl-ext-gremedy.c +41 -0
  119. data/ext/opengl/gl-ext-nv.c +679 -0
  120. data/ext/opengl/gl.c +265 -0
  121. data/ext/opengl/gl_buffer.c +202 -0
  122. data/ext/opengl/glimpl.c +187 -0
  123. data/ext/opengl/glimpl.h +47 -0
  124. data/ext/opengl/opengl.c +9 -0
  125. data/lib/gl.rb +1 -0
  126. data/lib/opengl.rb +79 -0
  127. data/lib/opengl/bindings_version.rb +4 -0
  128. data/lib/opengl/implementation.rb +38 -0
  129. data/lib/opengl/test_case.rb +86 -0
  130. data/test/dummy.xorg.conf +140 -0
  131. data/test/test_gl.rb +45 -0
  132. data/test/test_gl_10_11.rb +1363 -0
  133. data/test/test_gl_12.rb +71 -0
  134. data/test/test_gl_13.rb +221 -0
  135. data/test/test_gl_14.rb +218 -0
  136. data/test/test_gl_15.rb +258 -0
  137. data/test/test_gl_20.rb +417 -0
  138. data/test/test_gl_21.rb +436 -0
  139. data/test/test_gl_ext_arb.rb +508 -0
  140. data/test/test_gl_ext_ati.rb +28 -0
  141. data/test/test_gl_ext_ext.rb +608 -0
  142. data/test/test_gl_ext_gremedy.rb +29 -0
  143. data/test/test_gl_ext_nv.rb +349 -0
  144. data/test/test_glimpl.rb +23 -0
  145. data/test/test_opengl_buffer.rb +122 -0
  146. data/utils/README +6 -0
  147. data/utils/enumgen.rb +108 -0
  148. data/utils/extlistgen.rb +90 -0
  149. metadata +326 -0
@@ -0,0 +1,134 @@
1
+ #
2
+ # Copyright (c) Mark J. Kilgard, 1994.
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
+ # teaambient.c
40
+ # This program renders three lighted, shaded teapots, with
41
+ # different ambient values.
42
+ require 'opengl'
43
+ require 'glu'
44
+ require 'glut'
45
+ include Gl,Glu,Glut
46
+
47
+ # Initialize light source and lighting model.
48
+ def myinit
49
+ light_ambient = [0.0, 0.0, 0.0, 1.0]
50
+ light_diffuse = [1.0, 1.0, 1.0, 1.0]
51
+ light_specular = [1.0, 1.0, 1.0, 1.0]
52
+ # light_position is NOT default value
53
+ light_position = [1.0, 0.0, 0.0, 0.0]
54
+ global_ambient = [0.75, 0.75, 0.75, 1.0]
55
+
56
+ glLight(GL_LIGHT0, GL_AMBIENT, light_ambient)
57
+ glLight(GL_LIGHT0, GL_DIFFUSE, light_diffuse)
58
+ glLight(GL_LIGHT0, GL_SPECULAR, light_specular)
59
+ glLight(GL_LIGHT0, GL_POSITION, light_position)
60
+
61
+ glLightModel(GL_LIGHT_MODEL_AMBIENT, global_ambient)
62
+
63
+ glFrontFace(GL_CW)
64
+ glEnable(GL_LIGHTING)
65
+ glEnable(GL_LIGHT0)
66
+ glEnable(GL_AUTO_NORMAL)
67
+ glEnable(GL_NORMALIZE)
68
+ glDepthFunc(GL_LESS)
69
+ glEnable(GL_DEPTH_TEST)
70
+ end
71
+
72
+ display = proc do
73
+ low_ambient = [0.1, 0.1, 0.1, 1.0]
74
+ more_ambient = [0.4, 0.4, 0.4, 1.0]
75
+ most_ambient = [1.0, 1.0, 1.0, 1.0]
76
+
77
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
78
+
79
+ # material has small ambient reflection
80
+ glMaterial(GL_FRONT, GL_AMBIENT, low_ambient)
81
+ glMaterial(GL_FRONT, GL_SHININESS, 40.0)
82
+ glPushMatrix()
83
+ glTranslate(0.0, 2.0, 0.0)
84
+ glutSolidTeapot(1.0)
85
+ glPopMatrix()
86
+
87
+ # material has moderate ambient reflection
88
+ glMaterial(GL_FRONT, GL_AMBIENT, more_ambient)
89
+ glPushMatrix()
90
+ glTranslate(0.0, 0.0, 0.0)
91
+ glutSolidTeapot(1.0)
92
+ glPopMatrix()
93
+
94
+ # material has large ambient reflection
95
+ glMaterial(GL_FRONT, GL_AMBIENT, most_ambient)
96
+ glPushMatrix()
97
+ glTranslate(0.0, -2.0, 0.0)
98
+ glutSolidTeapot(1.0)
99
+ glPopMatrix()
100
+ glFlush()
101
+ end
102
+
103
+ myReshape = proc do |w, h|
104
+ glViewport(0, 0, w, h)
105
+ glMatrixMode(GL_PROJECTION)
106
+ glLoadIdentity()
107
+ if (w <= h)
108
+ glOrtho(-4.0, 4.0, -4.0 * h / w, 4.0 * h / w, -10.0, 10.0)
109
+ else
110
+ glOrtho(-4.0 * w / h, 4.0 * w / h, -4.0, 4.0, -10.0, 10.0)
111
+ end
112
+ glMatrixMode(GL_MODELVIEW)
113
+ end
114
+
115
+ keyboard = Proc.new do |key, x, y|
116
+ case (key)
117
+ when ?\e
118
+ exit(0);
119
+ end
120
+ end
121
+
122
+ # Main Loop
123
+ # Open window with initial window size, title bar,
124
+ # RGBA display mode, and handle input events.
125
+ glutInit()
126
+ glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH)
127
+ glutInitWindowSize(500, 500)
128
+ glutInitWindowPosition(100, 100)
129
+ glutCreateWindow()
130
+ myinit()
131
+ glutReshapeFunc(myReshape)
132
+ glutDisplayFunc(display)
133
+ glutKeyboardFunc(keyboard)
134
+ glutMainLoop()
@@ -0,0 +1,184 @@
1
+ #
2
+ # Copyright (c) Mark J. Kilgard, 1994.
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
+ # teapots.c
40
+ # This program demonstrates lots of material properties.
41
+ # A single light source illuminates the objects.
42
+ require 'opengl'
43
+ require 'glu'
44
+ require 'glut'
45
+ include Gl,Glu,Glut
46
+
47
+ # Initialize depth buffer, projection matrix, light source, and lighting
48
+ # model. Do not specify a material property here.
49
+ def myinit
50
+ ambient = [0.0, 0.0, 0.0, 1.0]
51
+ diffuse = [1.0, 1.0, 1.0, 1.0]
52
+ position = [0.0, 3.0, 3.0, 0.0]
53
+
54
+ lmodel_ambient = [0.2, 0.2, 0.2, 1.0]
55
+ local_view = [0.0]
56
+
57
+ glLight(GL_LIGHT0, GL_AMBIENT, ambient)
58
+ glLight(GL_LIGHT0, GL_DIFFUSE, diffuse)
59
+ glLight(GL_LIGHT0, GL_POSITION, position)
60
+ glLightModel(GL_LIGHT_MODEL_AMBIENT, lmodel_ambient)
61
+ glLightModel(GL_LIGHT_MODEL_LOCAL_VIEWER, local_view)
62
+
63
+ glFrontFace(GL_CW)
64
+ glEnable(GL_LIGHTING)
65
+ glEnable(GL_LIGHT0)
66
+ glEnable(GL_AUTO_NORMAL)
67
+ glEnable(GL_NORMALIZE)
68
+ glEnable(GL_DEPTH_TEST)
69
+ glDepthFunc(GL_LESS)
70
+ end
71
+
72
+ # Move object into position. Use 3rd through 12th parameters to specify the
73
+ # material property. Draw a teapot.
74
+ def renderTeapot(x, y, ambr, ambg, ambb, difr, difg, difb, specr, specg, specb, shine)
75
+ mat = []
76
+ glPushMatrix()
77
+ glTranslate(x, y, 0.0)
78
+ mat[0] = ambr
79
+ mat[1] = ambg
80
+ mat[2] = ambb
81
+ mat[3] = 1.0
82
+ glMaterial(GL_FRONT, GL_AMBIENT, mat)
83
+ mat[0] = difr
84
+ mat[1] = difg
85
+ mat[2] = difb
86
+ glMaterial(GL_FRONT, GL_DIFFUSE, mat)
87
+ mat[0] = specr
88
+ mat[1] = specg
89
+ mat[2] = specb
90
+ glMaterial(GL_FRONT, GL_SPECULAR, mat)
91
+ glMaterial(GL_FRONT, GL_SHININESS, shine * 128.0)
92
+ glutSolidTeapot(1.0)
93
+ glPopMatrix()
94
+ end
95
+
96
+ # First column: emerald, jade, obsidian, pearl, ruby, turquoise
97
+ # 2nd column: brass, bronze, chrome, copper, gold, silver
98
+ # 3rd column: black, cyan, green, red, white, yellow plastic
99
+ # 4th column: black, cyan, green, red, white, yellow rubber
100
+ display = proc do
101
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
102
+ renderTeapot(2.0, 17.0, 0.0215, 0.1745, 0.0215,
103
+ 0.07568, 0.61424, 0.07568, 0.633, 0.727811, 0.633, 0.6)
104
+ renderTeapot(2.0, 14.0, 0.135, 0.2225, 0.1575,
105
+ 0.54, 0.89, 0.63, 0.316228, 0.316228, 0.316228, 0.1)
106
+ renderTeapot(2.0, 11.0, 0.05375, 0.05, 0.06625,
107
+ 0.18275, 0.17, 0.22525, 0.332741, 0.328634, 0.346435, 0.3)
108
+ renderTeapot(2.0, 8.0, 0.25, 0.20725, 0.20725,
109
+ 1, 0.829, 0.829, 0.296648, 0.296648, 0.296648, 0.088)
110
+ renderTeapot(2.0, 5.0, 0.1745, 0.01175, 0.01175,
111
+ 0.61424, 0.04136, 0.04136, 0.727811, 0.626959, 0.626959, 0.6)
112
+ renderTeapot(2.0, 2.0, 0.1, 0.18725, 0.1745,
113
+ 0.396, 0.74151, 0.69102, 0.297254, 0.30829, 0.306678, 0.1)
114
+ renderTeapot(6.0, 17.0, 0.329412, 0.223529, 0.027451,
115
+ 0.780392, 0.568627, 0.113725, 0.992157, 0.941176, 0.807843,
116
+ 0.21794872)
117
+ renderTeapot(6.0, 14.0, 0.2125, 0.1275, 0.054,
118
+ 0.714, 0.4284, 0.18144, 0.393548, 0.271906, 0.166721, 0.2)
119
+ renderTeapot(6.0, 11.0, 0.25, 0.25, 0.25,
120
+ 0.4, 0.4, 0.4, 0.774597, 0.774597, 0.774597, 0.6)
121
+ renderTeapot(6.0, 8.0, 0.19125, 0.0735, 0.0225,
122
+ 0.7038, 0.27048, 0.0828, 0.256777, 0.137622, 0.086014, 0.1)
123
+ renderTeapot(6.0, 5.0, 0.24725, 0.1995, 0.0745,
124
+ 0.75164, 0.60648, 0.22648, 0.628281, 0.555802, 0.366065, 0.4)
125
+ renderTeapot(6.0, 2.0, 0.19225, 0.19225, 0.19225,
126
+ 0.50754, 0.50754, 0.50754, 0.508273, 0.508273, 0.508273, 0.4)
127
+ renderTeapot(10.0, 17.0, 0.0, 0.0, 0.0, 0.01, 0.01, 0.01,
128
+ 0.50, 0.50, 0.50, 0.25)
129
+ renderTeapot(10.0, 14.0, 0.0, 0.1, 0.06, 0.0, 0.50980392, 0.50980392,
130
+ 0.50196078, 0.50196078, 0.50196078, 0.25)
131
+ renderTeapot(10.0, 11.0, 0.0, 0.0, 0.0,
132
+ 0.1, 0.35, 0.1, 0.45, 0.55, 0.45, 0.25)
133
+ renderTeapot(10.0, 8.0, 0.0, 0.0, 0.0, 0.5, 0.0, 0.0,
134
+ 0.7, 0.6, 0.6, 0.25)
135
+ renderTeapot(10.0, 5.0, 0.0, 0.0, 0.0, 0.55, 0.55, 0.55,
136
+ 0.70, 0.70, 0.70, 0.25)
137
+ renderTeapot(10.0, 2.0, 0.0, 0.0, 0.0, 0.5, 0.5, 0.0,
138
+ 0.60, 0.60, 0.50, 0.25)
139
+ renderTeapot(14.0, 17.0, 0.02, 0.02, 0.02, 0.01, 0.01, 0.01,
140
+ 0.4, 0.4, 0.4, 0.078125)
141
+ renderTeapot(14.0, 14.0, 0.0, 0.05, 0.05, 0.4, 0.5, 0.5,
142
+ 0.04, 0.7, 0.7, 0.078125)
143
+ renderTeapot(14.0, 11.0, 0.0, 0.05, 0.0, 0.4, 0.5, 0.4,
144
+ 0.04, 0.7, 0.04, 0.078125)
145
+ renderTeapot(14.0, 8.0, 0.05, 0.0, 0.0, 0.5, 0.4, 0.4,
146
+ 0.7, 0.04, 0.04, 0.078125)
147
+ renderTeapot(14.0, 5.0, 0.05, 0.05, 0.05, 0.5, 0.5, 0.5,
148
+ 0.7, 0.7, 0.7, 0.078125)
149
+ renderTeapot(14.0, 2.0, 0.05, 0.05, 0.0, 0.5, 0.5, 0.4,
150
+ 0.7, 0.7, 0.04, 0.078125)
151
+ glutSwapBuffers()
152
+ end
153
+
154
+ myReshape = proc do |w, h|
155
+ glViewport(0, 0, w, h)
156
+ glMatrixMode(GL_PROJECTION)
157
+ glLoadIdentity()
158
+ if (w <= h)
159
+ glOrtho(0.0, 16.0, 0.0, 16.0 * h.to_f / w, -10.0, 10.0)
160
+ else
161
+ glOrtho(0.0, 16.0 * w.to_f / h, 0.0, 16.0,-10.0, 10.0)
162
+ end
163
+ glMatrixMode(GL_MODELVIEW)
164
+ end
165
+
166
+ keyboard = Proc.new do |key, x, y|
167
+ case (key)
168
+ when ?\e
169
+ exit(0);
170
+ end
171
+ end
172
+
173
+ # Main Loop Open window with initial window size, title bar, RGBA display
174
+ # mode, and handle input events.
175
+ glutInit()
176
+ glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH)
177
+ glutInitWindowSize(500, 500)
178
+ glutInitWindowPosition(100, 100)
179
+ glutCreateWindow()
180
+ myinit()
181
+ glutReshapeFunc(myReshape)
182
+ glutDisplayFunc(display)
183
+ glutKeyboardFunc(keyboard)
184
+ glutMainLoop()
@@ -0,0 +1,185 @@
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
+ # tess.c
38
+ # This program demonstrates polygon tessellation.
39
+ # Two tesselated objects are drawn. The first is a
40
+ # rectangle with a triangular hole. The second is a
41
+ # smooth shaded, self-intersecting star.
42
+ #
43
+ # Note the exterior rectangle is drawn with its vertices
44
+ # in counter-clockwise order, but its interior clockwise.
45
+ # Note the combineCallback is needed for the self-intersecting
46
+ # star. Also note that removing the TessProperty for the
47
+ # star will make the interior unshaded (WINDING_ODD).
48
+ require 'opengl'
49
+ require 'glu'
50
+ require 'glut'
51
+ include Gl,Glu,Glut
52
+
53
+ $startList = nil
54
+
55
+ display = proc do
56
+ glClear(GL_COLOR_BUFFER_BIT)
57
+ glColor(1.0, 1.0, 1.0)
58
+ glCallList($startList)
59
+ glCallList($startList + 1)
60
+ glutSwapBuffers()
61
+ end
62
+
63
+ $beginCallback = proc do |which|
64
+ glBegin(which)
65
+ end
66
+
67
+ $errorCallback = proc do |errorCode|
68
+ print "Tessellation Error: #{gluErrorString(errorCode)}"
69
+ exit(0)
70
+ end
71
+
72
+ $endCallback = proc do
73
+ glEnd()
74
+ end
75
+
76
+ $vertexCallback = proc do |vertex|
77
+ glColor(vertex[3], vertex[4], vertex[5])
78
+ glVertex(vertex[0], vertex[1], vertex[2])
79
+ end
80
+
81
+ # combineCallback is used to create a new vertex when edges
82
+ # intersect. coordinate location is trivial to calculate,
83
+ # but weight[4] may be used to average color, normal, or texture
84
+ # coordinate data. In this program, color is weighted.
85
+ $combineCallback = proc do |coords, vertex_data, weight|
86
+ vertex = []
87
+ vertex[0] = coords[0]
88
+ vertex[1] = coords[1]
89
+ vertex[2] = coords[2]
90
+ for i in 3...6
91
+ 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]
92
+ end
93
+ vertex
94
+ end
95
+
96
+ def init
97
+ rect = [[50.0, 50.0, 0.0],
98
+ [200.0, 50.0, 0.0],
99
+ [200.0, 200.0, 0.0],
100
+ [50.0, 200.0, 0.0]]
101
+ tri = [[75.0, 75.0, 0.0],
102
+ [125.0, 175.0, 0.0],
103
+ [175.0, 75.0, 0.0]]
104
+ star= [[250.0, 50.0, 0.0, 1.0, 0.0, 1.0],
105
+ [325.0, 200.0, 0.0, 1.0, 1.0, 0.0],
106
+ [400.0, 50.0, 0.0, 0.0, 1.0, 1.0],
107
+ [250.0, 150.0, 0.0, 1.0, 0.0, 0.0],
108
+ [400.0, 150.0, 0.0, 0.0, 1.0, 0.0]]
109
+
110
+ glClearColor(0.0, 0.0, 0.0, 0.0)
111
+
112
+ $startList = glGenLists(2)
113
+
114
+ tobj = gluNewTess()
115
+ gluTessCallback(tobj, GLU_TESS_VERTEX, proc do |v| glVertex(v) end )
116
+ gluTessCallback(tobj, GLU_TESS_BEGIN, $beginCallback)
117
+ gluTessCallback(tobj, GLU_TESS_END, $endCallback)
118
+ gluTessCallback(tobj, GLU_TESS_ERROR, $errorCallback)
119
+
120
+ # rectangle with triangular hole inside
121
+ glNewList($startList, GL_COMPILE)
122
+ glShadeModel(GL_FLAT)
123
+ gluTessBeginPolygon(tobj, nil)
124
+ gluTessBeginContour(tobj)
125
+ gluTessVertex(tobj, rect[0], rect[0])
126
+ gluTessVertex(tobj, rect[1], rect[1])
127
+ gluTessVertex(tobj, rect[2], rect[2])
128
+ gluTessVertex(tobj, rect[3], rect[3])
129
+ gluTessEndContour(tobj)
130
+ gluTessBeginContour(tobj)
131
+ gluTessVertex(tobj, tri[0], tri[0])
132
+ gluTessVertex(tobj, tri[1], tri[1])
133
+ gluTessVertex(tobj, tri[2], tri[2])
134
+ gluTessEndContour(tobj)
135
+ gluTessEndPolygon(tobj)
136
+ glEndList()
137
+
138
+ gluTessCallback(tobj, GLU_TESS_VERTEX, $vertexCallback)
139
+ gluTessCallback(tobj, GLU_TESS_BEGIN, $beginCallback)
140
+ gluTessCallback(tobj, GLU_TESS_END, $endCallback)
141
+ gluTessCallback(tobj, GLU_TESS_ERROR, $errorCallback)
142
+ gluTessCallback(tobj, GLU_TESS_COMBINE, $combineCallback)
143
+
144
+
145
+ # smooth shaded, self-intersecting star
146
+ glNewList($startList + 1, GL_COMPILE)
147
+ glShadeModel(GL_SMOOTH)
148
+ gluTessProperty(tobj, GLU_TESS_WINDING_RULE, GLU_TESS_WINDING_POSITIVE)
149
+ gluTessBeginPolygon(tobj, nil)
150
+ gluTessBeginContour(tobj)
151
+ gluTessVertex(tobj, star[0], star[0])
152
+ gluTessVertex(tobj, star[1], star[1])
153
+ gluTessVertex(tobj, star[2], star[2])
154
+ gluTessVertex(tobj, star[3], star[3])
155
+ gluTessVertex(tobj, star[4], star[4])
156
+ gluTessEndContour(tobj)
157
+ gluTessEndPolygon(tobj)
158
+ glEndList()
159
+ gluDeleteTess(tobj)
160
+ end
161
+
162
+ reshape = proc do |w, h|
163
+ glViewport(0, 0, w, h)
164
+ glMatrixMode(GL_PROJECTION)
165
+ glLoadIdentity()
166
+ gluOrtho2D(0.0, w, 0.0, h)
167
+ end
168
+
169
+ keyboard = proc do |key, x, y|
170
+ case (key)
171
+ when ?\e
172
+ exit(0)
173
+ end
174
+ end
175
+
176
+ glutInit()
177
+ glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB)
178
+ glutInitWindowSize(500, 500)
179
+ glutInitWindowPosition(100, 100)
180
+ glutCreateWindow()
181
+ init()
182
+ glutDisplayFunc(display)
183
+ glutReshapeFunc(reshape)
184
+ glutKeyboardFunc(keyboard)
185
+ glutMainLoop()