ruby-opengl 0.33.0 → 0.40.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (103) hide show
  1. data/Rakefile +42 -15
  2. data/doc/build_install.txt +70 -25
  3. data/doc/history.txt +4 -0
  4. data/doc/requirements_and_design.txt +2 -3
  5. data/doc/roadmap.txt +15 -2
  6. data/doc/screenshots.txt +23 -0
  7. data/doc/supplies/page_template.html +2 -1
  8. data/doc/thanks.txt +3 -0
  9. data/doc/tutorial.txt +5 -3
  10. data/examples/README +57 -7
  11. data/examples/legacy/COPYRIGHT +8 -0
  12. data/examples/{aaindex.rb → legacy/aaindex.rb} +6 -5
  13. data/examples/legacy/aapoly.rb +153 -0
  14. data/examples/legacy/aargb.rb +139 -0
  15. data/examples/legacy/accanti.rb +159 -0
  16. data/examples/legacy/accpersp.rb +216 -0
  17. data/examples/legacy/alpha.rb +133 -0
  18. data/examples/legacy/alpha3D.rb +165 -0
  19. data/examples/legacy/bezcurve.rb +107 -0
  20. data/examples/legacy/bezmesh.rb +131 -0
  21. data/examples/legacy/checker.rb +121 -0
  22. data/examples/legacy/clip.rb +104 -0
  23. data/examples/legacy/colormat.rb +145 -0
  24. data/examples/legacy/cube.rb +73 -0
  25. data/examples/legacy/depthcue.rb +101 -0
  26. data/examples/legacy/dof.rb +212 -0
  27. data/examples/legacy/double.rb +104 -0
  28. data/examples/legacy/drawf.rb +98 -0
  29. data/examples/legacy/feedback.rb +152 -0
  30. data/examples/legacy/fog.rb +172 -0
  31. data/examples/legacy/font-glut.rb +41 -0
  32. data/examples/legacy/font.rb +158 -0
  33. data/examples/legacy/hello.rb +75 -0
  34. data/examples/legacy/image.rb +145 -0
  35. data/examples/legacy/jitter.rb +209 -0
  36. data/examples/legacy/lines.rb +135 -0
  37. data/examples/legacy/list.rb +120 -0
  38. data/examples/legacy/material.rb +290 -0
  39. data/examples/legacy/mipmap.rb +159 -0
  40. data/examples/legacy/model.rb +119 -0
  41. data/examples/legacy/movelight.rb +140 -0
  42. data/examples/legacy/pickdepth.rb +180 -0
  43. data/examples/legacy/planet.rb +112 -0
  44. data/examples/legacy/quadric.rb +180 -0
  45. data/examples/legacy/readpixel.rb +59 -0
  46. data/examples/legacy/robot.rb +120 -0
  47. data/examples/legacy/select.rb +207 -0
  48. data/examples/{smooth_prev.rb → legacy/smooth.rb} +3 -2
  49. data/examples/legacy/stencil.rb +154 -0
  50. data/examples/legacy/stroke.rb +170 -0
  51. data/examples/legacy/surface.rb +170 -0
  52. data/examples/legacy/teaambient.rb +132 -0
  53. data/examples/legacy/teapots.rb +188 -0
  54. data/examples/legacy/tess.rb +222 -0
  55. data/examples/legacy/texbind.rb +157 -0
  56. data/examples/legacy/texgen.rb +171 -0
  57. data/examples/legacy/texturesurf.rb +128 -0
  58. data/examples/legacy/varray.rb +167 -0
  59. data/examples/legacy/wrap.rb +158 -0
  60. data/examples/nehe_lesson02.rb +117 -0
  61. data/examples/nehe_lesson03.rb +122 -0
  62. data/examples/nehe_lesson04.rb +133 -0
  63. data/examples/nehe_lesson05.rb +186 -0
  64. data/examples/plane.rb +1 -1
  65. data/examples/smooth.rb +4 -2
  66. data/examples/test.rb +3 -2
  67. data/ext/common/{rbogl.c → common.h} +99 -32
  68. data/ext/common/gl-enums.h +39 -1
  69. data/ext/gl/gl-1.0-1.1.c +350 -305
  70. data/ext/gl/gl-1.2.c +933 -38
  71. data/ext/gl/gl-1.3.c +725 -0
  72. data/ext/gl/gl-1.4.c +647 -0
  73. data/ext/gl/gl-1.5.c +362 -0
  74. data/ext/gl/gl-2.0.c +1632 -0
  75. data/ext/gl/gl-2.1.c +154 -0
  76. data/ext/gl/gl-enums.c +1 -2
  77. data/ext/gl/gl.c +58 -2
  78. data/ext/gl/mkrf_conf.rb +4 -1
  79. data/ext/glu/glu.c +5 -4
  80. data/ext/glu/mkrf_conf.rb +4 -1
  81. data/ext/glut/glut.c +7 -1
  82. data/ext/glut/mkrf_conf.rb +5 -0
  83. data/lib/gl_prev.rb +4 -3
  84. data/lib/glu_prev.rb +4 -3
  85. data/lib/glut_prev.rb +3 -3
  86. data/{examples/all_tests.rb → lib/opengl.rb} +9 -12
  87. data/test/README +5 -18
  88. data/test/tc_common.rb +79 -0
  89. data/test/tc_func_10_11.rb +1255 -0
  90. data/test/tc_func_12.rb +186 -0
  91. data/test/tc_func_13.rb +203 -0
  92. data/test/tc_func_14.rb +197 -0
  93. data/test/tc_func_15.rb +82 -0
  94. data/test/tc_func_20.rb +320 -0
  95. data/test/tc_func_21.rb +67 -0
  96. data/test/tc_include_gl.rb +1 -1
  97. data/test/{tc_opengl_namespace.rb → tc_misc.rb} +20 -20
  98. data/test/tc_require_gl.rb +1 -1
  99. metadata +99 -27
  100. data/ext/common/Rakefile +0 -39
  101. data/ext/common/rbogl.h +0 -52
  102. data/test/runtests.sh +0 -7
  103. data/test/tc_gl_vertex.rb +0 -180
@@ -0,0 +1,117 @@
1
+ #!/usr/bin/env ruby -rubygems
2
+ # Name: nehe_lesson02.rb
3
+ # Purpose: An implementation of NeHe's OpenGL Lesson #02
4
+ # using ruby-opengl (http://nehe.gamedev.net/)
5
+ #
6
+
7
+ require "gl"
8
+ require "glu"
9
+ require "glut"
10
+ require "mathn"
11
+
12
+ # Add GL and GLUT namespaces in to make porting easier
13
+ include Gl
14
+ include Glu
15
+ include Glut
16
+
17
+ # Placeholder for the window object
18
+ window = ""
19
+
20
+ def init_gl_window(width = 640, height = 480)
21
+ # Background color to black
22
+ glClearColor(0.0, 0.0, 0.0, 0)
23
+ # Enables clearing of depth buffer
24
+ glClearDepth(1.0)
25
+ # Set type of depth test
26
+ glDepthFunc(GL_LEQUAL)
27
+ # Enable depth testing
28
+ glEnable(GL_DEPTH_TEST)
29
+ # Enable smooth color shading
30
+ glShadeModel(GL_SMOOTH)
31
+
32
+ glMatrixMode(GL_PROJECTION)
33
+ glLoadIdentity
34
+ # Calculate aspect ratio of the window
35
+ gluPerspective(45.0, width / height, 0.1, 100.0)
36
+
37
+ glMatrixMode(GL_MODELVIEW)
38
+
39
+ draw_gl_scene
40
+ end
41
+
42
+ #reshape = Proc.new do |width, height|
43
+ def reshape(width, height)
44
+ height = 1 if height == 0
45
+
46
+ # Reset current viewpoint and perspective transformation
47
+ glViewport(0, 0, width, height)
48
+
49
+ glMatrixMode(GL_PROJECTION)
50
+ glLoadIdentity
51
+
52
+ gluPerspective(45.0, width / height, 0.1, 100.0)
53
+ end
54
+
55
+ #draw_gl_scene = Proc.new do
56
+ def draw_gl_scene
57
+ # Clear the screen and depth buffer
58
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
59
+
60
+ # Reset the view
61
+ glMatrixMode(GL_MODELVIEW)
62
+ glLoadIdentity
63
+
64
+ # Move left 1.5 units and into the screen 6.0 units
65
+ glTranslatef(-1.5, 0.0, -6.0)
66
+
67
+ # Draw a triangle
68
+ glBegin(GL_POLYGON)
69
+ glVertex3f( 0.0, 1.0, 0.0)
70
+ glVertex3f( 1.0, -1.0, 0.0)
71
+ glVertex3f(-1.0, -1.0, 0.0)
72
+ glEnd
73
+
74
+ # Move right 3 units
75
+ glTranslatef(3.0, 0.0, 0.0)
76
+
77
+ # Draw a rectangle
78
+ glBegin(GL_QUADS)
79
+ glVertex3f(-1.0, 1.0, 0.0)
80
+ glVertex3f( 1.0, 1.0, 0.0)
81
+ glVertex3f( 1.0, -1.0, 0.0)
82
+ glVertex3f(-1.0, -1.0, 0.0)
83
+ glEnd
84
+
85
+ # Swap buffers for display
86
+ glutSwapBuffers
87
+ end
88
+
89
+ # The idle function to handle
90
+ def idle
91
+ glutPostRedisplay
92
+ end
93
+
94
+ # Keyboard handler to exit when ESC is typed
95
+ keyboard = lambda do |key, x, y|
96
+ case(key)
97
+ when 27
98
+ glutDestroyWindow(window)
99
+ exit(0)
100
+ end
101
+ glutPostRedisplay
102
+ end
103
+
104
+
105
+ # Initliaze our GLUT code
106
+ glutInit;
107
+ # Setup a double buffer, RGBA color, alpha components and depth buffer
108
+ glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_ALPHA | GLUT_DEPTH);
109
+ glutInitWindowSize(640, 480);
110
+ glutInitWindowPosition(0, 0);
111
+ window = glutCreateWindow("NeHe Lesson 02 - ruby-opengl version");
112
+ glutDisplayFunc(method(:draw_gl_scene).to_proc);
113
+ glutReshapeFunc(method(:reshape).to_proc);
114
+ glutIdleFunc(method(:idle).to_proc);
115
+ glutKeyboardFunc(keyboard);
116
+ init_gl_window(640, 480)
117
+ glutMainLoop();
@@ -0,0 +1,122 @@
1
+ #!/usr/bin/env ruby -rubygems
2
+ # Name: nehe_lesson03.rb
3
+ # Purpose: An implementation of NeHe's OpenGL Lesson #03
4
+ # using ruby-opengl (http://nehe.gamedev.net/)
5
+ #
6
+
7
+ require "gl"
8
+ require "glu"
9
+ require "glut"
10
+ require "mathn"
11
+
12
+ # Add GL and GLUT namespaces in to make porting easier
13
+ include Gl
14
+ include Glu
15
+ include Glut
16
+
17
+ # Placeholder for the window object
18
+ window = ""
19
+
20
+ def init_gl_window(width = 640, height = 480)
21
+ # Background color to black
22
+ glClearColor(0.0, 0.0, 0.0, 0)
23
+ # Enables clearing of depth buffer
24
+ glClearDepth(1.0)
25
+ # Set type of depth test
26
+ glDepthFunc(GL_LEQUAL)
27
+ # Enable depth testing
28
+ glEnable(GL_DEPTH_TEST)
29
+ # Enable smooth color shading
30
+ glShadeModel(GL_SMOOTH)
31
+
32
+ glMatrixMode(GL_PROJECTION)
33
+ glLoadIdentity
34
+ # Calculate aspect ratio of the window
35
+ gluPerspective(45.0, width / height, 0.1, 100.0)
36
+
37
+ glMatrixMode(GL_MODELVIEW)
38
+
39
+ draw_gl_scene
40
+ end
41
+
42
+ #reshape = Proc.new do |width, height|
43
+ def reshape(width, height)
44
+ height = 1 if height == 0
45
+
46
+ # Reset current viewpoint and perspective transformation
47
+ glViewport(0, 0, width, height)
48
+
49
+ glMatrixMode(GL_PROJECTION)
50
+ glLoadIdentity
51
+
52
+ gluPerspective(45.0, width / height, 0.1, 100.0)
53
+ end
54
+
55
+ #draw_gl_scene = Proc.new do
56
+ def draw_gl_scene
57
+ # Clear the screen and depth buffer
58
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
59
+
60
+ # Reset the view
61
+ glMatrixMode(GL_MODELVIEW)
62
+ glLoadIdentity
63
+
64
+ # Move left 1.5 units and into the screen 6.0 units
65
+ glTranslatef(-1.5, 0.0, -6.0)
66
+
67
+ # Draw a triangle
68
+ glBegin(GL_POLYGON)
69
+ glColor3f(1.0, 0.0, 0.0)
70
+ glVertex3f( 0.0, 1.0, 0.0)
71
+ glColor3f(0.0, 1.0, 0.0)
72
+ glVertex3f( 1.0, -1.0, 0.0)
73
+ glColor3f(0.0, 0.0, 1.0)
74
+ glVertex3f(-1.0, -1.0, 0.0)
75
+ glEnd
76
+
77
+ # Move right 3 units
78
+ glTranslatef(3.0, 0.0, 0.0)
79
+
80
+ # Draw a rectangle
81
+ # Set it to a blue color one time only
82
+ glColor3f(0.5, 0.5, 1.0)
83
+ glBegin(GL_QUADS)
84
+ glVertex3f(-1.0, 1.0, 0.0)
85
+ glVertex3f( 1.0, 1.0, 0.0)
86
+ glVertex3f( 1.0, -1.0, 0.0)
87
+ glVertex3f(-1.0, -1.0, 0.0)
88
+ glEnd
89
+
90
+ # Swap buffers for display
91
+ glutSwapBuffers
92
+ end
93
+
94
+ # The idle function to handle
95
+ def idle
96
+ glutPostRedisplay
97
+ end
98
+
99
+ # Keyboard handler to exit when ESC is typed
100
+ keyboard = lambda do |key, x, y|
101
+ case(key)
102
+ when 27
103
+ glutDestroyWindow(window)
104
+ exit(0)
105
+ end
106
+ glutPostRedisplay
107
+ end
108
+
109
+
110
+ # Initliaze our GLUT code
111
+ glutInit;
112
+ # Setup a double buffer, RGBA color, alpha components and depth buffer
113
+ glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_ALPHA | GLUT_DEPTH);
114
+ glutInitWindowSize(640, 480);
115
+ glutInitWindowPosition(0, 0);
116
+ window = glutCreateWindow("NeHe Lesson 03 - ruby-opengl version");
117
+ glutDisplayFunc(method(:draw_gl_scene).to_proc);
118
+ glutReshapeFunc(method(:reshape).to_proc);
119
+ glutIdleFunc(method(:idle).to_proc);
120
+ glutKeyboardFunc(keyboard);
121
+ init_gl_window(640, 480)
122
+ glutMainLoop();
@@ -0,0 +1,133 @@
1
+ #!/usr/bin/env ruby -rubygems
2
+ # Name: nehe_lesson04.rb
3
+ # Purpose: An implementation of NeHe's OpenGL Lesson #04
4
+ # using ruby-opengl (http://nehe.gamedev.net/)
5
+ #
6
+
7
+ require "gl"
8
+ require "glu"
9
+ require "glut"
10
+ require "mathn"
11
+
12
+ # Add GL and GLUT namespaces in to make porting easier
13
+ include Gl
14
+ include Glu
15
+ include Glut
16
+
17
+ # Placeholder for the window object
18
+ $window = ""
19
+ # Angle for the triangle (Global)
20
+ $triangle_angle = 0
21
+ # Angle for the quadrilateral (Global)
22
+ $quad_angle = 0
23
+
24
+ def init_gl_window(width = 640, height = 480)
25
+ # Background color to black
26
+ glClearColor(0.0, 0.0, 0.0, 0)
27
+ # Enables clearing of depth buffer
28
+ glClearDepth(1.0)
29
+ # Set type of depth test
30
+ glDepthFunc(GL_LEQUAL)
31
+ # Enable depth testing
32
+ glEnable(GL_DEPTH_TEST)
33
+ # Enable smooth color shading
34
+ glShadeModel(GL_SMOOTH)
35
+
36
+ glMatrixMode(GL_PROJECTION)
37
+ glLoadIdentity
38
+ # Calculate aspect ratio of the window
39
+ gluPerspective(45.0, width / height, 0.1, 100.0)
40
+
41
+ glMatrixMode(GL_MODELVIEW)
42
+
43
+ draw_gl_scene
44
+ end
45
+
46
+ #reshape = Proc.new do |width, height|
47
+ def reshape(width, height)
48
+ height = 1 if height == 0
49
+
50
+ # Reset current viewpoint and perspective transformation
51
+ glViewport(0, 0, width, height)
52
+
53
+ glMatrixMode(GL_PROJECTION)
54
+ glLoadIdentity
55
+
56
+ gluPerspective(45.0, width / height, 0.1, 100.0)
57
+ end
58
+
59
+ #draw_gl_scene = Proc.new do
60
+ def draw_gl_scene
61
+ # Clear the screen and depth buffer
62
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
63
+
64
+ # Reset the view
65
+ glMatrixMode(GL_MODELVIEW)
66
+ glLoadIdentity
67
+
68
+ # Move left 1.5 units and into the screen 6.0 units
69
+ glTranslatef(-1.5, 0.0, -6.0)
70
+
71
+ # Rotate the triangle on the Y-axis
72
+ glRotatef($triangle_angle, 0.0, 1.0, 0.0)
73
+ # Draw a triangle
74
+ glBegin(GL_POLYGON)
75
+ glColor3f(1.0, 0.0, 0.0)
76
+ glVertex3f( 0.0, 1.0, 0.0)
77
+ glColor3f(0.0, 1.0, 0.0)
78
+ glVertex3f( 1.0, -1.0, 0.0)
79
+ glColor3f(0.0, 0.0, 1.0)
80
+ glVertex3f(-1.0, -1.0, 0.0)
81
+ glEnd
82
+
83
+ # Move right 3 units
84
+ glLoadIdentity
85
+ glTranslatef(1.5, 0.0, -6.0)
86
+
87
+ # Draw a quadrilateral
88
+ # Rotate the quad on the X-axis
89
+ glRotatef($quad_angle, 1.0, 0.0, 0.0)
90
+ # Set it to a blue color one time only
91
+ glColor3f(0.5, 0.5, 1.0)
92
+ glBegin(GL_QUADS)
93
+ glVertex3f(-1.0, 1.0, 0.0)
94
+ glVertex3f( 1.0, 1.0, 0.0)
95
+ glVertex3f( 1.0, -1.0, 0.0)
96
+ glVertex3f(-1.0, -1.0, 0.0)
97
+ glEnd
98
+
99
+ $triangle_angle += 0.2
100
+ $quad_angle -= 0.15
101
+ # Swap buffers for display
102
+ glutSwapBuffers
103
+ end
104
+
105
+ # The idle function to handle
106
+ def idle
107
+ glutPostRedisplay
108
+ end
109
+
110
+ # Keyboard handler to exit when ESC is typed
111
+ keyboard = lambda do |key, x, y|
112
+ case(key)
113
+ when 27
114
+ glutDestroyWindow($window)
115
+ exit(0)
116
+ end
117
+ glutPostRedisplay
118
+ end
119
+
120
+
121
+ # Initliaze our GLUT code
122
+ glutInit;
123
+ # Setup a double buffer, RGBA color, alpha components and depth buffer
124
+ glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_ALPHA | GLUT_DEPTH);
125
+ glutInitWindowSize(640, 480);
126
+ glutInitWindowPosition(0, 0);
127
+ $window = glutCreateWindow("NeHe Lesson 04 - ruby-opengl version");
128
+ glutDisplayFunc(method(:draw_gl_scene).to_proc);
129
+ glutReshapeFunc(method(:reshape).to_proc);
130
+ glutIdleFunc(method(:idle).to_proc);
131
+ glutKeyboardFunc(keyboard);
132
+ init_gl_window(640, 480)
133
+ glutMainLoop();
@@ -0,0 +1,186 @@
1
+ #!/usr/bin/env ruby -rubygems
2
+ # Name: nehe_lesson05.rb
3
+ # Purpose: An implementation of NeHe's OpenGL Lesson #05
4
+ # using ruby-opengl (http://nehe.gamedev.net/)
5
+ #
6
+
7
+ require "gl"
8
+ require "glu"
9
+ require "glut"
10
+ require "mathn"
11
+
12
+ # Add GL and GLUT namespaces in to make porting easier
13
+ include Gl
14
+ include Glu
15
+ include Glut
16
+
17
+ # Placeholder for the window object
18
+ $window = ""
19
+ # Angle for the triangle (Global)
20
+ $pyramid_angle = 0
21
+ # Angle for the quadrilateral (Global)
22
+ $cube_angle = 0
23
+
24
+ def init_gl_window(width = 640, height = 480)
25
+ # Background color to black
26
+ glClearColor(0.0, 0.0, 0.0, 0)
27
+ # Enables clearing of depth buffer
28
+ glClearDepth(1.0)
29
+ # Set type of depth test
30
+ glDepthFunc(GL_LEQUAL)
31
+ # Enable depth testing
32
+ glEnable(GL_DEPTH_TEST)
33
+ # Enable smooth color shading
34
+ glShadeModel(GL_SMOOTH)
35
+
36
+ glMatrixMode(GL_PROJECTION)
37
+ glLoadIdentity
38
+ # Calculate aspect ratio of the window
39
+ gluPerspective(45.0, width / height, 0.1, 100.0)
40
+
41
+ glMatrixMode(GL_MODELVIEW)
42
+
43
+ draw_gl_scene
44
+ end
45
+
46
+ #reshape = Proc.new do |width, height|
47
+ def reshape(width, height)
48
+ height = 1 if height == 0
49
+
50
+ # Reset current viewpoint and perspective transformation
51
+ glViewport(0, 0, width, height)
52
+
53
+ glMatrixMode(GL_PROJECTION)
54
+ glLoadIdentity
55
+
56
+ gluPerspective(45.0, width / height, 0.1, 100.0)
57
+ end
58
+
59
+ #draw_gl_scene = Proc.new do
60
+ def draw_gl_scene
61
+ # Clear the screen and depth buffer
62
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
63
+
64
+ # Reset the view
65
+ glMatrixMode(GL_MODELVIEW)
66
+ glLoadIdentity
67
+
68
+ # Move left 1.5 units and into the screen 6.0 units
69
+ glTranslatef(-1.5, 0.0, -6.0)
70
+
71
+ # Rotate the pyramid on the Y-axis
72
+ glRotatef($pyramid_angle, 0.0, 1.0, 0.0)
73
+ # Draw a pyramid
74
+ glBegin(GL_POLYGON)
75
+ # Draw front side of pyramid
76
+ glColor3f(1.0, 0.0, 0.0)
77
+ glVertex3f( 0.0, 1.0, 0.0)
78
+ glColor3f(0.0, 1.0, 0.0)
79
+ glVertex3f(-1.0, -1.0, 1.0)
80
+ glColor3f(0.0, 0.0, 1.0)
81
+ glVertex3f(1.0, -1.0, 1.0)
82
+ # Draw right side of pyramid
83
+ glColor3f(1.0, 0.0, 0.0)
84
+ glVertex3f( 0.0, 1.0, 0.0)
85
+ glColor3f(0.0, 0.0, 1.0)
86
+ glVertex3f( 1.0, -1.0, 1.0)
87
+ glColor3f(0.0, 1.0, 0.0)
88
+ glVertex3f(1.0, -1.0, -1.0)
89
+ # Draw back side of pyramid
90
+ glColor3f(1.0, 0.0, 0.0)
91
+ glVertex3f( 0.0, 1.0, 0.0)
92
+ glColor3f(0.0, 0.0, 1.0)
93
+ glVertex3f(1.0, -1.0, -1.0)
94
+ glColor3f(0.0, 1.0, 0.0)
95
+ glVertex3f(-1.0, -1.0, -1.0)
96
+ # Draw left side of pyramid
97
+ glColor3f(1.0, 0.0, 0.0)
98
+ glVertex3f( 0.0, 1.0, 0.0)
99
+ glColor3f(0.0, 0.0, 1.0)
100
+ glVertex3f(-1.0, -1.0, -1.0)
101
+ glColor3f(0.0, 1.0, 0.0)
102
+ glVertex3f(-1.0, -1.0, 1.0)
103
+ glEnd
104
+
105
+ glLoadIdentity
106
+ # Move right 3 units
107
+ glTranslatef(1.5, 0.0, -7.0)
108
+
109
+ # Draw a cube
110
+ # Rotate the cube on the X, Y and Z axis
111
+ glRotatef($cube_angle, 1.0, 1.0, 1.0)
112
+ # Set it to a blue color one time only
113
+ glBegin(GL_QUADS)
114
+ # Draw the top side in green
115
+ glColor3f(0.0, 1.0, 0.0)
116
+ glVertex3f( 1.0, 1.0, -1.0)
117
+ glVertex3f(-1.0, 1.0, -1.0)
118
+ glVertex3f(-1.0, 1.0, 1.0)
119
+ glVertex3f( 1.0, 1.0, 1.0)
120
+ # Draw the bottom side in orange
121
+ glColor3f(1.0, 0.5, 0.0)
122
+ glVertex3f( 1.0, -1.0, 1.0)
123
+ glVertex3f(-1.0, -1.0, 1.0)
124
+ glVertex3f(-1.0, -1.0, -1.0)
125
+ glVertex3f( 1.0, -1.0, -1.0)
126
+ # Draw the front side in red
127
+ glColor3f(1.0, 0.0, 0.0)
128
+ glVertex3f( 1.0, 1.0, 1.0)
129
+ glVertex3f(-1.0, 1.0, 1.0)
130
+ glVertex3f(-1.0, -1.0, 1.0)
131
+ glVertex3f( 1.0, -1.0, 1.0)
132
+ # Draw the back side in yellow
133
+ glColor3f(1.0, 1.0, 0.0)
134
+ glVertex3f( 1.0, -1.0, -1.0)
135
+ glVertex3f(-1.0, -1.0, -1.0)
136
+ glVertex3f(-1.0, 1.0, -1.0)
137
+ glVertex3f( 1.0, 1.0, -1.0)
138
+ # Draw the left side in blue
139
+ glColor3f(0.0, 0.0, 1.0)
140
+ glVertex3f(-1.0, 1.0, 1.0)
141
+ glVertex3f(-1.0, 1.0, -1.0)
142
+ glVertex3f(-1.0, -1.0, -1.0)
143
+ glVertex3f(-1.0, -1.0, 1.0)
144
+ # Draw the right side in violet
145
+ glColor3f(1.0, 0.0, 1.0)
146
+ glVertex3f( 1.0, 1.0, -1.0)
147
+ glVertex3f( 1.0, 1.0, 1.0)
148
+ glVertex3f( 1.0, -1.0, 1.0)
149
+ glVertex3f( 1.0, -1.0, -1.0)
150
+ glEnd
151
+
152
+ $pyramid_angle += 0.2
153
+ $cube_angle -= 0.15
154
+ # Swap buffers for display
155
+ glutSwapBuffers
156
+ end
157
+
158
+ # The idle function to handle
159
+ def idle
160
+ glutPostRedisplay
161
+ end
162
+
163
+ # Keyboard handler to exit when ESC is typed
164
+ keyboard = lambda do |key, x, y|
165
+ case(key)
166
+ when 27
167
+ glutDestroyWindow($window)
168
+ exit(0)
169
+ end
170
+ glutPostRedisplay
171
+ end
172
+
173
+
174
+ # Initliaze our GLUT code
175
+ glutInit;
176
+ # Setup a double buffer, RGBA color, alpha components and depth buffer
177
+ glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_ALPHA | GLUT_DEPTH);
178
+ glutInitWindowSize(640, 480);
179
+ glutInitWindowPosition(0, 0);
180
+ $window = glutCreateWindow("NeHe Lesson 05 - ruby-opengl version");
181
+ glutDisplayFunc(method(:draw_gl_scene).to_proc);
182
+ glutReshapeFunc(method(:reshape).to_proc);
183
+ glutIdleFunc(method(:idle).to_proc);
184
+ glutKeyboardFunc(keyboard);
185
+ init_gl_window(640, 480)
186
+ glutMainLoop();