ruby-opengl 0.33.0

Sign up to get free protection for your applications and to get access to all the features.
data/examples/README ADDED
@@ -0,0 +1,36 @@
1
+ Examples
2
+ ========
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
+ (Of course, if you haven't yet installed ruby-opengl on your system, you'll
26
+ need to include paths in those require statments above: as in,
27
+ `require "../lib/gl_prev"`.)
28
+
29
+
30
+ Status of examples
31
+ ------------------
32
+
33
+ * plane.rb -- works
34
+ * smooth.rb, smooth_prev.rb -- works
35
+ * aaindex.rb -- does not seem to work
36
+ * test.rb -- does not seem to work
@@ -0,0 +1,97 @@
1
+ require "../ext/gl/GL"
2
+ require "../ext/glut/GLUT"
3
+ require "rational"
4
+
5
+ require "../lib/gl_prev"
6
+ require "../lib/glut_prev"
7
+
8
+ RAMPSIZE=16
9
+ RAMP1START=32
10
+ RAMP2START=48
11
+
12
+ STDOUT.sync = TRUE
13
+ $rotAngle = 0
14
+
15
+ # Initialize antialiasing for color index mode,
16
+ # including loading a green color ramp starting
17
+ # at RAMP1START, and a blue color ramp starting
18
+ # at RAMP2START. The ramps must be a multiple of 16.
19
+ def myinit
20
+ for i in (0..RAMPSIZE)
21
+ shade = i.to_f/RAMPSIZE.to_f;
22
+ GLUT.SetColor(RAMP1START+i, 0, shade, 0.0);
23
+ GLUT.SetColor(RAMP2START+i, 0, 0, shade);
24
+ end
25
+
26
+ GL.Enable(GL::LINE_SMOOTH);
27
+ GL.Hint(GL::LINE_SMOOTH_HINT, GL::DONT_CARE);
28
+ GL.LineWidth(1.5);
29
+
30
+ GL.ClearIndex(RAMP1START);
31
+ end
32
+
33
+ display = Proc.new {
34
+ GL.Clear(GL::COLOR_BUFFER_BIT);
35
+
36
+ GL.Indexi(RAMP1START);
37
+ GL.PushMatrix();
38
+ GL.Rotate(-$rotAngle, 0.0, 0.0, 0.1);
39
+ GL.Begin(GL::LINES);
40
+ GL.Vertex(-0.5, 0.5);
41
+ GL.Vertex(0.5, -0.5);
42
+ GL.End
43
+ GL.PopMatrix();
44
+
45
+ GL.Indexi(RAMP2START);
46
+ GL.PushMatrix();
47
+ GL.Rotate($rotAngle, 0.0, 0.0, 0.1);
48
+ GL.Begin(GL::LINES);
49
+ GL.Vertex(0.5, 0.5);
50
+ GL.Vertex(-0.5, -0.5);
51
+ GL.End
52
+ GL.PopMatrix();
53
+
54
+ GL.Flush();
55
+ }
56
+
57
+ reshape = Proc.new {|w, h|
58
+ GL.Viewport(0, 0, w, h);
59
+ GL.MatrixMode(GL::PROJECTION);
60
+ GL.LoadIdentity();
61
+ if (w <= h)
62
+ GLU.Ortho2D(-1.0, 1.0, -h.to_f/w.to_f, h.to_f/w.to_f);
63
+ else
64
+ GLU.Ortho2D(w.to_f/h.to_f, w.to_f/h.to_f, -1.0, 1.0);
65
+ end
66
+ GL.MatrixMode(GL::MODELVIEW);
67
+ GL.LoadIdentity();
68
+ }
69
+
70
+ keyboard = Proc.new {|key, x, y|
71
+ case (key)
72
+ when 'r'[0]
73
+ $rotAngle += 20
74
+ $rotAngle = 0 if ($rotAngle >= 360)
75
+ GLUT.PostRedisplay();
76
+ when 'R'[0]
77
+ $rotAngle -= 20
78
+ $rotAngle = 360 if ($rotAngle <= 0)
79
+ GLUT.PostRedisplay();
80
+ when 27
81
+ exit(0);
82
+ end
83
+ }
84
+
85
+ # Main Loop
86
+ # Open window with initial window size, title bar,
87
+ # color index display mode, and handle input events.
88
+ #
89
+ GLUT.Init
90
+ GLUT.InitDisplayMode(GLUT::SINGLE | GLUT::INDEX);
91
+ GLUT.InitWindowSize(200, 200);
92
+ GLUT.CreateWindow($0);
93
+ myinit
94
+ GLUT.ReshapeFunc(reshape);
95
+ GLUT.KeyboardFunc(keyboard);
96
+ GLUT.DisplayFunc(display);
97
+ GLUT.MainLoop
@@ -0,0 +1,24 @@
1
+ #!/usr/bin/ruby -w
2
+ #--
3
+ # Copyright (C) 2006 Peter McLain <peter.mclain@gmail.com>
4
+ #
5
+ # This program is distributed under the terms of the MIT license.
6
+ # See the included MIT-LICENSE file for the terms of this license.
7
+ #
8
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
9
+ # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
10
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
11
+ # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
12
+ # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
13
+ # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
14
+ # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
15
+ #++
16
+
17
+ # Run all of *.rb files in the current directory
18
+ this_file_name = File.basename( __FILE__ )
19
+ Dir['*.rb'].each do |f|
20
+ f.strip!
21
+ next if f == this_file_name
22
+ puts "\n=== running #{f}"
23
+ system "ruby #{f}"
24
+ end
data/examples/plane.rb ADDED
@@ -0,0 +1,161 @@
1
+ #
2
+ #/* Copyright (c) Mark J. Kilgard, 1994. */
3
+ #
4
+ #/*
5
+ # * (c) Copyright 1993, Silicon Graphics, Inc.
6
+ # * ALL RIGHTS RESERVED
7
+ # * Permission to use, copy, modify, and distribute this software for
8
+ # * any purpose and without fee is hereby granted, provided that the above
9
+ # * copyright notice appear in all copies and that both the copyright notice
10
+ # * and this permission notice appear in supporting documentation, and that
11
+ # * the name of Silicon Graphics, Inc. not be used in advertising
12
+ # * or publicity pertaining to distribution of the software without specific,
13
+ # * written prior permission.
14
+ # *
15
+ # * THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS"
16
+ # * AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE,
17
+ # * INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR
18
+ # * FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
19
+ # * GRAPHICS, INC. BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT,
20
+ # * SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY
21
+ # * KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION,
22
+ # * LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF
23
+ # * THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC. HAS BEEN
24
+ # * ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON
25
+ # * ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE
26
+ # * POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE.
27
+ # *
28
+ # * US Government Users Restricted Rights
29
+ # * Use, duplication, or disclosure by the Government is subject to
30
+ # * restrictions set forth in FAR 52.227.19(c)(2) or subparagraph
31
+ # * (c)(1)(ii) of the Rights in Technical Data and Computer Software
32
+ # * clause at DFARS 252.227-7013 and/or in similar or successor
33
+ # * clauses in the FAR or the DOD or NASA FAR Supplement.
34
+ # * Unpublished-- rights reserved under the copyright laws of the
35
+ # * United States. Contractor/manufacturer is Silicon Graphics,
36
+ # * Inc., 2011 N. Shoreline Blvd., Mountain View, CA 94039-7311.
37
+ # *
38
+ # * OpenGL(TM) is a trademark of Silicon Graphics, Inc.
39
+ # */
40
+ #/*
41
+ # * plane.c
42
+ # * This program demonstrates the use of local versus
43
+ # * infinite lighting on a flat plane.
44
+ # */
45
+
46
+ require "gl"
47
+ require "glut"
48
+ require "mathn"
49
+
50
+ # /* Initialize material property, light source, and lighting model.
51
+ # */
52
+ def myinit
53
+ mat_ambient = [ 0.0, 0.0, 0.0, 1.0 ];
54
+ #/* mat_specular and mat_shininess are NOT default values */
55
+ mat_diffuse = [ 0.4, 0.4, 0.4, 1.0 ];
56
+ mat_specular = [ 1.0, 1.0, 1.0, 1.0 ];
57
+ mat_shininess = [ 15.0 ];
58
+
59
+ light_ambient = [ 0.0, 0.0, 0.0, 1.0 ];
60
+ light_diffuse = [ 1.0, 1.0, 1.0, 1.0 ];
61
+ light_specular = [ 1.0, 1.0, 1.0, 1.0 ];
62
+ lmodel_ambient = [ 0.2, 0.2, 0.2, 1.0 ];
63
+
64
+ Gl.glMaterial(Gl::GL_FRONT, Gl::GL_AMBIENT, mat_ambient);
65
+ Gl.glMaterial(Gl::GL_FRONT, Gl::GL_DIFFUSE, mat_diffuse);
66
+ Gl.glMaterial(Gl::GL_FRONT, Gl::GL_SPECULAR, mat_specular);
67
+ Gl.glMaterial(Gl::GL_FRONT, Gl::GL_SHININESS, *mat_shininess);
68
+ Gl.glLight(Gl::GL_LIGHT0, Gl::GL_AMBIENT, light_ambient);
69
+ Gl.glLight(Gl::GL_LIGHT0, Gl::GL_DIFFUSE, light_diffuse);
70
+ Gl.glLight(Gl::GL_LIGHT0, Gl::GL_SPECULAR, light_specular);
71
+ Gl.glLightModel(Gl::GL_LIGHT_MODEL_AMBIENT, lmodel_ambient);
72
+
73
+ Gl.glEnable(Gl::GL_LIGHTING);
74
+ Gl.glEnable(Gl::GL_LIGHT0);
75
+ Gl.glDepthFunc(Gl::GL_LESS);
76
+ Gl.glEnable(Gl::GL_DEPTH_TEST);
77
+ end
78
+
79
+ def drawPlane
80
+ Gl.glBegin(Gl::GL_QUADS);
81
+ Gl.glNormal(0.0, 0.0, 1.0);
82
+ Gl.glVertex(-1.0, -1.0, 0.0);
83
+ Gl.glVertex(0.0, -1.0, 0.0);
84
+ Gl.glVertex(0.0, 0.0, 0.0);
85
+ Gl.glVertex(-1.0, 0.0, 0.0);
86
+
87
+ Gl.glNormal(0.0, 0.0, 1.0);
88
+ Gl.glVertex(0.0, -1.0, 0.0);
89
+ Gl.glVertex(1.0, -1.0, 0.0);
90
+ Gl.glVertex(1.0, 0.0, 0.0);
91
+ Gl.glVertex(0.0, 0.0, 0.0);
92
+
93
+ Gl.glNormal(0.0, 0.0, 1.0);
94
+ Gl.glVertex(0.0, 0.0, 0.0);
95
+ Gl.glVertex(1.0, 0.0, 0.0);
96
+ Gl.glVertex(1.0, 1.0, 0.0);
97
+ Gl.glVertex(0.0, 1.0, 0.0);
98
+
99
+ Gl.glNormal(0.0, 0.0, 1.0);
100
+ Gl.glVertex(0.0, 0.0, 0.0);
101
+ Gl.glVertex(0.0, 1.0, 0.0);
102
+ Gl.glVertex(-1.0, 1.0, 0.0);
103
+ Gl.glVertex(-1.0, 0.0, 0.0);
104
+ Gl.glEnd();
105
+ end
106
+
107
+ display = Proc.new {
108
+ infinite_light = [ 1.0, 1.0, 1.0, 0.0 ];
109
+ local_light = [ 1.0, 1.0, 1.0, 1.0 ];
110
+
111
+ Gl.glClear(Gl::GL_COLOR_BUFFER_BIT | Gl::GL_DEPTH_BUFFER_BIT);
112
+
113
+ Gl.glPushMatrix();
114
+ Gl.glTranslate(-1.5, 0.0, 0.0);
115
+ Gl.glLight(Gl::GL_LIGHT0, Gl::GL_POSITION, infinite_light);
116
+ drawPlane();
117
+ Gl.glPopMatrix();
118
+
119
+ Gl.glPushMatrix();
120
+ Gl.glTranslate(1.5, 0.0, 0.0);
121
+ Gl.glLight(Gl::GL_LIGHT0, Gl::GL_POSITION, local_light);
122
+ drawPlane();
123
+ Gl.glPopMatrix();
124
+ Gl.glFlush();
125
+ }
126
+
127
+ myReshape = Proc.new {|w, h|
128
+ Gl.glViewport(0, 0, w, h);
129
+ Gl.glMatrixMode(Gl::GL_PROJECTION);
130
+ Gl.glLoadIdentity();
131
+ if (w <= h)
132
+ Gl.glOrtho(-1.5, 1.5, -1.5*h/w, 1.5*h/w, -10.0, 10.0);
133
+ else
134
+ Gl.glOrtho(-1.5*w/h, 1.5*w/h, -1.5, 1.5, -10.0, 10.0);
135
+ end
136
+ Gl.glMatrixMode(Gl::GL_MODELVIEW);
137
+ }
138
+
139
+ # Keyboard handler to exit when ESC is typed
140
+ keyboard = lambda do |key, x, y|
141
+ case(key)
142
+ when 27
143
+ exit(0)
144
+ end
145
+ end
146
+
147
+ #/* Main Loop
148
+ # * Open window with initial window size, title bar,
149
+ # * RGBA display mode, and handle input events.
150
+ # */
151
+ #int main(int argc, char** argv)
152
+ #{
153
+ Glut.glutInit
154
+ Glut.glutInitDisplayMode(Glut::GLUT_SINGLE | Glut::GLUT_RGB | Glut::GLUT_DEPTH);
155
+ Glut.glutInitWindowSize(500, 200);
156
+ Glut.glutCreateWindow($0);
157
+ myinit();
158
+ Glut.glutReshapeFunc(myReshape);
159
+ Glut.glutDisplayFunc(display);
160
+ Glut.glutKeyboardFunc(keyboard);
161
+ Glut.glutMainLoop();
@@ -0,0 +1,40 @@
1
+ require "../lib/gl"
2
+ require "../lib/glut"
3
+
4
+ STDOUT.sync=TRUE
5
+ disp = Proc.new {
6
+ Gl.glClear(Gl::GL_COLOR_BUFFER_BIT)
7
+ Gl.glBegin(Gl::GL_TRIANGLES)
8
+ Gl.glColor(0.0, 0.0, 1.0)
9
+ Gl.glVertex(0, 0)
10
+ Gl.glColor(0.0, 1.0, 0.0)
11
+ Gl.glVertex(200, 200)
12
+ Gl.glColor(1.0, 0.0, 0.0)
13
+ Gl.glVertex(20, 200)
14
+ Gl.glEnd
15
+ Gl.glFlush
16
+ }
17
+
18
+ reshape = Proc.new {|w, h|
19
+ Gl.glViewport(0, 0, w, h)
20
+ Gl.glMatrixMode(Gl::GL_PROJECTION)
21
+ Gl.glLoadIdentity
22
+ Gl.glOrtho(0, w, 0, h, -1, 1)
23
+ Gl.glScale(1, -1, 1)
24
+ Gl.glTranslate(0, -h, 0)
25
+ }
26
+
27
+ # Keyboard handler to exit when ESC is typed
28
+ keyboard = lambda do |key, x, y|
29
+ case(key)
30
+ when 27
31
+ exit(0)
32
+ end
33
+ end
34
+
35
+ Glut.glutInit
36
+ a = Glut.glutCreateWindow("single triangle");
37
+ Glut.glutDisplayFunc(disp);
38
+ Glut.glutReshapeFunc(reshape);
39
+ Glut.glutKeyboardFunc( keyboard )
40
+ Glut.glutMainLoop;
@@ -0,0 +1,40 @@
1
+ require "../lib/gl_prev"
2
+ require "../lib/glut_prev"
3
+
4
+ STDOUT.sync=TRUE
5
+ disp = Proc.new {
6
+ GL.Clear(GL::COLOR_BUFFER_BIT)
7
+ GL.Begin(GL::TRIANGLES)
8
+ GL.Color(0.0, 0.0, 1.0)
9
+ GL.Vertex(0, 0)
10
+ GL.Color(0.0, 1.0, 0.0)
11
+ GL.Vertex(200, 200)
12
+ GL.Color(1.0, 0.0, 0.0)
13
+ GL.Vertex(20, 200)
14
+ GL.End
15
+ GL.Flush
16
+ }
17
+
18
+ reshape = Proc.new {|w, h|
19
+ GL.Viewport(0, 0, w, h)
20
+ GL.MatrixMode(GL::PROJECTION)
21
+ GL.LoadIdentity
22
+ GL.Ortho(0, w, 0, h, -1, 1)
23
+ GL.Scale(1, -1, 1)
24
+ GL.Translate(0, -h, 0)
25
+ }
26
+
27
+ # Keyboard handler to exit when ESC is typed
28
+ keyboard = lambda do |key, x, y|
29
+ case(key)
30
+ when 27
31
+ exit(0)
32
+ end
33
+ end
34
+
35
+ GLUT.Init
36
+ a = GLUT.CreateWindow("single triangle");
37
+ GLUT.DisplayFunc(disp);
38
+ GLUT.ReshapeFunc(reshape);
39
+ GLUT.KeyboardFunc( keyboard )
40
+ GLUT.MainLoop;
data/examples/test.rb ADDED
@@ -0,0 +1,64 @@
1
+ # Copyright (C) 2006 Peter McLain <peter.mclain@gmail.com>
2
+ #
3
+ # This program is distributed under the terms of the MIT license.
4
+ # See the included MIT-LICENSE file for the terms of this license.
5
+ #
6
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
7
+ # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
8
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
9
+ # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
10
+ # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
11
+ # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
12
+ # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
13
+
14
+ require '../lib/glut'
15
+ require '../lib/gl'
16
+
17
+ class GlutTest
18
+
19
+ def initialize
20
+ puts "=== GlutTest.initialize ==="
21
+ # Setup the GLUT display loop callback
22
+ @display = lambda do
23
+ puts "=== In display routine"
24
+ Gl.glClear( Gl::GL_COLOR_BUFFER_BIT | Gl::GL_DEPTH_BUFFER_BIT )
25
+ Gl.glColor3f( 1.0, 1.0, 1.0 )
26
+
27
+ Gl.glBegin( Gl::GL_POLYGON )
28
+
29
+ Gl.glVertex2f( -0.5, -0.5 )
30
+ Gl.glVertex2f( -0.5, 0.5 )
31
+ Gl.glVertex2f( 0.5, 0.5 )
32
+ Gl.glVertex2f( 0.5, -0.5 )
33
+
34
+ Gl.glEnd
35
+
36
+ Gl.glFlush
37
+ end
38
+
39
+ # Keyboard handler to exit when ESC is typed
40
+ @keyboard = lambda do |key, x, y|
41
+ case(key)
42
+ when 27
43
+ exit(0)
44
+ end
45
+ end
46
+ end
47
+
48
+ def show
49
+ puts "=== GlutTest.show ==="
50
+ Glut.glutInit
51
+ Glut.glutInitDisplayMode( Glut::GLUT_DOUBLE | Glut::GLUT_RGB | Glut::GLUT_DEPTH )
52
+ Glut.glutCreateWindow( 'pbm' )
53
+ Glut.glutDisplayFunc( @display )
54
+ #Glut.glutReshapeFunc( @reshape )
55
+ Glut.glutKeyboardFunc( @keyboard ) if @keyboard
56
+ Glut.glutMainLoop
57
+ end
58
+ end
59
+
60
+ if __FILE__ == $0
61
+ gt = GlutTest.new
62
+ gt.show
63
+ end
64
+
@@ -0,0 +1,39 @@
1
+ # -*- ruby -*-
2
+
3
+ # Copyright (C) 2006 John M. Gabriele <jmg3000@gmail.com>
4
+ #
5
+ # This program is distributed under the terms of the MIT license.
6
+ # See the included COPYRIGHT file for the terms of this license.
7
+ #
8
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
9
+ # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
10
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
11
+ # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
12
+ # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
13
+ # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
14
+ # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
15
+
16
+ # Simple Rakefile for building rbogl.c.
17
+
18
+ require 'rake/clean'
19
+ require 'rbconfig'
20
+
21
+ INCLUDES = "-I#{Config::CONFIG['archdir']}"
22
+ CFLAGS = "#{Config::CONFIG['CFLAGS']}"
23
+
24
+ case RUBY_PLATFORM
25
+ when /darwin/
26
+ INCLUDES << ' -F/System/Library/Frameworks'
27
+ end
28
+
29
+ CLEAN.include( '*.o' )
30
+
31
+ SRC = FileList[ '*.c' ]
32
+ OBJ = SRC.ext( 'o' )
33
+
34
+ task :default => OBJ
35
+ file 'rbogl.c' => [ 'rbogl.h' ]
36
+
37
+ rule '.o' => '.c' do |t|
38
+ sh "cc -c #{CFLAGS} #{INCLUDES} -o #{t.name} #{t.source}"
39
+ end