ruby-opengl 0.40.1 → 0.50.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +2 -2
- data/doc/build_install.txt +48 -28
- data/doc/extensions.txt +361 -0
- data/doc/history.txt +8 -2
- data/doc/requirements_and_design.txt +0 -13
- data/doc/roadmap.txt +11 -13
- data/doc/supplies/page_template.html +11 -5
- data/doc/thanks.txt +2 -4
- data/doc/tutorial.txt +1 -4
- data/examples/{nehe_lesson02.rb → NeHe/nehe_lesson02.rb} +0 -0
- data/examples/{nehe_lesson03.rb → NeHe/nehe_lesson03.rb} +0 -0
- data/examples/{nehe_lesson04.rb → NeHe/nehe_lesson04.rb} +0 -0
- data/examples/{nehe_lesson05.rb → NeHe/nehe_lesson05.rb} +0 -0
- data/examples/NeHe/nehe_lesson36.rb +303 -0
- data/examples/OrangeBook/3Dlabs-License.txt +33 -0
- data/examples/OrangeBook/brick.frag +36 -0
- data/examples/OrangeBook/brick.rb +388 -0
- data/examples/OrangeBook/brick.vert +41 -0
- data/examples/OrangeBook/particle.frag +17 -0
- data/examples/OrangeBook/particle.rb +424 -0
- data/examples/OrangeBook/particle.vert +38 -0
- data/examples/README +13 -83
- data/examples/RedBook/aaindex.rb +97 -0
- data/examples/RedBook/aapoly.rb +142 -0
- data/examples/RedBook/aargb.rb +119 -0
- data/examples/RedBook/accanti.rb +162 -0
- data/examples/RedBook/accpersp.rb +215 -0
- data/examples/RedBook/alpha.rb +123 -0
- data/examples/RedBook/alpha3D.rb +158 -0
- data/examples/RedBook/bezcurve.rb +105 -0
- data/examples/RedBook/bezmesh.rb +137 -0
- data/examples/RedBook/checker.rb +124 -0
- data/examples/RedBook/clip.rb +95 -0
- data/examples/RedBook/colormat.rb +135 -0
- data/examples/RedBook/cube.rb +69 -0
- data/examples/RedBook/depthcue.rb +99 -0
- data/examples/RedBook/dof.rb +205 -0
- data/examples/{legacy → RedBook}/double.rb +59 -58
- data/examples/{legacy → RedBook}/drawf.rb +47 -54
- data/examples/RedBook/feedback.rb +145 -0
- data/examples/RedBook/fog.rb +167 -0
- data/examples/RedBook/font.rb +151 -0
- data/examples/RedBook/hello.rb +79 -0
- data/examples/RedBook/image.rb +137 -0
- data/examples/{legacy → RedBook}/jitter.rb +60 -62
- data/examples/RedBook/lines.rb +128 -0
- data/examples/RedBook/list.rb +111 -0
- data/examples/RedBook/material.rb +275 -0
- data/examples/RedBook/mipmap.rb +156 -0
- data/examples/{legacy → RedBook}/model.rb +66 -72
- data/examples/{legacy → RedBook}/movelight.rb +67 -75
- data/examples/RedBook/pickdepth.rb +179 -0
- data/examples/{legacy → RedBook}/planet.rb +62 -66
- data/examples/RedBook/quadric.rb +158 -0
- data/examples/RedBook/robot.rb +115 -0
- data/examples/RedBook/select.rb +196 -0
- data/examples/RedBook/smooth.rb +95 -0
- data/examples/RedBook/stencil.rb +163 -0
- data/examples/RedBook/stroke.rb +167 -0
- data/examples/RedBook/surface.rb +166 -0
- data/examples/RedBook/teaambient.rb +132 -0
- data/examples/RedBook/teapots.rb +182 -0
- data/examples/RedBook/tess.rb +183 -0
- data/examples/RedBook/texbind.rb +147 -0
- data/examples/RedBook/texgen.rb +169 -0
- data/examples/RedBook/texturesurf.rb +128 -0
- data/examples/RedBook/varray.rb +159 -0
- data/examples/RedBook/wrap.rb +148 -0
- data/examples/misc/anisotropic.rb +194 -0
- data/examples/misc/font-glut.rb +46 -0
- data/examples/{plane.rb → misc/plane.rb} +0 -0
- data/examples/misc/readpixel.rb +65 -0
- data/examples/{smooth.rb → misc/smooth.rb} +0 -0
- data/examples/{test.rb → misc/test.rb} +0 -0
- data/ext/common/common.h +252 -70
- data/ext/common/gl-enums.h +6102 -7334
- data/ext/common/gl-types.h +47 -0
- data/ext/common/glu-enums.h +469 -0
- data/ext/gl/gl-1.0-1.1.c +842 -2464
- data/ext/gl/gl-1.2.c +217 -281
- data/ext/gl/gl-1.3.c +113 -133
- data/ext/gl/gl-1.4.c +98 -334
- data/ext/gl/gl-1.5.c +28 -34
- data/ext/gl/gl-2.0.c +26 -235
- data/ext/gl/gl-2.1.c +31 -124
- data/ext/gl/gl-enums.c +786 -631
- data/ext/gl/gl-ext-arb.c +66 -0
- data/ext/gl/gl-ext-ext.c +218 -0
- data/ext/gl/gl.c +138 -31
- data/ext/gl/mkrf_conf.rb +1 -0
- data/ext/glu/glu-enums.c +163 -0
- data/ext/glu/glu.c +1003 -1205
- data/ext/glu/mkrf_conf.rb +1 -0
- data/ext/glut/glut.c +1056 -1175
- data/lib/opengl.rb +90 -3
- data/test/tc_common.rb +26 -13
- data/test/tc_ext_arb.rb +73 -0
- data/test/tc_ext_ext.rb +74 -0
- data/test/tc_func_12.rb +8 -8
- data/test/tc_func_13.rb +17 -11
- data/test/tc_func_14.rb +8 -8
- data/test/tc_func_15.rb +190 -2
- data/test/tc_func_20.rb +36 -10
- data/test/tc_func_21.rb +445 -2
- data/test/tc_glu.rb +305 -0
- data/test/tc_misc.rb +1 -0
- metadata +84 -68
- data/doc/screenshots.txt +0 -23
- data/examples/legacy/COPYRIGHT +0 -8
- data/examples/legacy/aaindex.rb +0 -98
- data/examples/legacy/aapoly.rb +0 -153
- data/examples/legacy/aargb.rb +0 -139
- data/examples/legacy/accanti.rb +0 -159
- data/examples/legacy/accpersp.rb +0 -216
- data/examples/legacy/alpha.rb +0 -133
- data/examples/legacy/alpha3D.rb +0 -165
- data/examples/legacy/bezcurve.rb +0 -107
- data/examples/legacy/bezmesh.rb +0 -131
- data/examples/legacy/checker.rb +0 -121
- data/examples/legacy/clip.rb +0 -104
- data/examples/legacy/colormat.rb +0 -145
- data/examples/legacy/cube.rb +0 -73
- data/examples/legacy/depthcue.rb +0 -101
- data/examples/legacy/dof.rb +0 -212
- data/examples/legacy/feedback.rb +0 -152
- data/examples/legacy/fog.rb +0 -172
- data/examples/legacy/font-glut.rb +0 -41
- data/examples/legacy/font.rb +0 -158
- data/examples/legacy/hello.rb +0 -75
- data/examples/legacy/image.rb +0 -145
- data/examples/legacy/lines.rb +0 -135
- data/examples/legacy/list.rb +0 -120
- data/examples/legacy/material.rb +0 -290
- data/examples/legacy/mipmap.rb +0 -159
- data/examples/legacy/pickdepth.rb +0 -180
- data/examples/legacy/quadric.rb +0 -180
- data/examples/legacy/readpixel.rb +0 -59
- data/examples/legacy/robot.rb +0 -120
- data/examples/legacy/select.rb +0 -207
- data/examples/legacy/smooth.rb +0 -41
- data/examples/legacy/stencil.rb +0 -154
- data/examples/legacy/stroke.rb +0 -170
- data/examples/legacy/surface.rb +0 -170
- data/examples/legacy/teaambient.rb +0 -132
- data/examples/legacy/teapots.rb +0 -188
- data/examples/legacy/tess.rb +0 -222
- data/examples/legacy/texbind.rb +0 -157
- data/examples/legacy/texgen.rb +0 -171
- data/examples/legacy/texturesurf.rb +0 -128
- data/examples/legacy/varray.rb +0 -167
- data/examples/legacy/wrap.rb +0 -158
- data/lib/gl_prev.rb +0 -46
- data/lib/glu_prev.rb +0 -46
- data/lib/glut_prev.rb +0 -45
@@ -0,0 +1,148 @@
|
|
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 'mathn'
|
49
|
+
include Gl,Glu,Glut
|
50
|
+
|
51
|
+
# Create checkerboard texture
|
52
|
+
CheckImageWidth=64
|
53
|
+
CheckImageHeight=64
|
54
|
+
$checkImage = []
|
55
|
+
|
56
|
+
$texName = 0
|
57
|
+
|
58
|
+
def makeCheckImage
|
59
|
+
for i in 0..CheckImageHeight-1
|
60
|
+
for j in 0..CheckImageWidth-1
|
61
|
+
c = if (((i&0x8)==0)!=((j&0x8)==0)) then 255 else 0 end
|
62
|
+
$checkImage[(i*CheckImageWidth+j)*4+0] = c
|
63
|
+
$checkImage[(i*CheckImageWidth+j)*4+1] = c
|
64
|
+
$checkImage[(i*CheckImageWidth+j)*4+2] = c
|
65
|
+
$checkImage[(i*CheckImageWidth+j)*4+3] = 255
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
def init
|
71
|
+
glClearColor(0.0, 0.0, 0.0, 0.0)
|
72
|
+
glShadeModel(GL_FLAT)
|
73
|
+
glEnable(GL_DEPTH_TEST)
|
74
|
+
|
75
|
+
makeCheckImage()
|
76
|
+
glPixelStore(GL_UNPACK_ALIGNMENT, 1)
|
77
|
+
|
78
|
+
$texName = glGenTextures(1)
|
79
|
+
glBindTexture(GL_TEXTURE_2D, $texName[0])
|
80
|
+
|
81
|
+
glTexParameter(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT)
|
82
|
+
glTexParameter(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT)
|
83
|
+
glTexParameter(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST)
|
84
|
+
glTexParameter(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST)
|
85
|
+
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, CheckImageWidth,
|
86
|
+
CheckImageHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, $checkImage.pack("C*"))
|
87
|
+
end
|
88
|
+
|
89
|
+
display = Proc.new do
|
90
|
+
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
|
91
|
+
glEnable(GL_TEXTURE_2D)
|
92
|
+
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL)
|
93
|
+
glBindTexture(GL_TEXTURE_2D, $texName[0])
|
94
|
+
|
95
|
+
glBegin(GL_QUADS)
|
96
|
+
glTexCoord(0.0, 0.0); glVertex(-2.0, -1.0, 0.0)
|
97
|
+
glTexCoord(0.0, 3.0); glVertex(-2.0, 1.0, 0.0)
|
98
|
+
glTexCoord(3.0, 3.0); glVertex(0.0, 1.0, 0.0)
|
99
|
+
glTexCoord(3.0, 0.0); glVertex(0.0, -1.0, 0.0)
|
100
|
+
|
101
|
+
glTexCoord(0.0, 0.0); glVertex(1.0, -1.0, 0.0)
|
102
|
+
glTexCoord(0.0, 3.0); glVertex(1.0, 1.0, 0.0)
|
103
|
+
glTexCoord(3.0, 3.0); glVertex(2.41421, 1.0, -1.41421)
|
104
|
+
glTexCoord(3.0, 0.0); glVertex(2.41421, -1.0, -1.41421)
|
105
|
+
glEnd()
|
106
|
+
glutSwapBuffers()
|
107
|
+
glDisable(GL_TEXTURE_2D)
|
108
|
+
end
|
109
|
+
|
110
|
+
reshape = Proc.new do |w, h|
|
111
|
+
glViewport(0, 0, w, h)
|
112
|
+
glMatrixMode(GL_PROJECTION)
|
113
|
+
glLoadIdentity()
|
114
|
+
GLU.Perspective(60.0, w/h, 1.0, 30.0)
|
115
|
+
glMatrixMode(GL_MODELVIEW)
|
116
|
+
glLoadIdentity()
|
117
|
+
glTranslate(0.0, 0.0, -3.6)
|
118
|
+
end
|
119
|
+
|
120
|
+
keyboard = Proc.new do |key, x, y|
|
121
|
+
case (key)
|
122
|
+
when 's'[0]
|
123
|
+
glTexParameter(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP)
|
124
|
+
glutPostRedisplay()
|
125
|
+
when 'S'[0]
|
126
|
+
glTexParameter(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT)
|
127
|
+
glutPostRedisplay()
|
128
|
+
when 't'[0]
|
129
|
+
glTexParameter(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP)
|
130
|
+
glutPostRedisplay()
|
131
|
+
when 'T'[0]
|
132
|
+
glTexParameter(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT)
|
133
|
+
glutPostRedisplay()
|
134
|
+
when 27
|
135
|
+
exit(0)
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
glutInit
|
140
|
+
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH)
|
141
|
+
glutInitWindowSize(500, 500)
|
142
|
+
glutInitWindowPosition(100, 100)
|
143
|
+
glutCreateWindow($0)
|
144
|
+
init()
|
145
|
+
glutDisplayFunc(display)
|
146
|
+
glutReshapeFunc(reshape)
|
147
|
+
glutKeyboardFunc(keyboard)
|
148
|
+
glutMainLoop()
|
@@ -0,0 +1,194 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (C) 2007 Jan Dvorak <jan.dvorak@kraxnet.cz>
|
3
|
+
#
|
4
|
+
# This program is distributed under the terms of the MIT license.
|
5
|
+
# See the included MIT-LICENSE file for the terms of this license.
|
6
|
+
#
|
7
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
8
|
+
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
9
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
10
|
+
# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
11
|
+
# CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
12
|
+
# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
13
|
+
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
14
|
+
#
|
15
|
+
|
16
|
+
#
|
17
|
+
# Showcase for anisotropic texture filtering
|
18
|
+
#
|
19
|
+
|
20
|
+
require 'opengl'
|
21
|
+
include Gl,Glu,Glut
|
22
|
+
|
23
|
+
# extend Array class with new function
|
24
|
+
class Array
|
25
|
+
def rotate!
|
26
|
+
self << self.shift
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
class App
|
31
|
+
@@filters = [[GL_NEAREST,"None"],[GL_LINEAR_MIPMAP_NEAREST,"Bilinear"],[GL_LINEAR_MIPMAP_LINEAR,"Trilinear"]]
|
32
|
+
@@anisotropy = [1,2,4,8,16,32]
|
33
|
+
@@color_tint = ["Off","On"]
|
34
|
+
|
35
|
+
def checker_texture(size,divide,color_a,color_b)
|
36
|
+
strip_a = color_a * (size/divide)
|
37
|
+
strip_b = color_b * (size/divide)
|
38
|
+
line_strip_a = (strip_a + strip_b) * (size/2)
|
39
|
+
line_strip_b = (strip_b + strip_a) * (size/2)
|
40
|
+
(line_strip_a + line_strip_b) * (divide/2)
|
41
|
+
end
|
42
|
+
|
43
|
+
def printGlutBitmapFont(string, font, x,y, r,g,b)
|
44
|
+
glDisable(GL_TEXTURE_2D)
|
45
|
+
glColor3f(r, g, b)
|
46
|
+
glRasterPos2i(x, y)
|
47
|
+
string.each_byte do |x|
|
48
|
+
glutBitmapCharacter(font, x)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def ortho(w,h)
|
53
|
+
glMatrixMode(GL_PROJECTION)
|
54
|
+
glLoadIdentity()
|
55
|
+
gluOrtho2D(0,w,0,h)
|
56
|
+
glScalef(1,-1,1)
|
57
|
+
glTranslatef(0,-h,0)
|
58
|
+
|
59
|
+
glMatrixMode(GL_MODELVIEW)
|
60
|
+
glLoadIdentity()
|
61
|
+
end
|
62
|
+
|
63
|
+
def persp(w,h)
|
64
|
+
glMatrixMode(GL_PROJECTION)
|
65
|
+
glLoadIdentity
|
66
|
+
gluPerspective(90,w.to_f/h.to_f,1,100)
|
67
|
+
|
68
|
+
glMatrixMode(GL_MODELVIEW)
|
69
|
+
glLoadIdentity
|
70
|
+
end
|
71
|
+
|
72
|
+
def reshape(w,h)
|
73
|
+
@@w,@@h = w,h
|
74
|
+
glViewport(0, 0, w, h)
|
75
|
+
persp(w,h)
|
76
|
+
end
|
77
|
+
|
78
|
+
def initialize
|
79
|
+
if (not Gl.is_available?("GL_EXT_texture_filter_anisotropic"))
|
80
|
+
puts "This program needs GL_EXT_texture_filter_anisotropic extension"
|
81
|
+
exit
|
82
|
+
end
|
83
|
+
@@w,@@h = glutGet(GLUT_WINDOW_WIDTH),glutGet(GLUT_WINDOW_HEIGHT)
|
84
|
+
|
85
|
+
@t = glGenTextures(2)
|
86
|
+
|
87
|
+
# default checkerboard texture
|
88
|
+
glBindTexture(GL_TEXTURE_2D,@t[0])
|
89
|
+
data = checker_texture(64,4,[1,1,1],[0,0,0])
|
90
|
+
gluBuild2DMipmaps(GL_TEXTURE_2D,GL_RGBA,64,64,GL_RGB,GL_FLOAT,data.pack("f*"))
|
91
|
+
|
92
|
+
# second texture with color tinted mipmaps
|
93
|
+
glBindTexture(GL_TEXTURE_2D,@t[1])
|
94
|
+
data = checker_texture(64,4,[1,1,1],[0,0,0])
|
95
|
+
glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA,64,64,0,GL_RGB,GL_FLOAT,data.pack("f*"))
|
96
|
+
data = checker_texture(32,4,[1,0,0],[0,0,0])
|
97
|
+
glTexImage2D(GL_TEXTURE_2D,1,GL_RGBA,32,32,0,GL_RGB,GL_FLOAT,data.pack("f*"))
|
98
|
+
data = checker_texture(16,4,[0,1,0],[0,0,0])
|
99
|
+
glTexImage2D(GL_TEXTURE_2D,2,GL_RGBA,16,16,0,GL_RGB,GL_FLOAT,data.pack("f*"))
|
100
|
+
data = checker_texture(8,4,[0,0,1],[0,0,0])
|
101
|
+
glTexImage2D(GL_TEXTURE_2D,3,GL_RGBA,8,8,0,GL_RGB,GL_FLOAT,data.pack("f*"))
|
102
|
+
data = checker_texture(4,4,[1,1,0],[0,0,0])
|
103
|
+
glTexImage2D(GL_TEXTURE_2D,4,GL_RGBA,4,4,0,GL_RGB,GL_FLOAT,data.pack("f*"))
|
104
|
+
data = checker_texture(2,2,[1,0,1],[0,0,0])
|
105
|
+
glTexImage2D(GL_TEXTURE_2D,5,GL_RGBA,2,2,0,GL_RGB,GL_FLOAT,data.pack("f*"))
|
106
|
+
data = [0.5,0.5,0.5] # single pixel texture, just average it
|
107
|
+
glTexImage2D(GL_TEXTURE_2D,6,GL_RGBA,1,1,0,GL_RGB,GL_FLOAT,data.pack("f*"))
|
108
|
+
end
|
109
|
+
|
110
|
+
def display_text
|
111
|
+
ortho(@@w,@@h)
|
112
|
+
printGlutBitmapFont("Texture Filtering ('f'): #{@@filters[0][1]}", GLUT_BITMAP_9_BY_15, 20, 20, 1.0, 1.0, 1.0)
|
113
|
+
printGlutBitmapFont("Anisotropy factor ('a'): #{@@anisotropy[0]}x", GLUT_BITMAP_9_BY_15, 20, 40, 1.0, 1.0, 1.0)
|
114
|
+
printGlutBitmapFont("Colored Mipmaps ('c'): #{@@color_tint[0]}", GLUT_BITMAP_9_BY_15, 20, 60, 1.0, 1.0, 1.0)
|
115
|
+
persp(@@w,@@h)
|
116
|
+
end
|
117
|
+
|
118
|
+
def display_plane()
|
119
|
+
glEnable(GL_TEXTURE_2D)
|
120
|
+
t_repeat = 16
|
121
|
+
# x,y,z,u,v
|
122
|
+
quad = [[-4,-1,1, 0,t_repeat],[4,-1,1, t_repeat,t_repeat],[4,1,-8, t_repeat,0],[-4,1,-8, 0,0]]
|
123
|
+
glBegin(GL_QUADS)
|
124
|
+
quad.each do |v|
|
125
|
+
glTexCoord2f(v[3],v[4])
|
126
|
+
glVertex3f(v[0],v[1],v[2])
|
127
|
+
end
|
128
|
+
glEnd()
|
129
|
+
glDisable(GL_TEXTURE_2D)
|
130
|
+
end
|
131
|
+
|
132
|
+
def display
|
133
|
+
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
|
134
|
+
|
135
|
+
persp(@@w,@@h)
|
136
|
+
|
137
|
+
# move back from scene
|
138
|
+
glTranslatef(0,0,-2)
|
139
|
+
|
140
|
+
# set anisotropy
|
141
|
+
glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MAX_ANISOTROPY_EXT,@@anisotropy[0])
|
142
|
+
|
143
|
+
# set color tint
|
144
|
+
if (@@color_tint[0] == "On")
|
145
|
+
glBindTexture(GL_TEXTURE_2D,@t[1])
|
146
|
+
else
|
147
|
+
glBindTexture(GL_TEXTURE_2D,@t[0])
|
148
|
+
end
|
149
|
+
|
150
|
+
# set filters
|
151
|
+
f = @@filters[0][0]
|
152
|
+
glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,f)
|
153
|
+
|
154
|
+
# draw scene
|
155
|
+
display_plane()
|
156
|
+
display_text()
|
157
|
+
|
158
|
+
sleep(0.001) # microsleep to avoid consuming all CPU time
|
159
|
+
glutSwapBuffers()
|
160
|
+
end
|
161
|
+
|
162
|
+
def idle
|
163
|
+
glutPostRedisplay()
|
164
|
+
end
|
165
|
+
|
166
|
+
def keyboard(key,x,y)
|
167
|
+
case (key)
|
168
|
+
when ?f
|
169
|
+
@@filters.rotate!
|
170
|
+
when ?a
|
171
|
+
max_anisotropy = glGetIntegerv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT)
|
172
|
+
begin @@anisotropy.rotate! end until @@anisotropy[0]<=max_anisotropy
|
173
|
+
when ?c
|
174
|
+
@@color_tint.rotate!
|
175
|
+
when 27 # Escape
|
176
|
+
exit(0)
|
177
|
+
end
|
178
|
+
glutPostRedisplay()
|
179
|
+
end
|
180
|
+
end
|
181
|
+
|
182
|
+
# main
|
183
|
+
glutInit()
|
184
|
+
glutInitDisplayMode(GLUT_RGBA | GLUT_DEPTH | GLUT_DOUBLE )
|
185
|
+
glutInitWindowPosition(150,50)
|
186
|
+
glutInitWindowSize(500,500)
|
187
|
+
glutCreateWindow($0)
|
188
|
+
|
189
|
+
app = App.new
|
190
|
+
glutReshapeFunc(app.method(:reshape).to_proc)
|
191
|
+
glutDisplayFunc(app.method(:display).to_proc)
|
192
|
+
glutIdleFunc(app.method(:idle).to_proc)
|
193
|
+
glutKeyboardFunc(app.method(:keyboard).to_proc)
|
194
|
+
glutMainLoop()
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'opengl'
|
2
|
+
include Gl,Glu,Glut
|
3
|
+
|
4
|
+
display = Proc.new do
|
5
|
+
glClear(GL_COLOR_BUFFER_BIT)
|
6
|
+
GL.LoadIdentity
|
7
|
+
|
8
|
+
glRasterPos2d(100,100)
|
9
|
+
"Hello Bitmap".each_byte { |x| glutBitmapCharacter(GLUT_BITMAP_9_BY_15, x) }
|
10
|
+
|
11
|
+
GL.Translate(100, 250, 0)
|
12
|
+
GL.Scale(0.5, 0.5, 1)
|
13
|
+
"Hello Stroke".each_byte { |x| glutStrokeCharacter(GLUT_STROKE_ROMAN, x) }
|
14
|
+
|
15
|
+
glutSwapBuffers()
|
16
|
+
end
|
17
|
+
|
18
|
+
reshape = Proc.new do |w, h|
|
19
|
+
glViewport(0, 0, w, h)
|
20
|
+
glMatrixMode(GL_PROJECTION)
|
21
|
+
glLoadIdentity()
|
22
|
+
glOrtho(0.0, w, 0.0, h, -1.0, 1.0)
|
23
|
+
glMatrixMode(GL_MODELVIEW)
|
24
|
+
end
|
25
|
+
|
26
|
+
keyboard = Proc.new do |key, x, y|
|
27
|
+
case (key)
|
28
|
+
when 27
|
29
|
+
exit(0)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
# Main Loop
|
34
|
+
# Open window with initial window size, title bar,
|
35
|
+
# color index display mode, and handle input events.
|
36
|
+
#
|
37
|
+
glutInit
|
38
|
+
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB)
|
39
|
+
glutInitWindowSize(500, 500)
|
40
|
+
glutInitWindowPosition(100, 100)
|
41
|
+
glutCreateWindow($0)
|
42
|
+
|
43
|
+
glutReshapeFunc(reshape)
|
44
|
+
glutDisplayFunc(display)
|
45
|
+
glutKeyboardFunc(keyboard)
|
46
|
+
glutMainLoop
|
File without changes
|
@@ -0,0 +1,65 @@
|
|
1
|
+
require 'opengl'
|
2
|
+
include Gl,Glu,Glut
|
3
|
+
|
4
|
+
begin
|
5
|
+
require "RMagick"
|
6
|
+
rescue Exception
|
7
|
+
print "This sample needs RMagick Module.\n"
|
8
|
+
exit
|
9
|
+
end
|
10
|
+
|
11
|
+
WIDTH = 500
|
12
|
+
HEIGHT = 500
|
13
|
+
|
14
|
+
display = Proc.new do
|
15
|
+
glClear(GL_COLOR_BUFFER_BIT)
|
16
|
+
|
17
|
+
glBegin(GL_LINES)
|
18
|
+
glVertex(0.5, 0.5)
|
19
|
+
glVertex(-0.5, -0.5)
|
20
|
+
glEnd
|
21
|
+
|
22
|
+
glFlush()
|
23
|
+
|
24
|
+
pixels = glReadPixels(0, 0, WIDTH, HEIGHT, GL_RGBA, GL_UNSIGNED_SHORT)
|
25
|
+
|
26
|
+
image = Magick::Image.new(WIDTH, HEIGHT)
|
27
|
+
image.import_pixels(0, 0, WIDTH, HEIGHT, "RGBA", pixels,Magick::ShortPixel)
|
28
|
+
image.flip!
|
29
|
+
image.write("opengl_window.gif")
|
30
|
+
end
|
31
|
+
|
32
|
+
reshape = Proc.new do |w, h|
|
33
|
+
glViewport(0, 0, w, h)
|
34
|
+
glMatrixMode(GL_PROJECTION)
|
35
|
+
glLoadIdentity()
|
36
|
+
if (w <= h)
|
37
|
+
gluOrtho2D(-1.0, 1.0, -h.to_f/w.to_f, h.to_f/w.to_f)
|
38
|
+
else
|
39
|
+
gluOrtho2D(w.to_f/h.to_f, w.to_f/h.to_f, -1.0, 1.0)
|
40
|
+
end
|
41
|
+
glMatrixMode(GL_MODELVIEW)
|
42
|
+
glLoadIdentity()
|
43
|
+
end
|
44
|
+
|
45
|
+
|
46
|
+
keyboard = Proc.new do |key, x, y|
|
47
|
+
case (key)
|
48
|
+
when 27
|
49
|
+
exit(0);
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
# Main Loop
|
54
|
+
# Open window with initial window size, title bar,
|
55
|
+
# color index display mode, and handle input events.
|
56
|
+
glutInit
|
57
|
+
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB | GLUT_ALPHA)
|
58
|
+
glutInitWindowSize(WIDTH, HEIGHT)
|
59
|
+
glutInitWindowPosition(100, 100)
|
60
|
+
glutCreateWindow($0)
|
61
|
+
glutReshapeFunc(reshape)
|
62
|
+
glutDisplayFunc(display)
|
63
|
+
glutKeyboardFunc(keyboard)
|
64
|
+
glutMainLoop
|
65
|
+
|