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,161 @@
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
+ # varray.c
38
+ # This program demonstrates vertex arrays.
39
+ require 'opengl'
40
+ require 'glu'
41
+ require 'glut'
42
+ include Gl,Glu,Glut
43
+
44
+ POINTER=1
45
+ INTERLEAVED=2
46
+
47
+ DRAWARRAY=1
48
+ ARRAYELEMENT=2
49
+ DRAWELEMENTS=3
50
+
51
+ $setupMethod = POINTER
52
+ $derefMethod = DRAWARRAY
53
+
54
+ def setupPointers
55
+ $vertices = [25, 25,
56
+ 100, 325,
57
+ 175, 25,
58
+ 175, 325,
59
+ 250, 25,
60
+ 325, 325].pack("i*")
61
+ $colors = [1.0, 0.2, 0.2,
62
+ 0.2, 0.2, 1.0,
63
+ 0.8, 1.0, 0.2,
64
+ 0.75, 0.75, 0.75,
65
+ 0.35, 0.35, 0.35,
66
+ 0.5, 0.5, 0.5].pack("f*")
67
+
68
+ glEnableClientState(GL_VERTEX_ARRAY)
69
+ glEnableClientState(GL_COLOR_ARRAY)
70
+
71
+ glVertexPointer(2, GL_INT, 0, $vertices)
72
+ glColorPointer(3, GL_FLOAT, 0, $colors)
73
+ end
74
+
75
+ def setupInterleave
76
+ $intertwined =
77
+ [1.0, 0.2, 1.0, 100.0, 100.0, 0.0,
78
+ 1.0, 0.2, 0.2, 0.0, 200.0, 0.0,
79
+ 1.0, 1.0, 0.2, 100.0, 300.0, 0.0,
80
+ 0.2, 1.0, 0.2, 200.0, 300.0, 0.0,
81
+ 0.2, 1.0, 1.0, 300.0, 200.0, 0.0,
82
+ 0.2, 0.2, 1.0, 200.0, 100.0, 0.0].pack("f*")
83
+
84
+ glInterleavedArrays(GL_C3F_V3F, 0, $intertwined)
85
+ end
86
+
87
+ def init
88
+ glClearColor(0.0, 0.0, 0.0, 0.0)
89
+ glShadeModel(GL_SMOOTH)
90
+ setupPointers()
91
+ end
92
+
93
+ display = proc do
94
+ glClear(GL_COLOR_BUFFER_BIT)
95
+ if ($derefMethod == DRAWARRAY)
96
+ glDrawArrays(GL_TRIANGLES, 0, 6)
97
+ elsif ($derefMethod == ARRAYELEMENT)
98
+ glBegin(GL_TRIANGLES)
99
+ glArrayElement(2)
100
+ glArrayElement(3)
101
+ glArrayElement(5)
102
+ glEnd()
103
+ elsif ($derefMethod == DRAWELEMENTS)
104
+ $indices = [0, 1, 3, 4].pack("I*")
105
+ glDrawElements(GL_POLYGON, 4, GL_UNSIGNED_INT, $indices)
106
+ end
107
+ glutSwapBuffers()
108
+ end
109
+
110
+ reshape = proc do|w, h|
111
+ glViewport(0, 0, w, h)
112
+ glMatrixMode(GL_PROJECTION)
113
+ glLoadIdentity()
114
+ gluOrtho2D(0.0, w, 0.0, h)
115
+ end
116
+
117
+ mouse = proc do |button, state, x, y|
118
+ case (button)
119
+ when GLUT_LEFT_BUTTON
120
+ if (state == GLUT_DOWN)
121
+ if ($setupMethod == POINTER)
122
+ $setupMethod = INTERLEAVED
123
+ setupInterleave()
124
+ elsif ($setupMethod == INTERLEAVED)
125
+ $setupMethod = POINTER
126
+ setupPointers()
127
+ end
128
+ glutPostRedisplay()
129
+ end
130
+ when GLUT_MIDDLE_BUTTON,GLUT_RIGHT_BUTTON
131
+ if (state == GLUT_DOWN)
132
+ if ($derefMethod == DRAWARRAY)
133
+ $derefMethod = ARRAYELEMENT
134
+ elsif ($derefMethod == ARRAYELEMENT)
135
+ $derefMethod = DRAWELEMENTS
136
+ elsif ($derefMethod == DRAWELEMENTS)
137
+ $derefMethod = DRAWARRAY
138
+ end
139
+ glutPostRedisplay()
140
+ end
141
+ end
142
+ end
143
+
144
+ keyboard = proc do |key, x, y|
145
+ case (key)
146
+ when ?\e
147
+ exit(0)
148
+ end
149
+ end
150
+
151
+ glutInit()
152
+ glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB)
153
+ glutInitWindowSize(350, 350)
154
+ glutInitWindowPosition(100, 100)
155
+ glutCreateWindow()
156
+ init()
157
+ glutDisplayFunc(display)
158
+ glutReshapeFunc(reshape)
159
+ glutMouseFunc(mouse)
160
+ glutKeyboardFunc(keyboard)
161
+ glutMainLoop()
@@ -0,0 +1,150 @@
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
+ # wrap.c
38
+ # This program texture maps a checkerboard image onto
39
+ # two rectangles. This program demonstrates the wrapping
40
+ # modes, if the texture coordinates fall outside 0.0 and 1.0.
41
+ # Interaction: Pressing the 's' and 'S' keys switch the
42
+ # wrapping between clamping and repeating for the s parameter.
43
+ # The 't' and 'T' keys control the wrapping for the t parameter.
44
+ #
45
+ # If running this program on OpenGL 1.0, texture objects are
46
+ # not used.
47
+ require 'opengl'
48
+ require 'glu'
49
+ require 'glut'
50
+ require 'mathn'
51
+ include Gl,Glu,Glut
52
+
53
+ # Create checkerboard texture
54
+ CheckImageWidth=64
55
+ CheckImageHeight=64
56
+ $checkImage = []
57
+
58
+ $texName = 0
59
+
60
+ def makeCheckImage
61
+ for i in 0..CheckImageHeight-1
62
+ for j in 0..CheckImageWidth-1
63
+ c = if (((i&0x8)==0)!=((j&0x8)==0)) then 255 else 0 end
64
+ $checkImage[(i*CheckImageWidth+j)*4+0] = c
65
+ $checkImage[(i*CheckImageWidth+j)*4+1] = c
66
+ $checkImage[(i*CheckImageWidth+j)*4+2] = c
67
+ $checkImage[(i*CheckImageWidth+j)*4+3] = 255
68
+ end
69
+ end
70
+ end
71
+
72
+ def init
73
+ glClearColor(0.0, 0.0, 0.0, 0.0)
74
+ glShadeModel(GL_FLAT)
75
+ glEnable(GL_DEPTH_TEST)
76
+
77
+ makeCheckImage()
78
+ glPixelStore(GL_UNPACK_ALIGNMENT, 1)
79
+
80
+ $texName = glGenTextures(1)
81
+ glBindTexture(GL_TEXTURE_2D, $texName[0])
82
+
83
+ glTexParameter(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT)
84
+ glTexParameter(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT)
85
+ glTexParameter(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST)
86
+ glTexParameter(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST)
87
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, CheckImageWidth,
88
+ CheckImageHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, $checkImage.pack("C*"))
89
+ end
90
+
91
+ display = Proc.new do
92
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
93
+ glEnable(GL_TEXTURE_2D)
94
+ glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL)
95
+ glBindTexture(GL_TEXTURE_2D, $texName[0])
96
+
97
+ glBegin(GL_QUADS)
98
+ glTexCoord(0.0, 0.0); glVertex(-2.0, -1.0, 0.0)
99
+ glTexCoord(0.0, 3.0); glVertex(-2.0, 1.0, 0.0)
100
+ glTexCoord(3.0, 3.0); glVertex(0.0, 1.0, 0.0)
101
+ glTexCoord(3.0, 0.0); glVertex(0.0, -1.0, 0.0)
102
+
103
+ glTexCoord(0.0, 0.0); glVertex(1.0, -1.0, 0.0)
104
+ glTexCoord(0.0, 3.0); glVertex(1.0, 1.0, 0.0)
105
+ glTexCoord(3.0, 3.0); glVertex(2.41421, 1.0, -1.41421)
106
+ glTexCoord(3.0, 0.0); glVertex(2.41421, -1.0, -1.41421)
107
+ glEnd()
108
+ glutSwapBuffers()
109
+ glDisable(GL_TEXTURE_2D)
110
+ end
111
+
112
+ reshape = Proc.new do |w, h|
113
+ glViewport(0, 0, w, h)
114
+ glMatrixMode(GL_PROJECTION)
115
+ glLoadIdentity()
116
+ GLU.Perspective(60.0, w/h, 1.0, 30.0)
117
+ glMatrixMode(GL_MODELVIEW)
118
+ glLoadIdentity()
119
+ glTranslate(0.0, 0.0, -3.6)
120
+ end
121
+
122
+ keyboard = Proc.new do |key, x, y|
123
+ case (key)
124
+ when ?s
125
+ glTexParameter(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP)
126
+ glutPostRedisplay()
127
+ when ?S
128
+ glTexParameter(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT)
129
+ glutPostRedisplay()
130
+ when ?t
131
+ glTexParameter(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP)
132
+ glutPostRedisplay()
133
+ when ?T
134
+ glTexParameter(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT)
135
+ glutPostRedisplay()
136
+ when ?\e
137
+ exit(0)
138
+ end
139
+ end
140
+
141
+ glutInit
142
+ glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH)
143
+ glutInitWindowSize(500, 500)
144
+ glutInitWindowPosition(100, 100)
145
+ glutCreateWindow($0)
146
+ init()
147
+ glutDisplayFunc(display)
148
+ glutReshapeFunc(reshape)
149
+ glutKeyboardFunc(keyboard)
150
+ glutMainLoop()
@@ -0,0 +1,338 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # Purpose: Factor out and clean up common code from OpenGL benchmarks
4
+
5
+ # Copyright (c) 2006, Geoff Broadwell; this module is released
6
+ # as open source and may be distributed and modified under the terms
7
+ # of either the Artistic License or the GNU General Public License,
8
+ # in the same manner as Perl itself. These licenses should have been
9
+ # distributed to you as part of your Perl distribution, and can be
10
+ # read using `perldoc perlartistic` and `perldoc perlgpl` respectively.
11
+
12
+ # Conversion to ruby by Jan Dvorak <jan.dvorak@kraxnet.cz>
13
+
14
+ module OGLBench
15
+
16
+ require 'opengl'
17
+ require 'glu'
18
+ require 'glut'
19
+ include Gl,Glu,Glut
20
+
21
+ require 'getoptlong'
22
+
23
+ VER = '0.1.4'
24
+
25
+ # Cached config and state, for simpler API
26
+ $CACHED = {}
27
+
28
+ # All resolutions listed in landscape orientation,
29
+ # even for natively portrait devices such as handhelds.
30
+ # Also, 'q' is annoyingly used as a prefix to mean both
31
+ # 'quarter' and 'quad'.
32
+ $KNOWN_RES = {
33
+ 'qqvga' => [ 160, 120, 'Quarter Quarter VGA' ],
34
+ 'palm' => [ 160, 160, 'Original Palm OS Devices' ],
35
+ 'eigthvga' => [ 240, 160, '1/8 VGA' ],
36
+ 'vcrntsc' => [ 240, 480, 'VCR NTSC' ],
37
+ 'vcrpal' => [ 240, 576, 'VCR PAL' ],
38
+ 'qcif' => [ 176, 144, 'Quarter CIF' ],
39
+ 'gears' => [ 300, 300, 'OpenGL Gears Benchmark' ],
40
+ 'glxgears' => [ 300, 300, 'OpenGL Gears Benchmark' ],
41
+ 'cga' => [ 320, 200, 'IBM PC CGA (Color Graphics Adapter)' ],
42
+ 'atarist16' => [ 320, 200, 'Atari ST 16 Color' ],
43
+ 'qvga' => [ 320, 240, 'Quarter VGA' ],
44
+ 'modex' => [ 320, 240, 'VGA Mode X' ],
45
+ 'pocketpc' => [ 320, 240, 'Common Pocket PCs' ],
46
+ 'clie' => [ 320, 320, 'Sony Clie (Palm OS)' ],
47
+ 'vcdntsc' => [ 352, 240, 'VCD (Video CD) NTSC' ],
48
+ 'vcdpal' => [ 352, 288, 'VCD (Video CD) PAL' ],
49
+ 'cif' => [ 352, 288, 'CIF (Common Image Format)' ],
50
+ 'tweakvga' => [ 360, 480, 'Highest 256-color mode for VGA monitors' ],
51
+ 'svhsntsc' => [ 400, 480, 'S-VHS NTSC' ],
52
+ 'svhspal' => [ 400, 576, 'S-VHS PAL' ],
53
+ 'tungsten' => [ 480, 320, 'Tungsten (Palm OS)' ],
54
+ 'bwmac9' => [ 512, 342, 'Black & White 9" Mac' ],
55
+ 'maclc' => [ 512, 384, 'Mac LC' ],
56
+ 'ldntsc' => [ 560, 480, 'Laserdisc NTSC' ],
57
+ 'ldpal' => [ 560, 576, 'Laserdisc PAL' ],
58
+ 'atarist4' => [ 640, 200, 'Atari ST 4 Color' ],
59
+ 'ega' => [ 640, 350, 'IBM PC-AT EGA (Extended Graphics Adapter)' ],
60
+ 'atarist2' => [ 640, 400, 'Atari ST 2 Color' ],
61
+ 'qcga' => [ 640, 400, 'Quad CGA' ],
62
+ 'vga400' => [ 640, 400, 'VGA 400 Line' ],
63
+ 'pgc' => [ 640, 480, 'Professional Graphics Controller' ],
64
+ 'mcga' => [ 640, 480, 'IBM PS/2 MultiColor Graphics Adapter' ],
65
+ 'vga' => [ 640, 480, 'IBM PS/2 VGA (Video Graphics Array)' ],
66
+ 'edtv1' => [ 640, 480, 'EDTV 1' ],
67
+ 'edtv2' => [ 704, 480, 'EDTV 2' ],
68
+ 'hgc' => [ 720, 348, 'Hercules Graphics Controller' ],
69
+ 'mda' => [ 720, 350, 'IBM PC MDA (Monochrome Display Adapter)' ],
70
+ 'lisa' => [ 720, 360, 'Apple Lisa' ],
71
+ 'dv525' => [ 720, 480, 'Digital Video 525/60 (D-1 NTSC, DVD NTSC)' ],
72
+ 'd1ntsc' => [ 720, 480, 'Digital Video 525/60 (D-1 NTSC, DVD NTSC)' ],
73
+ 'dvdntsc' => [ 720, 480, 'Digital Video 525/60 (D-1 NTSC, DVD NTSC)' ],
74
+ 'sp525' => [ 720, 540, 'Digital Video 525/60 (D-1 NTSC Square Pix)' ],
75
+ 'spd1ntsc' => [ 720, 540, 'Digital Video 525/60 (D-1 NTSC Square Pix)' ],
76
+ 'dv625' => [ 720, 576, 'Digital Video 625/50 (PAL, DVD PAL)' ],
77
+ 'dvpal' => [ 720, 576, 'Digital Video 625/50 (PAL, DVD PAL)' ],
78
+ 'dvdpal' => [ 720, 576, 'Digital Video 625/50 (PAL, DVD PAL)' ],
79
+ 'ns525' => [ 768, 483, 'Non-Standard DV 525/60' ],
80
+ 'sp625' => [ 768, 576, 'Square Pixel DV 625/50' ],
81
+ 'wga' => [ 800, 480, 'Wide VGA' ],
82
+ 'svga' => [ 800, 600, 'Super VGA' ],
83
+ 'edtv3' => [ 852, 480, 'EDTV 3' ],
84
+ 'ws480' => [ 854, 480, 'Wide Screen 480 Line' ],
85
+ 'ns625' => [ 948, 576, 'Non-Standard DV 625/60' ],
86
+ 'aacsict' => [ 960, 540, 'AACS Image Constraint Token, Degraded 1080' ],
87
+ 'ws576' => [ 1024, 576, 'Wide Screen 576 Line' ],
88
+ '8514' => [ 1024, 768, 'IBM 8514/A' ],
89
+ '8514a' => [ 1024, 768, 'IBM 8514/A' ],
90
+ 'evga' => [ 1024, 768, 'VESA Extended VGA' ],
91
+ 'xga' => [ 1024, 768, 'IBM XGA (eXtended Graphics Array)' ],
92
+ 'nextcube' => [ 1120, 832, 'NeXT Cube' ],
93
+ 'apple1mp' => [ 1152, 864, 'Apple "1 Megapixel"' ],
94
+ 'xga+' => [ 1152, 864, 'XGA+' ],
95
+ 'olpcmono' => [ 1200, 900, 'One Laptop Per Child Mono Mode (true res)' ],
96
+ 'olpc' => [ 1200, 900, 'One Laptop Per Child Mono Mode (true res)' ],
97
+ '720i' => [ 1280, 720, 'HDTV 720 Line Interlaced' ],
98
+ '720p' => [ 1280, 720, 'HDTV 720 Line Progressive' ],
99
+ 'hd720' => [ 1280, 720, 'HDTV 720 Line' ],
100
+ 'xga43' => [ 1280, 960, '4:3 XGA Alternative' ],
101
+ 'xga960' => [ 1280, 960, '4:3 XGA Alternative' ],
102
+ 'sxga' => [ 1280, 1024, 'Super XGA' ],
103
+ 'wxga' => [ 1366, 768, 'Wide XGA' ],
104
+ 'wxga768' => [ 1366, 768, 'Wide XGA' ],
105
+ 'wsxga' => [ 1440, 900, 'Wide Super XGA (Low Variant)' ],
106
+ 'wsxga1' => [ 1440, 900, 'Wide Super XGA (Low Variant)' ],
107
+ 'wxga+' => [ 1440, 900, 'Wide XGA+' ],
108
+ 'sxga+' => [ 1440, 1050, 'Super XGA+' ],
109
+ 'wsxga2' => [ 1600, 1024, 'Wide Super XGA (High Variant)' ],
110
+ 'uxga' => [ 1600, 1200, 'Ultra XGA' ],
111
+ 'wsxga+' => [ 1680, 1050, 'Wide Super XGA+' ],
112
+ 'academy2k' => [ 1828, 1332, 'Digital Film Academy 1.375:1 @ 2K' ],
113
+ '1080i' => [ 1920, 1080, 'HDTV 1080 Line Interlaced' ],
114
+ '1080p' => [ 1920, 1080, 'HDTV 1080 Line Progressive' ],
115
+ 'hd1080' => [ 1920, 1080, 'HDTV 1080 Line' ],
116
+ 'wuxga' => [ 1920, 1200, 'Wide Ultra XGA' ],
117
+ 'dc2k1' => [ 1998, 1080, 'Digital Film Digital Cinema 1.85:1 @ 2K ' ],
118
+ 'dc2k2' => [ 2048, 858, 'Digital Film Digital Cinema 2.39:1 @ 2K ' ],
119
+ 'eurohd' => [ 2048, 1152, 'European HDTV' ],
120
+ 'qxga' => [ 2048, 1536, 'Quad XGA' ],
121
+ 'wqxga' => [ 2560, 1600, 'Wide Quad XGA' ],
122
+ 'qsxga' => [ 2560, 2048, 'Quad Super XGA' ],
123
+ 'wqsxga' => [ 3200, 2048, 'Wide Quad Super XGA' ],
124
+ 'quxga' => [ 3200, 2400, 'Quad Ultra XGA' ],
125
+ 'academy4k' => [ 3656, 2664, 'Digital Film Academy 1.375:1 @ 4K' ],
126
+ 'wquxga' => [ 3840, 2400, 'Wide Quad Ultra XGA' ],
127
+ 'dc4k1' => [ 3996, 2160, 'Digital Film Digital Cinema 1.85:1 @ 4K ' ],
128
+ 'dc4k2' => [ 4096, 1714, 'Digital Film Digital Cinema 2.39:1 @ 4K ' ],
129
+ 'hxga' => [ 4096, 3072, 'Hexadecatuple XGA' ],
130
+ 'whxga' => [ 5120, 3200, 'Wide Hexadecatuple XGA' ],
131
+ 'hsxga' => [ 5120, 4096, 'Hexadecatuple Super XGA' ],
132
+ 'whsxga' => [ 6400, 4096, 'Wide Hexadecatuple Super XGA' ],
133
+ 'huxga' => [ 6400, 4800, 'Hexadecatuple Ultra XGA' ],
134
+ 'whuxga' => [ 7680, 4800, 'Wide Hexadecatuple Ultra XGA' ],
135
+ }
136
+
137
+ def OGLBench.w_h_from_geometry(geom)
138
+ geometry = geom.downcase
139
+
140
+ return $~[1,2] if geometry =~ /^(\d+)x(\d+)$/
141
+
142
+ dims = $KNOWN_RES[geometry] || [0, 0]
143
+ dims[0,2]
144
+ end
145
+
146
+ def OGLBench.show_known_geometries
147
+ puts "Known geometries:"
148
+
149
+ # convert the hash to array, sort by resolution and iterate
150
+ $KNOWN_RES.sort {|a,b| a[1][0,2] <=> b[1][0,2] }.each do |row|
151
+ name, res = row
152
+ x,y,fullname = res
153
+ printf "%-10s %4d x %4d %s\n", name, x, y, fullname
154
+ end
155
+ end
156
+
157
+ def OGLBench.show_usage(conf = $CACHED[:conf])
158
+ usage = conf[:usage]
159
+
160
+ if (not conf[:extra_usage].empty?)
161
+ conf[:_USAGE_LABEL_GENERAL] = "\nGENERAL OPTIONS:"
162
+ usage = "#{conf[:usage]}\nOTHER OPTIONS:\n#{conf[:extra_usage]}"
163
+ else
164
+ conf[:_USAGE_LABEL_GENERAL] = ''
165
+ end
166
+
167
+ usage.gsub!(/\$(\w+)/) do conf[$1.to_sym] end
168
+
169
+ print usage
170
+ end
171
+
172
+ def OGLBench.show_basic_config(conf,gl_info,version)
173
+ print <<CONFIG
174
+ #{conf[:title]}, version #{version}, with Ruby #{RUBY_VERSION}
175
+
176
+ window size: #{conf[:width]} x #{conf[:height]}
177
+ full screen: #{conf[:fs]}
178
+ rgba bits: #{gl_info[:r]} #{gl_info[:g]} #{gl_info[:b]} #{gl_info[:a]}
179
+ depth bits: #{gl_info[:d]}
180
+ min frames/test: #{conf[:frames]}
181
+ min seconds/test: #{conf[:seconds]}
182
+ CONFIG
183
+ end
184
+
185
+ def OGLBench.friendly_booleans(conf)
186
+ booleans = conf[:booleans].update(conf[:extra_booleans])
187
+
188
+ booleans.each_pair do |logical,readable|
189
+ conf[readable] = (conf[logical] ? 'yes' : 'no')
190
+ end
191
+ end
192
+
193
+ def OGLBench.basic_init(extra_conf = nil,extra_options = nil)
194
+ usage = <<'USAGE';
195
+ $title
196
+
197
+ usage: $0 [options...]
198
+ $_USAGE_LABEL_GENERAL
199
+ -f |--frames=[NNN] Set minimum frame count [$frames]
200
+ -s |--seconds=[NNN] Set minimum time [$seconds seconds]
201
+ --fs|--fullscreen Try to use full screen [$fs]
202
+ -g |--geometry=[WWW]x[HHH] Set viewport size [$width x $height]
203
+ -g |--geometry=<name> Set viewport size via well-known name
204
+ -k |--known-geometries Show list of known geometry names
205
+ -h |-?|--help Show this help message
206
+ USAGE
207
+
208
+ # conf = {:usage => usage, :frames => "150"}
209
+ # show_usage(conf)
210
+ # FIXME: $0 ?
211
+
212
+ conf = {
213
+ :title => 'Ruby-OpenGL Benchmark',
214
+ :usage => usage,
215
+ :extra_usage => '',
216
+ "0".to_sym => $0,
217
+
218
+ :frames => 100,
219
+ :seconds => 10,
220
+ :geometry => '300x300',
221
+
222
+ :fullscreen => false,
223
+ :known => false,
224
+ :help => false,
225
+
226
+ :booleans => {
227
+ :fullscreen => :fs,
228
+ :known => :show_known,
229
+ :help => :show_help,
230
+ },
231
+ :extra_booleans => {},
232
+ }
233
+
234
+ conf.update(extra_conf) if extra_conf
235
+
236
+ opts = GetoptLong.new(
237
+ [ "--frames", "-f", GetoptLong::REQUIRED_ARGUMENT ],
238
+ [ "--seconds", "-s", GetoptLong::REQUIRED_ARGUMENT ],
239
+ [ "--geometry", "-g", GetoptLong::REQUIRED_ARGUMENT ],
240
+ [ "--fullscreen", "--fs", GetoptLong::NO_ARGUMENT ],
241
+ [ "--known", "-k","--known-geometries", GetoptLong::NO_ARGUMENT ],
242
+ [ "--help", "-h", "-?", GetoptLong::NO_ARGUMENT ]
243
+ )
244
+
245
+ opts.each do |opt, arg|
246
+ name = opt.tr('-','')
247
+ if arg.empty?
248
+ conf[name.to_sym] = true
249
+ else
250
+ conf[name.to_sym] = arg
251
+ end
252
+ end
253
+
254
+ friendly_booleans(conf)
255
+
256
+
257
+ geometry = conf[:geometry]
258
+ w,h = w_h_from_geometry(geometry)
259
+ conf[:width] = w.to_i
260
+ conf[:height] = h.to_i
261
+
262
+ $stdout.sync = true
263
+
264
+ if (conf[:help])
265
+ show_usage(conf)
266
+ exit(0)
267
+ end
268
+
269
+ if (conf[:known])
270
+ show_known_geometries()
271
+ exit(0)
272
+ end
273
+
274
+
275
+ app = init_opengl(conf)
276
+ gl_info = get_gl_info(app)
277
+
278
+ [conf, app, gl_info]
279
+ end
280
+
281
+
282
+ def OGLBench.init_opengl(conf)
283
+ w,h = conf[:width], conf[:height]
284
+
285
+ raise "Could not determine sane width and height from '#{conf[:geometry]}'.\n" unless w > 0 && h > 0;
286
+
287
+ glutInit()
288
+ glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH)
289
+ glutInitWindowSize(w,h)
290
+ app = glutCreateWindow(conf[:title])
291
+ glViewport(0, 0, w, h)
292
+
293
+ glMatrixMode(GL_PROJECTION)
294
+ glLoadIdentity
295
+
296
+ glMatrixMode(GL_MODELVIEW)
297
+ glLoadIdentity
298
+
299
+ $CACHED[:conf] = conf
300
+ $CACHED[:app] = app
301
+
302
+ app
303
+ end
304
+
305
+ def OGLBench.get_gl_info(app = $CACHED[:app])
306
+ gl_info = {}
307
+
308
+ # These values are faked
309
+ conf = $CACHED[:conf]
310
+ gl_info[:r] = 8
311
+ gl_info[:g] = 8
312
+ gl_info[:b] = 8
313
+ gl_info[:a] = 0
314
+ gl_info[:d] = 24
315
+
316
+ $CACHED[:gl_info] = gl_info
317
+
318
+ gl_info
319
+ end
320
+
321
+ def OGLBench.fade_to_white(frac)
322
+ glColor4f(frac, frac, frac, 1)
323
+ glClearColor(frac, frac, frac, 1)
324
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
325
+ glFinish
326
+ end
327
+
328
+ def OGLBench.draw_string(font_style,str,x,y)
329
+ glRasterPos2i(x,y)
330
+ str.each_byte do |char|
331
+ glutBitmapCharacter(font_style, char)
332
+ end
333
+ end
334
+
335
+ # def init_bitmap_font
336
+ # def texture_from_texels
337
+
338
+ end # end module