opengl 0.9.0-x64-mingw32
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
 - checksums.yaml.gz.sig +3 -0
 - data.tar.gz.sig +0 -0
 - data/.autotest +29 -0
 - data/.gemtest +0 -0
 - data/.gitignore +6 -0
 - data/.travis.yml +19 -0
 - data/History.rdoc +77 -0
 - data/MIT-LICENSE +18 -0
 - data/Manifest.txt +138 -0
 - data/README.rdoc +102 -0
 - data/Rakefile +60 -0
 - data/examples/NeHe/NeHe.png +0 -0
 - data/examples/NeHe/crate.png +0 -0
 - data/examples/NeHe/glass.png +0 -0
 - data/examples/NeHe/nehe_lesson02.rb +117 -0
 - data/examples/NeHe/nehe_lesson03.rb +123 -0
 - data/examples/NeHe/nehe_lesson04.rb +132 -0
 - data/examples/NeHe/nehe_lesson05.rb +182 -0
 - data/examples/NeHe/nehe_lesson06.rb +186 -0
 - data/examples/NeHe/nehe_lesson07.rb +240 -0
 - data/examples/NeHe/nehe_lesson08.rb +255 -0
 - data/examples/NeHe/nehe_lesson09.rb +203 -0
 - data/examples/NeHe/nehe_lesson11.rb +176 -0
 - data/examples/NeHe/nehe_lesson12.rb +203 -0
 - data/examples/NeHe/nehe_lesson16.rb +211 -0
 - data/examples/NeHe/nehe_lesson19.rb +209 -0
 - data/examples/NeHe/nehe_lesson36.rb +308 -0
 - data/examples/NeHe/particle.png +0 -0
 - data/examples/NeHe/star.png +0 -0
 - data/examples/NeHe/tim.png +0 -0
 - data/examples/OrangeBook/3Dlabs-License.txt +33 -0
 - data/examples/OrangeBook/brick.frag +36 -0
 - data/examples/OrangeBook/brick.rb +378 -0
 - data/examples/OrangeBook/brick.vert +41 -0
 - data/examples/OrangeBook/particle.frag +17 -0
 - data/examples/OrangeBook/particle.rb +408 -0
 - data/examples/OrangeBook/particle.vert +38 -0
 - data/examples/README +16 -0
 - data/examples/RedBook/aapoly.rb +143 -0
 - data/examples/RedBook/aargb.rb +121 -0
 - data/examples/RedBook/accanti.rb +164 -0
 - data/examples/RedBook/accpersp.rb +217 -0
 - data/examples/RedBook/alpha.rb +125 -0
 - data/examples/RedBook/alpha3D.rb +160 -0
 - data/examples/RedBook/bezcurve.rb +107 -0
 - data/examples/RedBook/bezmesh.rb +139 -0
 - data/examples/RedBook/checker.rb +126 -0
 - data/examples/RedBook/clip.rb +97 -0
 - data/examples/RedBook/colormat.rb +137 -0
 - data/examples/RedBook/cube.rb +71 -0
 - data/examples/RedBook/depthcue.rb +101 -0
 - data/examples/RedBook/dof.rb +206 -0
 - data/examples/RedBook/double.rb +107 -0
 - data/examples/RedBook/drawf.rb +93 -0
 - data/examples/RedBook/feedback.rb +147 -0
 - data/examples/RedBook/fog.rb +168 -0
 - data/examples/RedBook/font.rb +153 -0
 - data/examples/RedBook/hello.rb +81 -0
 - data/examples/RedBook/image.rb +139 -0
 - data/examples/RedBook/jitter.rb +207 -0
 - data/examples/RedBook/light.rb +155 -0
 - data/examples/RedBook/lines.rb +130 -0
 - data/examples/RedBook/list.rb +113 -0
 - data/examples/RedBook/material.rb +276 -0
 - data/examples/RedBook/mipmap.rb +158 -0
 - data/examples/RedBook/model.rb +115 -0
 - data/examples/RedBook/movelight.rb +134 -0
 - data/examples/RedBook/pickdepth.rb +181 -0
 - data/examples/RedBook/planet.rb +110 -0
 - data/examples/RedBook/quadric.rb +160 -0
 - data/examples/RedBook/robot.rb +117 -0
 - data/examples/RedBook/select.rb +198 -0
 - data/examples/RedBook/smooth.rb +97 -0
 - data/examples/RedBook/stencil.rb +165 -0
 - data/examples/RedBook/stroke.rb +169 -0
 - data/examples/RedBook/surface.rb +168 -0
 - data/examples/RedBook/teaambient.rb +134 -0
 - data/examples/RedBook/teapots.rb +184 -0
 - data/examples/RedBook/tess.rb +185 -0
 - data/examples/RedBook/texbind.rb +149 -0
 - data/examples/RedBook/texgen.rb +171 -0
 - data/examples/RedBook/texturesurf.rb +130 -0
 - data/examples/RedBook/varray.rb +161 -0
 - data/examples/RedBook/wrap.rb +150 -0
 - data/examples/misc/OGLBench.rb +338 -0
 - data/examples/misc/anisotropic.rb +196 -0
 - data/examples/misc/fbo_test.rb +357 -0
 - data/examples/misc/font-glut.rb +47 -0
 - data/examples/misc/glfwtest.rb +30 -0
 - data/examples/misc/plane.rb +161 -0
 - data/examples/misc/readpixel.rb +66 -0
 - data/examples/misc/sdltest.rb +36 -0
 - data/examples/misc/trislam.rb +829 -0
 - data/ext/opengl/common.h +428 -0
 - data/ext/opengl/conv.h +244 -0
 - data/ext/opengl/extconf.rb +47 -0
 - data/ext/opengl/funcdef.h +313 -0
 - data/ext/opengl/gl-1.0-1.1.c +3075 -0
 - data/ext/opengl/gl-1.2.c +155 -0
 - data/ext/opengl/gl-1.3.c +443 -0
 - data/ext/opengl/gl-1.4.c +348 -0
 - data/ext/opengl/gl-1.5.c +224 -0
 - data/ext/opengl/gl-2.0.c +667 -0
 - data/ext/opengl/gl-2.1.c +57 -0
 - data/ext/opengl/gl-3.0.c +493 -0
 - data/ext/opengl/gl-enums.c +4873 -0
 - data/ext/opengl/gl-enums.h +14588 -0
 - data/ext/opengl/gl-error.c +112 -0
 - data/ext/opengl/gl-error.h +28 -0
 - data/ext/opengl/gl-ext-3dfx.c +27 -0
 - data/ext/opengl/gl-ext-arb.c +875 -0
 - data/ext/opengl/gl-ext-ati.c +41 -0
 - data/ext/opengl/gl-ext-ext.c +889 -0
 - data/ext/opengl/gl-ext-gremedy.c +41 -0
 - data/ext/opengl/gl-ext-nv.c +680 -0
 - data/ext/opengl/gl-types.h +67 -0
 - data/ext/opengl/gl.c +220 -0
 - data/ext/opengl/gl_buffer.c +177 -0
 - data/ext/opengl/opengl.c +7 -0
 - data/lib/gl.rb +1 -0
 - data/lib/opengl.rb +53 -0
 - data/lib/opengl/2.0/opengl.so +0 -0
 - data/lib/opengl/2.1/opengl.so +0 -0
 - data/lib/opengl/test_case.rb +86 -0
 - data/test/dummy.xorg.conf +140 -0
 - data/test/test_gl.rb +38 -0
 - data/test/test_gl_10_11.rb +1363 -0
 - data/test/test_gl_12.rb +71 -0
 - data/test/test_gl_13.rb +221 -0
 - data/test/test_gl_14.rb +218 -0
 - data/test/test_gl_15.rb +258 -0
 - data/test/test_gl_20.rb +417 -0
 - data/test/test_gl_21.rb +436 -0
 - data/test/test_gl_ext_arb.rb +508 -0
 - data/test/test_gl_ext_ati.rb +28 -0
 - data/test/test_gl_ext_ext.rb +608 -0
 - data/test/test_gl_ext_gremedy.rb +29 -0
 - data/test/test_gl_ext_nv.rb +349 -0
 - data/test/test_opengl_buffer.rb +120 -0
 - data/utils/README +6 -0
 - data/utils/enumgen.rb +108 -0
 - data/utils/extlistgen.rb +90 -0
 - metadata +319 -0
 - metadata.gz.sig +1 -0
 
| 
         @@ -0,0 +1,203 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            #!/usr/bin/env ruby
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            require 'opengl'
         
     | 
| 
      
 4 
     | 
    
         
            +
            require 'glu'
         
     | 
| 
      
 5 
     | 
    
         
            +
            require 'glut'
         
     | 
| 
      
 6 
     | 
    
         
            +
            require 'chunky_png'
         
     | 
| 
      
 7 
     | 
    
         
            +
             
     | 
| 
      
 8 
     | 
    
         
            +
            class Lesson09
         
     | 
| 
      
 9 
     | 
    
         
            +
              include Gl
         
     | 
| 
      
 10 
     | 
    
         
            +
              include Glu
         
     | 
| 
      
 11 
     | 
    
         
            +
              include Glut
         
     | 
| 
      
 12 
     | 
    
         
            +
             
     | 
| 
      
 13 
     | 
    
         
            +
              Star = Struct.new :r, :g, :b, :distance, :angle
         
     | 
| 
      
 14 
     | 
    
         
            +
             
     | 
| 
      
 15 
     | 
    
         
            +
              def initialize
         
     | 
| 
      
 16 
     | 
    
         
            +
                @textures = nil
         
     | 
| 
      
 17 
     | 
    
         
            +
                @filter = 0
         
     | 
| 
      
 18 
     | 
    
         
            +
                @twinkle = false
         
     | 
| 
      
 19 
     | 
    
         
            +
                @zoom = -15.0
         
     | 
| 
      
 20 
     | 
    
         
            +
                @tilt = 90.0
         
     | 
| 
      
 21 
     | 
    
         
            +
                @spin = 0.0
         
     | 
| 
      
 22 
     | 
    
         
            +
                @fullscreen = false
         
     | 
| 
      
 23 
     | 
    
         
            +
                @last_draw = Time.now
         
     | 
| 
      
 24 
     | 
    
         
            +
             
     | 
| 
      
 25 
     | 
    
         
            +
                @star_count = 50
         
     | 
| 
      
 26 
     | 
    
         
            +
                @stars = (0...@star_count).map do |i|
         
     | 
| 
      
 27 
     | 
    
         
            +
                  distance = i.to_f / @star_count * 5.0
         
     | 
| 
      
 28 
     | 
    
         
            +
                  angle = 0.0
         
     | 
| 
      
 29 
     | 
    
         
            +
             
     | 
| 
      
 30 
     | 
    
         
            +
                  Star.new rand(256), rand(256), rand(256), distance, angle
         
     | 
| 
      
 31 
     | 
    
         
            +
                end
         
     | 
| 
      
 32 
     | 
    
         
            +
             
     | 
| 
      
 33 
     | 
    
         
            +
                glutInit
         
     | 
| 
      
 34 
     | 
    
         
            +
             
     | 
| 
      
 35 
     | 
    
         
            +
                glutInitDisplayMode GLUT_RGB | GLUT_DOUBLE | GLUT_ALPHA | GLUT_DEPTH
         
     | 
| 
      
 36 
     | 
    
         
            +
                glutInitWindowSize 640, 480
         
     | 
| 
      
 37 
     | 
    
         
            +
                glutInitWindowPosition 0, 0
         
     | 
| 
      
 38 
     | 
    
         
            +
             
     | 
| 
      
 39 
     | 
    
         
            +
                @window = glutCreateWindow "NeHe Lesson 09 - ruby-opengl version"
         
     | 
| 
      
 40 
     | 
    
         
            +
             
     | 
| 
      
 41 
     | 
    
         
            +
                glutDisplayFunc :draw_gl_scene
         
     | 
| 
      
 42 
     | 
    
         
            +
                glutReshapeFunc :reshape
         
     | 
| 
      
 43 
     | 
    
         
            +
                glutIdleFunc :idle
         
     | 
| 
      
 44 
     | 
    
         
            +
                glutKeyboardFunc :keyboard
         
     | 
| 
      
 45 
     | 
    
         
            +
             
     | 
| 
      
 46 
     | 
    
         
            +
                reshape 640, 480
         
     | 
| 
      
 47 
     | 
    
         
            +
                load_texture
         
     | 
| 
      
 48 
     | 
    
         
            +
                init_gl
         
     | 
| 
      
 49 
     | 
    
         
            +
             
     | 
| 
      
 50 
     | 
    
         
            +
                glutMainLoop
         
     | 
| 
      
 51 
     | 
    
         
            +
              end
         
     | 
| 
      
 52 
     | 
    
         
            +
             
     | 
| 
      
 53 
     | 
    
         
            +
              def init_gl
         
     | 
| 
      
 54 
     | 
    
         
            +
                glEnable GL_TEXTURE_2D
         
     | 
| 
      
 55 
     | 
    
         
            +
                glShadeModel GL_SMOOTH
         
     | 
| 
      
 56 
     | 
    
         
            +
                glClearColor 0.0, 0.0, 0.0, 0.5
         
     | 
| 
      
 57 
     | 
    
         
            +
                glClearDepth 1.0
         
     | 
| 
      
 58 
     | 
    
         
            +
                glHint GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST
         
     | 
| 
      
 59 
     | 
    
         
            +
                glBlendFunc GL_SRC_ALPHA, GL_ONE
         
     | 
| 
      
 60 
     | 
    
         
            +
                glEnable GL_BLEND
         
     | 
| 
      
 61 
     | 
    
         
            +
             
     | 
| 
      
 62 
     | 
    
         
            +
                true
         
     | 
| 
      
 63 
     | 
    
         
            +
              end
         
     | 
| 
      
 64 
     | 
    
         
            +
             
     | 
| 
      
 65 
     | 
    
         
            +
              def reshape width, height
         
     | 
| 
      
 66 
     | 
    
         
            +
                width   = width.to_f
         
     | 
| 
      
 67 
     | 
    
         
            +
                height = height.to_f
         
     | 
| 
      
 68 
     | 
    
         
            +
                height = 1.0 if height.zero?
         
     | 
| 
      
 69 
     | 
    
         
            +
             
     | 
| 
      
 70 
     | 
    
         
            +
                glViewport 0, 0, width, height
         
     | 
| 
      
 71 
     | 
    
         
            +
             
     | 
| 
      
 72 
     | 
    
         
            +
                glMatrixMode GL_PROJECTION
         
     | 
| 
      
 73 
     | 
    
         
            +
                glLoadIdentity
         
     | 
| 
      
 74 
     | 
    
         
            +
             
     | 
| 
      
 75 
     | 
    
         
            +
                gluPerspective 45.0, width / height, 0.1, 100.0
         
     | 
| 
      
 76 
     | 
    
         
            +
             
     | 
| 
      
 77 
     | 
    
         
            +
                glMatrixMode GL_MODELVIEW
         
     | 
| 
      
 78 
     | 
    
         
            +
                glLoadIdentity
         
     | 
| 
      
 79 
     | 
    
         
            +
             
     | 
| 
      
 80 
     | 
    
         
            +
                true
         
     | 
| 
      
 81 
     | 
    
         
            +
              end
         
     | 
| 
      
 82 
     | 
    
         
            +
             
     | 
| 
      
 83 
     | 
    
         
            +
              def draw_gl_scene
         
     | 
| 
      
 84 
     | 
    
         
            +
                return if 0.01 > Time.now - @last_draw
         
     | 
| 
      
 85 
     | 
    
         
            +
                @last_draw = Time.now
         
     | 
| 
      
 86 
     | 
    
         
            +
             
     | 
| 
      
 87 
     | 
    
         
            +
                glClear GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT
         
     | 
| 
      
 88 
     | 
    
         
            +
                glBindTexture GL_TEXTURE_2D, @textures[@filter]
         
     | 
| 
      
 89 
     | 
    
         
            +
             
     | 
| 
      
 90 
     | 
    
         
            +
                @stars.each_with_index do |star, i|
         
     | 
| 
      
 91 
     | 
    
         
            +
                  glLoadIdentity
         
     | 
| 
      
 92 
     | 
    
         
            +
                  glTranslatef 0.0, 0.0, @zoom
         
     | 
| 
      
 93 
     | 
    
         
            +
                  glRotatef @tilt, 1.0, 0.0, 0.0
         
     | 
| 
      
 94 
     | 
    
         
            +
                  glRotatef star.angle, 0.0, 1.0, 0.0
         
     | 
| 
      
 95 
     | 
    
         
            +
             
     | 
| 
      
 96 
     | 
    
         
            +
                  glTranslatef star.distance, 0.0, 0.0
         
     | 
| 
      
 97 
     | 
    
         
            +
             
     | 
| 
      
 98 
     | 
    
         
            +
                  glRotatef star.angle, 0.0, -1.0, 0.0
         
     | 
| 
      
 99 
     | 
    
         
            +
                  glRotatef @tilt, -1.0, 0.0, 0.0
         
     | 
| 
      
 100 
     | 
    
         
            +
             
     | 
| 
      
 101 
     | 
    
         
            +
                  if @twinkle then
         
     | 
| 
      
 102 
     | 
    
         
            +
                    prev = @stars[i - 1]
         
     | 
| 
      
 103 
     | 
    
         
            +
                    glColor4ub prev.r, prev.g, prev.b, 255
         
     | 
| 
      
 104 
     | 
    
         
            +
             
     | 
| 
      
 105 
     | 
    
         
            +
                    glBegin GL_QUADS do
         
     | 
| 
      
 106 
     | 
    
         
            +
                      glTexCoord2f 0.0, 0.0; glVertex3f -1.0, -1.0,  0.0
         
     | 
| 
      
 107 
     | 
    
         
            +
                      glTexCoord2f 1.0, 0.0; glVertex3f  1.0, -1.0,  0.0
         
     | 
| 
      
 108 
     | 
    
         
            +
                      glTexCoord2f 1.0, 1.0; glVertex3f  1.0,  1.0,  0.0
         
     | 
| 
      
 109 
     | 
    
         
            +
                      glTexCoord2f 0.0, 1.0; glVertex3f -1.0,  1.0,  0.0
         
     | 
| 
      
 110 
     | 
    
         
            +
                    end
         
     | 
| 
      
 111 
     | 
    
         
            +
                  end
         
     | 
| 
      
 112 
     | 
    
         
            +
             
     | 
| 
      
 113 
     | 
    
         
            +
                  glRotatef @spin, 0.0, 0.0, 1.0
         
     | 
| 
      
 114 
     | 
    
         
            +
                  glColor4ub star.r, star.g, star.b, 255
         
     | 
| 
      
 115 
     | 
    
         
            +
             
     | 
| 
      
 116 
     | 
    
         
            +
                  glBegin GL_QUADS do
         
     | 
| 
      
 117 
     | 
    
         
            +
                    glTexCoord2f 0.0, 0.0; glVertex3f -1.0, -1.0,  0.0
         
     | 
| 
      
 118 
     | 
    
         
            +
                    glTexCoord2f 1.0, 0.0; glVertex3f  1.0, -1.0,  0.0
         
     | 
| 
      
 119 
     | 
    
         
            +
                    glTexCoord2f 1.0, 1.0; glVertex3f  1.0,  1.0,  0.0
         
     | 
| 
      
 120 
     | 
    
         
            +
                    glTexCoord2f 0.0, 1.0; glVertex3f -1.0,  1.0,  0.0
         
     | 
| 
      
 121 
     | 
    
         
            +
                  end
         
     | 
| 
      
 122 
     | 
    
         
            +
             
     | 
| 
      
 123 
     | 
    
         
            +
                  @spin += 0.01
         
     | 
| 
      
 124 
     | 
    
         
            +
                  star.angle += i.to_f / @star_count
         
     | 
| 
      
 125 
     | 
    
         
            +
                  star.distance -= 0.01
         
     | 
| 
      
 126 
     | 
    
         
            +
             
     | 
| 
      
 127 
     | 
    
         
            +
                  if star.distance < 0 then
         
     | 
| 
      
 128 
     | 
    
         
            +
                    star.distance += 5.0
         
     | 
| 
      
 129 
     | 
    
         
            +
                    star.r = rand 256
         
     | 
| 
      
 130 
     | 
    
         
            +
                    star.g = rand 256
         
     | 
| 
      
 131 
     | 
    
         
            +
                    star.b = rand 256
         
     | 
| 
      
 132 
     | 
    
         
            +
                  end
         
     | 
| 
      
 133 
     | 
    
         
            +
                end
         
     | 
| 
      
 134 
     | 
    
         
            +
             
     | 
| 
      
 135 
     | 
    
         
            +
                glutSwapBuffers
         
     | 
| 
      
 136 
     | 
    
         
            +
              end
         
     | 
| 
      
 137 
     | 
    
         
            +
             
     | 
| 
      
 138 
     | 
    
         
            +
              def idle
         
     | 
| 
      
 139 
     | 
    
         
            +
                glutPostRedisplay
         
     | 
| 
      
 140 
     | 
    
         
            +
              end
         
     | 
| 
      
 141 
     | 
    
         
            +
             
     | 
| 
      
 142 
     | 
    
         
            +
              def keyboard key, x, y
         
     | 
| 
      
 143 
     | 
    
         
            +
                case key
         
     | 
| 
      
 144 
     | 
    
         
            +
                when ?\e then
         
     | 
| 
      
 145 
     | 
    
         
            +
                  glutDestroyWindow @window
         
     | 
| 
      
 146 
     | 
    
         
            +
                  exit 0
         
     | 
| 
      
 147 
     | 
    
         
            +
                when 'F' then
         
     | 
| 
      
 148 
     | 
    
         
            +
                  @fullscreen = !@fullscreen
         
     | 
| 
      
 149 
     | 
    
         
            +
             
     | 
| 
      
 150 
     | 
    
         
            +
                  if @fullscreen then
         
     | 
| 
      
 151 
     | 
    
         
            +
                    glutFullScreen
         
     | 
| 
      
 152 
     | 
    
         
            +
                  else
         
     | 
| 
      
 153 
     | 
    
         
            +
                    glutPositionWindow 0, 0
         
     | 
| 
      
 154 
     | 
    
         
            +
                  end
         
     | 
| 
      
 155 
     | 
    
         
            +
                when 'f' then
         
     | 
| 
      
 156 
     | 
    
         
            +
                  @filter += 1
         
     | 
| 
      
 157 
     | 
    
         
            +
                  @filter %= 3
         
     | 
| 
      
 158 
     | 
    
         
            +
             
     | 
| 
      
 159 
     | 
    
         
            +
                  puts "texture #{@filter}"
         
     | 
| 
      
 160 
     | 
    
         
            +
                when 'W' then
         
     | 
| 
      
 161 
     | 
    
         
            +
                  @twinkle = !@twinkle
         
     | 
| 
      
 162 
     | 
    
         
            +
             
     | 
| 
      
 163 
     | 
    
         
            +
                  puts "twinkle #{@twinkle ? 'on' : 'off'}"
         
     | 
| 
      
 164 
     | 
    
         
            +
                when 'T' then @tilt += 0.5
         
     | 
| 
      
 165 
     | 
    
         
            +
                when 't' then @tilt -= 0.5
         
     | 
| 
      
 166 
     | 
    
         
            +
                when 'Z' then @zoom += 0.2
         
     | 
| 
      
 167 
     | 
    
         
            +
                when 'z' then @zoom -= 0.2
         
     | 
| 
      
 168 
     | 
    
         
            +
                else
         
     | 
| 
      
 169 
     | 
    
         
            +
                  puts key
         
     | 
| 
      
 170 
     | 
    
         
            +
                end
         
     | 
| 
      
 171 
     | 
    
         
            +
             
     | 
| 
      
 172 
     | 
    
         
            +
                glutPostRedisplay
         
     | 
| 
      
 173 
     | 
    
         
            +
              end
         
     | 
| 
      
 174 
     | 
    
         
            +
             
     | 
| 
      
 175 
     | 
    
         
            +
              def load_texture
         
     | 
| 
      
 176 
     | 
    
         
            +
             
     | 
| 
      
 177 
     | 
    
         
            +
                png = ChunkyPNG::Image.from_file(File.expand_path('../star.png', __FILE__))
         
     | 
| 
      
 178 
     | 
    
         
            +
             
     | 
| 
      
 179 
     | 
    
         
            +
                height = png.height
         
     | 
| 
      
 180 
     | 
    
         
            +
                width = png.width
         
     | 
| 
      
 181 
     | 
    
         
            +
             
     | 
| 
      
 182 
     | 
    
         
            +
                image = png.to_rgba_stream
         
     | 
| 
      
 183 
     | 
    
         
            +
             
     | 
| 
      
 184 
     | 
    
         
            +
                @textures = glGenTextures 3
         
     | 
| 
      
 185 
     | 
    
         
            +
                glBindTexture GL_TEXTURE_2D, @textures[0]
         
     | 
| 
      
 186 
     | 
    
         
            +
                glTexParameteri GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST
         
     | 
| 
      
 187 
     | 
    
         
            +
                glTexParameteri GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST
         
     | 
| 
      
 188 
     | 
    
         
            +
                glTexImage2D GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, image
         
     | 
| 
      
 189 
     | 
    
         
            +
             
     | 
| 
      
 190 
     | 
    
         
            +
                glBindTexture GL_TEXTURE_2D, @textures[1]
         
     | 
| 
      
 191 
     | 
    
         
            +
                glTexParameteri GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR
         
     | 
| 
      
 192 
     | 
    
         
            +
                glTexParameteri GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR
         
     | 
| 
      
 193 
     | 
    
         
            +
                glTexImage2D GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, image
         
     | 
| 
      
 194 
     | 
    
         
            +
             
     | 
| 
      
 195 
     | 
    
         
            +
                glBindTexture GL_TEXTURE_2D, @textures[2]
         
     | 
| 
      
 196 
     | 
    
         
            +
                glTexParameteri GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR
         
     | 
| 
      
 197 
     | 
    
         
            +
                glTexParameteri GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST
         
     | 
| 
      
 198 
     | 
    
         
            +
                gluBuild2DMipmaps GL_TEXTURE_2D, GL_RGBA, width, height, GL_RGBA, GL_UNSIGNED_BYTE, image
         
     | 
| 
      
 199 
     | 
    
         
            +
              end
         
     | 
| 
      
 200 
     | 
    
         
            +
             
     | 
| 
      
 201 
     | 
    
         
            +
            end
         
     | 
| 
      
 202 
     | 
    
         
            +
             
     | 
| 
      
 203 
     | 
    
         
            +
            Lesson09.new
         
     | 
| 
         @@ -0,0 +1,176 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            #!/usr/bin/env ruby
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            require 'opengl'
         
     | 
| 
      
 4 
     | 
    
         
            +
            require 'glu'
         
     | 
| 
      
 5 
     | 
    
         
            +
            require 'glut'
         
     | 
| 
      
 6 
     | 
    
         
            +
            require 'chunky_png'
         
     | 
| 
      
 7 
     | 
    
         
            +
             
     | 
| 
      
 8 
     | 
    
         
            +
            class Lesson11
         
     | 
| 
      
 9 
     | 
    
         
            +
              include Gl
         
     | 
| 
      
 10 
     | 
    
         
            +
              include Glu
         
     | 
| 
      
 11 
     | 
    
         
            +
              include Glut
         
     | 
| 
      
 12 
     | 
    
         
            +
             
     | 
| 
      
 13 
     | 
    
         
            +
              def initialize
         
     | 
| 
      
 14 
     | 
    
         
            +
                @textures = nil
         
     | 
| 
      
 15 
     | 
    
         
            +
                @xrot = 0.0
         
     | 
| 
      
 16 
     | 
    
         
            +
                @yrot = 0.0
         
     | 
| 
      
 17 
     | 
    
         
            +
                @zrot = 0.0
         
     | 
| 
      
 18 
     | 
    
         
            +
             
     | 
| 
      
 19 
     | 
    
         
            +
                factor = 10.0 / 9 * Math::PI
         
     | 
| 
      
 20 
     | 
    
         
            +
                @points = Array.new 45 do |x|
         
     | 
| 
      
 21 
     | 
    
         
            +
                  Array.new 45 do |y|
         
     | 
| 
      
 22 
     | 
    
         
            +
                    [x / 5.0 - 4.5, y / 5.0 - 4.5,
         
     | 
| 
      
 23 
     | 
    
         
            +
                     Math.sin(x / factor)]
         
     | 
| 
      
 24 
     | 
    
         
            +
                  end
         
     | 
| 
      
 25 
     | 
    
         
            +
                end
         
     | 
| 
      
 26 
     | 
    
         
            +
             
     | 
| 
      
 27 
     | 
    
         
            +
                @wiggle_count = 0
         
     | 
| 
      
 28 
     | 
    
         
            +
             
     | 
| 
      
 29 
     | 
    
         
            +
                glutInit
         
     | 
| 
      
 30 
     | 
    
         
            +
             
     | 
| 
      
 31 
     | 
    
         
            +
                glutInitDisplayMode GLUT_RGB | GLUT_DOUBLE | GLUT_ALPHA | GLUT_DEPTH
         
     | 
| 
      
 32 
     | 
    
         
            +
                glutInitWindowSize 640, 480
         
     | 
| 
      
 33 
     | 
    
         
            +
                glutInitWindowPosition 0, 0
         
     | 
| 
      
 34 
     | 
    
         
            +
             
     | 
| 
      
 35 
     | 
    
         
            +
                @window = glutCreateWindow "NeHe Lesson 11 - ruby-opengl version"
         
     | 
| 
      
 36 
     | 
    
         
            +
             
     | 
| 
      
 37 
     | 
    
         
            +
                glutDisplayFunc :draw_gl_scene
         
     | 
| 
      
 38 
     | 
    
         
            +
                glutReshapeFunc :reshape
         
     | 
| 
      
 39 
     | 
    
         
            +
                glutIdleFunc :idle
         
     | 
| 
      
 40 
     | 
    
         
            +
                glutKeyboardFunc :keyboard
         
     | 
| 
      
 41 
     | 
    
         
            +
             
     | 
| 
      
 42 
     | 
    
         
            +
                reshape 640, 480
         
     | 
| 
      
 43 
     | 
    
         
            +
                load_texture
         
     | 
| 
      
 44 
     | 
    
         
            +
                init_gl
         
     | 
| 
      
 45 
     | 
    
         
            +
             
     | 
| 
      
 46 
     | 
    
         
            +
                glutMainLoop
         
     | 
| 
      
 47 
     | 
    
         
            +
              end
         
     | 
| 
      
 48 
     | 
    
         
            +
             
     | 
| 
      
 49 
     | 
    
         
            +
              def init_gl
         
     | 
| 
      
 50 
     | 
    
         
            +
                glEnable GL_TEXTURE_2D
         
     | 
| 
      
 51 
     | 
    
         
            +
                glShadeModel GL_SMOOTH
         
     | 
| 
      
 52 
     | 
    
         
            +
                glClearColor 0.0, 0.0, 0.0, 0.5
         
     | 
| 
      
 53 
     | 
    
         
            +
                glClearDepth 1.0
         
     | 
| 
      
 54 
     | 
    
         
            +
                glEnable GL_DEPTH_TEST
         
     | 
| 
      
 55 
     | 
    
         
            +
                glDepthFunc GL_LEQUAL
         
     | 
| 
      
 56 
     | 
    
         
            +
                glHint GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST
         
     | 
| 
      
 57 
     | 
    
         
            +
             
     | 
| 
      
 58 
     | 
    
         
            +
                glPolygonMode GL_BACK, GL_FILL
         
     | 
| 
      
 59 
     | 
    
         
            +
                glPolygonMode GL_FRONT, GL_LINE
         
     | 
| 
      
 60 
     | 
    
         
            +
             
     | 
| 
      
 61 
     | 
    
         
            +
                true
         
     | 
| 
      
 62 
     | 
    
         
            +
              end
         
     | 
| 
      
 63 
     | 
    
         
            +
             
     | 
| 
      
 64 
     | 
    
         
            +
              def reshape width, height
         
     | 
| 
      
 65 
     | 
    
         
            +
                width   = width.to_f
         
     | 
| 
      
 66 
     | 
    
         
            +
                height = height.to_f
         
     | 
| 
      
 67 
     | 
    
         
            +
                height = 1.0 if height.zero?
         
     | 
| 
      
 68 
     | 
    
         
            +
             
     | 
| 
      
 69 
     | 
    
         
            +
                glViewport 0, 0, width, height
         
     | 
| 
      
 70 
     | 
    
         
            +
             
     | 
| 
      
 71 
     | 
    
         
            +
                glMatrixMode GL_PROJECTION
         
     | 
| 
      
 72 
     | 
    
         
            +
                glLoadIdentity
         
     | 
| 
      
 73 
     | 
    
         
            +
             
     | 
| 
      
 74 
     | 
    
         
            +
                gluPerspective 45.0, width / height, 0.1, 100.0
         
     | 
| 
      
 75 
     | 
    
         
            +
             
     | 
| 
      
 76 
     | 
    
         
            +
                glMatrixMode GL_MODELVIEW
         
     | 
| 
      
 77 
     | 
    
         
            +
                glLoadIdentity
         
     | 
| 
      
 78 
     | 
    
         
            +
             
     | 
| 
      
 79 
     | 
    
         
            +
                true
         
     | 
| 
      
 80 
     | 
    
         
            +
              end
         
     | 
| 
      
 81 
     | 
    
         
            +
             
     | 
| 
      
 82 
     | 
    
         
            +
              def draw_gl_scene
         
     | 
| 
      
 83 
     | 
    
         
            +
                glClear GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT
         
     | 
| 
      
 84 
     | 
    
         
            +
                glLoadIdentity
         
     | 
| 
      
 85 
     | 
    
         
            +
             
     | 
| 
      
 86 
     | 
    
         
            +
                glTranslatef 0.0, 0.0, -12.0
         
     | 
| 
      
 87 
     | 
    
         
            +
                glRotatef @xrot, 1.0, 0.0, 0.0
         
     | 
| 
      
 88 
     | 
    
         
            +
                glRotatef @yrot, 0.0, 1.0, 0.0
         
     | 
| 
      
 89 
     | 
    
         
            +
                glRotatef @zrot, 0.0, 0.0, 1.0
         
     | 
| 
      
 90 
     | 
    
         
            +
             
     | 
| 
      
 91 
     | 
    
         
            +
                glBindTexture GL_TEXTURE_2D, @textures[0]
         
     | 
| 
      
 92 
     | 
    
         
            +
             
     | 
| 
      
 93 
     | 
    
         
            +
                glBegin GL_QUADS do
         
     | 
| 
      
 94 
     | 
    
         
            +
                  (0...44).each do |x|
         
     | 
| 
      
 95 
     | 
    
         
            +
                    (0...44).each do |y|
         
     | 
| 
      
 96 
     | 
    
         
            +
                      tex_x = x / 44.0
         
     | 
| 
      
 97 
     | 
    
         
            +
                      tex_y = y / 44.0
         
     | 
| 
      
 98 
     | 
    
         
            +
                      tex_xb = (x + 1) / 44.0
         
     | 
| 
      
 99 
     | 
    
         
            +
                      tex_yb = (y + 1) / 44.0
         
     | 
| 
      
 100 
     | 
    
         
            +
             
     | 
| 
      
 101 
     | 
    
         
            +
                      glTexCoord2f tex_x, tex_y
         
     | 
| 
      
 102 
     | 
    
         
            +
                      glVertex3f @points[x][y][0], @points[x][y][1], @points[x][y][2]
         
     | 
| 
      
 103 
     | 
    
         
            +
             
     | 
| 
      
 104 
     | 
    
         
            +
                      glTexCoord2f tex_x, tex_yb
         
     | 
| 
      
 105 
     | 
    
         
            +
                      glVertex3f @points[x][y+1][0], @points[x][y+1][1], @points[x][y+1][2]
         
     | 
| 
      
 106 
     | 
    
         
            +
             
     | 
| 
      
 107 
     | 
    
         
            +
                      glTexCoord2f tex_xb, tex_yb
         
     | 
| 
      
 108 
     | 
    
         
            +
                      glVertex3f @points[x+1][y+1][0], @points[x+1][y+1][1], @points[x+1][y+1][2]
         
     | 
| 
      
 109 
     | 
    
         
            +
             
     | 
| 
      
 110 
     | 
    
         
            +
                      glTexCoord2f tex_xb, tex_y
         
     | 
| 
      
 111 
     | 
    
         
            +
                      glVertex3f @points[x+1][y][0], @points[x+1][y][1], @points[x+1][y][2]
         
     | 
| 
      
 112 
     | 
    
         
            +
                    end
         
     | 
| 
      
 113 
     | 
    
         
            +
                  end
         
     | 
| 
      
 114 
     | 
    
         
            +
                end
         
     | 
| 
      
 115 
     | 
    
         
            +
             
     | 
| 
      
 116 
     | 
    
         
            +
                if @wiggle_count == 4 then
         
     | 
| 
      
 117 
     | 
    
         
            +
                  (0...45).each do |y|
         
     | 
| 
      
 118 
     | 
    
         
            +
                    tmp = @points[0][y][2]
         
     | 
| 
      
 119 
     | 
    
         
            +
                    (0...44).each do |x|
         
     | 
| 
      
 120 
     | 
    
         
            +
                      @points[x][y][2] = @points[x+1][y][2]
         
     | 
| 
      
 121 
     | 
    
         
            +
                    end
         
     | 
| 
      
 122 
     | 
    
         
            +
                    @points[44][y][2] = tmp
         
     | 
| 
      
 123 
     | 
    
         
            +
                  end
         
     | 
| 
      
 124 
     | 
    
         
            +
             
     | 
| 
      
 125 
     | 
    
         
            +
                  @wiggle_count = 0
         
     | 
| 
      
 126 
     | 
    
         
            +
                end
         
     | 
| 
      
 127 
     | 
    
         
            +
             
     | 
| 
      
 128 
     | 
    
         
            +
                @wiggle_count += 1
         
     | 
| 
      
 129 
     | 
    
         
            +
             
     | 
| 
      
 130 
     | 
    
         
            +
                @xrot += 0.03
         
     | 
| 
      
 131 
     | 
    
         
            +
                @yrot += 0.02
         
     | 
| 
      
 132 
     | 
    
         
            +
                @zrot += 0.04
         
     | 
| 
      
 133 
     | 
    
         
            +
             
     | 
| 
      
 134 
     | 
    
         
            +
                glutSwapBuffers
         
     | 
| 
      
 135 
     | 
    
         
            +
              end
         
     | 
| 
      
 136 
     | 
    
         
            +
             
     | 
| 
      
 137 
     | 
    
         
            +
              def idle
         
     | 
| 
      
 138 
     | 
    
         
            +
                glutPostRedisplay
         
     | 
| 
      
 139 
     | 
    
         
            +
              end
         
     | 
| 
      
 140 
     | 
    
         
            +
             
     | 
| 
      
 141 
     | 
    
         
            +
              def keyboard key, x, y
         
     | 
| 
      
 142 
     | 
    
         
            +
                case key
         
     | 
| 
      
 143 
     | 
    
         
            +
                when ?\e
         
     | 
| 
      
 144 
     | 
    
         
            +
                  glutDestroyWindow @window
         
     | 
| 
      
 145 
     | 
    
         
            +
                  exit 0
         
     | 
| 
      
 146 
     | 
    
         
            +
                when 'F' then
         
     | 
| 
      
 147 
     | 
    
         
            +
                  @fullscreen = !@fullscreen
         
     | 
| 
      
 148 
     | 
    
         
            +
             
     | 
| 
      
 149 
     | 
    
         
            +
                  if @fullscreen then
         
     | 
| 
      
 150 
     | 
    
         
            +
                    glutFullScreen
         
     | 
| 
      
 151 
     | 
    
         
            +
                  else
         
     | 
| 
      
 152 
     | 
    
         
            +
                    glutPositionWindow 0, 0
         
     | 
| 
      
 153 
     | 
    
         
            +
                  end
         
     | 
| 
      
 154 
     | 
    
         
            +
                end
         
     | 
| 
      
 155 
     | 
    
         
            +
             
     | 
| 
      
 156 
     | 
    
         
            +
                glutPostRedisplay
         
     | 
| 
      
 157 
     | 
    
         
            +
              end
         
     | 
| 
      
 158 
     | 
    
         
            +
             
     | 
| 
      
 159 
     | 
    
         
            +
              def load_texture
         
     | 
| 
      
 160 
     | 
    
         
            +
                png = ChunkyPNG::Image.from_file(File.expand_path('../tim.png', __FILE__))
         
     | 
| 
      
 161 
     | 
    
         
            +
             
     | 
| 
      
 162 
     | 
    
         
            +
                height = png.height
         
     | 
| 
      
 163 
     | 
    
         
            +
                width = png.width
         
     | 
| 
      
 164 
     | 
    
         
            +
             
     | 
| 
      
 165 
     | 
    
         
            +
                image = png.to_rgba_stream.each_byte.to_a
         
     | 
| 
      
 166 
     | 
    
         
            +
             
     | 
| 
      
 167 
     | 
    
         
            +
                @textures = glGenTextures 1
         
     | 
| 
      
 168 
     | 
    
         
            +
                glBindTexture GL_TEXTURE_2D, @textures[0]
         
     | 
| 
      
 169 
     | 
    
         
            +
                glTexImage2D GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, image
         
     | 
| 
      
 170 
     | 
    
         
            +
                glTexParameteri GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR
         
     | 
| 
      
 171 
     | 
    
         
            +
                glTexParameteri GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR
         
     | 
| 
      
 172 
     | 
    
         
            +
              end
         
     | 
| 
      
 173 
     | 
    
         
            +
             
     | 
| 
      
 174 
     | 
    
         
            +
            end
         
     | 
| 
      
 175 
     | 
    
         
            +
             
     | 
| 
      
 176 
     | 
    
         
            +
            Lesson11.new
         
     | 
| 
         @@ -0,0 +1,203 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            #!/usr/bin/env ruby
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            require 'opengl'
         
     | 
| 
      
 4 
     | 
    
         
            +
            require 'glu'
         
     | 
| 
      
 5 
     | 
    
         
            +
            require 'glut'
         
     | 
| 
      
 6 
     | 
    
         
            +
            require 'chunky_png'
         
     | 
| 
      
 7 
     | 
    
         
            +
             
     | 
| 
      
 8 
     | 
    
         
            +
            class Lesson12
         
     | 
| 
      
 9 
     | 
    
         
            +
              include Gl
         
     | 
| 
      
 10 
     | 
    
         
            +
              include Glu
         
     | 
| 
      
 11 
     | 
    
         
            +
              include Glut
         
     | 
| 
      
 12 
     | 
    
         
            +
             
     | 
| 
      
 13 
     | 
    
         
            +
              def initialize
         
     | 
| 
      
 14 
     | 
    
         
            +
                @textures = nil
         
     | 
| 
      
 15 
     | 
    
         
            +
                @box = nil
         
     | 
| 
      
 16 
     | 
    
         
            +
                @top = nil
         
     | 
| 
      
 17 
     | 
    
         
            +
                @xrot = 0
         
     | 
| 
      
 18 
     | 
    
         
            +
                @yrot = 0
         
     | 
| 
      
 19 
     | 
    
         
            +
             
     | 
| 
      
 20 
     | 
    
         
            +
                @box_color = [
         
     | 
| 
      
 21 
     | 
    
         
            +
                  [1.0, 0.0, 0.0],
         
     | 
| 
      
 22 
     | 
    
         
            +
                  [1.0, 0.5, 0.0],
         
     | 
| 
      
 23 
     | 
    
         
            +
                  [1.0, 1.0, 0.0],
         
     | 
| 
      
 24 
     | 
    
         
            +
                  [0.0, 1.0, 0.0],
         
     | 
| 
      
 25 
     | 
    
         
            +
                  [0.0, 1.0, 1.0],
         
     | 
| 
      
 26 
     | 
    
         
            +
                ]
         
     | 
| 
      
 27 
     | 
    
         
            +
             
     | 
| 
      
 28 
     | 
    
         
            +
                @top_color = [
         
     | 
| 
      
 29 
     | 
    
         
            +
                  [0.5, 0.0, 0.0],
         
     | 
| 
      
 30 
     | 
    
         
            +
                  [0.5, 0.25, 0.0],
         
     | 
| 
      
 31 
     | 
    
         
            +
                  [0.5, 0.5, 0.0],
         
     | 
| 
      
 32 
     | 
    
         
            +
                  [0.0, 0.5, 0.0],
         
     | 
| 
      
 33 
     | 
    
         
            +
                  [0.0, 0.5, 0.5],
         
     | 
| 
      
 34 
     | 
    
         
            +
                ]
         
     | 
| 
      
 35 
     | 
    
         
            +
             
     | 
| 
      
 36 
     | 
    
         
            +
                glutInit
         
     | 
| 
      
 37 
     | 
    
         
            +
             
     | 
| 
      
 38 
     | 
    
         
            +
                glutInitDisplayMode GLUT_RGB | GLUT_DOUBLE | GLUT_ALPHA | GLUT_DEPTH
         
     | 
| 
      
 39 
     | 
    
         
            +
                glutInitWindowSize 640, 480
         
     | 
| 
      
 40 
     | 
    
         
            +
                glutInitWindowPosition 0, 0
         
     | 
| 
      
 41 
     | 
    
         
            +
             
     | 
| 
      
 42 
     | 
    
         
            +
                @window = glutCreateWindow "NeHe Lesson 12 - ruby-opengl version"
         
     | 
| 
      
 43 
     | 
    
         
            +
             
     | 
| 
      
 44 
     | 
    
         
            +
                glutDisplayFunc :draw_gl_scene
         
     | 
| 
      
 45 
     | 
    
         
            +
                glutReshapeFunc :reshape
         
     | 
| 
      
 46 
     | 
    
         
            +
                glutIdleFunc :idle
         
     | 
| 
      
 47 
     | 
    
         
            +
                glutKeyboardFunc :keyboard
         
     | 
| 
      
 48 
     | 
    
         
            +
             
     | 
| 
      
 49 
     | 
    
         
            +
                reshape 640, 480
         
     | 
| 
      
 50 
     | 
    
         
            +
                load_texture
         
     | 
| 
      
 51 
     | 
    
         
            +
                init_gl
         
     | 
| 
      
 52 
     | 
    
         
            +
             
     | 
| 
      
 53 
     | 
    
         
            +
                glutMainLoop
         
     | 
| 
      
 54 
     | 
    
         
            +
              end
         
     | 
| 
      
 55 
     | 
    
         
            +
             
     | 
| 
      
 56 
     | 
    
         
            +
              def init_gl
         
     | 
| 
      
 57 
     | 
    
         
            +
                build_lists
         
     | 
| 
      
 58 
     | 
    
         
            +
             
     | 
| 
      
 59 
     | 
    
         
            +
                glEnable GL_TEXTURE_2D
         
     | 
| 
      
 60 
     | 
    
         
            +
                glShadeModel GL_SMOOTH
         
     | 
| 
      
 61 
     | 
    
         
            +
                glClearColor 0.0, 0.0, 0.0, 0.5
         
     | 
| 
      
 62 
     | 
    
         
            +
                glClearDepth 1.0
         
     | 
| 
      
 63 
     | 
    
         
            +
                glEnable GL_DEPTH_TEST
         
     | 
| 
      
 64 
     | 
    
         
            +
                glDepthFunc GL_LEQUAL
         
     | 
| 
      
 65 
     | 
    
         
            +
             
     | 
| 
      
 66 
     | 
    
         
            +
                glEnable GL_LIGHT0
         
     | 
| 
      
 67 
     | 
    
         
            +
                glEnable GL_LIGHTING
         
     | 
| 
      
 68 
     | 
    
         
            +
                glEnable GL_COLOR_MATERIAL
         
     | 
| 
      
 69 
     | 
    
         
            +
             
     | 
| 
      
 70 
     | 
    
         
            +
                glHint GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST
         
     | 
| 
      
 71 
     | 
    
         
            +
              end
         
     | 
| 
      
 72 
     | 
    
         
            +
             
     | 
| 
      
 73 
     | 
    
         
            +
              def reshape width, height
         
     | 
| 
      
 74 
     | 
    
         
            +
                width   = width.to_f
         
     | 
| 
      
 75 
     | 
    
         
            +
                height = height.to_f
         
     | 
| 
      
 76 
     | 
    
         
            +
                height = 1.0 if height.zero?
         
     | 
| 
      
 77 
     | 
    
         
            +
             
     | 
| 
      
 78 
     | 
    
         
            +
                glViewport 0, 0, width, height
         
     | 
| 
      
 79 
     | 
    
         
            +
             
     | 
| 
      
 80 
     | 
    
         
            +
                glMatrixMode GL_PROJECTION
         
     | 
| 
      
 81 
     | 
    
         
            +
                glLoadIdentity
         
     | 
| 
      
 82 
     | 
    
         
            +
             
     | 
| 
      
 83 
     | 
    
         
            +
                gluPerspective 45.0, width / height, 0.1, 100.0
         
     | 
| 
      
 84 
     | 
    
         
            +
             
     | 
| 
      
 85 
     | 
    
         
            +
                glMatrixMode GL_MODELVIEW
         
     | 
| 
      
 86 
     | 
    
         
            +
                glLoadIdentity
         
     | 
| 
      
 87 
     | 
    
         
            +
             
     | 
| 
      
 88 
     | 
    
         
            +
                true
         
     | 
| 
      
 89 
     | 
    
         
            +
              end
         
     | 
| 
      
 90 
     | 
    
         
            +
             
     | 
| 
      
 91 
     | 
    
         
            +
              def build_lists
         
     | 
| 
      
 92 
     | 
    
         
            +
                @box = glGenLists 2
         
     | 
| 
      
 93 
     | 
    
         
            +
                @top = @box + 1
         
     | 
| 
      
 94 
     | 
    
         
            +
             
     | 
| 
      
 95 
     | 
    
         
            +
                glNewList @box, GL_COMPILE do
         
     | 
| 
      
 96 
     | 
    
         
            +
                  glBegin GL_QUADS do
         
     | 
| 
      
 97 
     | 
    
         
            +
                    # Bottom Face
         
     | 
| 
      
 98 
     | 
    
         
            +
                    glTexCoord2f(1, 1); glVertex3f(-1, -1, -1)
         
     | 
| 
      
 99 
     | 
    
         
            +
                    glTexCoord2f(0, 1); glVertex3f( 1, -1, -1)
         
     | 
| 
      
 100 
     | 
    
         
            +
                    glTexCoord2f(0, 0); glVertex3f( 1, -1,  1)
         
     | 
| 
      
 101 
     | 
    
         
            +
                    glTexCoord2f(1, 0); glVertex3f(-1, -1,  1)
         
     | 
| 
      
 102 
     | 
    
         
            +
                    # Front Face
         
     | 
| 
      
 103 
     | 
    
         
            +
                    glTexCoord2f(0, 0); glVertex3f(-1, -1,  1)
         
     | 
| 
      
 104 
     | 
    
         
            +
                    glTexCoord2f(1, 0); glVertex3f( 1, -1,  1)
         
     | 
| 
      
 105 
     | 
    
         
            +
                    glTexCoord2f(1, 1); glVertex3f( 1,  1,  1)
         
     | 
| 
      
 106 
     | 
    
         
            +
                    glTexCoord2f(0, 1); glVertex3f(-1,  1,  1)
         
     | 
| 
      
 107 
     | 
    
         
            +
                    # Back Face
         
     | 
| 
      
 108 
     | 
    
         
            +
                    glTexCoord2f(1, 0); glVertex3f(-1, -1, -1)
         
     | 
| 
      
 109 
     | 
    
         
            +
                    glTexCoord2f(1, 1); glVertex3f(-1,  1, -1)
         
     | 
| 
      
 110 
     | 
    
         
            +
                    glTexCoord2f(0, 1); glVertex3f( 1,  1, -1)
         
     | 
| 
      
 111 
     | 
    
         
            +
                    glTexCoord2f(0, 0); glVertex3f( 1, -1, -1)
         
     | 
| 
      
 112 
     | 
    
         
            +
                    # Right face
         
     | 
| 
      
 113 
     | 
    
         
            +
                    glTexCoord2f(1, 0); glVertex3f( 1, -1, -1)
         
     | 
| 
      
 114 
     | 
    
         
            +
                    glTexCoord2f(1, 1); glVertex3f( 1,  1, -1)
         
     | 
| 
      
 115 
     | 
    
         
            +
                    glTexCoord2f(0, 1); glVertex3f( 1,  1,  1)
         
     | 
| 
      
 116 
     | 
    
         
            +
                    glTexCoord2f(0, 0); glVertex3f( 1, -1,  1)
         
     | 
| 
      
 117 
     | 
    
         
            +
                    # Left Face
         
     | 
| 
      
 118 
     | 
    
         
            +
                    glTexCoord2f(0, 0); glVertex3f(-1, -1, -1)
         
     | 
| 
      
 119 
     | 
    
         
            +
                    glTexCoord2f(1, 0); glVertex3f(-1, -1,  1)
         
     | 
| 
      
 120 
     | 
    
         
            +
                    glTexCoord2f(1, 1); glVertex3f(-1,  1,  1)
         
     | 
| 
      
 121 
     | 
    
         
            +
                    glTexCoord2f(0, 1); glVertex3f(-1,  1, -1)
         
     | 
| 
      
 122 
     | 
    
         
            +
                  end
         
     | 
| 
      
 123 
     | 
    
         
            +
                end
         
     | 
| 
      
 124 
     | 
    
         
            +
             
     | 
| 
      
 125 
     | 
    
         
            +
                glNewList @top, GL_COMPILE do
         
     | 
| 
      
 126 
     | 
    
         
            +
                  glBegin GL_QUADS do
         
     | 
| 
      
 127 
     | 
    
         
            +
                    # Top Face
         
     | 
| 
      
 128 
     | 
    
         
            +
                    glTexCoord2f(0, 1); glVertex3f(-1,  1, -1)
         
     | 
| 
      
 129 
     | 
    
         
            +
                    glTexCoord2f(0, 0); glVertex3f(-1,  1,  1)
         
     | 
| 
      
 130 
     | 
    
         
            +
                    glTexCoord2f(1, 0); glVertex3f( 1,  1,  1)
         
     | 
| 
      
 131 
     | 
    
         
            +
                    glTexCoord2f(1, 1); glVertex3f( 1,  1, -1)
         
     | 
| 
      
 132 
     | 
    
         
            +
                  end
         
     | 
| 
      
 133 
     | 
    
         
            +
                end
         
     | 
| 
      
 134 
     | 
    
         
            +
              end
         
     | 
| 
      
 135 
     | 
    
         
            +
             
     | 
| 
      
 136 
     | 
    
         
            +
              def draw_gl_scene
         
     | 
| 
      
 137 
     | 
    
         
            +
                glClear GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT
         
     | 
| 
      
 138 
     | 
    
         
            +
             
     | 
| 
      
 139 
     | 
    
         
            +
                glBindTexture GL_TEXTURE_2D, @textures[0]
         
     | 
| 
      
 140 
     | 
    
         
            +
             
     | 
| 
      
 141 
     | 
    
         
            +
                (1..5).each do |y|
         
     | 
| 
      
 142 
     | 
    
         
            +
                  (0..y).each do |x|
         
     | 
| 
      
 143 
     | 
    
         
            +
                    glLoadIdentity
         
     | 
| 
      
 144 
     | 
    
         
            +
                    glTranslate 1.4 + x * 2.8 - y * 1.4, (6 - y) * 2.4 - 7, -20
         
     | 
| 
      
 145 
     | 
    
         
            +
             
     | 
| 
      
 146 
     | 
    
         
            +
                    glRotatef (45 - 2.0 * y) + @xrot, 1, 0, 0
         
     | 
| 
      
 147 
     | 
    
         
            +
                    glRotatef 45 + @yrot,             0, 1, 0
         
     | 
| 
      
 148 
     | 
    
         
            +
             
     | 
| 
      
 149 
     | 
    
         
            +
                    glColor3fv @box_color[y - 1]
         
     | 
| 
      
 150 
     | 
    
         
            +
                    glCallList @box
         
     | 
| 
      
 151 
     | 
    
         
            +
             
     | 
| 
      
 152 
     | 
    
         
            +
                    glColor3fv @top_color[y - 1]
         
     | 
| 
      
 153 
     | 
    
         
            +
                    glCallList @top
         
     | 
| 
      
 154 
     | 
    
         
            +
                  end
         
     | 
| 
      
 155 
     | 
    
         
            +
                end
         
     | 
| 
      
 156 
     | 
    
         
            +
             
     | 
| 
      
 157 
     | 
    
         
            +
                glutSwapBuffers
         
     | 
| 
      
 158 
     | 
    
         
            +
              end
         
     | 
| 
      
 159 
     | 
    
         
            +
             
     | 
| 
      
 160 
     | 
    
         
            +
              def idle
         
     | 
| 
      
 161 
     | 
    
         
            +
                glutPostRedisplay
         
     | 
| 
      
 162 
     | 
    
         
            +
              end
         
     | 
| 
      
 163 
     | 
    
         
            +
             
     | 
| 
      
 164 
     | 
    
         
            +
              def keyboard key, x, y
         
     | 
| 
      
 165 
     | 
    
         
            +
                case key
         
     | 
| 
      
 166 
     | 
    
         
            +
                when ?\e
         
     | 
| 
      
 167 
     | 
    
         
            +
                  glutDestroyWindow @window
         
     | 
| 
      
 168 
     | 
    
         
            +
                  exit 0
         
     | 
| 
      
 169 
     | 
    
         
            +
                when 'F' then
         
     | 
| 
      
 170 
     | 
    
         
            +
                  @fullscreen = !@fullscreen
         
     | 
| 
      
 171 
     | 
    
         
            +
             
     | 
| 
      
 172 
     | 
    
         
            +
                  if @fullscreen then
         
     | 
| 
      
 173 
     | 
    
         
            +
                    glutFullScreen
         
     | 
| 
      
 174 
     | 
    
         
            +
                  else
         
     | 
| 
      
 175 
     | 
    
         
            +
                    glutPositionWindow 0, 0
         
     | 
| 
      
 176 
     | 
    
         
            +
                  end
         
     | 
| 
      
 177 
     | 
    
         
            +
                when 'X' then @xrot += 0.5
         
     | 
| 
      
 178 
     | 
    
         
            +
                when 'x' then @xrot -= 0.5
         
     | 
| 
      
 179 
     | 
    
         
            +
                when 'Y' then @yrot += 0.5
         
     | 
| 
      
 180 
     | 
    
         
            +
                when 'y' then @yrot -= 0.5
         
     | 
| 
      
 181 
     | 
    
         
            +
                end
         
     | 
| 
      
 182 
     | 
    
         
            +
             
     | 
| 
      
 183 
     | 
    
         
            +
                glutPostRedisplay
         
     | 
| 
      
 184 
     | 
    
         
            +
              end
         
     | 
| 
      
 185 
     | 
    
         
            +
             
     | 
| 
      
 186 
     | 
    
         
            +
              def load_texture
         
     | 
| 
      
 187 
     | 
    
         
            +
                png = ChunkyPNG::Image.from_file(File.expand_path('../crate.png', __FILE__))
         
     | 
| 
      
 188 
     | 
    
         
            +
             
     | 
| 
      
 189 
     | 
    
         
            +
                height = png.height
         
     | 
| 
      
 190 
     | 
    
         
            +
                width = png.width
         
     | 
| 
      
 191 
     | 
    
         
            +
             
     | 
| 
      
 192 
     | 
    
         
            +
                image = png.to_rgba_stream.each_byte.to_a
         
     | 
| 
      
 193 
     | 
    
         
            +
             
     | 
| 
      
 194 
     | 
    
         
            +
                @textures = glGenTextures 1
         
     | 
| 
      
 195 
     | 
    
         
            +
                glBindTexture GL_TEXTURE_2D, @textures[0]
         
     | 
| 
      
 196 
     | 
    
         
            +
                glTexImage2D GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, image
         
     | 
| 
      
 197 
     | 
    
         
            +
                glTexParameteri GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR
         
     | 
| 
      
 198 
     | 
    
         
            +
                glTexParameteri GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR
         
     | 
| 
      
 199 
     | 
    
         
            +
              end
         
     | 
| 
      
 200 
     | 
    
         
            +
             
     | 
| 
      
 201 
     | 
    
         
            +
            end
         
     | 
| 
      
 202 
     | 
    
         
            +
             
     | 
| 
      
 203 
     | 
    
         
            +
            Lesson12.new
         
     |