├── doc ├── glxs_rb.jpg ├── brick_rb.jpg ├── simple_rb.jpg └── nehe_lesson36_rb.jpg ├── sample ├── glfw3.dll ├── freeglut.dll ├── GLExcess │ ├── data │ │ ├── cl.raw │ │ ├── e.raw │ │ ├── g1.raw │ │ ├── l.raw │ │ ├── s.raw │ │ ├── t.raw │ │ ├── to.raw │ │ ├── y.raw │ │ ├── art.raw │ │ ├── back.raw │ │ ├── bump5.raw │ │ ├── cl1.raw │ │ ├── cl2.raw │ │ ├── crite.raw │ │ ├── dust1.raw │ │ ├── dust2.raw │ │ ├── env17.raw │ │ ├── env26.raw │ │ ├── f16.raw │ │ ├── face.dat │ │ ├── face.raw │ │ ├── gotta.raw │ │ ├── land.raw │ │ ├── mamor.raw │ │ ├── metal.raw │ │ ├── moon.raw │ │ ├── moon1.raw │ │ ├── mtop.raw │ │ ├── noise.raw │ │ ├── say.raw │ │ ├── sh1.raw │ │ ├── ship.raw │ │ ├── sky17.raw │ │ ├── sky27.raw │ │ ├── sky7.raw │ │ ├── skygs.raw │ │ ├── smoke.raw │ │ ├── spot.raw │ │ ├── star.raw │ │ ├── sun2.raw │ │ ├── tail.raw │ │ ├── text.raw │ │ ├── text1.raw │ │ ├── text2.raw │ │ ├── trail.raw │ │ ├── water.raw │ │ ├── watpt.raw │ │ ├── white.raw │ │ ├── xp1.raw │ │ ├── xp10.raw │ │ ├── xp2.raw │ │ ├── xp4.raw │ │ ├── xp8.raw │ │ ├── xp9.raw │ │ ├── xs1.raw │ │ ├── yes.raw │ │ ├── you.raw │ │ ├── another.raw │ │ ├── basic2.raw │ │ ├── circle.raw │ │ ├── credits.raw │ │ ├── design.raw │ │ ├── designs.raw │ │ ├── envmap.raw │ │ ├── envmap1.raw │ │ ├── esaflr.raw │ │ ├── excess.raw │ │ ├── f16mask.raw │ │ ├── floor1.raw │ │ ├── glglow.raw │ │ ├── glxcess.raw │ │ ├── logocol.raw │ │ ├── logoxs.raw │ │ ├── mfloor1.raw │ │ ├── noise1.raw │ │ ├── opengl.raw │ │ ├── openglb.raw │ │ ├── profile.raw │ │ ├── provaz.raw │ │ ├── rusty2.raw │ │ ├── rusty3.raw │ │ ├── sayglow.raw │ │ ├── senv36.raw │ │ ├── sground.raw │ │ ├── spread.raw │ │ ├── stars1.raw │ │ ├── toglow.raw │ │ ├── water1.raw │ │ ├── yesglow.raw │ │ ├── youglow.raw │ │ ├── circlefill.raw │ │ ├── creditsneg.raw │ │ ├── excessglow.raw │ │ ├── experience.raw │ │ ├── fallfront1.raw │ │ ├── fallleft1.raw │ │ ├── fallright.raw │ │ ├── featuring.raw │ │ ├── featurings.raw │ │ ├── floodmask.raw │ │ ├── floodmask1.raw │ │ ├── glxcesss.raw │ │ ├── gottaglow.raw │ │ ├── lightmask.raw │ │ ├── linenoise.raw │ │ ├── moonmask.raw │ │ ├── technique.raw │ │ ├── techniques.raw │ │ ├── trailleft.raw │ │ ├── trailright.raw │ │ ├── trilogy1.raw │ │ ├── wholenew.raw │ │ ├── wholenews.raw │ │ ├── anotherglow.raw │ │ ├── circleempty.raw │ │ ├── experiences.raw │ │ ├── fallleftmask.raw │ │ ├── introducing.raw │ │ ├── introducings.raw │ │ ├── fallrightmask.raw │ │ └── README │ ├── README.md │ ├── texture.rb │ ├── glxs_glut.rb │ ├── glxs.rb │ ├── scene07data.rb │ └── scene12.rb ├── GLES │ ├── sample.vert │ ├── sample.frag │ └── gles.rb ├── data │ ├── 256px-Globe.svg.dds │ ├── 256px-Globe.svg.png │ └── README.md ├── SDL2 │ ├── README.md │ └── test_sdl2-bindings.rb ├── ComputeShader │ ├── README.md │ └── opengl_cs.rb ├── glfw_get.sh ├── glfw_get.bat ├── glfw_build_master.sh ├── DebugOutput │ ├── README.md │ └── debug_output.rb ├── glfw_build.sh ├── glfw_build_master.bat ├── Extension │ ├── README.md │ └── test_dds_texture.rb ├── report_env_es.rb ├── glfw_build.bat ├── OrangeBook │ ├── brick.frag │ ├── brick.vert │ └── 3Dlabs-License.txt ├── GLUT │ ├── glut_font.rb │ ├── glut_menu.rb │ ├── glut_minimal.rb │ └── glut_gears.rb ├── util │ ├── setup_dll.rb │ └── WavefrontOBJ.rb ├── simple.rb ├── simple_glut.rb ├── README.md ├── teapot.rb ├── Gosu │ └── lesson01.rb ├── report_env.rb └── RedBook │ ├── alpha.rb │ ├── bezmesh.rb │ ├── aapoly.rb │ ├── varray.rb │ ├── surface.rb │ └── teapots.rb ├── generator ├── get_gl_xml.bat ├── get_gl_xml.rb ├── generate_enum.rb ├── generate_es_enum.rb ├── generate_ext_enum.rb ├── generate_es_ext_enum.rb ├── generate_ext_command.rb ├── generate_es_ext_command.rb ├── generate_command.rb ├── generate_es_command.rb ├── aux_typemap.rb ├── Rakefile └── aux_generate_typemap.rb ├── LICENSE.txt ├── opengl-bindings.gemspec ├── lib ├── opengl_ext.rb ├── opengl_es_ext.rb ├── opengl_es.rb ├── opengl.rb ├── opengl_platform.rb ├── opengl_ext_common.rb ├── opengl_linux.rb ├── opengl_macosx.rb ├── opengl_windows.rb └── opengl_common.rb └── .github └── workflows └── generate.yml /doc/glxs_rb.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vaiorabbit/ruby-opengl/HEAD/doc/glxs_rb.jpg -------------------------------------------------------------------------------- /doc/brick_rb.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vaiorabbit/ruby-opengl/HEAD/doc/brick_rb.jpg -------------------------------------------------------------------------------- /doc/simple_rb.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vaiorabbit/ruby-opengl/HEAD/doc/simple_rb.jpg -------------------------------------------------------------------------------- /sample/glfw3.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vaiorabbit/ruby-opengl/HEAD/sample/glfw3.dll -------------------------------------------------------------------------------- /sample/freeglut.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vaiorabbit/ruby-opengl/HEAD/sample/freeglut.dll -------------------------------------------------------------------------------- /doc/nehe_lesson36_rb.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vaiorabbit/ruby-opengl/HEAD/doc/nehe_lesson36_rb.jpg -------------------------------------------------------------------------------- /sample/GLExcess/data/cl.raw: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vaiorabbit/ruby-opengl/HEAD/sample/GLExcess/data/cl.raw -------------------------------------------------------------------------------- /sample/GLExcess/data/e.raw: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vaiorabbit/ruby-opengl/HEAD/sample/GLExcess/data/e.raw -------------------------------------------------------------------------------- /sample/GLExcess/data/g1.raw: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vaiorabbit/ruby-opengl/HEAD/sample/GLExcess/data/g1.raw -------------------------------------------------------------------------------- /sample/GLExcess/data/l.raw: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vaiorabbit/ruby-opengl/HEAD/sample/GLExcess/data/l.raw -------------------------------------------------------------------------------- /sample/GLExcess/data/s.raw: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vaiorabbit/ruby-opengl/HEAD/sample/GLExcess/data/s.raw -------------------------------------------------------------------------------- /sample/GLExcess/data/t.raw: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vaiorabbit/ruby-opengl/HEAD/sample/GLExcess/data/t.raw -------------------------------------------------------------------------------- /sample/GLExcess/data/to.raw: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vaiorabbit/ruby-opengl/HEAD/sample/GLExcess/data/to.raw -------------------------------------------------------------------------------- /sample/GLExcess/data/y.raw: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vaiorabbit/ruby-opengl/HEAD/sample/GLExcess/data/y.raw -------------------------------------------------------------------------------- /sample/GLES/sample.vert: -------------------------------------------------------------------------------- 1 | attribute vec4 a_vertex; 2 | void main(void) 3 | { 4 | gl_Position = a_vertex; 5 | } 6 | -------------------------------------------------------------------------------- /sample/GLExcess/data/art.raw: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vaiorabbit/ruby-opengl/HEAD/sample/GLExcess/data/art.raw -------------------------------------------------------------------------------- /sample/GLExcess/data/back.raw: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vaiorabbit/ruby-opengl/HEAD/sample/GLExcess/data/back.raw -------------------------------------------------------------------------------- /sample/GLExcess/data/bump5.raw: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vaiorabbit/ruby-opengl/HEAD/sample/GLExcess/data/bump5.raw -------------------------------------------------------------------------------- /sample/GLExcess/data/cl1.raw: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vaiorabbit/ruby-opengl/HEAD/sample/GLExcess/data/cl1.raw -------------------------------------------------------------------------------- /sample/GLExcess/data/cl2.raw: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vaiorabbit/ruby-opengl/HEAD/sample/GLExcess/data/cl2.raw -------------------------------------------------------------------------------- /sample/GLExcess/data/crite.raw: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vaiorabbit/ruby-opengl/HEAD/sample/GLExcess/data/crite.raw -------------------------------------------------------------------------------- /sample/GLExcess/data/dust1.raw: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vaiorabbit/ruby-opengl/HEAD/sample/GLExcess/data/dust1.raw -------------------------------------------------------------------------------- /sample/GLExcess/data/dust2.raw: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vaiorabbit/ruby-opengl/HEAD/sample/GLExcess/data/dust2.raw -------------------------------------------------------------------------------- /sample/GLExcess/data/env17.raw: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vaiorabbit/ruby-opengl/HEAD/sample/GLExcess/data/env17.raw -------------------------------------------------------------------------------- /sample/GLExcess/data/env26.raw: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vaiorabbit/ruby-opengl/HEAD/sample/GLExcess/data/env26.raw -------------------------------------------------------------------------------- /sample/GLExcess/data/f16.raw: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vaiorabbit/ruby-opengl/HEAD/sample/GLExcess/data/f16.raw -------------------------------------------------------------------------------- /sample/GLExcess/data/face.dat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vaiorabbit/ruby-opengl/HEAD/sample/GLExcess/data/face.dat -------------------------------------------------------------------------------- /sample/GLExcess/data/face.raw: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vaiorabbit/ruby-opengl/HEAD/sample/GLExcess/data/face.raw -------------------------------------------------------------------------------- /sample/GLExcess/data/gotta.raw: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vaiorabbit/ruby-opengl/HEAD/sample/GLExcess/data/gotta.raw -------------------------------------------------------------------------------- /sample/GLExcess/data/land.raw: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vaiorabbit/ruby-opengl/HEAD/sample/GLExcess/data/land.raw -------------------------------------------------------------------------------- /sample/GLExcess/data/mamor.raw: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vaiorabbit/ruby-opengl/HEAD/sample/GLExcess/data/mamor.raw -------------------------------------------------------------------------------- /sample/GLExcess/data/metal.raw: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vaiorabbit/ruby-opengl/HEAD/sample/GLExcess/data/metal.raw -------------------------------------------------------------------------------- /sample/GLExcess/data/moon.raw: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vaiorabbit/ruby-opengl/HEAD/sample/GLExcess/data/moon.raw -------------------------------------------------------------------------------- /sample/GLExcess/data/moon1.raw: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vaiorabbit/ruby-opengl/HEAD/sample/GLExcess/data/moon1.raw -------------------------------------------------------------------------------- /sample/GLExcess/data/mtop.raw: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vaiorabbit/ruby-opengl/HEAD/sample/GLExcess/data/mtop.raw -------------------------------------------------------------------------------- /sample/GLExcess/data/noise.raw: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vaiorabbit/ruby-opengl/HEAD/sample/GLExcess/data/noise.raw -------------------------------------------------------------------------------- /sample/GLExcess/data/say.raw: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vaiorabbit/ruby-opengl/HEAD/sample/GLExcess/data/say.raw -------------------------------------------------------------------------------- /sample/GLExcess/data/sh1.raw: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vaiorabbit/ruby-opengl/HEAD/sample/GLExcess/data/sh1.raw -------------------------------------------------------------------------------- /sample/GLExcess/data/ship.raw: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vaiorabbit/ruby-opengl/HEAD/sample/GLExcess/data/ship.raw -------------------------------------------------------------------------------- /sample/GLExcess/data/sky17.raw: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vaiorabbit/ruby-opengl/HEAD/sample/GLExcess/data/sky17.raw -------------------------------------------------------------------------------- /sample/GLExcess/data/sky27.raw: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vaiorabbit/ruby-opengl/HEAD/sample/GLExcess/data/sky27.raw -------------------------------------------------------------------------------- /sample/GLExcess/data/sky7.raw: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vaiorabbit/ruby-opengl/HEAD/sample/GLExcess/data/sky7.raw -------------------------------------------------------------------------------- /sample/GLExcess/data/skygs.raw: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vaiorabbit/ruby-opengl/HEAD/sample/GLExcess/data/skygs.raw -------------------------------------------------------------------------------- /sample/GLExcess/data/smoke.raw: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vaiorabbit/ruby-opengl/HEAD/sample/GLExcess/data/smoke.raw -------------------------------------------------------------------------------- /sample/GLExcess/data/spot.raw: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vaiorabbit/ruby-opengl/HEAD/sample/GLExcess/data/spot.raw -------------------------------------------------------------------------------- /sample/GLExcess/data/star.raw: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vaiorabbit/ruby-opengl/HEAD/sample/GLExcess/data/star.raw -------------------------------------------------------------------------------- /sample/GLExcess/data/sun2.raw: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vaiorabbit/ruby-opengl/HEAD/sample/GLExcess/data/sun2.raw -------------------------------------------------------------------------------- /sample/GLExcess/data/tail.raw: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vaiorabbit/ruby-opengl/HEAD/sample/GLExcess/data/tail.raw -------------------------------------------------------------------------------- /sample/GLExcess/data/text.raw: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vaiorabbit/ruby-opengl/HEAD/sample/GLExcess/data/text.raw -------------------------------------------------------------------------------- /sample/GLExcess/data/text1.raw: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vaiorabbit/ruby-opengl/HEAD/sample/GLExcess/data/text1.raw -------------------------------------------------------------------------------- /sample/GLExcess/data/text2.raw: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vaiorabbit/ruby-opengl/HEAD/sample/GLExcess/data/text2.raw -------------------------------------------------------------------------------- /sample/GLExcess/data/trail.raw: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vaiorabbit/ruby-opengl/HEAD/sample/GLExcess/data/trail.raw -------------------------------------------------------------------------------- /sample/GLExcess/data/water.raw: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vaiorabbit/ruby-opengl/HEAD/sample/GLExcess/data/water.raw -------------------------------------------------------------------------------- /sample/GLExcess/data/watpt.raw: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vaiorabbit/ruby-opengl/HEAD/sample/GLExcess/data/watpt.raw -------------------------------------------------------------------------------- /sample/GLExcess/data/white.raw: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vaiorabbit/ruby-opengl/HEAD/sample/GLExcess/data/white.raw -------------------------------------------------------------------------------- /sample/GLExcess/data/xp1.raw: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vaiorabbit/ruby-opengl/HEAD/sample/GLExcess/data/xp1.raw -------------------------------------------------------------------------------- /sample/GLExcess/data/xp10.raw: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vaiorabbit/ruby-opengl/HEAD/sample/GLExcess/data/xp10.raw -------------------------------------------------------------------------------- /sample/GLExcess/data/xp2.raw: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vaiorabbit/ruby-opengl/HEAD/sample/GLExcess/data/xp2.raw -------------------------------------------------------------------------------- /sample/GLExcess/data/xp4.raw: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vaiorabbit/ruby-opengl/HEAD/sample/GLExcess/data/xp4.raw -------------------------------------------------------------------------------- /sample/GLExcess/data/xp8.raw: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vaiorabbit/ruby-opengl/HEAD/sample/GLExcess/data/xp8.raw -------------------------------------------------------------------------------- /sample/GLExcess/data/xp9.raw: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vaiorabbit/ruby-opengl/HEAD/sample/GLExcess/data/xp9.raw -------------------------------------------------------------------------------- /sample/GLExcess/data/xs1.raw: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vaiorabbit/ruby-opengl/HEAD/sample/GLExcess/data/xs1.raw -------------------------------------------------------------------------------- /sample/GLExcess/data/yes.raw: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vaiorabbit/ruby-opengl/HEAD/sample/GLExcess/data/yes.raw -------------------------------------------------------------------------------- /sample/GLExcess/data/you.raw: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vaiorabbit/ruby-opengl/HEAD/sample/GLExcess/data/you.raw -------------------------------------------------------------------------------- /sample/GLExcess/data/another.raw: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vaiorabbit/ruby-opengl/HEAD/sample/GLExcess/data/another.raw -------------------------------------------------------------------------------- /sample/GLExcess/data/basic2.raw: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vaiorabbit/ruby-opengl/HEAD/sample/GLExcess/data/basic2.raw -------------------------------------------------------------------------------- /sample/GLExcess/data/circle.raw: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vaiorabbit/ruby-opengl/HEAD/sample/GLExcess/data/circle.raw -------------------------------------------------------------------------------- /sample/GLExcess/data/credits.raw: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vaiorabbit/ruby-opengl/HEAD/sample/GLExcess/data/credits.raw -------------------------------------------------------------------------------- /sample/GLExcess/data/design.raw: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vaiorabbit/ruby-opengl/HEAD/sample/GLExcess/data/design.raw -------------------------------------------------------------------------------- /sample/GLExcess/data/designs.raw: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vaiorabbit/ruby-opengl/HEAD/sample/GLExcess/data/designs.raw -------------------------------------------------------------------------------- /sample/GLExcess/data/envmap.raw: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vaiorabbit/ruby-opengl/HEAD/sample/GLExcess/data/envmap.raw -------------------------------------------------------------------------------- /sample/GLExcess/data/envmap1.raw: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vaiorabbit/ruby-opengl/HEAD/sample/GLExcess/data/envmap1.raw -------------------------------------------------------------------------------- /sample/GLExcess/data/esaflr.raw: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vaiorabbit/ruby-opengl/HEAD/sample/GLExcess/data/esaflr.raw -------------------------------------------------------------------------------- /sample/GLExcess/data/excess.raw: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vaiorabbit/ruby-opengl/HEAD/sample/GLExcess/data/excess.raw -------------------------------------------------------------------------------- /sample/GLExcess/data/f16mask.raw: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vaiorabbit/ruby-opengl/HEAD/sample/GLExcess/data/f16mask.raw -------------------------------------------------------------------------------- /sample/GLExcess/data/floor1.raw: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vaiorabbit/ruby-opengl/HEAD/sample/GLExcess/data/floor1.raw -------------------------------------------------------------------------------- /sample/GLExcess/data/glglow.raw: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vaiorabbit/ruby-opengl/HEAD/sample/GLExcess/data/glglow.raw -------------------------------------------------------------------------------- /sample/GLExcess/data/glxcess.raw: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vaiorabbit/ruby-opengl/HEAD/sample/GLExcess/data/glxcess.raw -------------------------------------------------------------------------------- /sample/GLExcess/data/logocol.raw: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vaiorabbit/ruby-opengl/HEAD/sample/GLExcess/data/logocol.raw -------------------------------------------------------------------------------- /sample/GLExcess/data/logoxs.raw: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vaiorabbit/ruby-opengl/HEAD/sample/GLExcess/data/logoxs.raw -------------------------------------------------------------------------------- /sample/GLExcess/data/mfloor1.raw: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vaiorabbit/ruby-opengl/HEAD/sample/GLExcess/data/mfloor1.raw -------------------------------------------------------------------------------- /sample/GLExcess/data/noise1.raw: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vaiorabbit/ruby-opengl/HEAD/sample/GLExcess/data/noise1.raw -------------------------------------------------------------------------------- /sample/GLExcess/data/opengl.raw: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vaiorabbit/ruby-opengl/HEAD/sample/GLExcess/data/opengl.raw -------------------------------------------------------------------------------- /sample/GLExcess/data/openglb.raw: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vaiorabbit/ruby-opengl/HEAD/sample/GLExcess/data/openglb.raw -------------------------------------------------------------------------------- /sample/GLExcess/data/profile.raw: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vaiorabbit/ruby-opengl/HEAD/sample/GLExcess/data/profile.raw -------------------------------------------------------------------------------- /sample/GLExcess/data/provaz.raw: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vaiorabbit/ruby-opengl/HEAD/sample/GLExcess/data/provaz.raw -------------------------------------------------------------------------------- /sample/GLExcess/data/rusty2.raw: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vaiorabbit/ruby-opengl/HEAD/sample/GLExcess/data/rusty2.raw -------------------------------------------------------------------------------- /sample/GLExcess/data/rusty3.raw: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vaiorabbit/ruby-opengl/HEAD/sample/GLExcess/data/rusty3.raw -------------------------------------------------------------------------------- /sample/GLExcess/data/sayglow.raw: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vaiorabbit/ruby-opengl/HEAD/sample/GLExcess/data/sayglow.raw -------------------------------------------------------------------------------- /sample/GLExcess/data/senv36.raw: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vaiorabbit/ruby-opengl/HEAD/sample/GLExcess/data/senv36.raw -------------------------------------------------------------------------------- /sample/GLExcess/data/sground.raw: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vaiorabbit/ruby-opengl/HEAD/sample/GLExcess/data/sground.raw -------------------------------------------------------------------------------- /sample/GLExcess/data/spread.raw: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vaiorabbit/ruby-opengl/HEAD/sample/GLExcess/data/spread.raw -------------------------------------------------------------------------------- /sample/GLExcess/data/stars1.raw: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vaiorabbit/ruby-opengl/HEAD/sample/GLExcess/data/stars1.raw -------------------------------------------------------------------------------- /sample/GLExcess/data/toglow.raw: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vaiorabbit/ruby-opengl/HEAD/sample/GLExcess/data/toglow.raw -------------------------------------------------------------------------------- /sample/GLExcess/data/water1.raw: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vaiorabbit/ruby-opengl/HEAD/sample/GLExcess/data/water1.raw -------------------------------------------------------------------------------- /sample/GLExcess/data/yesglow.raw: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vaiorabbit/ruby-opengl/HEAD/sample/GLExcess/data/yesglow.raw -------------------------------------------------------------------------------- /sample/GLExcess/data/youglow.raw: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vaiorabbit/ruby-opengl/HEAD/sample/GLExcess/data/youglow.raw -------------------------------------------------------------------------------- /sample/data/256px-Globe.svg.dds: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vaiorabbit/ruby-opengl/HEAD/sample/data/256px-Globe.svg.dds -------------------------------------------------------------------------------- /sample/data/256px-Globe.svg.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vaiorabbit/ruby-opengl/HEAD/sample/data/256px-Globe.svg.png -------------------------------------------------------------------------------- /generator/get_gl_xml.bat: -------------------------------------------------------------------------------- 1 | curl -o gl.xml https://raw.githubusercontent.com/KhronosGroup/OpenGL-Registry/master/xml/gl.xml 2 | -------------------------------------------------------------------------------- /sample/GLExcess/data/circlefill.raw: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vaiorabbit/ruby-opengl/HEAD/sample/GLExcess/data/circlefill.raw -------------------------------------------------------------------------------- /sample/GLExcess/data/creditsneg.raw: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vaiorabbit/ruby-opengl/HEAD/sample/GLExcess/data/creditsneg.raw -------------------------------------------------------------------------------- /sample/GLExcess/data/excessglow.raw: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vaiorabbit/ruby-opengl/HEAD/sample/GLExcess/data/excessglow.raw -------------------------------------------------------------------------------- /sample/GLExcess/data/experience.raw: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vaiorabbit/ruby-opengl/HEAD/sample/GLExcess/data/experience.raw -------------------------------------------------------------------------------- /sample/GLExcess/data/fallfront1.raw: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vaiorabbit/ruby-opengl/HEAD/sample/GLExcess/data/fallfront1.raw -------------------------------------------------------------------------------- /sample/GLExcess/data/fallleft1.raw: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vaiorabbit/ruby-opengl/HEAD/sample/GLExcess/data/fallleft1.raw -------------------------------------------------------------------------------- /sample/GLExcess/data/fallright.raw: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vaiorabbit/ruby-opengl/HEAD/sample/GLExcess/data/fallright.raw -------------------------------------------------------------------------------- /sample/GLExcess/data/featuring.raw: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vaiorabbit/ruby-opengl/HEAD/sample/GLExcess/data/featuring.raw -------------------------------------------------------------------------------- /sample/GLExcess/data/featurings.raw: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vaiorabbit/ruby-opengl/HEAD/sample/GLExcess/data/featurings.raw -------------------------------------------------------------------------------- /sample/GLExcess/data/floodmask.raw: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vaiorabbit/ruby-opengl/HEAD/sample/GLExcess/data/floodmask.raw -------------------------------------------------------------------------------- /sample/GLExcess/data/floodmask1.raw: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vaiorabbit/ruby-opengl/HEAD/sample/GLExcess/data/floodmask1.raw -------------------------------------------------------------------------------- /sample/GLExcess/data/glxcesss.raw: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vaiorabbit/ruby-opengl/HEAD/sample/GLExcess/data/glxcesss.raw -------------------------------------------------------------------------------- /sample/GLExcess/data/gottaglow.raw: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vaiorabbit/ruby-opengl/HEAD/sample/GLExcess/data/gottaglow.raw -------------------------------------------------------------------------------- /sample/GLExcess/data/lightmask.raw: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vaiorabbit/ruby-opengl/HEAD/sample/GLExcess/data/lightmask.raw -------------------------------------------------------------------------------- /sample/GLExcess/data/linenoise.raw: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vaiorabbit/ruby-opengl/HEAD/sample/GLExcess/data/linenoise.raw -------------------------------------------------------------------------------- /sample/GLExcess/data/moonmask.raw: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vaiorabbit/ruby-opengl/HEAD/sample/GLExcess/data/moonmask.raw -------------------------------------------------------------------------------- /sample/GLExcess/data/technique.raw: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vaiorabbit/ruby-opengl/HEAD/sample/GLExcess/data/technique.raw -------------------------------------------------------------------------------- /sample/GLExcess/data/techniques.raw: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vaiorabbit/ruby-opengl/HEAD/sample/GLExcess/data/techniques.raw -------------------------------------------------------------------------------- /sample/GLExcess/data/trailleft.raw: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vaiorabbit/ruby-opengl/HEAD/sample/GLExcess/data/trailleft.raw -------------------------------------------------------------------------------- /sample/GLExcess/data/trailright.raw: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vaiorabbit/ruby-opengl/HEAD/sample/GLExcess/data/trailright.raw -------------------------------------------------------------------------------- /sample/GLExcess/data/trilogy1.raw: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vaiorabbit/ruby-opengl/HEAD/sample/GLExcess/data/trilogy1.raw -------------------------------------------------------------------------------- /sample/GLExcess/data/wholenew.raw: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vaiorabbit/ruby-opengl/HEAD/sample/GLExcess/data/wholenew.raw -------------------------------------------------------------------------------- /sample/GLExcess/data/wholenews.raw: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vaiorabbit/ruby-opengl/HEAD/sample/GLExcess/data/wholenews.raw -------------------------------------------------------------------------------- /sample/GLES/sample.frag: -------------------------------------------------------------------------------- 1 | precision lowp float; 2 | void main(void) 3 | { 4 | gl_FragColor = vec4(1.0, 1.0, 0.0, 1.0); 5 | } 6 | -------------------------------------------------------------------------------- /sample/GLExcess/data/anotherglow.raw: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vaiorabbit/ruby-opengl/HEAD/sample/GLExcess/data/anotherglow.raw -------------------------------------------------------------------------------- /sample/GLExcess/data/circleempty.raw: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vaiorabbit/ruby-opengl/HEAD/sample/GLExcess/data/circleempty.raw -------------------------------------------------------------------------------- /sample/GLExcess/data/experiences.raw: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vaiorabbit/ruby-opengl/HEAD/sample/GLExcess/data/experiences.raw -------------------------------------------------------------------------------- /sample/GLExcess/data/fallleftmask.raw: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vaiorabbit/ruby-opengl/HEAD/sample/GLExcess/data/fallleftmask.raw -------------------------------------------------------------------------------- /sample/GLExcess/data/introducing.raw: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vaiorabbit/ruby-opengl/HEAD/sample/GLExcess/data/introducing.raw -------------------------------------------------------------------------------- /sample/GLExcess/data/introducings.raw: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vaiorabbit/ruby-opengl/HEAD/sample/GLExcess/data/introducings.raw -------------------------------------------------------------------------------- /sample/GLExcess/data/fallrightmask.raw: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vaiorabbit/ruby-opengl/HEAD/sample/GLExcess/data/fallrightmask.raw -------------------------------------------------------------------------------- /sample/GLExcess/data/README: -------------------------------------------------------------------------------- 1 | = Notice 2 | 3 | All texture data in this directory are the copyrighted work of 4 | Paolo Martella (http://www.glexcess.com/). 5 | -------------------------------------------------------------------------------- /sample/SDL2/README.md: -------------------------------------------------------------------------------- 1 | How to run 2 | 3 | * Set path to libSDL2.dylib (macOS) /SDL2.dll (Windows) according to your environment 4 | * $ gem install sdl2-bindings 5 | * $ ruby testgl_ruby-sdl2.rb 6 | -------------------------------------------------------------------------------- /sample/ComputeShader/README.md: -------------------------------------------------------------------------------- 1 | * Ref.: OpenGL (4.3) compute shader example 2 | * http://wili.cc/blog/opengl-cs.html 3 | * http://wili.cc/blog/entries/opengl-cs/ogl_cs_example.tar.gz 4 | -------------------------------------------------------------------------------- /sample/glfw_get.sh: -------------------------------------------------------------------------------- 1 | curl -O -L https://github.com/glfw/glfw/releases/download/3.3.9/glfw-3.3.9.bin.MACOS.zip 2 | tar -xf glfw-3.3.9.bin.MACOS.zip 3 | cp glfw-3.3.9.bin.MACOS/lib-universal/libglfw.3.dylib ./libglfw.dylib 4 | -------------------------------------------------------------------------------- /sample/glfw_get.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | setlocal EnableDelayedExpansion 3 | 4 | curl -O -L https://github.com/glfw/glfw/releases/download/3.3.9/glfw-3.3.9.bin.WIN64.zip 5 | %WINDIR%\System32\tar.exe -xf glfw-3.3.9.bin.WIN64.zip 6 | xcopy /Y glfw-3.3.9.bin.WIN64\lib-mingw-w64\glfw3.dll . 7 | -------------------------------------------------------------------------------- /sample/data/README.md: -------------------------------------------------------------------------------- 1 | ## Copyright Notice ## 2 | 3 | * teapot.obj 4 | * https://www.khronos.org/registry/webgl/sdk/demos/webkit/resources/teapot.obj 5 | 6 | * 256px-Globe.svg.png (Public Domain) 7 | * https://commons.wikimedia.org/wiki/File:Globe.svg 8 | * https://upload.wikimedia.org/wikipedia/commons/thumb/f/fa/Globe.svg/256px-Globe.svg.png 9 | -------------------------------------------------------------------------------- /generator/get_gl_xml.rb: -------------------------------------------------------------------------------- 1 | require 'open-uri' 2 | require 'openssl' 3 | 4 | def get_gl_xml() 5 | open('gl.xml', 'wb') do |file| 6 | file << open('https://raw.githubusercontent.com/KhronosGroup/OpenGL-Registry/master/xml/gl.xml', :ssl_verify_mode => OpenSSL::SSL::VERIFY_NONE).read 7 | end 8 | end 9 | 10 | if $0 == __FILE__ 11 | get_gl_xml() 12 | end 13 | -------------------------------------------------------------------------------- /sample/glfw_build_master.sh: -------------------------------------------------------------------------------- 1 | # 2 | # For macOS + Xcode + CMake users. 3 | # 4 | # Ref.: https://github.com/malkia/ufo/blob/master/build/OSX/glfw.sh 5 | # 6 | git clone --depth=1 https://github.com/glfw/glfw.git glfw_master 7 | cd glfw_master/ 8 | mkdir build 9 | cd build 10 | export MACOSX_DEPLOYMENT_TARGET=10.14 11 | cmake -D CMAKE_BUILD_TYPE=Release -D GLFW_NATIVE_API=1 -D CMAKE_OSX_ARCHITECTURES="x86_64;arm64" -D BUILD_SHARED_LIBS=ON -D CMAKE_C_COMPILER=clang ../ 12 | make 13 | cp -R src/libglfw* ../../../sample 14 | -------------------------------------------------------------------------------- /sample/DebugOutput/README.md: -------------------------------------------------------------------------------- 1 | ## Reference ## 2 | 3 | * Introduction to OpenGL 4.1 - Tutorial 05 4 | * https://sites.google.com/site/opengltutorialsbyaks/introduction-to-opengl-4-1---tutorial-05 5 | * OpenGL Insights - Chapter 33 6 | * http://openglinsights.com/ 7 | * ARB_debug_output: A Helping Hand for Desperate Developers 8 | * http://www.seas.upenn.edu/~pcozzi/OpenGLInsights/OpenGLInsights-ARB_debug_output.pdf 9 | 10 | * Fiddle::Closure::BlockCaller 11 | * http://ruby-doc.org/stdlib-2.1.0//libdoc/fiddle/rdoc/Fiddle/Closure/BlockCaller.html 12 | -------------------------------------------------------------------------------- /sample/glfw_build.sh: -------------------------------------------------------------------------------- 1 | # 2 | # For macOS + Xcode + CMake users. 3 | # 4 | # Ref.: https://github.com/malkia/ufo/blob/master/build/OSX/glfw.sh 5 | # 6 | curl -O -L https://github.com/glfw/glfw/releases/download/3.4/glfw-3.4.zip 7 | tar xvjf glfw-3.4.zip 8 | cd glfw-3.4/ 9 | mkdir build 10 | cd build 11 | export MACOSX_DEPLOYMENT_TARGET=15.1 12 | cmake -D CMAKE_BUILD_TYPE=Release -D GLFW_NATIVE_API=1 -D GLFW_BUILD_EXAMPLES=OFF -D GLFW_BUILD_TESTS=OFF -D GLFW_BUILD_DOCS=OFF -D GLFW_INSTALL=OFF -D CMAKE_OSX_ARCHITECTURES="arm64;x86_64" -D BUILD_SHARED_LIBS=ON -D CMAKE_C_COMPILER=clang ../ 13 | cmake --build . 14 | cp -R src/libglfw* ../.. 15 | -------------------------------------------------------------------------------- /generator/generate_enum.rb: -------------------------------------------------------------------------------- 1 | require_relative 'generate_common' 2 | 3 | module GLEnumCodeGenerator 4 | 5 | def self.generate_enum( out ) 6 | 7 | doc = REXML::Document.new(open("./gl.xml")) 8 | 9 | gl_std_name_to_enums_map = GLCodeGeneratorCommon.build_enums_map(doc) 10 | 11 | # Output 12 | out.puts GLCodeGeneratorCommon::HeaderComment 13 | out.puts "" 14 | out.puts "module GL" 15 | out.puts "" 16 | GLCodeGeneratorCommon.generate_enums(out, gl_std_name_to_enums_map) 17 | out.puts "" 18 | out.puts "end" 19 | 20 | end 21 | 22 | end 23 | 24 | if __FILE__ == $0 25 | GLEnumCodeGenerator.generate_enum( $stdout ) 26 | end 27 | -------------------------------------------------------------------------------- /generator/generate_es_enum.rb: -------------------------------------------------------------------------------- 1 | require_relative 'generate_common' 2 | 3 | module GLESEnumCodeGenerator 4 | 5 | def self.generate_enum( out ) 6 | 7 | doc = REXML::Document.new(open("./gl.xml")) 8 | 9 | gl_es_enum_map = GLCodeGeneratorCommon.build_enums_map(doc, extract_api: "gles2") 10 | 11 | # Output 12 | out.puts GLCodeGeneratorCommon::HeaderComment 13 | out.puts "" 14 | out.puts "module GL" 15 | out.puts "" 16 | GLCodeGeneratorCommon.generate_enums(out, gl_es_enum_map) 17 | out.puts "" 18 | out.puts "end" 19 | 20 | end 21 | 22 | end 23 | 24 | if __FILE__ == $0 25 | GLESEnumCodeGenerator.generate_enum( $stdout ) 26 | end 27 | -------------------------------------------------------------------------------- /generator/generate_ext_enum.rb: -------------------------------------------------------------------------------- 1 | require_relative 'generate_common' 2 | 3 | module GLExtEnumCodeGenerator 4 | 5 | def self.generate_enum( out ) 6 | 7 | doc = REXML::Document.new(open("./gl.xml")) 8 | 9 | gl_ext_name_to_enums_map = GLCodeGeneratorCommon.build_ext_enums_map(doc, extract_api: "gl") 10 | 11 | # Output 12 | out.puts GLCodeGeneratorCommon::HeaderComment 13 | out.puts "" 14 | out.puts "module GLExt" 15 | out.puts "" 16 | GLCodeGeneratorCommon.generate_ext_enums(out, gl_ext_name_to_enums_map) 17 | out.puts "end" 18 | 19 | end 20 | 21 | end 22 | 23 | if __FILE__ == $0 24 | GLExtEnumCodeGenerator.generate_enum( $stdout ) 25 | end 26 | -------------------------------------------------------------------------------- /generator/generate_es_ext_enum.rb: -------------------------------------------------------------------------------- 1 | require_relative 'generate_common' 2 | 3 | module GLESExtEnumCodeGenerator 4 | 5 | def self.generate_enum( out ) 6 | 7 | doc = REXML::Document.new(open("./gl.xml")) 8 | 9 | gl_ext_name_to_enums_map = GLCodeGeneratorCommon.build_ext_enums_map(doc, extract_api: "gles2") 10 | 11 | # Output 12 | out.puts GLCodeGeneratorCommon::HeaderComment 13 | out.puts "" 14 | out.puts "module GLExt" 15 | out.puts "" 16 | GLCodeGeneratorCommon.generate_ext_enums(out, gl_ext_name_to_enums_map) 17 | out.puts "" 18 | out.puts "end" 19 | 20 | end 21 | 22 | end 23 | 24 | if __FILE__ == $0 25 | GLESExtEnumCodeGenerator.generate_enum( $stdout ) 26 | end 27 | -------------------------------------------------------------------------------- /sample/glfw_build_master.bat: -------------------------------------------------------------------------------- 1 | :: 2 | :: For Windows + RubyInstaller2 with DevKit(MSYS2 gcc & make) + CMake users. 3 | :: - Use this script after "ridk enable"d. See https://github.com/oneclick/rubyinstaller2/wiki/The-ridk-tool for details. 4 | :: 5 | @echo off 6 | setlocal EnableDelayedExpansion 7 | 8 | set CMAKE=%1 9 | if [%CMAKE%] == [] ( 10 | set CMAKE="%PROGRAMFILES%\CMake\bin\cmake.exe" 11 | ) 12 | 13 | git clone --depth=1 https://github.com/glfw/glfw.git glfw_master 14 | cd glfw_master/ 15 | mkdir build 16 | cd build 17 | %CMAKE% -G "MSYS Makefiles" -D CMAKE_BUILD_TYPE=Release -D GLFW_NATIVE_API=1 -D BUILD_SHARED_LIBS=ON -D CMAKE_C_COMPILER=gcc ../ 18 | make 19 | cp -R src/glfw3.dll ../.. 20 | -------------------------------------------------------------------------------- /sample/Extension/README.md: -------------------------------------------------------------------------------- 1 | ## nvpr_hello_world.rb ## 2 | 3 | * Demonstrates the OpenGL extension 'GL_NV_path_rendering'. 4 | * Only available on NVIDIA's GPU. 5 | * Ref.: NV Path Rendering 6 | * https://developer.nvidia.com/nv-path-rendering 7 | * http://developer.download.nvidia.com/assets/gamedev/files/NVprSDK.zip 8 | 9 | ## test_dds_texture.rb ## 10 | 11 | * Demonstrates the OpenGL extension 'GL_EXT_texture_compression_s3tc', which enables DDS support. 12 | * Copyright Notice 13 | * 256px-Globe.svg.png (Public Domain) 14 | * https://commons.wikimedia.org/wiki/File:Globe.svg 15 | * https://upload.wikimedia.org/wikipedia/commons/thumb/f/fa/Globe.svg/256px-Globe.svg.png 16 | -------------------------------------------------------------------------------- /generator/generate_ext_command.rb: -------------------------------------------------------------------------------- 1 | require_relative 'generate_common' 2 | 3 | module GLExtCommandCodeGenerator 4 | 5 | def self.generate_command( out ) 6 | 7 | doc = REXML::Document.new(open("./gl.xml")) 8 | 9 | gl_ext_name_to_commands_map = GLCodeGeneratorCommon.build_ext_commands_map(doc, extract_api: "gl") 10 | 11 | # Output 12 | out.puts GLCodeGeneratorCommon::HeaderComment 13 | out.puts "" 14 | out.puts "require 'fiddle'" 15 | out.puts "" 16 | out.puts "module GLExt" 17 | out.puts "" 18 | 19 | GLCodeGeneratorCommon.generate_ext_methods(out, gl_ext_name_to_commands_map) 20 | 21 | out.puts "end" 22 | end 23 | 24 | end 25 | 26 | if $0 == __FILE__ 27 | GLExtCommandCodeGenerator.generate_command( $stdout ) 28 | end 29 | -------------------------------------------------------------------------------- /generator/generate_es_ext_command.rb: -------------------------------------------------------------------------------- 1 | require_relative 'generate_common' 2 | 3 | module GLESExtCommandCodeGenerator 4 | 5 | def self.generate_command( out ) 6 | 7 | doc = REXML::Document.new(open("./gl.xml")) 8 | 9 | gl_ext_name_to_commands_map = GLCodeGeneratorCommon.build_ext_commands_map(doc, extract_api: "gles2") 10 | 11 | # Output 12 | out.puts GLCodeGeneratorCommon::HeaderComment 13 | out.puts "" 14 | out.puts "require 'fiddle'" 15 | out.puts "" 16 | out.puts "module GLExt" 17 | out.puts "" 18 | 19 | GLCodeGeneratorCommon.generate_ext_methods(out, gl_ext_name_to_commands_map) 20 | 21 | out.puts "end" 22 | end 23 | 24 | end 25 | 26 | if $0 == __FILE__ 27 | GLESExtCommandCodeGenerator.generate_command( $stdout ) 28 | end 29 | -------------------------------------------------------------------------------- /sample/report_env_es.rb: -------------------------------------------------------------------------------- 1 | require 'opengl_es' 2 | require 'glfw' 3 | 4 | if __FILE__ == $PROGRAM_NAME 5 | GLFW.load_lib() 6 | GLFW.Init() 7 | GLFW.WindowHint(GLFW::DECORATED, 0) 8 | GLFW.WindowHint(GLFW::CONTEXT_VERSION_MAJOR, 3) 9 | GLFW.WindowHint(GLFW::CLIENT_API, GLFW::OPENGL_ES_API) 10 | window = GLFW.CreateWindow(1, 1, "Report OpenGL Environment", nil, nil) 11 | if window.null? 12 | puts "Failed to create the OpenGL ES 3 context. You may need to get a GPU/driver that is compliant with OpenGL 4.3 or higher." 13 | exit 14 | end 15 | 16 | GLFW.MakeContextCurrent(window) 17 | GL.load_lib() 18 | puts "Version: #{GL.GetString(GL::VERSION).to_s}" 19 | puts "Extensions:" 20 | puts GL.GetString(GL::EXTENSIONS).to_s.split(/ /) 21 | GLFW.DestroyWindow(window) 22 | GLFW.Terminate() 23 | end 24 | -------------------------------------------------------------------------------- /sample/glfw_build.bat: -------------------------------------------------------------------------------- 1 | :: 2 | :: For Windows + RubyInstaller2 with DevKit(MSYS2 gcc & make) + CMake users. 3 | :: - Use this script after "ridk enable"d. See https://github.com/oneclick/rubyinstaller2/wiki/The-ridk-tool for details. 4 | :: 5 | @echo off 6 | setlocal EnableDelayedExpansion 7 | 8 | set CMAKE_EXE=%1 9 | if "%CMAKE_EXE%"=="" ( 10 | set CMAKE_EXE="%PROGRAMFILES%\CMake\bin\cmake" 11 | ) 12 | 13 | %WINDIR%\System32\curl -O -L https://github.com/glfw/glfw/releases/download/3.4/glfw-3.4.zip 14 | %WINDIR%\System32\tar.exe -xf glfw-3.4.zip 15 | cd glfw-3.4/ 16 | if not exist build ( 17 | mkdir build 18 | ) 19 | cd build 20 | %CMAKE_EXE% -G "MSYS Makefiles" -D CMAKE_BUILD_TYPE=Release -D GLFW_NATIVE_API=1 -D GLFW_BUILD_EXAMPLES=OFF -D GLFW_BUILD_TESTS=OFF -D GLFW_BUILD_DOCS=OFF -D GLFW_INSTALL=OFF -D BUILD_SHARED_LIBS=ON -D CMAKE_C_COMPILER=gcc .. 21 | 22 | cmake --build . 23 | cp -R src/glfw3.dll ../.. 24 | -------------------------------------------------------------------------------- /generator/generate_command.rb: -------------------------------------------------------------------------------- 1 | require_relative 'generate_common' 2 | 3 | module GLCommandCodeGenerator 4 | 5 | def self.generate_command( out ) 6 | 7 | doc = REXML::Document.new(open("./gl.xml")) 8 | 9 | gl_std_cmd_map = GLCodeGeneratorCommon.build_commands_map(doc, extract_api: "gl") 10 | 11 | # Output 12 | out.puts GLCodeGeneratorCommon::HeaderComment 13 | out.puts "" 14 | out.puts "require 'fiddle'" 15 | out.puts "" 16 | out.puts "module GL" 17 | out.puts "" 18 | GLCodeGeneratorCommon.generate_symbols(out, gl_std_cmd_map) 19 | out.puts "" 20 | GLCodeGeneratorCommon.generate_args_map(out, gl_std_cmd_map) 21 | out.puts "" 22 | GLCodeGeneratorCommon.generate_retval_map(out, gl_std_cmd_map) 23 | out.puts "" 24 | GLCodeGeneratorCommon.generate_methods(out, gl_std_cmd_map) 25 | out.puts "end" 26 | end 27 | 28 | end 29 | 30 | if $0 == __FILE__ 31 | GLCommandCodeGenerator.generate_command( $stdout ) 32 | end 33 | -------------------------------------------------------------------------------- /generator/generate_es_command.rb: -------------------------------------------------------------------------------- 1 | require_relative 'generate_common' 2 | 3 | module GLESCommandCodeGenerator 4 | 5 | def self.generate_command( out ) 6 | 7 | doc = REXML::Document.new(open("./gl.xml")) 8 | 9 | gl_es_cmd_map = GLCodeGeneratorCommon.build_commands_map(doc, extract_api: "gles2") 10 | 11 | # Output 12 | out.puts GLCodeGeneratorCommon::HeaderComment 13 | out.puts "" 14 | out.puts "require 'fiddle'" 15 | out.puts "" 16 | out.puts "module GL" 17 | out.puts "" 18 | GLCodeGeneratorCommon.generate_symbols(out, gl_es_cmd_map) 19 | out.puts "" 20 | GLCodeGeneratorCommon.generate_args_map(out, gl_es_cmd_map) 21 | out.puts "" 22 | GLCodeGeneratorCommon.generate_retval_map(out, gl_es_cmd_map) 23 | out.puts "" 24 | GLCodeGeneratorCommon.generate_methods(out, gl_es_cmd_map) 25 | out.puts "end" 26 | end 27 | 28 | end 29 | 30 | if $0 == __FILE__ 31 | GLESCommandCodeGenerator.generate_command( $stdout ) 32 | end 33 | -------------------------------------------------------------------------------- /sample/OrangeBook/brick.frag: -------------------------------------------------------------------------------- 1 | // 2 | // Fragment shader for procedural bricks 3 | // 4 | // Authors: Dave Baldwin, Steve Koren, Randi Rost 5 | // based on a shader by Darwyn Peachey 6 | // 7 | // Copyright (c) 2002-2004 3Dlabs Inc. Ltd. 8 | // 9 | // See 3Dlabs-License.txt for license information 10 | // 11 | 12 | uniform vec3 BrickColor, MortarColor; 13 | uniform vec2 BrickSize; 14 | uniform vec2 BrickPct; 15 | 16 | varying vec2 MCposition; 17 | varying float LightIntensity; 18 | 19 | void main(void) 20 | { 21 | vec3 color; 22 | vec2 position, useBrick; 23 | 24 | position = MCposition / BrickSize; 25 | 26 | if (fract(position.y * 0.5) > 0.5) 27 | position.x += 0.5; 28 | 29 | position = fract(position); 30 | 31 | useBrick = step(position, BrickPct); 32 | 33 | color = mix(MortarColor, BrickColor, useBrick.x * useBrick.y); 34 | color *= LightIntensity; 35 | gl_FragColor = vec4 (color, 1.0); 36 | } 37 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | Ruby-OpenGL : Yet another OpenGL wrapper for Ruby (and wrapper code generator) 2 | Copyright (c) 2013-2025 vaiorabbit 3 | 4 | This software is provided 'as-is', without any express or implied 5 | warranty. In no event will the authors be held liable for any damages 6 | arising from the use of this software. 7 | 8 | Permission is granted to anyone to use this software for any purpose, 9 | including commercial applications, and to alter it and redistribute it 10 | freely, subject to the following restrictions: 11 | 12 | 1. The origin of this software must not be misrepresented; you must not 13 | claim that you wrote the original software. If you use this software 14 | in a product, an acknowledgment in the product documentation would be 15 | appreciated but is not required. 16 | 17 | 2. Altered source versions must be plainly marked as such, and must not be 18 | misrepresented as being the original software. 19 | 20 | 3. This notice may not be removed or altered from any source 21 | distribution. 22 | -------------------------------------------------------------------------------- /opengl-bindings.gemspec: -------------------------------------------------------------------------------- 1 | # -*- encoding: utf-8 -*- 2 | lib = File.expand_path('../lib', __FILE__) 3 | $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) 4 | 5 | Gem::Specification.new do |gem| 6 | gem.name = "opengl-bindings2" 7 | gem.version = "2.0.4" 8 | gem.authors = ["vaiorabbit"] 9 | gem.email = ["vaiorabbit@gmail.com"] 10 | gem.summary = %q{Bindings for OpenGL/GLFW/GLUT/GLU} 11 | gem.homepage = "https://github.com/vaiorabbit/ruby-opengl" 12 | gem.require_paths = ["lib"] 13 | gem.license = "Zlib" 14 | gem.description = <<-DESC 15 | Ruby bindings for OpenGL - 4.6, OpenGL ES - 3.2 and all extensions using Fiddle (For MRI >= 2.4.0). GLFW/GLUT/GLU bindings are also available. 16 | DESC 17 | 18 | gem.required_ruby_version = '>= 2.4.0' 19 | 20 | gem.files = Dir.glob("lib/*.rb") + 21 | ["README.md", "LICENSE.txt", "ChangeLog"] + 22 | ["sample/simple.rb", "sample/report_env.rb", "sample/glfw_get.sh", "sample/glfw_get.bat", "sample/README.md"] 23 | 24 | gem.add_runtime_dependency "fiddle", "~> 1.0" 25 | end 26 | -------------------------------------------------------------------------------- /lib/opengl_ext.rb: -------------------------------------------------------------------------------- 1 | require_relative 'opengl_common' 2 | require_relative 'opengl_ext_common' 3 | require_relative 'opengl_ext_enum' 4 | require_relative 'opengl_ext_command' 5 | 6 | =begin 7 | Ruby-OpenGL : Yet another OpenGL wrapper for Ruby (and wrapper code generator) 8 | Copyright (c) 2013-2025 vaiorabbit 9 | 10 | This software is provided 'as-is', without any express or implied 11 | warranty. In no event will the authors be held liable for any damages 12 | arising from the use of this software. 13 | 14 | Permission is granted to anyone to use this software for any purpose, 15 | including commercial applications, and to alter it and redistribute it 16 | freely, subject to the following restrictions: 17 | 18 | 1. The origin of this software must not be misrepresented; you must not 19 | claim that you wrote the original software. If you use this software 20 | in a product, an acknowledgment in the product documentation would be 21 | appreciated but is not required. 22 | 23 | 2. Altered source versions must be plainly marked as such, and must not be 24 | misrepresented as being the original software. 25 | 26 | 3. This notice may not be removed or altered from any source 27 | distribution. 28 | =end 29 | -------------------------------------------------------------------------------- /lib/opengl_es_ext.rb: -------------------------------------------------------------------------------- 1 | require_relative 'opengl_common' 2 | require_relative 'opengl_ext_common' 3 | require_relative 'opengl_es_ext_enum' 4 | require_relative 'opengl_es_ext_command' 5 | 6 | =begin 7 | Ruby-OpenGL : Yet another OpenGL wrapper for Ruby (and wrapper code generator) 8 | Copyright (c) 2013-2025 vaiorabbit 9 | 10 | This software is provided 'as-is', without any express or implied 11 | warranty. In no event will the authors be held liable for any damages 12 | arising from the use of this software. 13 | 14 | Permission is granted to anyone to use this software for any purpose, 15 | including commercial applications, and to alter it and redistribute it 16 | freely, subject to the following restrictions: 17 | 18 | 1. The origin of this software must not be misrepresented; you must not 19 | claim that you wrote the original software. If you use this software 20 | in a product, an acknowledgment in the product documentation would be 21 | appreciated but is not required. 22 | 23 | 2. Altered source versions must be plainly marked as such, and must not be 24 | misrepresented as being the original software. 25 | 26 | 3. This notice may not be removed or altered from any source 27 | distribution. 28 | =end 29 | -------------------------------------------------------------------------------- /sample/OrangeBook/brick.vert: -------------------------------------------------------------------------------- 1 | // 2 | // Vertex shader for procedural bricks 3 | // 4 | // Authors: Dave Baldwin, Steve Koren, Randi Rost 5 | // based on a shader by Darwyn Peachey 6 | // 7 | // Copyright (c) 2002-2004 3Dlabs Inc. Ltd. 8 | // 9 | // See 3Dlabs-License.txt for license information 10 | // 11 | 12 | uniform vec3 LightPosition; 13 | 14 | const float SpecularContribution = 0.3; 15 | const float DiffuseContribution = 1.0 - SpecularContribution; 16 | 17 | varying float LightIntensity; 18 | varying vec2 MCposition; 19 | 20 | void main(void) 21 | { 22 | vec3 ecPosition = vec3 (gl_ModelViewMatrix * gl_Vertex); 23 | vec3 tnorm = normalize(gl_NormalMatrix * gl_Normal); 24 | vec3 lightVec = normalize(LightPosition - ecPosition); 25 | vec3 reflectVec = reflect(-lightVec, tnorm); 26 | vec3 viewVec = normalize(-ecPosition); 27 | float diffuse = max(dot(lightVec, tnorm), 0.0); 28 | float spec = 0.0; 29 | 30 | if (diffuse > 0.0) 31 | { 32 | spec = max(dot(reflectVec, viewVec), 0.0); 33 | spec = pow(spec, 16.0); 34 | } 35 | 36 | LightIntensity = DiffuseContribution * diffuse + 37 | SpecularContribution * spec; 38 | 39 | MCposition = gl_Vertex.xy; 40 | gl_Position = ftransform(); 41 | } -------------------------------------------------------------------------------- /lib/opengl_es.rb: -------------------------------------------------------------------------------- 1 | require_relative 'opengl_platform' 2 | require_relative 'opengl_common' 3 | require_relative 'opengl_es_enum' 4 | require_relative 'opengl_es_command' 5 | if GL.get_platform == :OPENGL_PLATFORM_WINDOWS 6 | require_relative 'opengl_windows' 7 | end 8 | 9 | =begin 10 | Ruby-OpenGL : Yet another OpenGL wrapper for Ruby (and wrapper code generator) 11 | Copyright (c) 2013-2025 vaiorabbit 12 | 13 | This software is provided 'as-is', without any express or implied 14 | warranty. In no event will the authors be held liable for any damages 15 | arising from the use of this software. 16 | 17 | Permission is granted to anyone to use this software for any purpose, 18 | including commercial applications, and to alter it and redistribute it 19 | freely, subject to the following restrictions: 20 | 21 | 1. The origin of this software must not be misrepresented; you must not 22 | claim that you wrote the original software. If you use this software 23 | in a product, an acknowledgment in the product documentation would be 24 | appreciated but is not required. 25 | 26 | 2. Altered source versions must be plainly marked as such, and must not be 27 | misrepresented as being the original software. 28 | 29 | 3. This notice may not be removed or altered from any source 30 | distribution. 31 | =end 32 | -------------------------------------------------------------------------------- /.github/workflows/generate.yml: -------------------------------------------------------------------------------- 1 | name: Update schema and regenerate codes 2 | 3 | on: 4 | workflow_dispatch: 5 | inputs: 6 | branch: 7 | description: 'branch name' 8 | default: 'version/2.0' 9 | required: true 10 | 11 | jobs: 12 | build: 13 | permissions: 14 | contents: write 15 | runs-on: ubuntu-latest 16 | strategy: 17 | fail-fast: false 18 | max-parallel: 1 19 | 20 | steps: 21 | - name: Setup Ruby 22 | uses: ruby/setup-ruby@v1 23 | with: 24 | ruby-version: "3.2" 25 | 26 | - name: Checkout 27 | uses: actions/checkout@v3 28 | with: 29 | ref: "${{ github.event.inputs.branch }}" 30 | fetch-depth: 1 31 | submodules: recursive 32 | 33 | - name: Run rebuild script 34 | run: | 35 | which ruby 36 | which gem 37 | which rake 38 | cd ${GITHUB_WORKSPACE}/generator 39 | curl -O https://raw.githubusercontent.com/KhronosGroup/OpenGL-Registry/master/xml/gl.xml 40 | ls -al 41 | rake clean 42 | rake 43 | cd ${GITHUB_WORKSPACE} 44 | 45 | - name: Commit new libraries 46 | continue-on-error: true 47 | run: | 48 | git config user.name "${GITHUB_ACTOR}" 49 | git config user.email "${GITHUB_ACTOR}" 50 | git commit -a -m "commit by ${GITHUB_ACTOR} via GitHub Actions" 51 | git push --force-with-lease -u origin "${{ github.event.inputs.branch }}" 52 | -------------------------------------------------------------------------------- /lib/opengl.rb: -------------------------------------------------------------------------------- 1 | require_relative 'opengl_platform' 2 | require_relative 'opengl_common' 3 | require_relative 'opengl_enum' 4 | require_relative 'opengl_command' 5 | case GL.get_platform 6 | when :OPENGL_PLATFORM_WINDOWS 7 | require_relative 'opengl_windows' 8 | when :OPENGL_PLATFORM_MACOSX 9 | require_relative 'opengl_macosx' 10 | when :OPENGL_PLATFORM_LINUX 11 | require_relative 'opengl_linux' 12 | end 13 | 14 | =begin 15 | Ruby-OpenGL : Yet another OpenGL wrapper for Ruby (and wrapper code generator) 16 | Copyright (c) 2013-2025 vaiorabbit 17 | 18 | This software is provided 'as-is', without any express or implied 19 | warranty. In no event will the authors be held liable for any damages 20 | arising from the use of this software. 21 | 22 | Permission is granted to anyone to use this software for any purpose, 23 | including commercial applications, and to alter it and redistribute it 24 | freely, subject to the following restrictions: 25 | 26 | 1. The origin of this software must not be misrepresented; you must not 27 | claim that you wrote the original software. If you use this software 28 | in a product, an acknowledgment in the product documentation would be 29 | appreciated but is not required. 30 | 31 | 2. Altered source versions must be plainly marked as such, and must not be 32 | misrepresented as being the original software. 33 | 34 | 3. This notice may not be removed or altered from any source 35 | distribution. 36 | =end 37 | -------------------------------------------------------------------------------- /sample/OrangeBook/3Dlabs-License.txt: -------------------------------------------------------------------------------- 1 | Copyright (C) 2002-2005 3Dlabs Inc. Ltd. 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions 6 | are met: 7 | 8 | Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | 11 | Redistributions in binary form must reproduce the above 12 | copyright notice, this list of conditions and the following 13 | disclaimer in the documentation and/or other materials provided 14 | with the distribution. 15 | 16 | Neither the name of 3Dlabs Inc. Ltd. nor the names of its 17 | contributors may be used to endorse or promote products derived 18 | from this software without specific prior written permission. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 23 | FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 24 | COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 25 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 26 | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 27 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 28 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 30 | ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31 | POSSIBILITY OF SUCH DAMAGE. 32 | 33 | 34 | -------------------------------------------------------------------------------- /lib/opengl_platform.rb: -------------------------------------------------------------------------------- 1 | require 'rbconfig' 2 | 3 | module GL 4 | @@opengl_platform = case RbConfig::CONFIG['host_os'] 5 | when /mswin|msys|mingw|cygwin/ 6 | :OPENGL_PLATFORM_WINDOWS 7 | when /darwin/ 8 | :OPENGL_PLATFORM_MACOSX 9 | when /linux/ 10 | :OPENGL_PLATFORM_LINUX 11 | else 12 | raise RuntimeError, "OpenGL : Unknown OS: #{host_os.inspect}" 13 | end 14 | 15 | def self.get_platform() 16 | return @@opengl_platform 17 | end 18 | 19 | end 20 | 21 | =begin 22 | Ruby-OpenGL : Yet another OpenGL wrapper for Ruby (and wrapper code generator) 23 | Copyright (c) 2013-2025 vaiorabbit 24 | 25 | This software is provided 'as-is', without any express or implied 26 | warranty. In no event will the authors be held liable for any damages 27 | arising from the use of this software. 28 | 29 | Permission is granted to anyone to use this software for any purpose, 30 | including commercial applications, and to alter it and redistribute it 31 | freely, subject to the following restrictions: 32 | 33 | 1. The origin of this software must not be misrepresented; you must not 34 | claim that you wrote the original software. If you use this software 35 | in a product, an acknowledgment in the product documentation would be 36 | appreciated but is not required. 37 | 38 | 2. Altered source versions must be plainly marked as such, and must not be 39 | misrepresented as being the original software. 40 | 41 | 3. This notice may not be removed or altered from any source 42 | distribution. 43 | =end 44 | -------------------------------------------------------------------------------- /sample/GLUT/glut_font.rb: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | require_relative '../util/setup_dll' 3 | require 'opengl' 4 | require 'glu' 5 | require 'glut' 6 | 7 | def display 8 | GL.Clear(GL::COLOR_BUFFER_BIT | GL::DEPTH_BUFFER_BIT) 9 | 10 | GL.Color3f(0.0, 1.0, 0.0) 11 | messages = ["opengl-bindings", "http://rubygems.org/gems/opengl-bindings", "http://github.com/vaiorabbit/ruby-opengl"] 12 | messages.each_with_index do |m, i| 13 | GL.RasterPos2i(10, 45 - 15 * i) 14 | m.each_char do |c| 15 | GLUT.BitmapCharacter(GLUT::BITMAP_9_BY_15, c.ord) 16 | end 17 | end 18 | 19 | GLUT.SwapBuffers() 20 | end 21 | 22 | def reshape(width, height) 23 | GL.Viewport(0, 0, width, height) 24 | 25 | GL.MatrixMode(GL::PROJECTION) 26 | GL.LoadIdentity() 27 | GLU.Ortho2D(0.0, width.to_f, 0.0, height.to_f) 28 | 29 | GL.MatrixMode(GL::MODELVIEW) 30 | GL.LoadIdentity() 31 | end 32 | 33 | def keyboard(key, x, y) 34 | exit if key == 27 # Press ESC to exit. 35 | end 36 | 37 | if __FILE__ == $PROGRAM_NAME 38 | GLUT.load_lib(SampleUtil.glut_library_path) 39 | GLUT.Init([1].pack('I'), [""].pack('p')) 40 | GLUT.InitDisplayMode(GLUT::DOUBLE | GLUT::RGBA | GLUT::DEPTH) 41 | GLUT.InitWindowSize(500, 100) 42 | GLUT.InitWindowPosition(100, 100) 43 | GLUT.CreateWindow("test") 44 | GL.load_lib() 45 | GLU.load_lib() 46 | GLUT.DisplayFunc(GLUT.create_callback(:GLUTDisplayFunc, method(:display).to_proc)) 47 | GLUT.ReshapeFunc(GLUT.create_callback(:GLUTReshapeFunc, method(:reshape).to_proc)) 48 | GLUT.KeyboardFunc(GLUT.create_callback(:GLUTKeyboardFunc, method(:keyboard).to_proc)) 49 | 50 | 51 | GL.ClearColor(0.0, 0.0, 0.0, 1) 52 | 53 | GL.Enable(GL::DEPTH_TEST) 54 | GL.DepthFunc(GL::LESS) 55 | 56 | GLUT.MainLoop() 57 | end 58 | -------------------------------------------------------------------------------- /sample/util/setup_dll.rb: -------------------------------------------------------------------------------- 1 | module SampleUtil 2 | 3 | def self.gl_library_path() 4 | case GL.get_platform 5 | when :OPENGL_PLATFORM_WINDOWS 6 | 'C:/Windows/System32/opengl32.dll' 7 | when :OPENGL_PLATFORM_MACOSX 8 | '/System/Library/Frameworks/OpenGL.framework/Libraries/libGL.dylib' 9 | when :OPENGL_PLATFORM_LINUX 10 | '/usr/lib/x86_64-linux-gnu/libGL.so' 11 | else 12 | raise RuntimeError, "Unsupported platform." 13 | end 14 | end 15 | 16 | def self.glu_library_path() 17 | case GL.get_platform 18 | when :OPENGL_PLATFORM_WINDOWS 19 | 'C:/Windows/System32/GLU32.dll' 20 | when :OPENGL_PLATFORM_MACOSX 21 | '/System/Library/Frameworks/OpenGL.framework/Libraries/libGLU.dylib' 22 | when :OPENGL_PLATFORM_LINUX 23 | '/usr/lib/x86_64-linux-gnu/libGLU.so' 24 | else 25 | raise RuntimeError, "Unsupported platform." 26 | end 27 | end 28 | 29 | def self.glut_library_path() 30 | case GL.get_platform 31 | when :OPENGL_PLATFORM_WINDOWS 32 | Dir.pwd + '/../freeglut.dll' 33 | when :OPENGL_PLATFORM_MACOSX 34 | '/System/Library/Frameworks/GLUT.framework/GLUT' 35 | when :OPENGL_PLATFORM_LINUX 36 | 'libglut.so' # not tested 37 | else 38 | raise RuntimeError, "Unsupported platform." 39 | end 40 | end 41 | 42 | def self.glfw_library_path() 43 | case GL.get_platform 44 | when :OPENGL_PLATFORM_WINDOWS 45 | Dir.pwd + '/../glfw3.dll' 46 | when :OPENGL_PLATFORM_MACOSX 47 | '../libglfw.dylib' 48 | when :OPENGL_PLATFORM_LINUX 49 | '/usr/lib/x86_64-linux-gnu/libglfw.so.3' 50 | else 51 | raise RuntimeError, "Unsupported platform." 52 | end 53 | end 54 | 55 | end 56 | -------------------------------------------------------------------------------- /sample/simple.rb: -------------------------------------------------------------------------------- 1 | # 2 | # For more samples, visit https://github.com/vaiorabbit/ruby-opengl/tree/master/sample . 3 | # 4 | # Ref.: /glfw-3.0.1/examples/simple.c 5 | # 6 | require 'opengl' 7 | require 'glfw' 8 | 9 | # Press ESC to exit. 10 | key_callback = GLFW::create_callback(:GLFWkeyfun) do |window, key, scancode, action, mods| 11 | GLFW.SetWindowShouldClose(window, 1) if key == GLFW::KEY_ESCAPE && action == GLFW::PRESS 12 | end 13 | 14 | if __FILE__ == $PROGRAM_NAME 15 | GLFW.load_lib() # Give path to "glfw3.dll (Windows)" or "libglfw.dylib (macOS)" if needed 16 | GLFW.Init() 17 | 18 | window = GLFW.CreateWindow(640, 480, "Simple example", nil, nil) 19 | GLFW.MakeContextCurrent(window) 20 | GLFW.SetKeyCallback(window, key_callback) 21 | 22 | GL.load_lib() # Call GL.load_lib after OpenGL context is available 23 | 24 | width_buf = ' ' * 8 25 | height_buf = ' ' * 8 26 | until GLFW.WindowShouldClose(window) == GLFW::TRUE 27 | GLFW.GetFramebufferSize(window, width_buf, height_buf) 28 | width = width_buf.unpack1('L') 29 | height = height_buf.unpack1('L') 30 | ratio = width.to_f / height.to_f 31 | 32 | GL.Viewport(0, 0, width, height) 33 | GL.Clear(GL::COLOR_BUFFER_BIT) 34 | GL.MatrixMode(GL::PROJECTION) 35 | GL.LoadIdentity() 36 | GL.Ortho(-ratio, ratio, -1.0, 1.0, 1.0, -1.0) 37 | GL.MatrixMode(GL::MODELVIEW) 38 | 39 | GL.LoadIdentity() 40 | GL.Rotatef(GLFW.GetTime() * 50.0, 0.0, 0.0, 1.0) 41 | 42 | GL.Begin(GL::TRIANGLES) 43 | GL.Color3f(1.0, 0.0, 0.0) 44 | GL.Vertex3f(-0.6, -0.4, 0.0) 45 | GL.Color3f(0.0, 1.0, 0.0) 46 | GL.Vertex3f(0.6, -0.4, 0.0) 47 | GL.Color3f(0.0, 0.0, 1.0) 48 | GL.Vertex3f(0.0, 0.6, 0.0) 49 | GL.End() 50 | 51 | GLFW.SwapBuffers(window) 52 | GLFW.PollEvents() 53 | end 54 | 55 | GLFW.DestroyWindow(window) 56 | GLFW.Terminate() 57 | end 58 | -------------------------------------------------------------------------------- /sample/simple_glut.rb: -------------------------------------------------------------------------------- 1 | # 2 | # For more samples, visit https://github.com/vaiorabbit/ruby-opengl/tree/master/sample . 3 | # 4 | # Ref.: /glfw-3.0.1/examples/simple.c 5 | # 6 | require 'opengl' 7 | require 'glut' 8 | 9 | $radian = 0 10 | 11 | def display 12 | GL.Clear(GL::COLOR_BUFFER_BIT) 13 | GL.LoadIdentity() 14 | GL.Rotatef($radian * 50.0, 0.0, 0.0, 1.0) 15 | 16 | GL.Begin(GL::TRIANGLES) 17 | GL.Color3f(1.0, 0.0, 0.0) 18 | GL.Vertex3f(-0.6, -0.4, 0.0) 19 | GL.Color3f(0.0, 1.0, 0.0) 20 | GL.Vertex3f(0.6, -0.4, 0.0) 21 | GL.Color3f(0.0, 0.0, 1.0) 22 | GL.Vertex3f(0.0, 0.6, 0.0) 23 | GL.End() 24 | 25 | GLUT.SwapBuffers() 26 | end 27 | 28 | def reshape(width, height) 29 | ratio = width.to_f / height.to_f 30 | GL.Viewport(0, 0, width, height) 31 | GL.MatrixMode(GL::PROJECTION) 32 | GL.LoadIdentity() 33 | GL.Ortho(-ratio, ratio, -1.0, 1.0, 1.0, -1.0) 34 | GL.MatrixMode(GL::MODELVIEW) 35 | end 36 | 37 | def keyboard(key, x, y) 38 | exit if key == 27 # Press ESC to exit. 39 | end 40 | 41 | def timer(value) 42 | $radian += (1.0 * Math::PI / 180.0) 43 | GLUT.TimerFunc(0, GLUT.create_callback(:GLUTTimerFunc, method(:timer).to_proc), value) 44 | GLUT.PostRedisplay() 45 | end 46 | 47 | if __FILE__ == $PROGRAM_NAME 48 | GLUT.load_lib() 49 | GLUT.Init([1].pack('I'), [""].pack('p')) 50 | GLUT.InitDisplayMode(GLUT::DOUBLE | GLUT::RGBA | GLUT::DEPTH) 51 | GLUT.InitWindowSize(640, 480); 52 | GLUT.InitWindowPosition(100, 100) 53 | GLUT.CreateWindow("Simple example") 54 | GL.load_lib() 55 | GLUT.DisplayFunc(GLUT.create_callback(:GLUTDisplayFunc, method(:display).to_proc)) 56 | GLUT.ReshapeFunc(GLUT.create_callback(:GLUTReshapeFunc, method(:reshape).to_proc)) 57 | GLUT.KeyboardFunc(GLUT.create_callback(:GLUTKeyboardFunc, method(:keyboard).to_proc)) 58 | GLUT.TimerFunc(0, GLUT.create_callback(:GLUTTimerFunc, method(:timer).to_proc), 0) 59 | 60 | GL.ClearColor(0.0, 0.0, 0.0, 1) 61 | 62 | GLUT.MainLoop() 63 | end 64 | -------------------------------------------------------------------------------- /lib/opengl_ext_common.rb: -------------------------------------------------------------------------------- 1 | module GL 2 | 3 | def self.check_extension(ext_name) 4 | get_string = GL.get_command(:glGetString) # [INTERNAL] Shortcut to get pointer without proper user setup. 5 | version_number = get_string.call(GL::VERSION).to_s.split(/\./) 6 | if version_number[0].to_i >= 3 7 | # glGetString(GL_EXTENSIONS) was deprecated in OpenGL 3.0 8 | # Ref.: http://sourceforge.net/p/glew/bugs/120/ 9 | get_integerv = GL.get_command(:glGetIntegerv) 10 | get_stringi = GL.get_command(:glGetStringi) 11 | extensions_count_buf = ' ' 12 | get_integerv.call(GL::NUM_EXTENSIONS, extensions_count_buf) 13 | extensions_count = extensions_count_buf.unpack('L')[0] 14 | extensions_count.times do |i| 15 | supported_ext_name = get_stringi.call(GL::EXTENSIONS, i).to_s 16 | return true if ext_name == supported_ext_name 17 | end 18 | return false 19 | else 20 | ext_strings = get_string.call(GL::EXTENSIONS).to_s.split(/ /) 21 | return ext_strings.include? ext_name 22 | end 23 | end 24 | 25 | def self.setup_extension(ext_name, skip_check: false) 26 | if skip_check || self.check_extension(ext_name) 27 | define_ext_enum = "define_ext_enum_#{ext_name}".to_sym 28 | define_ext_command = "define_ext_command_#{ext_name}".to_sym 29 | GLExt.send(define_ext_enum) 30 | GLExt.send(define_ext_command) 31 | end 32 | end 33 | 34 | def self.setup_extension_all(skip_check: false) 35 | self.methods.each do |method_name| 36 | if method_name =~ /define_ext_command_(.*)/ 37 | setup_extension($1, skip_check) 38 | end 39 | end 40 | end 41 | 42 | def self.get_extension_enum_symbols(ext_name) 43 | get_ext_enum = "get_ext_enum_#{ext_name}".to_sym 44 | GLExt.send(get_ext_enum) 45 | end 46 | 47 | def self.get_extension_command_symbols(ext_name) 48 | get_ext_command = "get_ext_command_#{ext_name}".to_sym 49 | GLExt.send(get_ext_command) 50 | end 51 | 52 | end 53 | -------------------------------------------------------------------------------- /sample/Extension/test_dds_texture.rb: -------------------------------------------------------------------------------- 1 | require '../util/setup_dll' 2 | require 'opengl' 3 | require 'opengl_ext' 4 | require 'glfw' 5 | 6 | require_relative '../util/texture' 7 | 8 | $texture = nil 9 | 10 | # Press ESC to exit. 11 | key_callback = GLFW::create_callback(:GLFWkeyfun) do |window_handle, key, scancode, action, mods| 12 | GLFW.SetWindowShouldClose(window_handle, 1) if key == GLFW::KEY_ESCAPE && action == GLFW::PRESS 13 | end 14 | 15 | if __FILE__ == $PROGRAM_NAME 16 | GLFW.load_lib(SampleUtil.glfw_library_path) 17 | GLFW.Init() 18 | 19 | window = GLFW.CreateWindow(640, 480, "OpenGL Extension example", nil, nil) 20 | GLFW.MakeContextCurrent(window) 21 | GLFW.SetKeyCallback(window, key_callback) 22 | 23 | GL.load_lib() 24 | 25 | GL.setup_extension('GL_EXT_texture_compression_s3tc') 26 | Texture.enable_dds_support 27 | $texture = Texture.new('../data/256px-Globe.svg.dds') 28 | $texture.generate 29 | width_buf = ' ' * 8 30 | height_buf = ' ' * 8 31 | while GLFW.WindowShouldClose(window) == 0 32 | GLFW.GetFramebufferSize(window, width_buf, height_buf) 33 | width = width_buf.unpack1('L') 34 | height = height_buf.unpack1('L') 35 | ratio = width.to_f / height.to_f 36 | 37 | GL.Viewport(0, 0, width, height) 38 | GL.Clear(GL::COLOR_BUFFER_BIT) 39 | GL.MatrixMode(GL::PROJECTION) 40 | GL.LoadIdentity() 41 | GL.Ortho(-ratio, ratio, -1.0, 1.0, 1.0, -1.0) 42 | GL.MatrixMode(GL::MODELVIEW) 43 | 44 | GL.LoadIdentity() 45 | GL.Rotatef(GLFW.GetTime() * 50.0, 0.0, 0.0, 1.0) 46 | 47 | GL.Enable(GL::TEXTURE_2D) 48 | 49 | $texture.bind 50 | 51 | GL.Begin(GL::QUADS) 52 | 53 | GL.TexCoord2f(0.0, 0.0) 54 | GL.Vertex3f(-1.0, -1.0, 0.0) 55 | 56 | GL.TexCoord2f(0.0, 1.0) 57 | GL.Vertex3f(-1.0, 1.0, 0.0) 58 | 59 | GL.TexCoord2f(1.0, 1.0) 60 | GL.Vertex3f(1.0, 1.0, 0.0) 61 | 62 | GL.TexCoord2f(1.0, 0.0) 63 | GL.Vertex3f(1.0, -1.0, 0.0) 64 | 65 | GL.End() 66 | 67 | $texture.unbind 68 | 69 | GLFW.SwapBuffers(window) 70 | GLFW.PollEvents() 71 | end 72 | 73 | GLFW.DestroyWindow(window) 74 | GLFW.Terminate() 75 | end 76 | -------------------------------------------------------------------------------- /sample/README.md: -------------------------------------------------------------------------------- 1 | For more samples, visit https://github.com/vaiorabbit/ruby-opengl/tree/master/sample . 2 | 3 | ## Getting GLFW (http://www.glfw.org) ## 4 | 5 | * Windows 6 | * Put glfw3.dll here. You can download pre-compiled binaries via: 7 | * http://www.glfw.org/download.html 8 | * If you have RubyInstaller2 with DevKit(MSYS2 gcc & make) and CMake, you can use glfw_build.bat: 9 | * > ./glfw_build.bat 10 | 11 | * Mac OS X 12 | * Run ./glfw_build.sh to get ./libglfw.dylib. 13 | 14 | ## Getting GLUT ## 15 | 16 | * Windows 17 | * Use freeglut (http://freeglut.sourceforge.net). 18 | * See https://sourceforge.net/p/freeglut/code/HEAD/tree/trunk/freeglut/freeglut/COPYING for copyright information 19 | * Put freeglut.dll here. 20 | * Windows pre-compiled binaries: 21 | * http://www.transmissionzero.co.uk/software/freeglut-devel/ 22 | 23 | * Mac OS X 24 | * glut.rb refers /System/Library/Frameworks/GLUT.framework by default. 25 | * If you want to use other GLUT dll, specify the dll path and file name 26 | via the arguments of 'GLUT.load_dll'. 27 | * See util/setup_dll.rb for example. 28 | * https://github.com/vaiorabbit/ruby-opengl/blob/master/sample/util/setup_dll.rb 29 | 30 | ------------------------------------------------------------------------------- 31 | 32 | ## GLFWのセットアップ (http://www.glfw.org) ## 33 | 34 | * Windows 35 | * glfw3.dll をここに配置してください。コンパイル済みバイナリはこちら: 36 | * http://www.glfw.org/download.html 37 | * RubyInstaller2 とその DevKit(MSYS2 gcc & make)、さらに CMake もインストールしている場合は glfw_build.bat も使えます: 38 | * > ./glfw_build.bat 39 | 40 | * Mac OS X 41 | * ./glfw_build.sh を実行すると ./libglfw.dylib ができあがります。 42 | 43 | ## GLUTのセットアップ ## 44 | 45 | * Windows 46 | * freeglut を使ってください (http://freeglut.sourceforge.net). 47 | * freeglut.dll をここに配置してください。 48 | * コンパイル済みバイナリはこちら: 49 | * http://www.transmissionzero.co.uk/software/freeglut-devel/ 50 | 51 | * Mac OS X 52 | * glut.rb はデフォルトで /System/Library/Frameworks/GLUT.framework を使います。 53 | * もしこれとは別のGLUTを使いたい場合は 'GLUT.load_dll' の引数で指定してください。 54 | * util/setup_dll.rb が使用例となっています。 55 | * https://github.com/vaiorabbit/ruby-opengl/blob/master/sample/util/setup_dll.rb 56 | -------------------------------------------------------------------------------- /sample/teapot.rb: -------------------------------------------------------------------------------- 1 | # Ref.: /glfw-3.0.1/examples/simple.c 2 | require 'opengl' 3 | require 'glfw' 4 | require 'glu' 5 | require_relative 'util/WavefrontOBJ' 6 | require_relative 'util/setup_dll' 7 | 8 | key_callback = GLFW::create_callback(:GLFWkeyfun) do |window_handle, key, scancode, action, mods| 9 | if key == GLFW::KEY_ESCAPE && action == GLFW::PRESS 10 | GLFW.SetWindowShouldClose(window_handle, 1) 11 | end 12 | end 13 | 14 | size_callback = GLFW::create_callback(:GLFWwindowsizefun) do |window_handle, w, h| 15 | ratio = w.to_f / h.to_f 16 | GL.Viewport(0, 0, w, h) 17 | GL.MatrixMode(GL::PROJECTION) 18 | GL.LoadIdentity() 19 | GLU.Perspective(45.0, ratio, 1.0, 1000.0) 20 | GL.MatrixMode(GL::MODELVIEW) 21 | end 22 | 23 | def init(window) 24 | GL.Enable(GL::DEPTH_TEST) 25 | 26 | GL.Enable(GL::LIGHTING) 27 | GL.Enable(GL::LIGHT0) 28 | 29 | light0_ambient = [0.8, 0.8, 0.8, 1.0] 30 | light0_position = [0.0, 0.0, 2.0, 1.0] 31 | 32 | GL.Lightfv(GL::LIGHT0, GL::AMBIENT, light0_ambient.pack('F*')) 33 | GL.Lightfv(GL::LIGHT0, GL::POSITION, light0_position.pack('F*')) 34 | end 35 | 36 | if __FILE__ == $PROGRAM_NAME 37 | GLFW.load_lib(Dir.pwd + '/glfw3.dll') 38 | GLFW.Init() 39 | 40 | window = GLFW.CreateWindow(640, 480, $0, nil, nil) 41 | GLFW.MakeContextCurrent(window) 42 | GLFW.SetKeyCallback(window, key_callback) 43 | GLFW.SetWindowSizeCallback(window, size_callback) 44 | 45 | GL.load_lib() 46 | GLU.load_lib() 47 | 48 | init(window) 49 | 50 | width_ptr = ' ' * 4 51 | height_ptr = ' ' * 4 52 | GLFW.GetFramebufferSize(window, width_ptr, height_ptr) 53 | width = width_ptr.unpack('L')[0] 54 | height = height_ptr.unpack('L')[0] 55 | size_callback.call(window, width, height) 56 | 57 | teapot = WavefrontOBJ::Model.new 58 | teapot.parse('data/teapot.obj') 59 | teapot.setup 60 | 61 | while GLFW.WindowShouldClose(window) == 0 62 | GL.Clear(GL::COLOR_BUFFER_BIT | GL::DEPTH_BUFFER_BIT) 63 | 64 | GL.LoadIdentity() 65 | GL.Translatef(0.0, 0.0, -50.0) 66 | GL.Rotatef(GLFW.GetTime() * 50.0, 0.0, 1.0, 0.0) 67 | 68 | teapot.render 69 | 70 | GLFW.SwapBuffers(window) 71 | GLFW.PollEvents() 72 | end 73 | 74 | GLFW.DestroyWindow(window) 75 | GLFW.Terminate() 76 | end 77 | -------------------------------------------------------------------------------- /lib/opengl_linux.rb: -------------------------------------------------------------------------------- 1 | require 'fiddle' 2 | 3 | module GL 4 | 5 | GLX_FUNCTIONS_MAP = {} 6 | GLX_FUNCTIONS_ARGS_MAP = {} 7 | GLX_FUNCTIONS_RETVAL_MAP = {} 8 | 9 | def self.get_glx_command(sym) 10 | if GLX_FUNCTIONS_MAP[sym] == nil 11 | bind_glx_command(sym) 12 | end 13 | return GLX_FUNCTIONS_MAP[sym] 14 | end 15 | 16 | def self.bind_glx_command(sym) 17 | GLX_FUNCTIONS_MAP[sym] = Fiddle::Function.new(@@gl_dll[sym.to_s], 18 | GLX_FUNCTIONS_ARGS_MAP[sym], 19 | GLX_FUNCTIONS_RETVAL_MAP[sym]) 20 | raise RuntimeError if GLX_FUNCTIONS_RETVAL_MAP[sym] == nil 21 | end 22 | 23 | GLX_FUNCTIONS_ARGS_MAP[:glXGetCurrentContext] = [] 24 | GLX_FUNCTIONS_RETVAL_MAP[:glXGetCurrentContext] = Fiddle::TYPE_VOIDP 25 | 26 | def glXGetCurrentContext() 27 | f = GL::get_glx_command(:glXGetCurrentContext) 28 | f.call() 29 | end 30 | 31 | GLX_FUNCTIONS_ARGS_MAP[:glXGetCurrentDisplay] = [Fiddle::TYPE_VOIDP] 32 | GLX_FUNCTIONS_RETVAL_MAP[:glXGetCurrentDisplay] = Fiddle::TYPE_VOIDP 33 | 34 | def glXGetCurrentDisplay(_glx_ctxobj_) 35 | f = GL::get_glx_command(:glXGetCurrentDisplay) 36 | f.call(_glx_ctxobj_) 37 | end 38 | 39 | end 40 | 41 | =begin 42 | Ruby-OpenGL : Yet another OpenGL wrapper for Ruby (and wrapper code generator) 43 | Copyright (c) 2013-2025 vaiorabbit 44 | 45 | This software is provided 'as-is', without any express or implied 46 | warranty. In no event will the authors be held liable for any damages 47 | arising from the use of this software. 48 | 49 | Permission is granted to anyone to use this software for any purpose, 50 | including commercial applications, and to alter it and redistribute it 51 | freely, subject to the following restrictions: 52 | 53 | 1. The origin of this software must not be misrepresented; you must not 54 | claim that you wrote the original software. If you use this software 55 | in a product, an acknowledgment in the product documentation would be 56 | appreciated but is not required. 57 | 58 | 2. Altered source versions must be plainly marked as such, and must not be 59 | misrepresented as being the original software. 60 | 61 | 3. This notice may not be removed or altered from any source 62 | distribution. 63 | =end 64 | -------------------------------------------------------------------------------- /lib/opengl_macosx.rb: -------------------------------------------------------------------------------- 1 | require 'fiddle' 2 | 3 | module GL 4 | 5 | CGL_FUNCTIONS_MAP = {} 6 | CGL_FUNCTIONS_ARGS_MAP = {} 7 | CGL_FUNCTIONS_RETVAL_MAP = {} 8 | 9 | @@cgl_dll = nil 10 | 11 | def self.get_cgl_command(sym) 12 | if @@cgl_dll == nil 13 | @@cgl_dll = Fiddle.dlopen('/System/Library/Frameworks/OpenGL.framework/OpenGL') 14 | end 15 | if CGL_FUNCTIONS_MAP[sym] == nil 16 | bind_cgl_command(sym) 17 | end 18 | return CGL_FUNCTIONS_MAP[sym] 19 | end 20 | 21 | def self.bind_cgl_command(sym) 22 | CGL_FUNCTIONS_MAP[sym] = Fiddle::Function.new(@@cgl_dll[sym.to_s], 23 | CGL_FUNCTIONS_ARGS_MAP[sym], 24 | CGL_FUNCTIONS_RETVAL_MAP[sym]) 25 | raise RuntimeError if CGL_FUNCTIONS_RETVAL_MAP[sym] == nil 26 | end 27 | 28 | CGL_FUNCTIONS_ARGS_MAP[:CGLGetCurrentContext] = [] 29 | CGL_FUNCTIONS_RETVAL_MAP[:CGLGetCurrentContext] = Fiddle::TYPE_VOIDP 30 | 31 | def CGLGetCurrentContext() 32 | f = GL::get_cgl_command(:CGLGetCurrentContext) 33 | f.call() 34 | end 35 | 36 | CGL_FUNCTIONS_ARGS_MAP[:CGLGetShareGroup] = [Fiddle::TYPE_VOIDP] 37 | CGL_FUNCTIONS_RETVAL_MAP[:CGLGetShareGroup] = Fiddle::TYPE_VOIDP 38 | 39 | def CGLGetShareGroup(_cgl_ctxobj_) 40 | f = GL::get_cgl_command(:CGLGetShareGroup) 41 | f.call(_cgl_ctxobj_) 42 | end 43 | 44 | end 45 | 46 | =begin 47 | Ruby-OpenGL : Yet another OpenGL wrapper for Ruby (and wrapper code generator) 48 | Copyright (c) 2013-2025 vaiorabbit 49 | 50 | This software is provided 'as-is', without any express or implied 51 | warranty. In no event will the authors be held liable for any damages 52 | arising from the use of this software. 53 | 54 | Permission is granted to anyone to use this software for any purpose, 55 | including commercial applications, and to alter it and redistribute it 56 | freely, subject to the following restrictions: 57 | 58 | 1. The origin of this software must not be misrepresented; you must not 59 | claim that you wrote the original software. If you use this software 60 | in a product, an acknowledgment in the product documentation would be 61 | appreciated but is not required. 62 | 63 | 2. Altered source versions must be plainly marked as such, and must not be 64 | misrepresented as being the original software. 65 | 66 | 3. This notice may not be removed or altered from any source 67 | distribution. 68 | =end 69 | -------------------------------------------------------------------------------- /sample/GLExcess/README.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | # GLExcess / Ruby # 4 | 5 | This is a Ruby port of GLExcess (http://www.glexcess.com/), 6 | a Paolo Martella's excellent OpenGL demo project. 7 | 8 | All source codes are available under the terms of the GNU General 9 | Public License version 2 (see GPL2.txt). 10 | 11 | For ruby-opengl2 (https://rubygems.org/gems/ruby-opengl2) version, 12 | See http://code.google.com/p/glexcess-ruby . 13 | 14 | 15 | ## Usage ## 16 | 17 | $ ruby glxs.rb [options] 18 | 19 | -s, --scene : Scene ID [1-12] 20 | 21 | ex.) To begin the progmram from Scene 11 (closing credits), 22 | 23 | X:\> ruby glxs.rb -s 11 24 | or 25 | X:\> ruby glxs.rb --scene=11 26 | 27 | ## Keyboard Operation ## 28 | 29 | * 'q' or 'Esc' : quit the program. 30 | * 'a' : increment the step of time (@step += 1) 31 | * 'z' : decrement the step of time (@step -= 1) 32 | * 's' : suspend / resume 33 | * 'n' : next scene 34 | * 'p' : previous scene 35 | 36 | Unfortunately, this Ruby version runs slow. I recommend you to hit 'a' repeatedly. 37 | 38 | ## Original Copyright Notice ## 39 | 40 | 41 | GLExcess v1.0 Demo 42 | Copyright (C) 2001-2003 Paolo Martella 43 | 44 | This program is free software; you can redistribute it and/or 45 | modify it under the terms of the GNU General Public License 46 | as published by the Free Software Foundation; either version 2 47 | of the License, or (at your option) any later version. 48 | 49 | This program is distributed in the hope that it will be useful, 50 | but WITHOUT ANY WARRANTY; without even the implied warranty of 51 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 52 | GNU General Public License for more details. 53 | 54 | ------------------------------------------------------------------------------- 55 | 56 | # GLExcess / Ruby # 57 | 58 | * Paolo Martella 氏の OpenGL デモ・ GL Excess の Ruby 移植です。 59 | * このフォルダ以下の配布物は GNU General Public License Version 2 で利用可能です。 60 | * 2009年頃に作った ruby-opengl2 版が欲しい場合は http://code.google.com/p/glexcess-ruby へどうぞ。 61 | 62 | 63 | ## 使い方 ## 64 | 65 | $ ruby glxs.rb [options] 66 | 67 | -s, --scene : Scene ID [1-12] 68 | 69 | このデモにある12個のシーンのうち、どこから始めるかを指定します。 70 | 71 | ## キーボード操作 ## 72 | 73 | * 'q' or 'Esc' : 終了 74 | * 'a' : 時間ステップを大きくする (@step += 1) 75 | * 'z' : 時間ステップを小さくする (@step -= 1) 76 | * 's' : 一時停止切り替え 77 | * 'n' : 次のシーンへ 78 | * 'p' : 前のシーンへ 79 | 80 | 残念ながらこのRuby版デモは動作が遅いです。'a'を連射する方向でよろしくお願いします。 81 | -------------------------------------------------------------------------------- /sample/Gosu/lesson01.rb: -------------------------------------------------------------------------------- 1 | # Ref.: https://github.com/tjbladez/gosu-opengl-tutorials/blob/master/lessons/lesson01.rb 2 | # Usage: 3 | # > gem install gosu 4 | # > ruby lesson01.rb 5 | 6 | require '../util/setup_dll' 7 | require 'opengl' 8 | require 'glu' 9 | require 'gosu' 10 | 11 | class Window < Gosu::Window 12 | def initialize 13 | GL.load_lib() 14 | GLU.load_lib() 15 | super(800, 600, false) 16 | self.caption = "Lesson #1 - Texture Loading" 17 | texture = Gosu::Image.new(self, "../data/256px-Globe.svg.png", true) 18 | @texture_info = texture.gl_tex_info #helper structure that contains image data 19 | end 20 | 21 | def update 22 | end 23 | 24 | def draw 25 | gl do 26 | GL.Clear(GL::COLOR_BUFFER_BIT | GL::DEPTH_BUFFER_BIT) # clear the screen and the depth buffer 27 | 28 | #glMatrixMode(matrix) indicates that following [matrix] is going to get used 29 | GL.MatrixMode(GL::PROJECTION) # The projection matrix is responsible for adding perspective to our scene. 30 | GL.LoadIdentity # Resets current modelview matrix 31 | 32 | # Calculates aspect ratio of the window. Gets perspective view. 45 is degree viewing angle, (0.1, 100) are ranges how deep can we draw into the screen 33 | GLU.Perspective(45.0, width / height, 0.1, 100.0) 34 | GL.MatrixMode(GL::MODELVIEW) # The modelview matrix is where object information is stored. 35 | GL.LoadIdentity 36 | # Think 3-d coordinate system (x,y,z). +- on each movies on that axis 37 | GL.Translatef(0, 0, -2) # Moving function from the current point by x,y,z change 38 | 39 | GL.Enable(GL::TEXTURE_2D) # enables two-dimensional texturing to perform 40 | GL.BindTexture(GL::TEXTURE_2D, @texture_info.tex_name) # bing named texture to a target 41 | 42 | GL.Begin(GL::QUADS) # begin drawing model 43 | GL.TexCoord2d(@texture_info.left, @texture_info.top) #sets texture coordinates 44 | GL.Vertex3d(0, 0, 0) # place a point at (x,y,z) location from the current point 45 | GL.TexCoord2d(@texture_info.right, @texture_info.top) 46 | GL.Vertex3d(0.5, 0, 0) 47 | GL.TexCoord2d(@texture_info.right, @texture_info.bottom) 48 | GL.Vertex3d(0.5, -0.5, 0) 49 | GL.TexCoord2d(@texture_info.left, @texture_info.bottom) 50 | GL.Vertex3d(0, -0.5, 0) 51 | GL.End 52 | end 53 | end 54 | 55 | def button_down(id) 56 | if id == Gosu::KbEscape 57 | close 58 | end 59 | end 60 | end 61 | 62 | window = Window.new 63 | window.show 64 | -------------------------------------------------------------------------------- /lib/opengl_windows.rb: -------------------------------------------------------------------------------- 1 | require 'fiddle' 2 | 3 | module GL 4 | 5 | WGL_FUNCTIONS_MAP = {} 6 | WGL_FUNCTIONS_ARGS_MAP = {} 7 | WGL_FUNCTIONS_RETVAL_MAP = {} 8 | 9 | def self.get_wgl_command(sym) 10 | if WGL_FUNCTIONS_MAP[sym] == nil 11 | bind_wgl_command(sym) 12 | end 13 | return WGL_FUNCTIONS_MAP[sym] 14 | end 15 | 16 | def self.bind_wgl_command(sym) 17 | WGL_FUNCTIONS_MAP[sym] = Fiddle::Function.new(@@gl_dll[sym.to_s], 18 | WGL_FUNCTIONS_ARGS_MAP[sym], 19 | WGL_FUNCTIONS_RETVAL_MAP[sym]) 20 | raise RuntimeError if WGL_FUNCTIONS_RETVAL_MAP[sym] == nil 21 | end 22 | 23 | WGL_FUNCTIONS_ARGS_MAP[:wglGetProcAddress] = [Fiddle::TYPE_VOIDP] 24 | WGL_FUNCTIONS_RETVAL_MAP[:wglGetProcAddress] = Fiddle::TYPE_VOIDP 25 | 26 | def self.wglGetProcAddress(_lpszProc_) 27 | f = GL::get_wgl_command(:wglGetProcAddress) 28 | f.call(_lpszProc_) 29 | end 30 | 31 | WGL_FUNCTIONS_ARGS_MAP[:wglGetCurrentContext] = [] 32 | WGL_FUNCTIONS_RETVAL_MAP[:wglGetCurrentContext] = Fiddle::TYPE_VOIDP 33 | 34 | def wglGetCurrentContext() 35 | f = GL::get_wgl_command(:wglGetCurrentContext) 36 | f.call() 37 | end 38 | 39 | WGL_FUNCTIONS_ARGS_MAP[:wglGetCurrentDC] = [] 40 | WGL_FUNCTIONS_RETVAL_MAP[:wglGetCurrentDC] = Fiddle::TYPE_VOIDP 41 | 42 | def wglGetCurrentDC() 43 | f = GL::get_wgl_command(:wglGetCurrentDC) 44 | f.call() 45 | end 46 | 47 | end 48 | 49 | =begin 50 | Ruby-OpenGL : Yet another OpenGL wrapper for Ruby (and wrapper code generator) 51 | Copyright (c) 2013-2025 vaiorabbit 52 | 53 | This software is provided 'as-is', without any express or implied 54 | warranty. In no event will the authors be held liable for any damages 55 | arising from the use of this software. 56 | 57 | Permission is granted to anyone to use this software for any purpose, 58 | including commercial applications, and to alter it and redistribute it 59 | freely, subject to the following restrictions: 60 | 61 | 1. The origin of this software must not be misrepresented; you must not 62 | claim that you wrote the original software. If you use this software 63 | in a product, an acknowledgment in the product documentation would be 64 | appreciated but is not required. 65 | 66 | 2. Altered source versions must be plainly marked as such, and must not be 67 | misrepresented as being the original software. 68 | 69 | 3. This notice may not be removed or altered from any source 70 | distribution. 71 | =end 72 | -------------------------------------------------------------------------------- /sample/report_env.rb: -------------------------------------------------------------------------------- 1 | # coding: utf-8 2 | # 3 | # opengl-bindings 4 | # * http://rubygems.org/gems/opengl-bindings 5 | # * http://github.com/vaiorabbit/ruby-opengl 6 | # 7 | require 'opengl' 8 | require 'glfw' 9 | 10 | if __FILE__ == $PROGRAM_NAME 11 | 12 | GLFW.load_lib() 13 | GLFW.Init() 14 | 15 | window = nil 16 | 17 | # https://www.opengl.org/wiki/History_of_OpenGL 18 | versions = [[4, 5], [4, 4], [4, 3], [4, 2], [4, 1], [4, 0], 19 | [3, 3], [3, 2], [3, 1], [3, 0], 20 | [2, 1], [2, 0], 21 | [1, 5], [1, 4], [1, 3], [1, 2], [1, 1], [1, 0]] 22 | 23 | versions.each do |version| 24 | ver_major = version[0] 25 | ver_minor = version[1] 26 | GLFW.DefaultWindowHints() 27 | if GL.get_platform == :OPENGL_PLATFORM_MACOSX 28 | GLFW.WindowHint(GLFW::OPENGL_FORWARD_COMPAT, GLFW::TRUE) 29 | end 30 | if ver_major >= 4 || (ver_major >= 3 && ver_minor >= 2) 31 | GLFW.WindowHint(GLFW::OPENGL_PROFILE, GLFW::OPENGL_CORE_PROFILE) 32 | else 33 | GLFW.WindowHint(GLFW::OPENGL_PROFILE, GLFW::OPENGL_ANY_PROFILE) 34 | end 35 | GLFW.WindowHint(GLFW::CONTEXT_VERSION_MAJOR, ver_major) 36 | GLFW.WindowHint(GLFW::CONTEXT_VERSION_MINOR, ver_minor) 37 | GLFW.WindowHint(GLFW::DECORATED, 0) 38 | window = GLFW.CreateWindow(1, 1, "Report OpenGL Environment", nil, nil) 39 | break unless window.null? 40 | end 41 | 42 | if window.null? 43 | GLFW.DefaultWindowHints() 44 | GLFW.WindowHint(GLFW::DECORATED, 0) 45 | window = GLFW.CreateWindow(1, 1, "Report OpenGL Environment", nil, nil) 46 | if window.null? 47 | puts "Failed to create the OpenGL context." 48 | GLFW.Terminate() 49 | exit 50 | end 51 | end 52 | 53 | GLFW.MakeContextCurrent(window) 54 | 55 | GL.load_lib() 56 | 57 | version_string = GL::GetString(GL::VERSION).to_s 58 | version_number = version_string.split(/\./) 59 | 60 | vendor_string = GL::GetString(GL::VENDOR).to_s 61 | renderer_string = GL::GetString(GL::RENDERER).to_s 62 | slangver_string = GL::GetString(GL::SHADING_LANGUAGE_VERSION).to_s 63 | 64 | puts "Version : #{version_string}" 65 | puts "Vendor : #{vendor_string}" 66 | puts "Renderer : #{renderer_string}" 67 | puts "Shader : #{slangver_string}" 68 | puts "Extensions :" 69 | if version_number[0].to_i >= 3 70 | # glGetString(GL_EXTENSIONS) was deprecated in OpenGL 3.0 71 | # Ref.: http://sourceforge.net/p/glew/bugs/120/ 72 | extensions_count_buf = ' ' 73 | GL::GetIntegerv(GL::NUM_EXTENSIONS, extensions_count_buf) 74 | extensions_count = extensions_count_buf.unpack('L')[0] 75 | extensions_count.times do |i| 76 | puts GL::GetStringi(GL::EXTENSIONS, i).to_s 77 | end 78 | else 79 | puts GL::GetString(GL::EXTENSIONS).to_s.split(/ /) 80 | end 81 | 82 | GLFW.DestroyWindow(window) 83 | GLFW.Terminate() 84 | end 85 | -------------------------------------------------------------------------------- /sample/GLUT/glut_menu.rb: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # Ref.: /freeglut-2.8.1/progs/demos/CallbackMaker 3 | require_relative '../util/setup_dll' 4 | require 'opengl' 5 | require 'glu' 6 | require 'glut' 7 | 8 | # Callback functions 9 | 10 | def display 11 | GL.Clear(GL::COLOR_BUFFER_BIT | GL::DEPTH_BUFFER_BIT) 12 | GLUT.SwapBuffers() 13 | end 14 | 15 | def reshape(width, height) 16 | GL.Viewport(0, 0, width, height) 17 | 18 | GL.MatrixMode(GL::PROJECTION) 19 | GL.LoadIdentity 20 | GLU.Perspective(45.0, width.to_f/height.to_f, 0.1, 1000.0) 21 | 22 | GL.MatrixMode(GL::MODELVIEW) 23 | GL.LoadIdentity 24 | end 25 | 26 | def keyboard(key, x, y) 27 | case key 28 | when 27 # 27 == ESC 29 | exit 30 | end 31 | end 32 | 33 | def menu_callback(menu_id) 34 | puts "menu selected (menu_id=#{menu_id})" 35 | end 36 | 37 | def menu_status(status, x, y) 38 | puts "menu_status=#{status}, (x, y)=(#{x}, #{y})" 39 | end 40 | 41 | $menu_ID = nil 42 | $submenu_A = nil 43 | $submenu_B = nil 44 | 45 | 46 | # Main 47 | 48 | if __FILE__ == $PROGRAM_NAME 49 | GLUT.load_lib(SampleUtil.glut_library_path) 50 | GLUT.Init([1].pack('I'), [""].pack('p')) 51 | GLUT.InitDisplayMode(GLUT::DOUBLE | GLUT::RGBA | GLUT::DEPTH) 52 | GLUT.InitWindowSize(500, 500); 53 | GLUT.InitWindowPosition(100, 100) 54 | GLUT.CreateWindow("test") 55 | GL.load_lib() 56 | GLU.load_lib() 57 | GLUT.DisplayFunc(GLUT.create_callback(:GLUTDisplayFunc, method(:display).to_proc)) 58 | GLUT.ReshapeFunc(GLUT.create_callback(:GLUTReshapeFunc, method(:reshape).to_proc)) 59 | GLUT.KeyboardFunc(GLUT.create_callback(:GLUTKeyboardFunc, method(:keyboard).to_proc)) 60 | 61 | GLUT.MenuStatusFunc(GLUT.create_callback(:GLUTMenuStatusFunc, method(:menu_status).to_proc)) 62 | 63 | $submenu_A = GLUT.CreateMenu(GLUT.create_callback(:GLUTMenuFunc, method(:menu_callback).to_proc)) 64 | GLUT.AddMenuEntry("Sub menu A1 (01)", 1) 65 | GLUT.AddMenuEntry("Sub menu A2 (02)", 2) 66 | GLUT.AddMenuEntry("Sub menu A3 (03)", 3) 67 | 68 | $submenu_B = GLUT.CreateMenu(GLUT.create_callback(:GLUTMenuFunc, method(:menu_callback).to_proc)) 69 | GLUT.AddMenuEntry("Sub menu B1 (04)", 4) 70 | GLUT.AddMenuEntry("Sub menu B2 (05)", 5) 71 | GLUT.AddMenuEntry("Sub menu B3 (06)", 6) 72 | GLUT.AddSubMenu("Going to sub menu A", $submenu_A) 73 | 74 | $menu_ID = GLUT.CreateMenu(GLUT.create_callback(:GLUTMenuFunc, method(:menu_callback).to_proc)) 75 | GLUT.AddMenuEntry("Entry one", 1) 76 | GLUT.AddMenuEntry("Entry two", 2) 77 | GLUT.AddMenuEntry("Entry three", 3) 78 | GLUT.AddMenuEntry("Entry four", 4) 79 | GLUT.AddMenuEntry("Entry five", 5) 80 | GLUT.AddSubMenu("Enter sub menu A", $submenu_A) 81 | GLUT.AddSubMenu("Enter sub menu B", $submenu_B) 82 | 83 | GLUT.AttachMenu(GLUT::LEFT_BUTTON) 84 | 85 | GL.ClearColor(0.0, 0.0, 0.0, 1) 86 | 87 | begin 88 | GLUT.MainLoop() 89 | ensure 90 | GLUT.DestroyMenu($submenu_A) 91 | GLUT.DestroyMenu($submenu_B) 92 | GLUT.DestroyMenu($menu_ID) 93 | end 94 | end 95 | -------------------------------------------------------------------------------- /lib/opengl_common.rb: -------------------------------------------------------------------------------- 1 | module GL 2 | 3 | GL_FUNCTIONS_MAP = Hash.new { |hash, sym| hash[sym] = bind_command(sym) } 4 | @@gl_dll = nil 5 | 6 | # Open dll/dylib/so for symbol import 7 | # - Note that OpenGL APIs won't be available until you call import_symbols 8 | def self.open_lib(lib_path: nil) 9 | if lib_path == nil 10 | case self.get_platform 11 | when :OPENGL_PLATFORM_WINDOWS 12 | lib_path = 'C:/Windows/System32/opengl32.dll' 13 | when :OPENGL_PLATFORM_MACOSX 14 | lib_path = '/System/Library/Frameworks/OpenGL.framework/Libraries/libGL.dylib' 15 | else 16 | lib_path = 'libGL.so' 17 | end 18 | end 19 | @@gl_dll = Fiddle.dlopen(lib_path) 20 | end 21 | 22 | # Import OpenGL APIs 23 | # - Call this after OpenGL context becomes vailable (e.g.: glfwMakeContextCurrent) 24 | def self.import_symbols(output_error: false) 25 | GL_FUNCTION_SYMBOLS.each do |sym| 26 | begin 27 | bind_command(sym) if GL_FUNCTIONS_MAP[sym] == nil || GL_FUNCTIONS_MAP[sym].ptr == 0 28 | rescue 29 | $stderr.puts("[Warning] opengl_common.rb : Failed to import #{sym}.") if output_error 30 | end 31 | end 32 | end 33 | 34 | def self.load_lib(lib_path = nil, output_import_error = false) 35 | if lib_path == nil 36 | lib_path = case self.get_platform 37 | when :OPENGL_PLATFORM_WINDOWS 38 | 'C:/Windows/System32/opengl32.dll' 39 | when :OPENGL_PLATFORM_MACOSX 40 | '/System/Library/Frameworks/OpenGL.framework/Libraries/libGL.dylib' 41 | else 42 | 'libGL.so' # not tested 43 | end 44 | end 45 | 46 | open_lib(lib_path: lib_path) 47 | import_symbols(output_error: output_import_error) 48 | end 49 | 50 | # [OBSOLETE] 51 | def self.load_dll(lib = nil, path = nil) 52 | $stderr.puts "[Warning] opengl_common.rb : OpenGL.load_dll is deprecated, use OpenGL.load_lib instead" 53 | self.load_lib(lib, path) 54 | end 55 | 56 | # [INTERNAL] 57 | def self.get_command(sym) 58 | if GL_FUNCTIONS_MAP[sym] == nil 59 | bind_command(sym) 60 | end 61 | return GL_FUNCTIONS_MAP[sym] 62 | end 63 | 64 | # [INTERNAL] 65 | def self.bind_command(sym) 66 | begin 67 | GL_FUNCTIONS_MAP[sym] = Fiddle::Function.new(@@gl_dll[sym.to_s], 68 | GL_FUNCTIONS_ARGS_MAP[sym], 69 | GL_FUNCTIONS_RETVAL_MAP[sym]) 70 | rescue 71 | if self.get_platform == :OPENGL_PLATFORM_WINDOWS 72 | func_ptr = wglGetProcAddress(sym.to_s) 73 | raise RuntimeError, "wglGetProcAddress(#{sym}) returned NULL" if func_ptr.null? 74 | GL_FUNCTIONS_MAP[sym] = Fiddle::Function.new(func_ptr, 75 | GL_FUNCTIONS_ARGS_MAP[sym], 76 | GL_FUNCTIONS_RETVAL_MAP[sym]) 77 | else 78 | raise 79 | end 80 | end 81 | end 82 | 83 | end 84 | -------------------------------------------------------------------------------- /generator/aux_typemap.rb: -------------------------------------------------------------------------------- 1 | # [NOTICE] Automatically generated file 2 | module GL 3 | GL_TYPE_MAP = { 4 | 'GLenum' => '-Fiddle::TYPE_INT', 5 | 'GLboolean' => '-Fiddle::TYPE_CHAR', 6 | 'GLbitfield' => '-Fiddle::TYPE_INT', 7 | 'GLvoid' => 'Fiddle::TYPE_VOID', 8 | 'GLbyte' => 'Fiddle::TYPE_CHAR', 9 | 'GLshort' => 'Fiddle::TYPE_SHORT', 10 | 'GLint' => 'Fiddle::TYPE_INT', 11 | 'GLclampx' => 'Fiddle::TYPE_INT', 12 | 'GLubyte' => '-Fiddle::TYPE_CHAR', 13 | 'GLushort' => '-Fiddle::TYPE_SHORT', 14 | 'GLuint' => '-Fiddle::TYPE_INT', 15 | 'GLsizei' => 'Fiddle::TYPE_INT', 16 | 'GLfloat' => 'Fiddle::TYPE_FLOAT', 17 | 'GLclampf' => 'Fiddle::TYPE_FLOAT', 18 | 'GLdouble' => 'Fiddle::TYPE_DOUBLE', 19 | 'GLclampd' => 'Fiddle::TYPE_DOUBLE', 20 | 'GLeglClientBufferEXT' => 'Fiddle::TYPE_VOIDP', 21 | 'GLeglImageOES' => 'Fiddle::TYPE_VOIDP', 22 | 'GLchar' => 'Fiddle::TYPE_CHAR', 23 | 'GLcharARB' => 'Fiddle::TYPE_CHAR', 24 | 'GLhandleARB' => 'Fiddle::TYPE_VOIDP', # <- *** [CHECK] Cannot resolved to any Fiddle type. You might need tweaking for this. *** 25 | 'GLhalfARB' => '-Fiddle::TYPE_SHORT', 26 | 'GLhalf' => '-Fiddle::TYPE_SHORT', 27 | 'GLfixed' => 'Fiddle::TYPE_INT', 28 | 'GLintptr' => 'Fiddle::TYPE_PTRDIFF_T', 29 | 'GLsizeiptr' => 'Fiddle::TYPE_PTRDIFF_T', 30 | 'GLint64' => 'Fiddle::TYPE_LONG_LONG', 31 | 'GLuint64' => '-Fiddle::TYPE_LONG_LONG', 32 | 'GLintptrARB' => 'Fiddle::TYPE_PTRDIFF_T', 33 | 'GLsizeiptrARB' => 'Fiddle::TYPE_PTRDIFF_T', 34 | 'GLint64EXT' => 'Fiddle::TYPE_LONG_LONG', 35 | 'GLuint64EXT' => '-Fiddle::TYPE_LONG_LONG', 36 | 'GLsync' => 'Fiddle::TYPE_VOIDP', # <- *** [CHECK] Cannot resolved to any Fiddle type. You might need tweaking for this. *** 37 | 'struct _cl_context' => 'Fiddle::TYPE_VOIDP', # <- *** [CHECK] Cannot resolved to any Fiddle type. You might need tweaking for this. *** 38 | 'struct _cl_event' => 'Fiddle::TYPE_VOIDP', # <- *** [CHECK] Cannot resolved to any Fiddle type. You might need tweaking for this. *** 39 | 'GLDEBUGPROC' => 'Fiddle::TYPE_VOIDP', 40 | 'GLDEBUGPROCARB' => 'Fiddle::TYPE_VOIDP', 41 | 'GLDEBUGPROCKHR' => 'Fiddle::TYPE_VOIDP', 42 | 'GLDEBUGPROCAMD' => 'Fiddle::TYPE_VOIDP', 43 | 'GLhalfNV' => '-Fiddle::TYPE_SHORT', 44 | 'GLvdpauSurfaceNV' => 'Fiddle::TYPE_PTRDIFF_T', 45 | 'GLVULKANPROCNV' => 'Fiddle::TYPE_VOIDP', 46 | 47 | 'char' => 'Fiddle::TYPE_CHAR', 48 | 'signed char' => 'Fiddle::TYPE_CHAR', 49 | 'unsigned char' => '-Fiddle::TYPE_CHAR', 50 | 'short' => 'Fiddle::TYPE_SHORT', 51 | 'signed short' => 'Fiddle::TYPE_SHORT', 52 | 'unsigned short' => '-Fiddle::TYPE_SHORT', 53 | 'int' => 'Fiddle::TYPE_INT', 54 | 'signed int' => 'Fiddle::TYPE_INT', 55 | 'unsigned int' => '-Fiddle::TYPE_INT', 56 | 'int64_t' => 'Fiddle::TYPE_LONG_LONG', 57 | 'uint64_t' => '-Fiddle::TYPE_LONG_LONG', 58 | 'float' => 'Fiddle::TYPE_FLOAT', 59 | 'double' => 'Fiddle::TYPE_DOUBLE', 60 | 'ptrdiff_t' => 'Fiddle::TYPE_PTRDIFF_T', 61 | 'void' => 'Fiddle::TYPE_VOID', 62 | 'void *' => 'Fiddle::TYPE_VOIDP', 63 | } 64 | end 65 | -------------------------------------------------------------------------------- /generator/Rakefile: -------------------------------------------------------------------------------- 1 | # 2 | # 'rake' to generate 'opengl_command.rb', etc. 3 | # 4 | require 'rake/clean' 5 | require_relative 'get_gl_xml' 6 | require_relative 'generate_enum' 7 | require_relative 'generate_command' 8 | require_relative 'generate_ext_enum' 9 | require_relative 'generate_ext_command' 10 | require_relative 'generate_es_enum' 11 | require_relative 'generate_es_command' 12 | require_relative 'generate_es_ext_enum' 13 | require_relative 'generate_es_ext_command' 14 | 15 | CLEAN.include( FileList['../lib/opengl_enum.rb', 16 | '../lib/opengl_command.rb', 17 | '../lib/opengl_ext_enum.rb', 18 | '../lib/opengl_ext_command.rb', 19 | '../lib/opengl_es_enum.rb', 20 | '../lib/opengl_es_command.rb', 21 | '../lib/opengl_es_ext_enum.rb', 22 | '../lib/opengl_es_ext_command.rb'] ) 23 | 24 | 25 | task 'default' => 'wrapper' 26 | 27 | task 'wrapper' => ['enum', 'command', 'ext_enum', 'ext_command', 'es_enum', 'es_command', 'es_ext_enum', 'es_ext_command'] 28 | 29 | task 'enum' => '../lib/opengl_enum.rb' 30 | task 'command' => '../lib/opengl_command.rb' 31 | task 'ext_enum' => '../lib/opengl_ext_enum.rb' 32 | task 'ext_command' => '../lib/opengl_ext_command.rb' 33 | task 'es_enum' => '../lib/opengl_es_enum.rb' 34 | task 'es_command' => '../lib/opengl_es_command.rb' 35 | task 'es_ext_enum' => '../lib/opengl_es_ext_enum.rb' 36 | task 'es_ext_command' => '../lib/opengl_es_ext_command.rb' 37 | 38 | file '../lib/opengl_enum.rb' => './gl.xml' do |t| 39 | open('../lib/opengl_enum.rb', 'wb') do |file| 40 | GLEnumCodeGenerator.generate_enum(file) 41 | end 42 | end 43 | 44 | file '../lib/opengl_command.rb' => './gl.xml' do |t| 45 | open('../lib/opengl_command.rb', 'wb') do |file| 46 | GLCommandCodeGenerator.generate_command(file) 47 | end 48 | end 49 | 50 | file '../lib/opengl_ext_enum.rb' => './gl.xml' do |t| 51 | open('../lib/opengl_ext_enum.rb', 'wb') do |file| 52 | GLExtEnumCodeGenerator.generate_enum(file) 53 | end 54 | end 55 | 56 | file '../lib/opengl_ext_command.rb' => './gl.xml' do |t| 57 | open('../lib/opengl_ext_command.rb', 'wb') do |file| 58 | GLExtCommandCodeGenerator.generate_command(file) 59 | end 60 | end 61 | 62 | file '../lib/opengl_es_enum.rb' => './gl.xml' do |t| 63 | open('../lib/opengl_es_enum.rb', 'wb') do |file| 64 | GLESEnumCodeGenerator.generate_enum(file) 65 | end 66 | end 67 | 68 | file '../lib/opengl_es_command.rb' => './gl.xml' do |t| 69 | open('../lib/opengl_es_command.rb', 'wb') do |file| 70 | GLESCommandCodeGenerator.generate_command(file) 71 | end 72 | end 73 | 74 | file '../lib/opengl_es_ext_enum.rb' => './gl.xml' do |t| 75 | open('../lib/opengl_es_ext_enum.rb', 'wb') do |file| 76 | GLESExtEnumCodeGenerator.generate_enum(file) 77 | end 78 | end 79 | 80 | file '../lib/opengl_es_ext_command.rb' => './gl.xml' do |t| 81 | open('../lib/opengl_es_ext_command.rb', 'wb') do |file| 82 | GLESExtCommandCodeGenerator.generate_command(file) 83 | end 84 | end 85 | 86 | file './gl.xml' do 87 | get_gl_xml() 88 | end 89 | -------------------------------------------------------------------------------- /sample/GLExcess/texture.rb: -------------------------------------------------------------------------------- 1 | =begin 2 | GLExcess v1.0 Demo 3 | Copyright (C) 2001-2003 Paolo Martella 4 | 5 | This program is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU General Public License 7 | as published by the Free Software Foundation; either version 2 8 | of the License, or (at your option) any later version. 9 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | 15 | * Original code : Paolo Martella 16 | * Ruby Porting : vaiorabbit 17 | =end 18 | 19 | class Texture 20 | 21 | attr_reader :width, :height 22 | 23 | def initialize 24 | @tex_name = 0 25 | @width = 0 26 | @height = 0 27 | end 28 | 29 | def pow2(exp) 30 | result = 1 31 | return result if exp == 0 32 | 33 | exp.times { result *= 2 } 34 | 35 | return result 36 | end 37 | private :pow2 38 | 39 | def gen_texture(filename) 40 | kill 41 | tex_name_buf = ' ' * 4 42 | GL.GenTextures(1, tex_name_buf) # Note : glGenTextures returns Array instance. 43 | @tex_name = tex_name_buf.unpack1('L') 44 | GL.BindTexture(GL::TEXTURE_2D, @tex_name) 45 | GL.TexParameteri(GL::TEXTURE_2D, GL::TEXTURE_WRAP_S, GL::REPEAT) 46 | GL.TexParameteri(GL::TEXTURE_2D, GL::TEXTURE_WRAP_T, GL::REPEAT) 47 | GL.TexParameteri(GL::TEXTURE_2D, GL::TEXTURE_MAG_FILTER, GL::LINEAR) 48 | GL.TexParameteri(GL::TEXTURE_2D, GL::TEXTURE_MIN_FILTER, GL::LINEAR_MIPMAP_LINEAR) 49 | 50 | return true; 51 | end 52 | private :gen_texture 53 | 54 | def kill 55 | if @tex_name != 0 56 | # Note : glDeleteTextures expects Array instance. 57 | GL.DeleteTextures(1, [@tex_name].pack('L')) 58 | @tex_name = 0 59 | end 60 | end 61 | 62 | def use 63 | GL.BindTexture(GL::TEXTURE_2D, @tex_name) 64 | end 65 | 66 | def load(filename) 67 | return false if filename == nil 68 | return false if gen_texture(filename) == false 69 | 70 | f = File.new(filename, "rb") 71 | return false if f == nil 72 | 73 | w = f.read(1) 74 | h = f.read(1) 75 | 76 | width = nil 77 | height = nil 78 | 79 | major, minor, micro = RUBY_VERSION.scan(/\d+/) 80 | 81 | if (major == "1" && minor == "8") 82 | # for Ruby 1.8. 83 | width = pow2(w[0].to_i - "0"[0].to_i) 84 | height = pow2(h[0].to_i - "0"[0].to_i) 85 | else 86 | # for Ruby 1.9. 87 | # A little bit cryptic. In Ruby 1.9, String#to_i no longer returns 88 | # its character code. 89 | width = pow2(w[0].unpack1("U").to_i - "0"[0].unpack1("U").to_i) 90 | height = pow2(h[0].unpack1("U").to_i - "0"[0].unpack1("U").to_i) 91 | end 92 | 93 | size = width * height * 3 94 | 95 | rgbdata = f.read(size) 96 | 97 | f.close() 98 | 99 | GLU.Build2DMipmaps(GL::TEXTURE_2D, 3, width, height, GL::RGB, GL::UNSIGNED_BYTE, rgbdata) 100 | 101 | rgbdata = nil 102 | 103 | @width = width 104 | @height = height 105 | 106 | return true 107 | end 108 | 109 | end 110 | -------------------------------------------------------------------------------- /sample/GLUT/glut_minimal.rb: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | require_relative '../util/setup_dll' 3 | require 'opengl' 4 | require 'glu' 5 | require 'glut' 6 | 7 | light_pos = nil 8 | light_diffuse = nil 9 | light_specular = nil 10 | light_ambient = nil 11 | 12 | teapot_diffuse = nil 13 | teapot_specular = nil 14 | teapot_ambient = nil 15 | teapot_shininess = nil 16 | 17 | def display 18 | GL.PushAttrib(GL::ALL_ATTRIB_BITS) 19 | 20 | GL.Clear(GL::COLOR_BUFFER_BIT | GL::DEPTH_BUFFER_BIT) 21 | 22 | GL.PushMatrix() 23 | 24 | GLU.LookAt(0.0, 5.0, 15.0, 25 | 0.0, 0.0, 0.0, 26 | 0.0, 1.0, 0.0); 27 | 28 | light_pos = [2.5, 10.0, 5.0, 1.0].pack('F4') unless light_pos 29 | light_diffuse = [1.0, 1.0, 1.0, 1.0].pack('F4') unless light_diffuse 30 | light_specular = [1.0, 1.0, 1.0, 1.0].pack('F4') unless light_specular 31 | light_ambient = [1.0, 1.0, 1.0, 1.0].pack('F4') unless light_ambient 32 | GL.Lightfv(GL::LIGHT0, GL::POSITION, light_pos) 33 | GL.Lightfv(GL::LIGHT0, GL::DIFFUSE, light_diffuse) 34 | GL.Lightfv(GL::LIGHT0, GL::SPECULAR, light_specular) 35 | GL.Lightfv(GL::LIGHT0, GL::AMBIENT, light_ambient) 36 | 37 | teapot_diffuse = [0.8, 1.0, 0.0, 1.0].pack('F4') unless teapot_diffuse 38 | teapot_specular = [1.0, 1.0, 1.0, 1.0].pack('F4') unless teapot_specular 39 | teapot_ambient = [0.2, 0.2, 0.0, 1.0].pack('F4') unless teapot_ambient 40 | teapot_shininess = 32.0 unless teapot_shininess 41 | GL.Materialfv(GL::FRONT_AND_BACK, GL::DIFFUSE, teapot_diffuse) 42 | GL.Materialfv(GL::FRONT_AND_BACK, GL::SPECULAR, teapot_specular) 43 | GL.Materialfv(GL::FRONT_AND_BACK, GL::AMBIENT, teapot_ambient) 44 | GL.Materialf( GL::FRONT_AND_BACK, GL::SHININESS, teapot_shininess) 45 | 46 | # Ref.: https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man3/glutSolidTeapot.3.html 47 | GL.FrontFace(GL::CW) 48 | GLUT.SolidTeapot(3.0) 49 | GL.FrontFace(GL::CCW) 50 | 51 | GL.PopMatrix() 52 | 53 | GL.PopAttrib() 54 | 55 | GLUT.SwapBuffers() 56 | end 57 | 58 | def reshape(width, height) 59 | GL.Viewport(0, 0, width, height) 60 | 61 | GL.MatrixMode(GL::PROJECTION) 62 | GL.LoadIdentity 63 | GLU.Perspective(45.0, width.to_f/height.to_f, 0.1, 1000.0) 64 | 65 | GL.MatrixMode(GL::MODELVIEW) 66 | GL.LoadIdentity 67 | end 68 | 69 | $keyboard = GLUT.create_callback(:GLUTKeyboardFunc) do |key, x, y| 70 | case key 71 | when 27 # 27 == ESC 72 | exit 73 | end 74 | end 75 | 76 | if __FILE__ == $PROGRAM_NAME 77 | GLUT.load_lib(SampleUtil.glut_library_path) 78 | GLUT.Init([1].pack('I'), [""].pack('p')) 79 | GLUT.InitDisplayMode(GLUT::DOUBLE | GLUT::RGBA | GLUT::DEPTH) 80 | GLUT.InitWindowSize(500, 500); 81 | GLUT.InitWindowPosition(100, 100) 82 | GLUT.CreateWindow("test") 83 | 84 | GL.load_lib() 85 | GLU.load_lib() 86 | 87 | GLUT.DisplayFunc(GLUT.create_callback(:GLUTDisplayFunc, method(:display).to_proc)) # Example of callback registration (1) 88 | GLUT.ReshapeFunc(GLUT.create_callback(:GLUTReshapeFunc, method(:reshape).to_proc)) # Example of callback registration (1) 89 | GLUT.KeyboardFunc($keyboard) # Example of callback registration (2) 90 | 91 | GL.ClearColor(0.0, 0.0, 0.0, 1) 92 | 93 | GL.Enable(GL::CULL_FACE) 94 | GL.CullFace(GL::BACK) 95 | 96 | GL.Enable(GL::DEPTH_TEST) 97 | GL.DepthFunc(GL::LESS) 98 | 99 | GL.Enable(GL::LIGHTING) 100 | GL.Enable(GL::LIGHT0) 101 | 102 | GL.Enable(GL::NORMALIZE) 103 | 104 | GLUT.MainLoop() 105 | end 106 | -------------------------------------------------------------------------------- /sample/GLES/gles.rb: -------------------------------------------------------------------------------- 1 | # Ref.: https://github.com/McNopper/OpenGL_ES/blob/master/Example02_ES2/ 2 | require 'opengl_es' 3 | require 'glfw' 4 | 5 | require '../util/setup_dll' 6 | 7 | $g_vertex_location = nil 8 | $g_vbo = nil 9 | 10 | key_callback = GLFW::create_callback(:GLFWkeyfun) do |window_handle, key, scancode, action, mods| 11 | case key 12 | when GLFW::KEY_ESCAPE, GLFW::KEY_Q 13 | GLFW.SetWindowShouldClose(window_handle, 1) 14 | end 15 | end 16 | 17 | size_callback = GLFW::create_callback(:GLFWwindowsizefun) do |xowindow_handle, w, h| 18 | GL.Viewport(0, 0, w, h) 19 | end 20 | 21 | def get_attrib_location(program, name) 22 | loc = GL.GetAttribLocation(program, name) 23 | if loc == -1 24 | puts "No such attribute named #{name}" 25 | end 26 | return loc 27 | end 28 | 29 | def setup_geometry 30 | points = [ -0.5, 0.0, 0.0, 1.0, 0.5, 0.0, 0.0, 1.0, 0.0, 0.5, 0.0, 1.0 ] 31 | 32 | vbo_buf = ' ' * 4 33 | GL.GenBuffers(1, vbo_buf) 34 | $g_vbo = vbo_buf.unpack('L')[0] 35 | GL.BindBuffer(GL::ARRAY_BUFFER, $g_vbo) 36 | GL.BufferData(GL::ARRAY_BUFFER, 3 * 4 * Fiddle::SIZEOF_FLOAT, points.pack('F*'), GL::STATIC_DRAW) 37 | 38 | GL.VertexAttribPointer($g_vertex_location, 4, GL::FLOAT, GL::FALSE, 0, 0) 39 | GL.EnableVertexAttribArray($g_vertex_location) 40 | 41 | return true 42 | end 43 | 44 | def setup_shader(vs_fname,fs_fname) 45 | vs_handle = GL.CreateShader(GL::VERTEX_SHADER) 46 | fs_handle = GL.CreateShader(GL::FRAGMENT_SHADER) 47 | 48 | vs_srcs = [File.read(vs_fname)].pack('p') 49 | vs_lens = [File.size(vs_fname)].pack('I') 50 | GL.ShaderSource(vs_handle, 1, vs_srcs, vs_lens) 51 | 52 | fs_srcs = [File.read(fs_fname)].pack('p') 53 | fs_lens = [File.size(fs_fname)].pack('I') 54 | GL.ShaderSource(fs_handle, 1, fs_srcs, fs_lens) 55 | 56 | GL.CompileShader(vs_handle) 57 | vertCompiled_buf = ' ' * 4 58 | GL.GetShaderiv(vs_handle, GL::COMPILE_STATUS, vertCompiled_buf) 59 | vertCompiled = vertCompiled_buf.unpack('L')[0] 60 | if vertCompiled == 0 61 | infoLog = ' ' * 1024 62 | GL.GetShaderInfoLog(vs_handle, 1023, nil, infoLog) 63 | puts "Shader InfoLog:\n#{infoLog}\n" 64 | end 65 | 66 | GL.CompileShader(fs_handle) 67 | fragCompiled_buf = ' ' * 4 68 | GL.GetShaderiv(fs_handle, GL::COMPILE_STATUS, fragCompiled_buf) 69 | fragCompiled = fragCompiled_buf.unpack('L')[0] 70 | if fragCompiled == 0 71 | infoLog = ' ' * 1024 72 | GL.GetShaderInfoLog(fs_handle, 1023, nil, infoLog) 73 | puts "Shader InfoLog:\n#{infoLog}\n" 74 | end 75 | return false if (vertCompiled == 0 || fragCompiled == 0) 76 | 77 | prog_handle = GL.CreateProgram() 78 | GL.AttachShader(prog_handle,vs_handle) 79 | GL.AttachShader(prog_handle,fs_handle) 80 | 81 | GL.LinkProgram(prog_handle) 82 | 83 | linked_buf = ' ' * 4 84 | GL.GetProgramiv(prog_handle, GL::LINK_STATUS, linked_buf) 85 | linked = linked_buf.unpack('L')[0] 86 | if linked == 0 87 | infoLog = ' ' * 1024 88 | GL.GetProgramInfoLog(prog_handle, 1023, nil, infoLog) 89 | puts "Program InfoLog:\n#{infoLog}\n" 90 | end 91 | return false if linked==0 92 | 93 | GL.UseProgram(prog_handle) 94 | 95 | $g_vertex_location = get_attrib_location(prog_handle, "a_vertex") 96 | 97 | return true 98 | end 99 | 100 | # Main 101 | 102 | if __FILE__ == $PROGRAM_NAME 103 | GLFW.load_lib(SampleUtil.glfw_library_path) 104 | GLFW.Init() 105 | GLFW.WindowHint(GLFW::CONTEXT_VERSION_MAJOR, 3) 106 | GLFW.WindowHint(GLFW::CLIENT_API, GLFW::OPENGL_ES_API) 107 | GLFW.WindowHint(GLFW::OPENGL_PROFILE, GLFW::OPENGL_CORE_PROFILE) 108 | window = GLFW.CreateWindow(320, 240, "OpenGL ES", nil, nil) 109 | if window.null? 110 | puts "Failed to create the OpenGL ES 3 context. You may need to get a GPU/driver that is compliant with OpenGL 4.3 or higher." 111 | exit 112 | end 113 | GLFW.SetWindowPos(window, 100, 100) 114 | GLFW.MakeContextCurrent(window) 115 | GLFW.SetKeyCallback(window, key_callback) 116 | GLFW.SetWindowSizeCallback(window, size_callback) 117 | 118 | GL.load_lib() 119 | 120 | width_ptr = ' ' * 4 121 | height_ptr = ' ' * 4 122 | GLFW.GetFramebufferSize(window, width_ptr, height_ptr) 123 | width = width_ptr.unpack('L')[0] 124 | height = height_ptr.unpack('L')[0] 125 | size_callback.call(window, width, height) 126 | 127 | GL.ClearColor(0.0, 0.0, 0.0, 0.0) 128 | exit unless setup_shader("sample.vert","sample.frag") 129 | exit unless setup_geometry() 130 | 131 | while GLFW.WindowShouldClose(window) == 0 132 | GL.Clear(GL::COLOR_BUFFER_BIT) 133 | GL.DrawArrays(GL::TRIANGLES, 0, 3) 134 | 135 | GLFW.SwapBuffers(window) 136 | GLFW.PollEvents() 137 | end 138 | end 139 | -------------------------------------------------------------------------------- /sample/SDL2/test_sdl2-bindings.rb: -------------------------------------------------------------------------------- 1 | # testgl.rb (sdl2-bindings version : https://github.com/vaiorabbit/sdl2-bindings) 2 | # Ref.: /ruby-sdl2-0.2.0/sample/testgl.rb 3 | 4 | require 'opengl' 5 | require '../util/setup_dll' 6 | require 'sdl2' 7 | 8 | # Set path to libSDL2.dylib (macOS) /SDL2.dll (Windows) according to your environment 9 | def load_sdl2_lib() 10 | case RbConfig::CONFIG['host_os'] 11 | when /mswin|msys|mingw|cygwin/ 12 | SDL2.load_lib(Dir.pwd + '/SDL2.dll') 13 | when /darwin/ 14 | SDL2.load_lib('libSDL2.dylib') 15 | when /linux/ 16 | SDL2.load_lib('libSDL2.so') # not tested 17 | else 18 | raise RuntimeError, "Unsupported platform." 19 | end 20 | end 21 | 22 | $color = 23 | [[ 1.0, 1.0, 0.0].pack("D3"), 24 | [ 1.0, 0.0, 0.0].pack("D3"), 25 | [ 0.0, 0.0, 0.0].pack("D3"), 26 | [ 0.0, 1.0, 0.0].pack("D3"), 27 | [ 0.0, 1.0, 1.0].pack("D3"), 28 | [ 1.0, 1.0, 1.0].pack("D3"), 29 | [ 1.0, 0.0, 1.0].pack("D3"), 30 | [ 0.0, 0.0, 1.0].pack("D3")] 31 | 32 | $cube = 33 | [[ 0.5, 0.5, -0.5].pack("D3"), 34 | [ 0.5, -0.5, -0.5].pack("D3"), 35 | [-0.5, -0.5, -0.5].pack("D3"), 36 | [-0.5, 0.5, -0.5].pack("D3"), 37 | [-0.5, 0.5, 0.5].pack("D3"), 38 | [ 0.5, 0.5, 0.5].pack("D3"), 39 | [ 0.5, -0.5, 0.5].pack("D3"), 40 | [-0.5, -0.5, 0.5].pack("D3")] 41 | 42 | def render() 43 | GL.ClearColor(0.0, 0.0, 0.0, 1.0) 44 | GL.Clear(GL::COLOR_BUFFER_BIT|GL::DEPTH_BUFFER_BIT) 45 | 46 | GL.Begin(GL::QUADS) 47 | 48 | GL.Color3dv($color[0]) 49 | GL.Vertex3dv($cube[0]) 50 | GL.Color3dv($color[1]) 51 | GL.Vertex3dv($cube[1]) 52 | GL.Color3dv($color[2]) 53 | GL.Vertex3dv($cube[2]) 54 | GL.Color3dv($color[3]) 55 | GL.Vertex3dv($cube[3]) 56 | 57 | GL.Color3dv($color[3]) 58 | GL.Vertex3dv($cube[3]) 59 | GL.Color3dv($color[4]) 60 | GL.Vertex3dv($cube[4]) 61 | GL.Color3dv($color[7]) 62 | GL.Vertex3dv($cube[7]) 63 | GL.Color3dv($color[2]) 64 | GL.Vertex3dv($cube[2]) 65 | 66 | GL.Color3dv($color[0]) 67 | GL.Vertex3dv($cube[0]) 68 | GL.Color3dv($color[5]) 69 | GL.Vertex3dv($cube[5]) 70 | GL.Color3dv($color[6]) 71 | GL.Vertex3dv($cube[6]) 72 | GL.Color3dv($color[1]) 73 | GL.Vertex3dv($cube[1]) 74 | 75 | GL.Color3dv($color[5]) 76 | GL.Vertex3dv($cube[5]) 77 | GL.Color3dv($color[4]) 78 | GL.Vertex3dv($cube[4]) 79 | GL.Color3dv($color[7]) 80 | GL.Vertex3dv($cube[7]) 81 | GL.Color3dv($color[6]) 82 | GL.Vertex3dv($cube[6]) 83 | 84 | GL.Color3dv($color[5]) 85 | GL.Vertex3dv($cube[5]) 86 | GL.Color3dv($color[0]) 87 | GL.Vertex3dv($cube[0]) 88 | GL.Color3dv($color[3]) 89 | GL.Vertex3dv($cube[3]) 90 | GL.Color3dv($color[4]) 91 | GL.Vertex3dv($cube[4]) 92 | 93 | GL.Color3dv($color[6]) 94 | GL.Vertex3dv($cube[6]) 95 | GL.Color3dv($color[1]) 96 | GL.Vertex3dv($cube[1]) 97 | GL.Color3dv($color[2]) 98 | GL.Vertex3dv($cube[2]) 99 | GL.Color3dv($color[7]) 100 | GL.Vertex3dv($cube[7]) 101 | 102 | GL.End() 103 | 104 | GL.MatrixMode(GL::MODELVIEW) 105 | GL.Rotated(5.0, 1.0, 1.0, 1.0) 106 | end 107 | 108 | 109 | if __FILE__ == $PROGRAM_NAME 110 | load_sdl2_lib() 111 | success = SDL2::SDL_Init(SDL2::SDL_INIT_EVERYTHING) 112 | exit if success < 0 113 | 114 | WINDOW_W = 640 115 | WINDOW_H = 360 116 | window = SDL2::SDL_CreateWindow("OpenGL Window via sdl2-bindings", 32, 32, WINDOW_W, WINDOW_H, SDL2::SDL_WINDOW_OPENGL) 117 | 118 | ratio = WINDOW_W.to_f / WINDOW_H 119 | 120 | context = SDL2::SDL_GL_CreateContext(window) 121 | 122 | GL.load_lib() 123 | 124 | SDL2::SDL_GL_SetSwapInterval(1) 125 | 126 | GL.Viewport(0, 0, WINDOW_W, WINDOW_H) 127 | GL.MatrixMode(GL::PROJECTION) 128 | GL.LoadIdentity() 129 | GL.Ortho(-ratio, ratio, -1.0, 1.0, -1.0, 1.0) 130 | GL.MatrixMode(GL::MODELVIEW) 131 | GL.LoadIdentity() 132 | 133 | GL.Enable(GL::DEPTH_TEST) 134 | GL.DepthFunc(GL::LESS) 135 | GL.ShadeModel(GL::SMOOTH) 136 | 137 | # w_buf = ' ' 138 | # h_buf = ' ' 139 | 140 | event = SDL2::SDL_Event.new 141 | done = false 142 | while not done 143 | while SDL2::SDL_PollEvent(event) != 0 144 | # 'type' and 'timestamp' are common members for all SDL Event structs. 145 | event_type = event[:common][:type] 146 | event_timestamp = event[:common][:timestamp] 147 | # puts "Event : type=0x#{event_type.to_s(16)}, timestamp=#{event_timestamp}" 148 | case event_type 149 | when SDL2::SDL_KEYDOWN 150 | if event[:key][:keysym][:sym] == SDLK_ESCAPE 151 | done = true 152 | end 153 | end 154 | end 155 | 156 | SDL2::SDL_GL_MakeCurrent(window, context) 157 | # SDL2::SDL_GL_GetDrawableSize(window, w_buf, h_buf) 158 | # glViewport(0, 0, w_buf.unpack("S")[0], h_buf.unpack("S")[0]) 159 | render() 160 | SDL2::SDL_GL_SwapWindow(window) 161 | end 162 | 163 | SDL2::SDL_GL_DeleteContext(context) 164 | SDL2::SDL_DestroyWindow(window) 165 | SDL2::SDL_Quit() 166 | end 167 | -------------------------------------------------------------------------------- /sample/RedBook/alpha.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 1993-1997, Silicon Graphics, Inc. 3 | # ALL RIGHTS RESERVED 4 | # Permission to use, copy, modify, and distribute this software for 5 | # any purpose and without fee is hereby granted, provided that the above 6 | # copyright notice appear in all copies and that both the copyright notice 7 | # and this permission notice appear in supporting documentation, and that 8 | # the name of Silicon Graphics, Inc. not be used in advertising 9 | # or publicity pertaining to distribution of the software without specific, 10 | # written prior permission. 11 | # 12 | # THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS" 13 | # AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE, 14 | # INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR 15 | # FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON 16 | # GRAPHICS, INC. BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT, 17 | # SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY 18 | # KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION, 19 | # LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF 20 | # THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC. HAS BEEN 21 | # ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON 22 | # ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE 23 | # POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE. 24 | # 25 | # US Government Users Restricted Rights 26 | # Use, duplication, or disclosure by the Government is subject to 27 | # restrictions set forth in FAR 52.227.19(c)(2) or subparagraph 28 | # (c)(1)(ii) of the Rights in Technical Data and Computer Software 29 | # clause at DFARS 252.227-7013 and/or in similar or successor 30 | # clauses in the FAR or the DOD or NASA FAR Supplement. 31 | # Unpublished-- rights reserved under the copyright laws of the 32 | # United States. Contractor/manufacturer is Silicon Graphics, 33 | # Inc., 2011 N. Shoreline Blvd., Mountain View, CA 94039-7311. 34 | # 35 | # OpenGL(R) is a registered trademark of Silicon Graphics, Inc. 36 | # 37 | # alpha.c 38 | # This program draws several overlapping filled polygons 39 | # to demonstrate the effect order has on alpha blending results. 40 | # Use the 't' key to toggle the order of drawing polygons. 41 | 42 | require 'opengl' 43 | require 'glu' 44 | require 'glfw' 45 | require '../util/setup_dll' 46 | 47 | $leftFirst = GL::TRUE 48 | 49 | # Initialize alpha blending function. 50 | def init 51 | GL.CullFace(GL::BACK) 52 | GL.Enable(GL::CULL_FACE) 53 | GL.BlendFunc(GL::SRC_ALPHA_SATURATE, GL::ONE) 54 | GL.ClearColor(0.0, 0.0, 0.0, 0.0) 55 | end 56 | 57 | def drawLeftTriangle 58 | # draw yellow triangle on LHS of screen 59 | 60 | GL.Begin(GL::TRIANGLES) 61 | GL.Color4f(1.0, 1.0, 0.0, 0.75) 62 | GL.Vertex3f(0.1, 0.9, 0.0) 63 | GL.Vertex3f(0.1, 0.1, 0.0) 64 | GL.Vertex3f(0.7, 0.5, 0.0) 65 | GL.End() 66 | end 67 | 68 | def drawRightTriangle 69 | # draw cyan triangle on RHS of screen 70 | 71 | GL.Begin(GL::TRIANGLES) 72 | GL.Color4f(0.0, 1.0, 1.0, 0.75) 73 | GL.Vertex3f(0.9, 0.9, 0.0) 74 | GL.Vertex3f(0.3, 0.5, 0.0) 75 | GL.Vertex3f(0.9, 0.1, 0.0) 76 | GL.End() 77 | end 78 | 79 | display = Proc.new do 80 | GL.Clear(GL::COLOR_BUFFER_BIT) 81 | 82 | if ($leftFirst) 83 | drawLeftTriangle() 84 | drawRightTriangle() 85 | else 86 | drawRightTriangle() 87 | drawLeftTriangle() 88 | end 89 | end 90 | 91 | size_callback = GLFW::create_callback(:GLFWwindowsizefun) do |window_handle, w, h| 92 | GL.Viewport(0, 0, w, h) 93 | GL.MatrixMode(GL::PROJECTION) 94 | GL.LoadIdentity() 95 | if (w <= h) 96 | GLU.Ortho2D(0.0, 1.0, 0.0, 1.0*h/w) 97 | else 98 | GLU.Ortho2D(0.0, 1.0*w/h, 0.0, 1.0) 99 | end 100 | end 101 | 102 | key_callback = GLFW::create_callback(:GLFWkeyfun) do |window_handle, key, scancode, action, mods| 103 | case key 104 | when GLFW::KEY_T 105 | if action == GLFW::PRESS 106 | $leftFirst = !$leftFirst 107 | end 108 | when GLFW::KEY_ESCAPE 109 | GLFW.SetWindowShouldClose(window_handle, 1) 110 | end 111 | end 112 | 113 | if __FILE__ == $PROGRAM_NAME 114 | GLFW.load_lib(SampleUtil.glfw_library_path) 115 | GLFW.Init() 116 | window = GLFW.CreateWindow(500, 500, $0, nil, nil) 117 | GLFW.SetWindowPos(window, 100, 100) 118 | GLFW.MakeContextCurrent(window) 119 | GLFW.SetKeyCallback(window, key_callback) 120 | GLFW.SetWindowSizeCallback(window, size_callback) 121 | 122 | GL.load_lib() 123 | GLU.load_lib() 124 | 125 | init() 126 | 127 | width_ptr = ' ' * 4 128 | height_ptr = ' ' * 4 129 | GLFW.GetFramebufferSize(window, width_ptr, height_ptr) 130 | width = width_ptr.unpack('L')[0] 131 | height = height_ptr.unpack('L')[0] 132 | size_callback.call(window, width, height) 133 | 134 | while GLFW.WindowShouldClose(window) == 0 135 | display.call 136 | GLFW.SwapBuffers(window) 137 | GLFW.PollEvents() 138 | end 139 | 140 | GLFW.DestroyWindow(window) 141 | GLFW.Terminate() 142 | end 143 | -------------------------------------------------------------------------------- /sample/GLExcess/glxs_glut.rb: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env ruby 2 | 3 | =begin 4 | GLExcess v1.0 Demo 5 | Copyright (C) 2001-2003 Paolo Martella 6 | 7 | This program is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU General Public License 9 | as published by the Free Software Foundation; either version 2 10 | of the License, or (at your option) any later version. 11 | 12 | This program is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | * Original code : Paolo Martella 18 | * Ruby Porting : vaiorabbit 19 | =end 20 | 21 | require 'opengl' 22 | require 'glu' 23 | require 'glut' 24 | 25 | require 'optparse' 26 | 27 | require_relative 'texture' 28 | require_relative 'scene01' 29 | require_relative 'scene02' 30 | require_relative 'scene03' 31 | require_relative 'scene04' 32 | require_relative 'scene05' 33 | require_relative 'scene06' 34 | require_relative 'scene07' 35 | require_relative 'scene08' 36 | require_relative 'scene09' 37 | require_relative 'scene10' 38 | require_relative 'scene11' 39 | require_relative 'scene12' 40 | 41 | $app = nil 42 | 43 | class GLExcess 44 | 45 | attr_accessor :step, :run 46 | 47 | def next_scene 48 | if @scene != nil 49 | @scene.clean 50 | @scene = nil 51 | GC.start 52 | @timing = 0 53 | @step = 1.0 54 | @current_scene += 1 55 | @current_scene %= 12 56 | @scene = @scenes[@current_scene].new 57 | GLUT.SetWindowTitle("GLExcess/Ruby : " + @scene.class.to_s) 58 | end 59 | end 60 | 61 | def prev_scene 62 | if @scene != nil 63 | @scene.clean 64 | @scene = nil 65 | GC.start 66 | @timing = 0 67 | @step = 1.0 68 | @current_scene -= 1 69 | @current_scene %= 12 70 | @scene = @scenes[@current_scene].new 71 | GLUT.SetWindowTitle("GLExcess/Ruby : " + @scene.class.to_s) 72 | end 73 | end 74 | 75 | def draw 76 | if @run 77 | if @scene != nil && !@scene.render(@timing) 78 | next_scene() 79 | end 80 | @timing += @step 81 | end 82 | 83 | GLUT.SwapBuffers() 84 | end 85 | 86 | $idle = GLUT.create_callback(:GLUTIdleFunc) do 87 | GLUT.PostRedisplay() 88 | end 89 | 90 | def key(key, x, y) 91 | case key.ord 92 | when ?a.ord 93 | @step += 1 94 | when ?z.ord 95 | @step = [-1, @step-1].max 96 | when ?s.ord 97 | # Suspend/Resume 98 | @run = !@run 99 | when ?n.ord 100 | # Next Scene 101 | next_scene() 102 | when ?p.ord 103 | # Previous Scene 104 | prev_scene() 105 | when ?\e.ord, ?q.ord 106 | # 'Esc' or 'q' : Quit program. 107 | exit 108 | end 109 | end 110 | 111 | def reshape(width, height) 112 | GL.Viewport(0, 0, width, height) 113 | 114 | GL.MatrixMode(GL::PROJECTION) 115 | GL.LoadIdentity 116 | GLU.Perspective(45.0, width.to_f/height.to_f, 0.1, 1000.0) 117 | 118 | GL.MatrixMode(GL::MODELVIEW) 119 | GL.LoadIdentity 120 | 121 | @scene.render(@timing) 122 | 123 | GLUT.PostRedisplay() 124 | end 125 | 126 | def visible(vis) 127 | GLUT.IdleFunc((vis == GLUT::VISIBLE ? $idle : nil)) 128 | end 129 | 130 | def initialize 131 | # Parse Option 132 | scene = 1 133 | ARGV.options do |opt| 134 | opt.on('-s', '--scene : # of Scene [1-12]', Integer, /1[0-2]|[1-9]/) { |v| scene = v.to_i } 135 | opt.parse! 136 | end 137 | 138 | @current_scene = scene - 1 139 | 140 | @scenes = [ Scene01, Scene02, Scene03, Scene04, Scene05, Scene06, 141 | Scene07, Scene08, Scene09, Scene10, Scene11, Scene12 ] 142 | 143 | @window_width = 640 144 | @window_height = 480 145 | 146 | if GL.get_platform == :OPENGL_PLATFORM_WINDOWS 147 | GLUT.load_lib(Dir.pwd + '/../freeglut.dll') 148 | else 149 | GLUT.load_lib() 150 | end 151 | GLUT.Init([1].pack('I'), [""].pack('p')) 152 | 153 | GLUT.InitDisplayMode(GLUT::RGBA | GLUT::DEPTH | GLUT::DOUBLE) 154 | GLUT.InitWindowPosition(0, 0) 155 | GLUT.InitWindowSize(@window_width, @window_height) 156 | @window = GLUT.CreateWindow("") 157 | 158 | GL.load_lib() 159 | GLU.load_lib() 160 | 161 | GLUT.DisplayFunc(GLUT.create_callback(:GLUTDisplayFunc, method(:draw).to_proc)) 162 | GLUT.ReshapeFunc(GLUT.create_callback(:GLUTReshapeFunc, method(:reshape).to_proc)) 163 | GLUT.KeyboardFunc(GLUT.create_callback(:GLUTKeyboardFunc, method(:key).to_proc)) 164 | GLUT.VisibilityFunc(GLUT.create_callback(:GLUTVisibilityFunc, method(:visible).to_proc)) 165 | 166 | @timing = 0.0 167 | @step = 1.0 168 | 169 | @run = true 170 | 171 | @scene = @scenes[@current_scene].new 172 | scene_name = (@scene == nil ? "" : @scene.class.to_s) 173 | GLUT.SetWindowTitle("GLExcess/Ruby : " + scene_name) 174 | end 175 | 176 | def main 177 | GLUT.MainLoop() 178 | end 179 | 180 | def destroy 181 | GLUT.DestroyWindow(@window) 182 | end 183 | 184 | end 185 | 186 | 187 | if __FILE__ == $PROGRAM_NAME 188 | $app = GLExcess.new 189 | begin 190 | $app.main 191 | ensure 192 | $app.destroy 193 | end 194 | end 195 | -------------------------------------------------------------------------------- /sample/RedBook/bezmesh.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) Mark J. Kilgard, 1994. 3 | # 4 | # (c) Copyright 1993, Silicon Graphics, Inc. 5 | # ALL RIGHTS RESERVED 6 | # Permission to use, copy, modify, and distribute this software for 7 | # any purpose and without fee is hereby granted, provided that the above 8 | # copyright notice appear in all copies and that both the copyright notice 9 | # and this permission notice appear in supporting documentation, and that 10 | # the name of Silicon Graphics, Inc. not be used in advertising 11 | # or publicity pertaining to distribution of the software without specific, 12 | # written prior permission. 13 | # 14 | # THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS" 15 | # AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE, 16 | # INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR 17 | # FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON 18 | # GRAPHICS, INC. BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT, 19 | # SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY 20 | # KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION, 21 | # LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF 22 | # THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC. HAS BEEN 23 | # ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON 24 | # ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE 25 | # POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE. 26 | # 27 | # US Government Users Restricted Rights 28 | # Use, duplication, or disclosure by the Government is subject to 29 | # restrictions set forth in FAR 52.227.19(c)(2) or subparagraph 30 | # (c)(1)(ii) of the Rights in Technical Data and Computer Software 31 | # clause at DFARS 252.227-7013 and/or in similar or successor 32 | # clauses in the FAR or the DOD or NASA FAR Supplement. 33 | # Unpublished-- rights reserved under the copyright laws of the 34 | # United States. Contractor/manufacturer is Silicon Graphics, 35 | # Inc., 2011 N. Shoreline Blvd., Mountain View, CA 94039-7311. 36 | # 37 | # OpenGL(TM) is a trademark of Silicon Graphics, Inc. 38 | # 39 | # bezsurf.c 40 | # This program renders a lighted, filled Bezier surface, 41 | # using two-dimensional evaluators. 42 | # 43 | 44 | require 'opengl' 45 | require 'glfw' 46 | require '../util/setup_dll' 47 | 48 | $ctrlpoints = [ 49 | [ 50 | [-1.5, -1.5, 4.0], 51 | [-0.5, -1.5, 2.0], 52 | [0.5, -1.5, -1.0], 53 | [1.5, -1.5, 2.0]], 54 | [ 55 | [-1.5, -0.5, 1.0], 56 | [-0.5, -0.5, 3.0], 57 | [0.5, -0.5, 0.0], 58 | [1.5, -0.5, -1.0]], 59 | [ 60 | [-1.5, 0.5, 4.0], 61 | [-0.5, 0.5, 0.0], 62 | [0.5, 0.5, 3.0], 63 | [1.5, 0.5, 4.0]], 64 | [ 65 | [-1.5, 1.5, -2.0], 66 | [-0.5, 1.5, -2.0], 67 | [0.5, 1.5, 0.0], 68 | [1.5, 1.5, -1.0]] 69 | ] 70 | 71 | def initlights 72 | ambient = [0.2, 0.2, 0.2, 1.0] 73 | position = [0.0, 0.0, 2.0, 1.0] 74 | mat_diffuse = [0.6, 0.6, 0.6, 1.0] 75 | mat_specular = [1.0, 1.0, 1.0, 1.0] 76 | mat_shininess = [50.0] 77 | 78 | GL.Enable(GL::LIGHTING) 79 | GL.Enable(GL::LIGHT0) 80 | 81 | GL.Lightfv(GL::LIGHT0, GL::AMBIENT, ambient.pack('F*')) 82 | GL.Lightfv(GL::LIGHT0, GL::POSITION, position.pack('F*')) 83 | 84 | GL.Materialfv(GL::FRONT, GL::DIFFUSE, mat_diffuse.pack('F*')) 85 | GL.Materialfv(GL::FRONT, GL::SPECULAR, mat_specular.pack('F*')) 86 | GL.Materialfv(GL::FRONT, GL::SHININESS, mat_shininess.pack('F*')) 87 | end 88 | 89 | display = proc do 90 | GL.Clear(GL::COLOR_BUFFER_BIT | GL::DEPTH_BUFFER_BIT) 91 | GL.PushMatrix() 92 | GL.Rotatef(85.0, 1.0, 1.0, 1.0) 93 | GL.EvalMesh2(GL::FILL, 0, 20, 0, 20) 94 | GL.PopMatrix() 95 | end 96 | 97 | def myinit 98 | GL.ClearColor(0.0, 0.0, 0.0, 1.0) 99 | GL.Enable(GL::DEPTH_TEST) 100 | GL.Map2d(GL::MAP2_VERTEX_3, 0, 1, 3, 4, 0, 1, 12, 4, $ctrlpoints.flatten.pack('D*')) 101 | GL.Enable(GL::MAP2_VERTEX_3) 102 | GL.Enable(GL::AUTO_NORMAL) 103 | GL.Enable(GL::NORMALIZE) 104 | GL.MapGrid2d(20, 0.0, 1.0, 20, 0.0, 1.0) 105 | initlights() # for lighted version only 106 | end 107 | 108 | size_callback = GLFW::create_callback(:GLFWwindowsizefun) do |window_handle, w, h| 109 | GL.Viewport(0, 0, w, h) 110 | GL.MatrixMode(GL::PROJECTION) 111 | GL.LoadIdentity() 112 | if (w <= h) 113 | GL.Ortho(-4.0, 4.0, -4.0 * h / w, 4.0 * h / w, -4.0, 4.0) 114 | else 115 | GL.Ortho(-4.0 * w / h, 4.0 * w / h, -4.0, 4.0, -4.0, 4.0) 116 | end 117 | GL.MatrixMode(GL::MODELVIEW) 118 | GL.LoadIdentity() 119 | end 120 | 121 | key_callback = GLFW::create_callback(:GLFWkeyfun) do |window_handle, key, scancode, action, mods| 122 | case key 123 | when GLFW::KEY_ESCAPE 124 | GLFW.SetWindowShouldClose(window_handle, 1) 125 | end 126 | end 127 | 128 | if __FILE__ == $0 129 | 130 | GLFW.load_lib(SampleUtil.glfw_library_path) 131 | GLFW.Init() 132 | window = GLFW.CreateWindow(500, 500, $0, nil, nil) 133 | GLFW.SetWindowPos(window, 100, 100) 134 | GLFW.MakeContextCurrent(window) 135 | GLFW.SetKeyCallback(window, key_callback) 136 | GLFW.SetWindowSizeCallback(window, size_callback) 137 | 138 | GL.load_lib() 139 | 140 | myinit() 141 | 142 | width_ptr = ' ' * 4 143 | height_ptr = ' ' * 4 144 | GLFW.GetFramebufferSize(window, width_ptr, height_ptr) 145 | width = width_ptr.unpack('L')[0] 146 | height = height_ptr.unpack('L')[0] 147 | size_callback.call(window, width, height) 148 | 149 | while GLFW.WindowShouldClose(window) == 0 150 | display.call() 151 | GLFW.SwapBuffers(window) 152 | GLFW.PollEvents() 153 | end 154 | 155 | GLFW.DestroyWindow(window) 156 | GLFW.Terminate() 157 | 158 | end 159 | -------------------------------------------------------------------------------- /sample/GLExcess/glxs.rb: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env ruby 2 | 3 | =begin 4 | GLExcess v1.0 Demo 5 | Copyright (C) 2001-2003 Paolo Martella 6 | 7 | This program is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU General Public License 9 | as published by the Free Software Foundation; either version 2 10 | of the License, or (at your option) any later version. 11 | 12 | This program is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | * Original code : Paolo Martella 18 | * Ruby Porting : vaiorabbit 19 | =end 20 | 21 | require 'optparse' 22 | 23 | require 'opengl' 24 | require 'glu' 25 | require 'glfw' 26 | require_relative '../util/setup_dll' 27 | 28 | require_relative '../util/geometry' 29 | require_relative 'texture' 30 | require_relative 'scene01' 31 | require_relative 'scene02' 32 | require_relative 'scene03' 33 | require_relative 'scene04' 34 | require_relative 'scene05' 35 | require_relative 'scene06' 36 | require_relative 'scene07' 37 | require_relative 'scene08' 38 | require_relative 'scene09' 39 | require_relative 'scene10' 40 | require_relative 'scene11' 41 | require_relative 'scene12' 42 | 43 | $app = nil 44 | 45 | $key_callback = GLFW::create_callback(:GLFWkeyfun) do |window_handle, key, scancode, action, mods| 46 | case key 47 | when GLFW::KEY_A 48 | $app.step += 1 if action == GLFW::PRESS 49 | when GLFW::KEY_Z 50 | $app.step = [-1, $app.step-1].max if action == GLFW::PRESS 51 | when GLFW::KEY_S 52 | # Suspend/Resume 53 | $app.run = !$app.run if action == GLFW::PRESS 54 | when GLFW::KEY_N 55 | # Next Scene 56 | $app.next_scene() if action == GLFW::PRESS 57 | when GLFW::KEY_P 58 | # Previous Scene 59 | $app.prev_scene() if action == GLFW::PRESS 60 | when GLFW::KEY_ESCAPE, GLFW::KEY_Q 61 | GLFW.SetWindowShouldClose(window_handle, 1) 62 | end 63 | end 64 | 65 | 66 | class GLExcess 67 | 68 | attr_accessor :step, :run 69 | 70 | def next_scene 71 | if @scene != nil 72 | @scene.clean 73 | @scene = nil 74 | GC.start 75 | @timing = 0 76 | @step = 1.0 77 | @current_scene += 1 78 | @current_scene %= 12 79 | @scene = @scenes[@current_scene].new 80 | GLFW.SetWindowTitle(@window, "GLExcess/Ruby : " + @scene.class.to_s) 81 | end 82 | end 83 | 84 | def prev_scene 85 | if @scene != nil 86 | @scene.clean 87 | @scene = nil 88 | GC.start 89 | @timing = 0 90 | @step = 1.0 91 | @current_scene -= 1 92 | @current_scene %= 12 93 | @scene = @scenes[@current_scene].new 94 | GLFW.SetWindowTitle(@window, "GLExcess/Ruby : " + @scene.class.to_s) 95 | end 96 | end 97 | 98 | def draw 99 | if @run 100 | if @scene != nil && !@scene.render(@timing) 101 | next_scene() 102 | end 103 | @timing += @step 104 | end 105 | end 106 | 107 | def initialize 108 | GLFW.load_lib(SampleUtil.glfw_library_path) 109 | # Parse Option 110 | scene = 1 111 | ARGV.options do |opt| 112 | opt.on('-s', '--scene : # of Scene [1-12]', Integer, /1[0-2]|[1-9]/) { |v| scene = v.to_i } 113 | opt.parse! 114 | end 115 | 116 | @current_scene = scene - 1 117 | 118 | @scenes = [ Scene01, Scene02, Scene03, Scene04, Scene05, Scene06, 119 | Scene07, Scene08, Scene09, Scene10, Scene11, Scene12 ] 120 | 121 | @window_width = 640 122 | @window_height = 480 123 | 124 | @size_callback = GLFW::create_callback(:GLFWwindowsizefun) do |window_handle, w, h| 125 | @window_width = w 126 | @window_height = h 127 | 128 | GL.Viewport(0, 0, @window_width, @window_height) 129 | 130 | GL.MatrixMode(GL::PROJECTION) 131 | GL.LoadIdentity 132 | GLU.Perspective(45.0, @window_width.to_f/@window_height.to_f, 0.1, 110.0) 133 | 134 | GL.MatrixMode(GL::MODELVIEW) 135 | GL.LoadIdentity 136 | 137 | @scene.render(@timing) if @scene != nil 138 | end 139 | 140 | GLFW.Init() 141 | @window = GLFW.CreateWindow(@window_width, @window_height, "OpenGL compute shader demo", nil, nil) 142 | GLFW.SetWindowPos(@window, 100, 100) 143 | GLFW.MakeContextCurrent(@window) 144 | GLFW.SetKeyCallback(@window, $key_callback) 145 | GLFW.SetWindowSizeCallback(@window, @size_callback) 146 | 147 | GL.load_lib() 148 | GLU.load_lib() 149 | 150 | width_ptr = ' ' * 4 151 | height_ptr = ' ' * 4 152 | GLFW.GetFramebufferSize(@window, width_ptr, height_ptr) 153 | width = width_ptr.unpack('L')[0] 154 | height = height_ptr.unpack('L')[0] 155 | @size_callback.call(@window, width, height) 156 | 157 | @timing = 0.0 158 | @step = 1.0 159 | 160 | @run = true 161 | 162 | @scene = @scenes[@current_scene].new 163 | scene_name = (@scene == nil ? "" : @scene.class.to_s) 164 | GLFW.SetWindowTitle(@window, "GLExcess/Ruby : " + scene_name) 165 | end 166 | 167 | def main 168 | while GLFW.WindowShouldClose(@window) == 0 169 | draw() 170 | GLFW.SwapBuffers(@window) 171 | GLFW.PollEvents() 172 | end 173 | end 174 | 175 | def destroy 176 | GLFW.DestroyWindow(@window) 177 | GLFW.Terminate() 178 | end 179 | 180 | end 181 | 182 | 183 | if __FILE__ == $PROGRAM_NAME 184 | $app = GLExcess.new 185 | begin 186 | $app.main 187 | ensure 188 | $app.destroy 189 | end 190 | end 191 | -------------------------------------------------------------------------------- /sample/util/WavefrontOBJ.rb: -------------------------------------------------------------------------------- 1 | module WavefrontOBJ 2 | 3 | class Face 4 | attr_accessor :vertex_count # must be >= 3 5 | attr_accessor :vtx_index, :nrm_index, :tex_index 6 | 7 | def initialize(vtx_count=3) 8 | @vertex_count = vtx_count 9 | @vtx_index = Array.new(@vertex_count, -1) 10 | @nrm_index = Array.new(@vertex_count, -1) 11 | @tex_index = Array.new(@vertex_count, -1) 12 | end 13 | end # class Face 14 | 15 | class Group 16 | attr_accessor :name, :face_index, :mtl_name, :displaylist 17 | attr_accessor :faces 18 | 19 | def initialize(name="") 20 | @name = name 21 | @face_index = Array.new 22 | @mtl_name = nil 23 | @displaylist = nil 24 | @faces = Array.new # Face 25 | end 26 | 27 | def draw(model) 28 | @face_index.each do |fidx| 29 | GL.Begin(GL::POLYGON) 30 | face = @faces[fidx] 31 | for i in 0...face.vertex_count do 32 | vi = face.vtx_index[i] 33 | ni = face.nrm_index[0] != -1 ? face.nrm_index[i] : nil 34 | ti = face.tex_index[0] != -1 ? face.tex_index[i] : nil 35 | 36 | GL.Normal3f(model.normal[ni][0], model.normal[ni][1], model.normal[ni][2]) if ni 37 | GL.TexCoord2f(model.texcoord[ti][0], model.texcoord[ti][1]) if ti 38 | GL.Vertex3f(model.vertex[vi][0], model.vertex[vi][1], model.vertex[vi][2]) 39 | end 40 | GL.End() 41 | end 42 | end # draw 43 | end # class Group 44 | 45 | 46 | class Model 47 | attr_reader :vertex, :normal, :texcoord 48 | attr_reader :groups 49 | 50 | def initialize 51 | @vertex = Array.new 52 | @normal = Array.new 53 | @texcoord = Array.new 54 | @groups = Hash.new # Group 55 | end 56 | 57 | # returns Group object (or creates new Group when there's no matching group found) 58 | def get_group(name) 59 | if (!@groups.has_key?(name)) 60 | @groups[name] = Group.new(name) 61 | end 62 | return @groups[name] 63 | end 64 | private :get_group 65 | 66 | def process_line(key, values) 67 | case key 68 | 69 | when "v" 70 | values.collect! { |v| v.to_f } 71 | @vertex.push(values) 72 | 73 | when "vn" 74 | values.collect! { |v| v.to_f } 75 | @normal.push(values) 76 | 77 | when "vt" 78 | values.collect! { |v| v.to_f } 79 | @texcoord.push(values[0..1]) # u and v 80 | 81 | when "g", "group" 82 | if values.length == 0 83 | # p "anonymous group detected. treat as \"default\"." 84 | @current_group = get_group("default") 85 | else 86 | # Only the first group is adopted even if there are multiple group names on the line. 87 | @current_group = get_group(values[0]) 88 | end 89 | @current_group.mtl_name = @current_material_name 90 | 91 | when "f" 92 | vertex_count = values.length 93 | case values[0] 94 | when /\d+\/\d+\/\d+/ # v/vt/vn 95 | face = Face.new(vertex_count) 96 | values.each_with_index do |value, i| 97 | v, vt, vn = value.split('/') 98 | face.vtx_index[i] = v.to_i - 1 99 | face.tex_index[i] = vt.to_i - 1 100 | face.nrm_index[i] = vn.to_i - 1 101 | end 102 | 103 | when /\d+\/\/\d+/ # v//vn 104 | face = Face.new(vertex_count) 105 | values.each_with_index do |value, i| 106 | v, vn = value.split('//') 107 | face.vtx_index[i] = v.to_i - 1 108 | face.nrm_index[i] = vn.to_i - 1 109 | end 110 | 111 | when /\d+\/\d+/ # v/vt 112 | face = Face.new(vertex_count) 113 | values.each_with_index do |value, i| 114 | v, vt = value.split('/') 115 | face.vtx_index[i] = v.to_i - 1 116 | face.tex_index[i] = vt.to_i - 1 117 | end 118 | 119 | when /\d+/ # v 120 | face = Face.new(vertex_count) 121 | values.each_with_index do |value, i| 122 | face.vtx_index[i] = value.to_i - 1 123 | end 124 | 125 | else 126 | p "unknown face format detected." 127 | end 128 | @current_group.faces.push(face) 129 | @current_group.face_index.push(@current_group.faces.length - 1) 130 | 131 | when /^\#+/, nil 132 | # puts "comment or empty line." 133 | else 134 | puts "Unsupported token #{key} given. Ignored." 135 | end 136 | end # process_line 137 | private :process_line 138 | 139 | def render 140 | @groups.each_value do |grp| 141 | GL.CallList(grp.displaylist) 142 | end 143 | end # render 144 | 145 | def parse(wofilename) 146 | wo_lines = IO.readlines(wofilename) 147 | 148 | # parse context 149 | @current_group = get_group("default") 150 | @current_material_name = "default" 151 | 152 | wo_lines.each do |line| 153 | tokens = line.split 154 | process_line(tokens[0], tokens[1..tokens.length-1]) 155 | end 156 | 157 | if get_group("default").faces.empty? 158 | @groups.delete("default") 159 | end 160 | @current_group = nil 161 | @current_material_name = nil 162 | end # parse 163 | 164 | def setup 165 | @groups.each_value do |grp| 166 | grp.displaylist = GL.GenLists(1) 167 | GL.NewList(grp.displaylist, GL::COMPILE) 168 | grp.draw(self) 169 | GL.EndList() 170 | end 171 | end # setup 172 | 173 | end # class Model 174 | 175 | end # model WavefrontOBJ 176 | -------------------------------------------------------------------------------- /sample/DebugOutput/debug_output.rb: -------------------------------------------------------------------------------- 1 | require '../util/setup_dll' 2 | require 'opengl' 3 | require 'opengl_ext' 4 | require 'glfw' 5 | 6 | # Press ESC to exit. 7 | key_callback = GLFW::create_callback(:GLFWkeyfun) do |window_handle, key, scancode, action, mods| 8 | if key == GLFW::KEY_ESCAPE && action == GLFW::PRESS 9 | GLFW.SetWindowShouldClose(window_handle, 1) 10 | end 11 | end 12 | 13 | =begin 14 | # https://www.opengl.org/sdk/docs/man4/html/glDebugMessageCallback.xhtml 15 | typedef void (APIENTRY *DEBUGPROC)(GLenum source, 16 | GLenum type, 17 | GLuint id, 18 | GLenum severity, 19 | GLsizei length, 20 | const GLchar *message, 21 | void *userParam); 22 | =end 23 | 24 | cb_args = [-Fiddle::TYPE_INT, -Fiddle::TYPE_INT, -Fiddle::TYPE_INT, -Fiddle::TYPE_INT, Fiddle::TYPE_INT, Fiddle::TYPE_VOIDP, Fiddle::TYPE_VOIDP] 25 | cb_retval = Fiddle::TYPE_VOID 26 | 27 | $debug_log_callback = Fiddle::Closure::BlockCaller.new(cb_retval, cb_args, Fiddle::Function::DEFAULT) { |source, type, id, severity, length, message, userParam| 28 | # p source, type, id, severity, length, message.to_s, userParam 29 | str_source = case source 30 | when GL::DEBUG_SOURCE_API; "API" 31 | when GL::DEBUG_SOURCE_WINDOW_SYSTEM; "Window System" 32 | when GL::DEBUG_SOURCE_SHADER_COMPILER; "Shader Compiler" 33 | when GL::DEBUG_SOURCE_THIRD_PARTY; "Third Party" 34 | when GL::DEBUG_SOURCE_APPLICATION; "Application" 35 | when GL::DEBUG_SOURCE_OTHER; "Other" 36 | else; "[Unknown]" 37 | end 38 | 39 | str_type = case type 40 | when GL::DEBUG_TYPE_ERROR; "Type Error" 41 | when GL::DEBUG_TYPE_DEPRECATED_BEHAVIOR; "Deprecated Behavior" 42 | when GL::DEBUG_TYPE_UNDEFINED_BEHAVIOR; "Undefined Behavior" 43 | when GL::DEBUG_TYPE_PORTABILITY; "Portability" 44 | when GL::DEBUG_TYPE_PERFORMANCE; "Performance" 45 | when GL::DEBUG_TYPE_OTHER; "Other" 46 | when GL::DEBUG_TYPE_MARKER; "Marker" 47 | when GL::DEBUG_TYPE_PUSH_GROUP; "Push Group" 48 | when GL::DEBUG_TYPE_POP_GROUP; "Pop Group" 49 | else; "[Unknown]" 50 | end 51 | 52 | str_severity = case severity 53 | when GL::DEBUG_SEVERITY_HIGH; "High" 54 | when GL::DEBUG_SEVERITY_MEDIUM; "Medium" 55 | when GL::DEBUG_SEVERITY_LOW; "Low" 56 | else; "[Unknown]" 57 | end 58 | puts "[OpenGL Error] Source:#{str_source}, Type:#{str_type}, ID:#{id}, Severity:#{str_severity}" 59 | print "[OpenGL Error] Message: ", message.to_s, "\n" 60 | } 61 | 62 | if __FILE__ == $PROGRAM_NAME 63 | GLFW.load_lib(SampleUtil.glfw_library_path) 64 | GLFW.Init() 65 | GLFW.WindowHint(GLFW::OPENGL_DEBUG_CONTEXT, GLFW::TRUE) 66 | window = GLFW.CreateWindow(640, 480, "OpenGL Debug Context Test", nil, nil) 67 | GLFW.SetWindowPos(window, 100, 100) 68 | GLFW.MakeContextCurrent(window) 69 | GLFW.SetKeyCallback(window, key_callback) 70 | 71 | GL.load_lib() 72 | 73 | # Make sure that OpenGL 4.3 is supported by the driver 74 | major,minor,*rest = GL.GetString(GL::VERSION).to_s.split(/\.| /) 75 | puts "Supports OpenGL Version #{major}.#{minor} #{rest}" 76 | ext_available = ((major.to_i > 4) || (major.to_i == 4 && minor.to_i >= 3)) 77 | unless ext_available 78 | puts "GL_VERSION major=#{major} minor=#{minor}" 79 | puts "Support for OpenGL 4.3 is required for this demo...exiting" 80 | exit(1) 81 | end 82 | 83 | # for OpenGL 4.3 84 | GL.DebugMessageCallback($debug_log_callback.to_i, nil) 85 | GL.Enable(GL::DEBUG_OUTPUT_SYNCHRONOUS) 86 | 87 | # for OpenGL 3 88 | =begin 89 | if OpenGL.check_extension('GL_ARB_debug_output') 90 | OpenGL.setup_extension('GL_ARB_debug_output') 91 | GL.DebugMessageCallbackARB($debug_log_callback, nil) 92 | GL.Enable(GL::DEBUG_OUTPUT_SYNCHRONOUS_ARB) 93 | end 94 | =end 95 | 96 | # for OpenGL ES 97 | =begin 98 | if OpenGL.check_extension('GL_KHR_debug') 99 | OpenGL.setup_extension('GL_KHR_debug') 100 | GL.DebugMessageCallback($debug_log_callback, nil) 101 | GL.Enable(GL::DEBUG_OUTPUT_SYNCHRONOUS) 102 | end 103 | =end 104 | 105 | width_ptr = ' ' * 8 106 | height_ptr = ' ' * 8 107 | GLFW.GetFramebufferSize(window, width_ptr, height_ptr) 108 | width = width_ptr.unpack('L')[0] 109 | height = height_ptr.unpack('L')[0] 110 | ratio = width.to_f / height.to_f 111 | 112 | GL.Viewport(0, 0, width, height) 113 | 114 | while GLFW.WindowShouldClose(window) == 0 115 | GL.Clear(GL::COLOR_BUFFER_BIT) 116 | GL.MatrixMode(GL::PROJECTION) 117 | GL.LoadIdentity() 118 | GL.Ortho(-ratio, ratio, -1.0, 1.0, 1.0, -1.0) 119 | GL.MatrixMode(GL::MODELVIEW) 120 | 121 | GL.LoadIdentity() 122 | GL.Rotatef(GLFW.GetTime() * 50.0, 0.0, 0.0, 1.0) 123 | 124 | GL.Begin(GL::TRIANGLES) 125 | GL.Color3f(1.0, 0.0, 0.0) 126 | GL.Vertex3f(-0.6, -0.4, 0.0) 127 | GL.Color3f(0.0, 1.0, 0.0) 128 | GL.Vertex3f(0.6, -0.4, 0.0) 129 | GL.Color3f(0.0, 0.0, 1.0) 130 | GL.Vertex3f(0.0, 0.6, 0.0) 131 | GL.End() 132 | 133 | GLFW.SwapBuffers(window) 134 | GLFW.PollEvents() 135 | 136 | # *** ERROR *** 137 | GL.Enable(GL::TEXTURE) 138 | # *** ERROR *** 139 | =begin 140 | The above line will generate message like: 141 | [OpenGL Error] Source:API, Type:Type Error, ID:1280, Severity:High 142 | [OpenGL Error] Message: GL_INVALID_ENUM error generated. enum is invalid; expected GL_ALPHA_TEST, GL_BLEND, GL_COLOR_MATERIAL, GL_CULL_FACE, GL_DEPTH_TEST, GL_DITHER, GL_FOG, etc. (136 others). 143 | =end 144 | end 145 | 146 | GLFW.DestroyWindow(window) 147 | GLFW.Terminate() 148 | end 149 | -------------------------------------------------------------------------------- /sample/RedBook/aapoly.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 1993-1997, Silicon Graphics, Inc. 3 | # ALL RIGHTS RESERVED 4 | # Permission to use, copy, modify, and distribute this software for 5 | # any purpose and without fee is hereby granted, provided that the above 6 | # copyright notice appear in all copies and that both the copyright notice 7 | # and this permission notice appear in supporting documentation, and that 8 | # the name of Silicon Graphics, Inc. not be used in advertising 9 | # or publicity pertaining to distribution of the software without specific, 10 | # written prior permission. 11 | # 12 | # THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS" 13 | # AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE, 14 | # INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR 15 | # FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON 16 | # GRAPHICS, INC. BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT, 17 | # SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY 18 | # KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION, 19 | # LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF 20 | # THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC. HAS BEEN 21 | # ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON 22 | # ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE 23 | # POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE. 24 | # 25 | # US Government Users Restricted Rights 26 | # Use, duplication, or disclosure by the Government is subject to 27 | # restrictions set forth in FAR 52.227.19(c)(2) or subparagraph 28 | # (c)(1)(ii) of the Rights in Technical Data and Computer Software 29 | # clause at DFARS 252.227-7013 and/or in similar or successor 30 | # clauses in the FAR or the DOD or NASA FAR Supplement. 31 | # Unpublished-- rights reserved under the copyright laws of the 32 | # United States. Contractor/manufacturer is Silicon Graphics, 33 | # Inc., 2011 N. Shoreline Blvd., Mountain View, CA 94039-7311. 34 | # 35 | # OpenGL(R) is a registered trademark of Silicon Graphics, Inc. 36 | # 37 | # aapoly.c 38 | # This program draws filled polygons with antialiased 39 | # edges. The special GL_SRC_ALPHA_SATURATE blending 40 | # function is used. 41 | # Pressing the 't' key turns the antialiasing on and off. 42 | 43 | require 'opengl' 44 | require 'glu' 45 | require 'glfw' 46 | require_relative '../util/setup_dll' 47 | 48 | $polySmooth = true 49 | 50 | def init 51 | GL.CullFace(GL::BACK) 52 | GL.Enable(GL::CULL_FACE) 53 | GL.BlendFunc(GL::SRC_ALPHA_SATURATE, GL::ONE) 54 | GL.ClearColor(0.0, 0.0, 0.0, 0.0) 55 | end 56 | 57 | NFACE=6 58 | NVERT=8 59 | $indices = [ 60 | [4, 5, 6, 7], [2, 3, 7, 6], [0, 4, 7, 3], 61 | [0, 1, 5, 4], [1, 5, 6, 2], [0, 3, 2, 1] 62 | ] 63 | 64 | def drawCube(x0, x1, y0, y1, z0, z1) 65 | v = [[],[],[],[],[],[],[],[]] 66 | c = [ 67 | [0.0, 0.0, 0.0, 1.0], [1.0, 0.0, 0.0, 1.0], 68 | [0.0, 1.0, 0.0, 1.0], [1.0, 1.0, 0.0, 1.0], 69 | [0.0, 0.0, 1.0, 1.0], [1.0, 0.0, 1.0, 1.0], 70 | [0.0, 1.0, 1.0, 1.0], [1.0, 1.0, 1.0, 1.0] 71 | ] 72 | 73 | # indices of front, top, left, bottom, right, back faces 74 | 75 | v[0][0] = v[3][0] = v[4][0] = v[7][0] = x0 76 | v[1][0] = v[2][0] = v[5][0] = v[6][0] = x1 77 | v[0][1] = v[1][1] = v[4][1] = v[5][1] = y0 78 | v[2][1] = v[3][1] = v[6][1] = v[7][1] = y1 79 | v[0][2] = v[1][2] = v[2][2] = v[3][2] = z0 80 | v[4][2] = v[5][2] = v[6][2] = v[7][2] = z1 81 | 82 | GL.EnableClientState(GL::VERTEX_ARRAY) 83 | GL.EnableClientState(GL::COLOR_ARRAY) 84 | GL.VertexPointer(3, GL::FLOAT, 0, v.flatten!.pack("f*")) 85 | GL.ColorPointer(4, GL::FLOAT, 0, c.flatten!.pack("f*")) 86 | GL.DrawElements(GL::QUADS, NFACE*4, GL::UNSIGNED_BYTE, $indices.flatten.pack("C*")) 87 | GL.DisableClientState(GL::VERTEX_ARRAY) 88 | GL.DisableClientState(GL::COLOR_ARRAY) 89 | end 90 | 91 | # Note: polygons must be drawn from front to back 92 | # for proper blending. 93 | display = proc do 94 | if ($polySmooth) 95 | GL.Clear(GL::COLOR_BUFFER_BIT) 96 | GL.Enable(GL::BLEND) 97 | GL.Enable(GL::POLYGON_SMOOTH) 98 | GL.Disable(GL::DEPTH_TEST) 99 | else 100 | GL.Clear(GL::COLOR_BUFFER_BIT | GL::DEPTH_BUFFER_BIT) 101 | GL.Disable(GL::BLEND) 102 | GL.Disable(GL::POLYGON_SMOOTH) 103 | GL.Enable(GL::DEPTH_TEST) 104 | end 105 | 106 | GL.PushMatrix() 107 | GL.Translated(0.0, 0.0, -8.0) 108 | GL.Rotated(30.0, 1.0, 0.0, 0.0) 109 | GL.Rotated(60.0, 0.0, 1.0, 0.0) 110 | drawCube(-0.5, 0.5, -0.5, 0.5, -0.5, 0.5) 111 | GL.PopMatrix() 112 | end 113 | 114 | size_callback = GLFW::create_callback(:GLFWwindowsizefun) do |window_handle, w, h| 115 | GL.Viewport(0, 0, w, h) 116 | GL.MatrixMode(GL::PROJECTION) 117 | GL.LoadIdentity() 118 | GLU.Perspective(30.0, w.to_f/ h.to_f, 1.0, 20.0) 119 | GL.MatrixMode(GL::MODELVIEW) 120 | GL.LoadIdentity() 121 | end 122 | 123 | key_callback = GLFW::create_callback(:GLFWkeyfun) do |window_handle, key, scancode, action, mods| 124 | case key 125 | when GLFW::KEY_T 126 | if action == GLFW::PRESS 127 | $polySmooth = !$polySmooth 128 | end 129 | when GLFW::KEY_ESCAPE 130 | GLFW.SetWindowShouldClose(window_handle, 1) 131 | end 132 | end 133 | 134 | # Main Loop 135 | if __FILE__ == $PROGRAM_NAME 136 | GLFW.load_lib(SampleUtil.glfw_library_path) 137 | GLFW.Init() 138 | window = GLFW.CreateWindow(500, 500, $0, nil, nil) 139 | GLFW.SetWindowPos(window, 100, 100) 140 | GLFW.MakeContextCurrent(window) 141 | GLFW.SetKeyCallback(window, key_callback) 142 | GLFW.SetWindowSizeCallback(window, size_callback) 143 | 144 | GL.load_lib() 145 | GLU.load_lib() 146 | 147 | init() 148 | 149 | width_ptr = ' ' * 4 150 | height_ptr = ' ' * 4 151 | GLFW.GetFramebufferSize(window, width_ptr, height_ptr) 152 | width = width_ptr.unpack1('L') 153 | height = height_ptr.unpack1('L') 154 | size_callback.call(window, width, height) 155 | 156 | while GLFW.WindowShouldClose(window) == 0 157 | display.call 158 | GLFW.SwapBuffers(window) 159 | GLFW.PollEvents() 160 | end 161 | 162 | GLFW.DestroyWindow(window) 163 | GLFW.Terminate() 164 | end 165 | -------------------------------------------------------------------------------- /sample/RedBook/varray.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 1993-1997, Silicon Graphics, Inc. 3 | # ALL RIGHTS RESERVED 4 | # Permission to use, copy, modify, and distribute this software for 5 | # any purpose and without fee is hereby granted, provided that the above 6 | # copyright notice appear in all copies and that both the copyright notice 7 | # and this permission notice appear in supporting documentation, and that 8 | # the name of Silicon Graphics, Inc. not be used in advertising 9 | # or publicity pertaining to distribution of the software without specific, 10 | # written prior permission. 11 | # 12 | # THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS" 13 | # AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE, 14 | # INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR 15 | # FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON 16 | # GRAPHICS, INC. BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT, 17 | # SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY 18 | # KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION, 19 | # LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF 20 | # THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC. HAS BEEN 21 | # ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON 22 | # ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE 23 | # POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE. 24 | # 25 | # US Government Users Restricted Rights 26 | # Use, duplication, or disclosure by the Government is subject to 27 | # restrictions set forth in FAR 52.227.19(c)(2) or subparagraph 28 | # (c)(1)(ii) of the Rights in Technical Data and Computer Software 29 | # clause at DFARS 252.227-7013 and/or in similar or successor 30 | # clauses in the FAR or the DOD or NASA FAR Supplement. 31 | # Unpublished-- rights reserved under the copyright laws of the 32 | # United States. Contractor/manufacturer is Silicon Graphics, 33 | # Inc., 2011 N. Shoreline Blvd., Mountain View, CA 94039-7311. 34 | # 35 | # OpenGL(R) is a registered trademark of Silicon Graphics, Inc. 36 | # 37 | # varray.c 38 | # This program demonstrates vertex arrays. 39 | 40 | require 'opengl' 41 | require 'glu' 42 | require 'glfw' 43 | require '../util/setup_dll' 44 | 45 | POINTER=1 46 | INTERLEAVED=2 47 | 48 | DRAWARRAY=1 49 | ARRAYELEMENT=2 50 | DRAWELEMENTS=3 51 | 52 | $setupMethod = POINTER 53 | $derefMethod = DRAWARRAY 54 | 55 | def setupPointers 56 | $vertices = [25, 25, 57 | 100, 325, 58 | 175, 25, 59 | 175, 325, 60 | 250, 25, 61 | 325, 325].pack("i*") 62 | $colors = [1.0, 0.2, 0.2, 63 | 0.2, 0.2, 1.0, 64 | 0.8, 1.0, 0.2, 65 | 0.75, 0.75, 0.75, 66 | 0.35, 0.35, 0.35, 67 | 0.5, 0.5, 0.5].pack("f*") 68 | 69 | GL.EnableClientState(GL::VERTEX_ARRAY) 70 | GL.EnableClientState(GL::COLOR_ARRAY) 71 | 72 | GL.VertexPointer(2, GL::INT, 0, $vertices) 73 | GL.ColorPointer(3, GL::FLOAT, 0, $colors) 74 | end 75 | 76 | def setupInterleave 77 | $intertwined = 78 | [1.0, 0.2, 1.0, 100.0, 100.0, 0.0, 79 | 1.0, 0.2, 0.2, 0.0, 200.0, 0.0, 80 | 1.0, 1.0, 0.2, 100.0, 300.0, 0.0, 81 | 0.2, 1.0, 0.2, 200.0, 300.0, 0.0, 82 | 0.2, 1.0, 1.0, 300.0, 200.0, 0.0, 83 | 0.2, 0.2, 1.0, 200.0, 100.0, 0.0].pack("f*") 84 | 85 | GL.InterleavedArrays(GL::C3F_V3F, 0, $intertwined) 86 | end 87 | 88 | def init 89 | GL.ClearColor(0.0, 0.0, 0.0, 0.0) 90 | GL.ShadeModel(GL::SMOOTH) 91 | setupPointers() 92 | end 93 | 94 | display = proc do 95 | GL.Clear(GL::COLOR_BUFFER_BIT) 96 | if ($derefMethod == DRAWARRAY) 97 | GL.DrawArrays(GL::TRIANGLES, 0, 6) 98 | elsif ($derefMethod == ARRAYELEMENT) 99 | GL.Begin(GL::TRIANGLES) 100 | GL.ArrayElement(2) 101 | GL.ArrayElement(3) 102 | GL.ArrayElement(5) 103 | GL.End() 104 | elsif ($derefMethod == DRAWELEMENTS) 105 | $indices = [0, 1, 3, 4].pack("I*") 106 | GL.DrawElements(GL::POLYGON, 4, GL::UNSIGNED_INT, $indices) 107 | end 108 | end 109 | 110 | size_callback = GLFW::create_callback(:GLFWwindowsizefun) do |window_handle, w, h| 111 | GL.Viewport(0, 0, w, h) 112 | GL.MatrixMode(GL::PROJECTION) 113 | GL.LoadIdentity() 114 | GLU.Ortho2D(0.0, w, 0.0, h) 115 | end 116 | 117 | mouse_callback = GLFW::create_callback(:GLFWmousebuttonfun) do |window_handle, button, action, mods| 118 | case button 119 | when GLFW::MOUSE_BUTTON_LEFT 120 | if action == GLFW::PRESS 121 | if $setupMethod == POINTER 122 | $setupMethod = INTERLEAVED 123 | setupInterleave() 124 | elsif $setupMethod == INTERLEAVED 125 | $setupMethod = POINTER 126 | setupPointers() 127 | end 128 | end 129 | when GLFW::MOUSE_BUTTON_MIDDLE,GLFW::MOUSE_BUTTON_RIGHT 130 | if action == GLFW::PRESS 131 | if $derefMethod == DRAWARRAY 132 | $derefMethod = ARRAYELEMENT 133 | elsif $derefMethod == ARRAYELEMENT 134 | $derefMethod = DRAWELEMENTS 135 | elsif $derefMethod == DRAWELEMENTS 136 | $derefMethod = DRAWARRAY 137 | end 138 | end 139 | end 140 | end 141 | 142 | key_callback = GLFW::create_callback(:GLFWkeyfun) do |window_handle, key, scancode, action, mods| 143 | case key 144 | when GLFW::KEY_ESCAPE 145 | GLFW.SetWindowShouldClose(window_handle, 1) 146 | end 147 | end 148 | 149 | 150 | if __FILE__ == $0 151 | GLFW.load_lib(SampleUtil.glfw_library_path) 152 | GLFW.Init() 153 | window = GLFW.CreateWindow(350, 350, $0, nil, nil) 154 | GLFW.SetWindowPos(window, 100, 100) 155 | GLFW.MakeContextCurrent(window) 156 | GLFW.SetKeyCallback(window, key_callback) 157 | GLFW.SetMouseButtonCallback(window, mouse_callback) 158 | GLFW.SetWindowSizeCallback(window, size_callback) 159 | 160 | GL.load_lib() 161 | GLU.load_lib() 162 | 163 | init() 164 | 165 | width_ptr = ' ' * 4 166 | height_ptr = ' ' * 4 167 | GLFW.GetFramebufferSize(window, width_ptr, height_ptr) 168 | width = width_ptr.unpack('L')[0] 169 | height = height_ptr.unpack('L')[0] 170 | size_callback.call(window, width, height) 171 | 172 | while GLFW.WindowShouldClose(window) == 0 173 | display.call() 174 | GLFW.SwapBuffers(window) 175 | GLFW.PollEvents() 176 | end 177 | 178 | GLFW.DestroyWindow(window) 179 | GLFW.Terminate() 180 | end 181 | -------------------------------------------------------------------------------- /sample/RedBook/surface.rb: -------------------------------------------------------------------------------- 1 | # 2 | # (c) Copyright 1993, Silicon Graphics, Inc. 3 | # ALL RIGHTS RESERVED 4 | # Permission to use, copy, modify, and distribute this software for 5 | # any purpose and without fee is hereby granted, provided that the above 6 | # copyright notice appear in all copies and that both the copyright notice 7 | # and this permission notice appear in supporting documentation, and that 8 | # the name of Silicon Graphics, Inc. not be used in advertising 9 | # or publicity pertaining to distribution of the software without specific, 10 | # written prior permission. 11 | # 12 | # THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS" 13 | # AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE, 14 | # INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR 15 | # FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON 16 | # GRAPHICS, INC. BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT, 17 | # SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY 18 | # KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION, 19 | # LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF 20 | # THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC. HAS BEEN 21 | # ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON 22 | # ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE 23 | # POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE. 24 | # 25 | # US Government Users Restricted Rights 26 | # Use, duplication, or disclosure by the Government is subject to 27 | # restrictions set forth in FAR 52.227.19(c)(2) or subparagraph 28 | # (c)(1)(ii) of the Rights in Technical Data and Computer Software 29 | # clause at DFARS 252.227-7013 and/or in similar or successor 30 | # clauses in the FAR or the DOD or NASA FAR Supplement. 31 | # Unpublished-- rights reserved under the copyright laws of the 32 | # United States. Contractor/manufacturer is Silicon Graphics, 33 | # Inc., 2011 N. Shoreline Blvd., Mountain View, CA 94039-7311. 34 | # 35 | # OpenGL(TM) is a trademark of Silicon Graphics, Inc. 36 | # 37 | # 38 | # surface.c 39 | # This program draws a NURBS surface in the shape of a 40 | # symmetrical hill. 41 | # 42 | 43 | require 'opengl' 44 | require 'glu' 45 | require 'glfw' 46 | require '../util/setup_dll' 47 | 48 | $ctlpoints = Array.new(4).collect { Array.new(4).collect { Array.new(3, nil) } } # 4*4*3 array 49 | $showPoints = 0 50 | 51 | $theNurb = nil 52 | 53 | # Initializes the control points of the surface to a small hill. 54 | # The control points range from -3 to +3 in x, y, and z 55 | def init_surface 56 | for u in 0..3 57 | for v in 0..3 58 | $ctlpoints[u][v][0] = 2.0*(u - 1.5) 59 | $ctlpoints[u][v][1] = 2.0*(v - 1.5) 60 | 61 | if ((u == 1 || u == 2) && (v == 1 || v == 2)) 62 | $ctlpoints[u][v][2] = 3 63 | else 64 | $ctlpoints[u][v][2] = -3 65 | end 66 | end 67 | end 68 | end 69 | 70 | # Initialize material property and depth buffer. 71 | def myinit 72 | mat_diffuse = [ 0.7, 0.7, 0.7, 1.0 ] 73 | mat_specular = [ 1.0, 1.0, 1.0, 1.0 ] 74 | mat_shininess = 100.0 75 | 76 | GL.ClearColor(0.0, 0.0, 0.0, 1.0) 77 | GL.Materialfv(GL::FRONT, GL::DIFFUSE, mat_diffuse.pack('F*')) 78 | GL.Materialfv(GL::FRONT, GL::SPECULAR, mat_specular.pack('F*')) 79 | GL.Materialf(GL::FRONT, GL::SHININESS, mat_shininess) 80 | 81 | GL.Enable(GL::LIGHTING) 82 | GL.Enable(GL::LIGHT0) 83 | GL.DepthFunc(GL::LESS) 84 | GL.Enable(GL::DEPTH_TEST) 85 | GL.Enable(GL::AUTO_NORMAL) 86 | GL.Enable(GL::NORMALIZE) 87 | 88 | init_surface() 89 | 90 | $theNurb = GLU.NewNurbsRenderer() 91 | GLU.NurbsProperty($theNurb, GLU::SAMPLING_TOLERANCE, 25.0) 92 | GLU.NurbsProperty($theNurb, GLU::DISPLAY_MODE, GLU::FILL) 93 | end 94 | 95 | display = Proc.new do 96 | knots = [0.0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0] 97 | 98 | GL.Clear(GL::COLOR_BUFFER_BIT | GL::DEPTH_BUFFER_BIT) 99 | 100 | GL.PushMatrix() 101 | GL.Rotatef(330.0, 1.0,0.0,0.0) 102 | GL.Scalef(0.5, 0.5, 0.5) 103 | 104 | GLU.BeginSurface($theNurb) 105 | GLU.NurbsSurface($theNurb, 106 | 8, knots.pack('F*'), 107 | 8, knots.pack('F*'), 108 | 4 * 3, 109 | 3, 110 | $ctlpoints.flatten.pack('F*'), 111 | 4, 4, 112 | GL::MAP2_VERTEX_3) 113 | GLU.EndSurface($theNurb) 114 | 115 | if($showPoints==1) 116 | GL.PointSize(5.0) 117 | GL.Disable(GL::LIGHTING) 118 | GL.Color3f(1.0, 1.0, 0.0) 119 | GL.Begin(GL::POINTS) 120 | for i in 0..3 121 | for j in 0..3 122 | GL.Vertex3f($ctlpoints[i][j][0], $ctlpoints[i][j][1], $ctlpoints[i][j][2]) 123 | end 124 | end 125 | GL.End() 126 | GL.Enable(GL::LIGHTING) 127 | end 128 | 129 | GL.PopMatrix() 130 | end 131 | 132 | size_callback = GLFW::create_callback(:GLFWwindowsizefun) do |window_handle, w, h| 133 | GL.Viewport(0, 0, w, h) 134 | GL.MatrixMode(GL::PROJECTION) 135 | GL.LoadIdentity() 136 | GLU.Perspective(45.0, w/h, 3.0, 8.0) 137 | 138 | GL.MatrixMode(GL::MODELVIEW) 139 | GL.LoadIdentity() 140 | GL.Translatef(0.0, 0.0, -5.0) 141 | end 142 | 143 | key_callback = GLFW::create_callback(:GLFWkeyfun) do |window_handle, key, scancode, action, mods| 144 | case key 145 | when GLFW::KEY_S 146 | if action == GLFW::PRESS 147 | $showPoints = ($showPoints == 0 ? 1 : 0) 148 | end 149 | when GLFW::KEY_ESCAPE 150 | GLFW.SetWindowShouldClose(window_handle, 1) 151 | end 152 | end 153 | 154 | if __FILE__ == $0 155 | GLFW.load_lib(SampleUtil.glfw_library_path) 156 | GLFW.Init() 157 | window = GLFW.CreateWindow(500, 500, $0, nil, nil) 158 | GLFW.SetWindowPos(window, 100, 100) 159 | GLFW.MakeContextCurrent(window) 160 | GLFW.SetKeyCallback(window, key_callback) 161 | GLFW.SetWindowSizeCallback(window, size_callback) 162 | 163 | GL.load_lib() 164 | GLU.load_lib() 165 | 166 | myinit() 167 | 168 | width_ptr = ' ' * 4 169 | height_ptr = ' ' * 4 170 | GLFW.GetFramebufferSize(window, width_ptr, height_ptr) 171 | width = width_ptr.unpack('L')[0] 172 | height = height_ptr.unpack('L')[0] 173 | size_callback.call(window, width, height) 174 | 175 | while GLFW.WindowShouldClose(window) == 0 176 | display.call 177 | GLFW.SwapBuffers(window) 178 | GLFW.PollEvents() 179 | end 180 | 181 | GLFW.DestroyWindow(window) 182 | GLFW.Terminate() 183 | end 184 | -------------------------------------------------------------------------------- /generator/aux_generate_typemap.rb: -------------------------------------------------------------------------------- 1 | # (Execution example) 2 | # $ ruby aux_generate_typemap.rb > aux_typemap.rb 3 | # $ head aux_typemap.rb 4 | # # [NOTICE] Automatically generated file 5 | # module OpenGL 6 | # GL_TYPE_MAP = { 7 | # 'GLenum' => 'Fiddle::TYPE_INT', 8 | # 'GLboolean' => 'Fiddle::TYPE_CHAR', 9 | # 'GLbitfield' => 'Fiddle::TYPE_INT', 10 | # 'GLvoid' => 'Fiddle::TYPE_VOID', 11 | # 'GLbyte' => 'Fiddle::TYPE_CHAR', 12 | # 'GLshort' => 'Fiddle::TYPE_SHORT', 13 | # 'GLint' => 'Fiddle::TYPE_INT', 14 | # $ 15 | 16 | require 'rexml/document' 17 | require 'fiddle' 18 | 19 | CToFiddleTypeMap = { 20 | 'char' => 'Fiddle::TYPE_CHAR', 21 | 'signed char' => 'Fiddle::TYPE_CHAR', 22 | 'unsigned char' => '-Fiddle::TYPE_CHAR', 23 | 'short' => 'Fiddle::TYPE_SHORT', 24 | 'signed short' => 'Fiddle::TYPE_SHORT', 25 | 'unsigned short' => '-Fiddle::TYPE_SHORT', 26 | 'int' => 'Fiddle::TYPE_INT', 27 | 'signed int' => 'Fiddle::TYPE_INT', 28 | 'unsigned int' => '-Fiddle::TYPE_INT', 29 | 'int64_t' => 'Fiddle::TYPE_LONG_LONG', 30 | 'uint64_t' => '-Fiddle::TYPE_LONG_LONG', 31 | 'float' => 'Fiddle::TYPE_FLOAT', 32 | 'double' => 'Fiddle::TYPE_DOUBLE', 33 | 'ptrdiff_t' => 'Fiddle::TYPE_PTRDIFF_T', 34 | 'void' => 'Fiddle::TYPE_VOID', 35 | 'void *' => 'Fiddle::TYPE_VOIDP', 36 | } 37 | 38 | GLToFiddleTypeMap = { 39 | 'GLenum' => '-Fiddle::TYPE_INT', 40 | 'GLboolean' => '-Fiddle::TYPE_CHAR', 41 | 'GLbitfield' => '-Fiddle::TYPE_INT', 42 | 'GLvoid' => 'Fiddle::TYPE_VOID', 43 | 'GLbyte' => 'Fiddle::TYPE_CHAR', 44 | 'GLshort' => 'Fiddle::TYPE_SHORT', 45 | 'GLint' => 'Fiddle::TYPE_INT', 46 | 'GLclampx' => 'Fiddle::TYPE_INT', 47 | 'GLubyte' => '-Fiddle::TYPE_CHAR', 48 | 'GLushort' => '-Fiddle::TYPE_SHORT', 49 | 'GLuint' => '-Fiddle::TYPE_INT', 50 | 'GLsizei' => 'Fiddle::TYPE_INT', 51 | 'GLfloat' => 'Fiddle::TYPE_FLOAT', 52 | 'GLclampf' => 'Fiddle::TYPE_FLOAT', 53 | 'GLdouble' => 'Fiddle::TYPE_DOUBLE', 54 | 'GLclampd' => 'Fiddle::TYPE_DOUBLE', 55 | 'GLeglImageOES' => 'Fiddle::TYPE_VOIDP', 56 | 'GLchar' => 'Fiddle::TYPE_CHAR', 57 | 'GLcharARB' => 'Fiddle::TYPE_CHAR', 58 | 'GLhandleARB' => 'Fiddle::TYPE_VOIDP', # should be Fiddle::TYPE_INT for platforms other than __APPLE__ 59 | 'GLhalfARB' => '-Fiddle::TYPE_SHORT', 60 | 'GLhalf' => '-Fiddle::TYPE_SHORT', 61 | 'GLfixed' => 'Fiddle::TYPE_INT', 62 | 'GLintptr' => 'Fiddle::TYPE_PTRDIFF_T', 63 | 'GLsizeiptr' => 'Fiddle::TYPE_PTRDIFF_T', 64 | 'GLint64' => 'Fiddle::TYPE_LONG_LONG', 65 | 'GLuint64' => '-Fiddle::TYPE_LONG_LONG', 66 | 'GLintptrARB' => 'Fiddle::TYPE_PTRDIFF_T', 67 | 'GLsizeiptrARB' => 'Fiddle::TYPE_PTRDIFF_T', 68 | 'GLint64EXT' => 'Fiddle::TYPE_LONG_LONG', 69 | 'GLuint64EXT' => '-Fiddle::TYPE_LONG_LONG', 70 | 'GLsync' => 'Fiddle::TYPE_VOIDP', # == struct __GLsync * 71 | # 'struct _cl_context' => 'Fiddle::TYPE_VOIDP' 72 | # 'struct _cl_event' => 'Fiddle::TYPE_VOIDP' 73 | 'GLDEBUGPROC' => 'Fiddle::TYPE_VOIDP', # == void ( *GLDEBUGPROC)(GLenum source,GLenum type,GLuint id,GLenum severity,GLsizei length,const GLchar *message,const void *userParam); 74 | 'GLDEBUGPROCARB' => 'Fiddle::TYPE_VOIDP', # == void ( *GLDEBUGPROCARB)(GLenum source,GLenum type,GLuint id,GLenum severity,GLsizei length,const GLchar *message,const void *userParam); 75 | 'GLDEBUGPROCKHR' => 'Fiddle::TYPE_VOIDP', # == void ( *GLDEBUGPROCKHR)(GLenum source,GLenum type,GLuint id,GLenum severity,GLsizei length,const GLchar *message,const void *userParam); 76 | 77 | 'GLDEBUGPROCAMD' => 'Fiddle::TYPE_VOIDP', # == void ( *GLDEBUGPROCAMD)(GLuint id,GLenum category,GLenum severity,GLsizei length,const GLchar *message,void *userParam); 78 | 'GLhalfNV' => '-Fiddle::TYPE_SHORT', 79 | 'GLvdpauSurfaceNV' => 'Fiddle::TYPE_PTRDIFF_T', # == GLintptr 80 | 'GLVULKANPROCNV' => 'Fiddle::TYPE_VOIDP', # == typedef GLVULKANPROCNV (APIENTRYP PFNGLGETVKPROCADDRNVPROC) (const GLchar *name); 81 | } 82 | 83 | GLTypeMapEntry = Struct.new( :def_name, :ctype_name ) 84 | gl_type_map = [] 85 | 86 | doc = REXML::Document.new(open("./gl.xml")) 87 | 88 | REXML::XPath.each(doc, 'registry/types/type') do |type_tag| 89 | # Skip stddef/khrplatform/inttypes to process actual GL types 90 | name_attr = type_tag.attribute('name') 91 | next if name_attr != nil && (name_attr.value == 'stddef' || name_attr.value == 'khrplatform' || name_attr.value == 'inttypes') 92 | 93 | # Skip ES1/2 types 94 | api_attr = type_tag.attribute('api') 95 | if api_attr != nil 96 | next if api_attr.value == 'gles1' || api_attr.value == 'gles2' || api_attr.value == 'glsc2' 97 | end 98 | 99 | # Analyze the content of ... 100 | content = type_tag.text 101 | name_tag = type_tag.get_elements('name').first 102 | 103 | if name_tag != nil 104 | if type_tag.elements['apientry'] != nil 105 | # ex.) typedef void ( *GLVULKANPROCNV)(void); 106 | def_name = name_tag.text.strip # ex.) def_name <- GLVULKANPROCNV 107 | ctype_name = 'void *' 108 | else 109 | # ex.) typedef float GLfloat; 110 | def_name = name_tag.text.strip # ex.) def_name <- GLfloat 111 | ctype_name = content.chomp(def_name + ';').sub('typedef ','').strip # ex.) ctype_name <- float 112 | end 113 | else 114 | # The actual type of 'GLhandleARB' should be changed depending on your platform (#ifdef __APPLE__, ...) 115 | def_name = name_attr.value 116 | ctype_name = "Needs tweaking by hand..." 117 | end 118 | 119 | # Store the result into name -> ctype map 120 | map_entry = GLTypeMapEntry.new 121 | map_entry.def_name = def_name 122 | map_entry.ctype_name = ctype_name 123 | gl_type_map << map_entry 124 | end 125 | 126 | 127 | if __FILE__ == $0 128 | puts "# [NOTICE] Automatically generated file" 129 | puts "module GL" 130 | puts " GL_TYPE_MAP = {" 131 | 132 | # Resolve OpenGL types to corresponding Fiddle type ('Fiddle::TYPE_XX') 133 | gl_type_map.each do |t| 134 | fiddle_type = CToFiddleTypeMap[t.ctype_name] # ex.) GLint -> Fiddle::TYPE_INT 135 | comment = nil 136 | if fiddle_type == nil # GL types defined by typdef of another GL type (GLfixed, etc.). 137 | fiddle_type = GLToFiddleTypeMap[t.ctype_name] # ex.) GLfixed -> GLint -> Fiddle::TYPE_INT 138 | if fiddle_type == nil # fallback 139 | fiddle_type = 'Fiddle::TYPE_VOIDP' 140 | comment = '<- *** [CHECK] Cannot resolved to any Fiddle type. You might need tweaking for this. ***' 141 | end 142 | end 143 | printf " '#{t.def_name}' => '#{fiddle_type}',%s\n", (comment ? " # #{comment}" : '') 144 | end 145 | 146 | puts "" 147 | 148 | # Copy C/C++ type map 149 | CToFiddleTypeMap.each do |t| 150 | puts " '#{t[0]}' => '#{t[1]}'," 151 | end 152 | 153 | puts " }" 154 | puts "end" 155 | end 156 | -------------------------------------------------------------------------------- /sample/GLExcess/scene07data.rb: -------------------------------------------------------------------------------- 1 | class Scene07 2 | @@datas = [ 3 | 0,4,2,2,2,9,3,0,1,9,0,6,0,0,6,0,3,4,7,5,2,0,7,6,3,4,2,2,0,8,7,6,3,1,4,2,1,0,9,6,0,9,0,6,3,3,5,4,2,2,5,1, 4 | 2,7,3,1,0,3,6,2,1,3,7,4,0,4,2,3,1,2,9,5,2,2,7,3,1,0,0,0,0,5,5,2,1,9,7,0,0,1,6,6,1,7,2,4,0,5,1,6,0,5,0,4, 5 | 1,4,7,0,2,9,5,5,2,5,5,6,1,4,6,6,0,3,6,2,2,2,5,2,0,3,8,2,0,8,1,1,0,5,9,2,1,1,2,1,2,0,8,0,3,2,1,5,2,1,6,5, 6 | 2,1,7,2,1,8,6,5,3,5,2,2,1,8,7,2,3,2,1,3,1,9,7,2,3,5,7,3,0,7,0,6,1,0,0,6,1,8,7,1,3,2,6,4,2,7,8,3,1,7,8,3, 7 | 1,0,1,0,2,1,3,1,0,8,6,3,3,3,3,1,1,3,6,6,0,3,8,6,3,5,5,6,0,6,1,6,2,4,3,2,2,9,9,3,0,8,9,2,2,6,8,0,2,7,5,3, 8 | 2,0,8,2,2,1,2,5,1,7,8,6,1,0,3,5,1,5,1,5,0,4,0,3,0,0,9,2,0,6,0,2,2,1,3,0,2,2,6,1,3,1,4,5,2,2,6,3,0,2,0,6, 9 | 2,2,9,0,2,4,7,1,0,8,4,3,0,4,7,1,0,7,0,2,0,3,1,1,2,1,3,2,2,8,9,1,2,8,0,1,2,2,2,3,0,7,0,0,0,6,2,3,2,8,9,3, 10 | 1,6,1,1,3,0,5,6,1,6,7,6,0,5,9,6,3,5,8,4,0,8,9,0,0,6,6,6,2,4,3,6,1,2,2,0,0,6,3,3,3,3,7,1,1,0,9,0,2,5,7,1, 11 | 3,0,2,0,1,2,7,4,1,0,3,5,1,9,5,6,2,9,6,3,2,2,2,1,0,5,0,2,2,6,5,1,0,4,7,2,0,2,7,0,1,9,6,6,1,9,5,3,3,4,1,2, 12 | 2,5,5,1,0,8,0,6,1,8,1,1,1,3,3,2,1,0,4,2,1,2,4,5,0,1,4,6,3,3,5,6,2,5,5,3,1,0,6,6,0,8,0,1,0,6,4,3,3,1,2,6, 13 | 2,9,6,2,0,6,6,0,2,9,6,3,2,5,3,3,1,7,6,2,1,4,5,1,0,1,8,1,3,3,9,5,2,6,4,2,0,1,0,2,2,1,5,3,2,7,5,1,3,0,7,5, 14 | 0,0,2,2,2,2,8,2,1,2,2,3,3,3,5,1,3,3,5,1,2,3,9,2,0,9,8,6,2,1,3,6,0,2,0,3,0,5,3,2,3,2,6,5,2,2,8,2,3,0,5,4, 15 | 0,4,7,0,1,5,4,3,1,9,0,3,2,8,8,6,2,5,7,1,3,4,5,3,3,0,5,4,2,7,3,5,1,0,6,3,1,6,5,4,1,6,7,2,1,1,1,5,3,0,3,0, 16 | 2,0,3,3,2,6,3,1,0,0,9,6,3,2,0,3,0,5,1,6,1,7,8,3,2,1,8,0,2,2,5,6,3,4,9,0,3,4,3,1,2,8,2,3,2,0,2,2,0,1,5,5, 17 | 1,6,7,0,0,9,0,1,1,1,1,5,3,4,4,2,0,4,9,0,1,1,6,0,0,5,7,0,0,0,8,5,1,2,0,6,2,0,8,4,1,8,7,0,0,9,3,0,0,4,8,3, 18 | 1,3,6,0,0,7,8,3,1,7,6,0,1,8,0,0,0,6,1,4,2,5,3,2,3,2,5,4,1,7,1,3,2,4,8,3,0,6,6,5,3,1,9,1,0,7,0,4,0,5,0,3, 19 | 1,8,4,6,1,9,4,1,2,6,8,3,0,5,2,6,3,5,8,4,3,5,9,1,3,1,9,6,2,0,8,5,0,5,0,2,3,1,6,5,3,0,8,1,1,1,7,5,0,8,3,4, 20 | 1,2,1,3,2,3,0,5,3,2,0,5,2,5,4,1,0,4,4,5,2,0,4,5,3,0,1,4,2,2,7,1,1,8,2,4,1,5,8,5,0,7,4,4,2,4,5,5,0,5,2,4, 21 | 2,7,6,3,2,3,7,0,1,5,7,6,2,3,0,4,2,4,8,3,2,4,9,1,0,7,1,4,0,3,5,1,3,1,9,1,1,8,9,6,2,8,4,0,2,3,5,5,1,5,5,0, 22 | 3,5,6,6,1,4,2,6,2,2,8,4,0,9,2,1,1,1,0,2,0,0,7,5,2,8,6,0,3,0,6,5,2,1,4,2,3,4,7,2,1,1,1,4,1,7,3,4,1,4,6,1, 23 | 0,4,9,6,2,8,7,1,2,0,6,5,0,4,7,5,1,1,0,1,0,0,5,5,2,9,1,4,0,4,2,1,0,4,2,3,1,8,5,4,0,3,8,5,3,1,1,4,0,1,7,6, 24 | 0,9,5,4,1,9,1,6,3,5,0,0,1,0,7,2,0,1,0,6,0,3,7,5,0,0,0,4,1,3,2,0,2,3,9,1,1,2,9,5,0,6,3,2,2,8,4,0,0,8,6,0, 25 | 3,2,4,3,0,1,2,6,1,4,5,2,0,6,9,0,2,6,7,0,3,1,9,1,2,9,6,1,0,4,4,2,2,5,0,1,0,6,6,3,2,0,8,5,2,4,2,4,1,1,9,6, 26 | 2,6,2,0,0,4,7,0,0,4,6,3,0,5,0,2,2,7,6,1,3,5,5,1,0,2,3,6,1,0,0,6,0,1,3,5,1,1,5,1,2,2,1,0,1,8,1,4,1,9,6,6, 27 | 2,9,8,5,3,1,7,2,2,2,8,1,1,1,0,2,0,7,5,2,0,2,5,0,0,7,4,3,0,1,7,0,2,4,8,0,1,9,8,6,2,7,1,4,2,0,2,3,1,0,5,2, 28 | 2,6,0,6,0,4,4,2,0,3,7,6,0,0,3,3,2,9,8,0,2,2,4,6,2,3,3,1,3,5,8,6,2,3,9,3,3,4,8,5,0,0,1,0,1,4,3,0,0,2,6,3, 29 | 0,8,6,6,2,6,8,3,0,7,6,0,1,4,6,6,2,3,3,0,0,3,8,1,0,0,2,2,2,7,1,3,0,2,7,1,2,3,7,1,1,7,8,3,0,6,4,0,2,5,4,1, 30 | 0,0,5,2,3,4,4,0,2,6,6,4,1,2,0,6,0,6,9,6,2,1,1,4,1,2,7,5,2,2,7,1,0,2,3,2,2,3,2,6,2,3,7,4,1,2,6,3,1,9,5,4, 31 | 2,3,9,6,2,5,1,1,0,9,0,2,2,3,7,6,0,6,7,3,1,3,5,4,0,1,4,5,2,3,5,3,2,9,4,5,3,3,1,6,0,4,3,3,2,4,0,0,2,6,0,6, 32 | 0,8,3,0,0,7,2,6,2,2,7,6,1,3,9,3,3,3,7,1,3,0,3,1,2,8,1,4,3,1,3,6,1,9,4,1,3,1,8,4,0,3,8,6,1,1,0,4,0,9,4,1, 33 | 2,0,8,1,3,0,4,0,0,0,6,5,3,1,5,4,2,9,7,1,2,0,5,0,2,0,0,3,1,3,8,4,0,7,8,4,1,2,8,0,2,6,6,4,1,8,5,6,2,9,0,2, 34 | 2,8,0,4,1,6,2,0,0,6,3,2,3,4,6,2,2,5,7,5,0,8,6,6,2,6,8,5,3,4,6,3,0,4,9,4,0,1,3,4,0,7,8,3,1,9,7,1,2,3,5,2, 35 | 1,9,6,4,1,0,9,0,0,9,0,2,0,2,4,4,1,9,5,6,0,8,0,4,2,4,9,1,2,3,3,3,0,3,7,2,2,4,5,2,2,7,4,1,1,3,4,3,2,3,5,0, 36 | 1,2,5,6,1,7,5,2,0,5,8,5,3,5,3,2,2,0,5,6,0,4,5,4,2,2,9,6,3,3,5,3,2,3,9,6,2,5,4,6,0,7,3,1,1,0,6,2,0,8,7,2, 37 | 3,0,6,6,2,0,5,5,0,7,3,6,1,5,0,1,0,7,3,4,1,8,9,2,2,4,0,4,2,9,1,0,2,8,3,4,1,2,8,1,3,2,0,3,1,7,3,1,1,2,0,5, 38 | 0,6,5,4,1,6,5,6,2,6,6,6,1,3,6,6,0,5,4,4,1,5,9,3,2,6,7,2,1,0,1,3,2,5,2,4,0,9,0,0,0,4,5,4,0,4,4,3,1,1,3,1, 39 | 2,3,0,3,1,3,7,1,1,5,2,6,2,1,6,3,0,7,1,4,0,6,1,0,3,1,8,6,3,0,5,6,0,2,9,2,1,4,6,2,2,8,2,2,2,7,1,0,1,2,5,3, 40 | 1,4,8,5,1,3,7,2,2,8,8,6,1,5,1,1,2,9,3,0,1,0,0,0,2,4,8,0,0,3,9,2,0,9,0,0,1,5,6,2,1,9,8,2,3,0,0,0,0,6,0,1, 41 | 0,8,8,5,0,1,3,6,1,7,9,5,0,8,8,0,1,4,4,4,1,1,6,4,1,3,3,0,3,1,1,1,2,4,6,5,3,1,9,3,2,5,3,6,1,6,7,4,1,9,2,5, 42 | 1,4,0,3,1,3,1,3,2,0,0,0,2,4,8,4,0,5,5,2,0,9,2,2,3,2,9,0,1,4,8,6,2,2,3,1,2,4,7,1,1,6,0,5,3,1,0,0,3,1,8,5, 43 | 1,9,3,6,3,3,3,4,0,6,8,0,2,6,0,2,1,0,7,1,2,7,2,2,2,0,9,6,2,9,3,0,0,3,9,2,1,6,6,0,0,4,2,0,2,4,7,0,1,7,4,6, 44 | 0,3,2,1,1,8,6,6,2,0,5,3,0,2,8,2,2,0,4,2,2,9,5,1,0,4,7,2,0,9,8,1,2,7,4,2,3,0,7,0,0,3,1,4,1,8,8,5,2,3,2,2, 45 | 2,5,2,6,2,3,7,5,2,9,7,1,0,4,7,1,3,0,0,0,0,0,4,2,2,9,4,0,3,4,0,1,1,2,2,5,1,3,0,6,2,9,8,6,0,6,4,4,3,4,3,1, 46 | 0,4,4,4,3,4,7,1,3,1,9,3,2,9,7,5,3,4,5,3,2,8,8,3,2,1,3,6,1,6,4,3,2,1,0,2,0,4,5,1,1,4,8,0,0,6,0,5,1,5,2,5, 47 | 1,8,7,2,1,4,4,4,2,6,0,2,1,4,2,6,2,9,3,5,1,4,7,3,2,3,4,1,0,6,6,2,1,4,7,0,0,5,7,5,1,9,2,1,2,8,0,4,1,5,5,2, 48 | 0,0,6,6,0,6,1,2,2,0,8,2,3,0,7,1,1,8,6,3,1,9,4,6,1,9,5,4,1,6,9,2,0,2,8,3,2,5,4,3,0,6,6,5,2,3,5,3,1,2,4,2, 49 | 2,1,8,3,1,5,1,1,0,2,3,5,1,6,8,1,2,2,9,6,0,8,9,4,1,0,8,3,1,2,0,5,0,7,4,0,1,6,4,3,0,9,5,0,1,8,6,0,0,3,7,2, 50 | 3,5,9,5,1,7,5,5,1,0,2,3,2,7,3,6,1,5,6,2,1,4,5,3,1,0,7,2,1,4,1,4,0,2,8,4,1,1,7,0,1,5,2,3,0,0,2,1,0,6,5,6, 51 | 1,8,4,5,0,2,8,5,1,1,9,1,3,2,2,1,3,1,2,4,3,1,1,4,1,7,4,5,0,1,0,4,2,5,8,2,2,4,7,3,2,4,4,1,3,4,5,2,1,2,7,4, 52 | 3,5,6,0,2,6,1,4,0,3,4,2,1,8,6,4,2,9,1,6,1,4,9,5,1,3,1,2,2,4,4,2,2,6,3,1,2,8,8,1,2,4,0,3,0,9,7,3,1,8,7,4, 53 | 0,9,1,2,0,0,0,5,2,6,5,3,0,1,0,0,2,0,8,5,2,3,8,4,1,8,4,5,1,7,5,4,3,0,2,5,0,4,1,2,2,8,5,3,0,6,1,4,0,5,5,2, 54 | 3,3,3,3,1,1,1,0,1,6,9,1,1,0,4,6,1,8,4,4,3,0,7,3,0,7,5,2,0,8,5,5,2,3,8,5,2,5,5,1,2,1,6,3,1,7,9,4,0,2,2,3, 55 | 0,1,9,3,0,9,1,2,1,7,1,0,2,5,8,4,0,1,8,1,3,1,1,0,1,7,3,1,0,1,1,4,0,0,6,4,3,4,2,2,3,1,5,3,0,1,8,1,1,2,1,1, 56 | 1,3,4,3,2,9,8,0,1,3,6,2,0,9,3,0,2,7,1,4,0,5,3,0,0,2,3,0,2,3,6,6,2,8,6,0,3,4,6,4,1,0,3,6,1,9,2,0,1,3,3,0, 57 | 0,4,2,6,0,0,2,4,1,8,9,6,2,5,6,4,2,4,5,6,1,5,2,2,0,7,5,2,0,5,0,6,0,2,8,1,1,0,8,3,0,9,3,5,0,0,6,5,1,2,5,4, 58 | 1,0,9,6,2,2,8,4,1,1,8,5,0,3,5,6,3,4,2,6,1,4,8,3,1,0,3,4,1,4,8,5,2,7,0,0,2,2,1,3,2,2,7,1,2,0,1,0,3,2,9,5, 59 | 0,0,3,4,0,3,0,3,2,4,8,1,0,7,7,0,2,0,7,4,1,3,8,0,1,2,5,6,1,8,2,2,0,2,8,1,1,5,6,6,3,0,1,5,0,6,6,5,0,6,7,4, 60 | 0,4,4,4,1,4,6,2,2,3,7,6,3,3,6,6,0,6,4,3,2,0,3,1,1,7,5,3,2,0,3,1,2,9,7,4,3,3,7,2,1,7,7,3,2,1,6,2,1,0,0,5, 61 | 0,7,4,2,2,6,8,5,2,3,8,6,1,0,7,3,3,2,1,6,1,6,9,3,0,4,3,0,1,0,6,2,3,4,8,4,2,5,8,1,2,6,3,4,2,2,7,4,1,2,5,6, 62 | 3,5,2,6,0,0,5,2,2,2,6,2,1,1,4,2,2,4,3,2,2,3,0,4,1,6,9,6,2,7,8,0,1,8,2,5,2,0,5,0,0,1,3,6,1,4,1,6,2,7,1,0, 63 | 0,8,3,6,1,8,3,4,2,0,3,1,0,8,3,0,1,1,7,2,3,4,9,1,1,2,6,6,1,4,4,6,2,6,5,4,2,7,0,4,0,8,7,6,0,6,5,2,1,0,1,4, 64 | 3,0,5,6,2,7,8,6,2,4,6,3,0,5,6,1,3,4,3,0,0,0,3,6,2,7,4,5,1,7,5,5,2,0,4,0,0,0,5,6,2,2,7,1,2,0,9,5,3,3,8,0, 65 | 3,5,8,1,0,2,9,5,0,7,5,6,2,8,6,0,1,9,7,6,2,7,1,5,2,2,1,1,0,2,5,5,2,2,7,4,1,0,8,1,1,6,3,1,1,4,4,2,1,5,9,0, 66 | 1,0,0,0,2,5,3,5,1,9,7,4,0,5,1,1,0,1,7,0,1,0,4,2,2,5,9,6,2,2,0,0,1,8,6,0,2,1,8,5,2,7,0,0,2,8,5,0,2,7,5,5, 67 | 0,5,8,4,0,4,1,2,0,9,3,3,1,4,6,4,2,3,8,2,2,7,8,2,1,2,4,1,0,3,6,5,1,3,8,2,0,5,0,6,1,0,6,5,2,4,6,1,0,6,4,3, 68 | 2,2,2,3,1,2,8,1,1,0,1,0,1,5,5,1,0,3,9,3,2,1,3,0,1,3,5,4,3,2,2,2,2,2,2,1,2,3,5,0,1,8,3,1,1,3,2,4,1,2,1,5, 69 | 1,6,0,0,0,6,1,5,1,0,2,4,3,3,6,6,2,2,1,3,0,9,9,1,0,5,4,5,1,9,3,1,3,4,6,0,2,6,5,4,3,2,4,5,2,6,9,5,2,3,1,1, 70 | 2,8,2,2,0,2,7,3,0,9,7,4,1,3,2,3,0,5,3,1,3,0,8,4,2,7,0,1,1,3,9,5,1,0,9,1,0,4,4,1,0,8,1,3,1,4,5,2,0,8,9,5, 71 | 0,4,1,4,1,8,7,5,1,1,3,0,2,0,5,1,1,1,3,3,2,3,4,0,2,8,8,0,0,0,7,6,3,0,7,6,3,0,2,6,3,3,0,0,0,5,9,0,0,4,3,6, 72 | 2,5,3,6,1,6,4,0,3,3,5,4,3,3,1,4,0,3,2,6,0,6,4,2,3,0,3,3,3,0,1,2,3,1,5,4,3,5,6,2,1,3,1,5,0,5,0,6,2,3,3,3, 73 | 3,3,1,1,3,3,2,1,3,2,6,5,0,9,4,2,0,1,0,2,3,4,7,3,2,5,7,6,0,9,1,5,0,6,8,5,2,5,0,3,1,3,5,4,0,3,0,2,2,3,1,5, 74 | 0,0,0,3,2,0,9,0,1,3,5,6,2,1,2,6,2,8,9,5,0,7,4,0,3,2,4,6,2,1,9,3,2,7,6,4,2,9,1,2,2,0,5,5,2,7,7,6,1,8,8,5, 75 | 2,4,0,5,0,4,9,3,3,2,9,5,3,4,4,4,3,5,2,0,3,2,8,2,2,2,3,4,0,9,8,1,2,5,7,3,1,1,8,5,0,2,4,1,0,0,3,6,1,8,6,1, 76 | 1,1,1,4,2,9,2,2,3,1,0,0,1,3,5,4,2,1,3,3,1,6,2,3,1,7,7,4,0,4,8,2,3,2,3,2,0,3,6,3,3,5,9,1,0,2,6,6,3,5,0,5, 77 | 2,8,0,3,1,9,3,0,0,4,5,0,1,6,6,5,2,5,6,6,2,0,0,1,0,4,4,6,2,7,4,0,1,3,9,6,0,3,6,3,2,9,6,2,2,4,9,2,2,4,2,1, 78 | 3,3,6,3,3,3,4,6,3,4,6,6,2,1,9,5,1,5,5,5,3,1,6,4,2,5,3,1,0,9,8,5,2,0,1,5,1,9,2,2,2,3,2,2,0,9,1,0,1,6,1,1, 79 | 2,7,3,6,1,1,5,5,1,3,7,2,0,5,3,5,3,1,6,2,0,7,5,2,3,1,4,0,0,0,4,0,3,5,2,4,1,7,1,5,2,8,8,6,0,5,1,1 80 | ] 81 | end 82 | -------------------------------------------------------------------------------- /sample/ComputeShader/opengl_cs.rb: -------------------------------------------------------------------------------- 1 | require 'opengl' 2 | require 'glfw' 3 | require_relative '../util/setup_dll' 4 | 5 | WIN_WIDTH, WIN_HEIGHT = 800, 600 6 | $renderHandle = nil 7 | $computeHandle = nil 8 | 9 | def checkErrors(desc) 10 | e = GL.GetError() 11 | if e != GL::NO_ERROR 12 | $stderr.puts "OpenGL error in \"#{desc}\": #{gluErrorString(e)} (#{e})\n" 13 | exit 14 | end 15 | end 16 | 17 | def genComputeProg(texHandle) 18 | # Creating the compute shader, and the program object containing the shader 19 | progHandle = GL.CreateProgram() 20 | cs = GL.CreateShader(GL::COMPUTE_SHADER) 21 | 22 | # In order to write to a texture, we have to introduce it as image2D. 23 | # local_size_x/y/z layout variables define the work group size. 24 | # gl_GlobalInvocationID is a uvec3 variable giving the global ID of the thread, 25 | # gl_LocalInvocationID is the local index within the work group, and 26 | # gl_WorkGroupID is the work group's index 27 | csSrc = <<-'SRC' 28 | #version 430 29 | uniform float roll; 30 | uniform writeonly image2D destTex; 31 | layout (local_size_x = 16, local_size_y = 16) in; 32 | void main() { 33 | ivec2 storePos = ivec2(gl_GlobalInvocationID.xy); 34 | float localCoef = length(vec2(ivec2(gl_LocalInvocationID.xy)-8)/8.0); 35 | float globalCoef = sin(float(gl_WorkGroupID.x+gl_WorkGroupID.y)*0.1 + roll)*0.5; 36 | imageStore(destTex, storePos, vec4(1.0-globalCoef*localCoef, 0.0, 0.0, 0.0)); 37 | } 38 | SRC 39 | 40 | GL.ShaderSource(cs, 1, [csSrc].pack('p'), [csSrc.size].pack('I')) 41 | GL.CompileShader(cs) 42 | rvalue_buf = ' ' * 4 43 | GL.GetShaderiv(cs, GL::COMPILE_STATUS, rvalue_buf) 44 | rvalue = rvalue_buf.unpack('L')[0] 45 | if rvalue == 0 46 | $stderr.puts "Error in compiling the compute shader" 47 | log_buf = ' ' * 10240 48 | length_buf = ' ' * 4 49 | GL.GetShaderInfoLog(cs, 10239, length_buf, log_buf) 50 | $stderr.puts "Compiler log:\n#{log_buf}" 51 | exit() 52 | end 53 | GL.AttachShader(progHandle, cs) 54 | 55 | GL.LinkProgram(progHandle) 56 | GL.GetProgramiv(progHandle, GL::LINK_STATUS, rvalue_buf) 57 | rvalue = rvalue_buf.unpack('L')[0] 58 | if rvalue == 0 59 | $stderr.puts "Error in linking compute shader program" 60 | log_buf = ' ' * 10240 61 | length_buf = ' ' * 4 62 | GL.GetProgramInfoLog(progHandle, 10239, length_buf, log_buf) 63 | $stderr.puts "Linker log:\n#{log_buf}" 64 | exit() 65 | end 66 | GL.UseProgram(progHandle) 67 | 68 | GL.Uniform1i(GL.GetUniformLocation(progHandle, "destTex"), 0) 69 | 70 | checkErrors("Compute shader"); 71 | return progHandle 72 | end 73 | 74 | def initGL() 75 | GL.Viewport(0, 0, WIN_WIDTH, WIN_HEIGHT) 76 | checkErrors("Window init") 77 | end 78 | 79 | def genRenderProg(texHandle) 80 | progHandle = GL.CreateProgram() 81 | vp = GL.CreateShader(GL::VERTEX_SHADER) 82 | fp = GL.CreateShader(GL::FRAGMENT_SHADER) 83 | 84 | vpSrc = <<-'VPSRC' 85 | #version 430 86 | in vec2 pos; 87 | out vec2 texCoord; 88 | void main() { 89 | texCoord = pos*0.5f + 0.5f; 90 | gl_Position = vec4(pos.x, pos.y, 0.0, 1.0); 91 | } 92 | VPSRC 93 | 94 | fpSrc = <<-'FPSRC' 95 | #version 430 96 | uniform sampler2D srcTex; 97 | in vec2 texCoord; 98 | out vec4 color; 99 | void main() { 100 | float c = texture(srcTex, texCoord).x; 101 | color = vec4(c, 1.0, 1.0, 1.0); 102 | } 103 | FPSRC 104 | 105 | GL.ShaderSource(vp, 1, [vpSrc].pack('p'), [vpSrc.size].pack('I')) 106 | GL.ShaderSource(fp, 1, [fpSrc].pack('p'), [fpSrc.size].pack('I')) 107 | GL.CompileShader(vp) 108 | rvalue_buf = ' ' * 4 109 | GL.GetShaderiv(vp, GL::COMPILE_STATUS, rvalue_buf); 110 | rvalue = rvalue_buf.unpack('L')[0] 111 | 112 | if rvalue == 0 113 | $stderr.puts "Error in compiling vp" 114 | exit() 115 | end 116 | GL.AttachShader(progHandle, vp) 117 | 118 | GL.CompileShader(fp) 119 | GL.GetShaderiv(fp, GL::COMPILE_STATUS, rvalue_buf) 120 | rvalue = rvalue_buf.unpack('L')[0] 121 | if rvalue == 0 122 | $stderr.puts "Error in compiling fp" 123 | exit() 124 | end 125 | GL.AttachShader(progHandle, fp) 126 | 127 | GL.BindFragDataLocation(progHandle, 0, "color") 128 | GL.LinkProgram(progHandle) 129 | 130 | GL.GetProgramiv(progHandle, GL::LINK_STATUS, rvalue_buf) 131 | rvalue = rvalue_buf.unpack('L')[0] 132 | if rvalue == 0 133 | $stderr.puts "Error in linking sp" 134 | exit() 135 | end 136 | 137 | GL.UseProgram(progHandle) 138 | GL.Uniform1i(GL.GetUniformLocation(progHandle, "srcTex"), 0) 139 | 140 | vertArray_buf = ' ' * 4 141 | GL.GenVertexArrays(1, vertArray_buf) 142 | vertArray = vertArray_buf.unpack('L')[0] 143 | GL.BindVertexArray(vertArray) 144 | 145 | posBuf = ' ' * 4 146 | GL.GenBuffers(1, posBuf) 147 | GL.BindBuffer(GL::ARRAY_BUFFER, posBuf.unpack('L')[0]) 148 | data = [-1.0, -1.0, 149 | -1.0, 1.0, 150 | 1.0, -1.0, 151 | 1.0, 1.0] 152 | 153 | GL.BufferData(GL::ARRAY_BUFFER, 4*8, data.pack('F*'), GL::STREAM_DRAW) 154 | posPtr = GL.GetAttribLocation(progHandle, "pos"); 155 | GL.VertexAttribPointer(posPtr, 2, GL::FLOAT, GL::FALSE, 0, 0) 156 | GL.EnableVertexAttribArray(posPtr) 157 | 158 | checkErrors("Render shaders") 159 | return progHandle 160 | end 161 | 162 | def genTexture() 163 | # We create a single float channel 512^2 texture 164 | texHandle_buf = ' ' * 4 165 | GL.GenTextures(1, texHandle_buf) 166 | texHandle = texHandle_buf.unpack('L')[0] 167 | 168 | GL.ActiveTexture(GL::TEXTURE0) 169 | GL.BindTexture(GL::TEXTURE_2D, texHandle) 170 | GL.TexParameteri(GL::TEXTURE_2D, GL::TEXTURE_MIN_FILTER, GL::LINEAR) 171 | GL.TexParameteri(GL::TEXTURE_2D, GL::TEXTURE_MAG_FILTER, GL::LINEAR) 172 | GL.TexImage2D(GL::TEXTURE_2D, 0, GL::R32F, 512, 512, 0, GL::RED, GL::FLOAT, nil) 173 | 174 | # Because we're also using this tex as an image (in order to write to it), 175 | # we bind it to an image unit as well 176 | GL.BindImageTexture(0, texHandle, 0, GL::FALSE, 0, GL::WRITE_ONLY, GL::R32F) 177 | checkErrors("Gen texture") 178 | return texHandle 179 | end 180 | 181 | def updateTex(frame) 182 | GL.UseProgram($computeHandle) 183 | GL.Uniform1f(GL.GetUniformLocation($computeHandle, "roll"), frame*0.01) 184 | GL.DispatchCompute(512/16, 512/16, 1) # 512^2 threads in blocks of 16^2 185 | checkErrors("Dispatch compute shader") 186 | end 187 | 188 | def draw() 189 | GL.UseProgram($renderHandle) 190 | GL.DrawArrays(GL::TRIANGLE_STRIP, 0, 4) 191 | checkErrors("Draw screen") 192 | end 193 | 194 | key_callback = GLFW::create_callback(:GLFWkeyfun) do |window_handle, key, scancode, action, mods| 195 | case key 196 | when GLFW::KEY_ESCAPE, GLFW::KEY_Q 197 | GLFW.SetWindowShouldClose(window_handle, 1) 198 | end 199 | end 200 | 201 | size_callback = GLFW::create_callback(:GLFWwindowsizefun)do |window_handle, w, h| 202 | GL.Viewport(0, 0, w, h) 203 | end 204 | 205 | if __FILE__ == $PROGRAM_NAME 206 | GLFW.load_lib(SampleUtil.glfw_library_path) 207 | GLFW.Init() 208 | window = GLFW.CreateWindow(WIN_WIDTH, WIN_HEIGHT, "OpenGL compute shader demo", nil, nil ) 209 | GLFW.SetWindowPos(window, 100, 100 ) 210 | GLFW.MakeContextCurrent(window ) 211 | GLFW.SetKeyCallback(window, key_callback ) 212 | GLFW.SetWindowSizeCallback(window, size_callback ) 213 | 214 | GL.load_lib(SampleUtil.gl_library_path) 215 | 216 | width_ptr = ' ' * 4 217 | height_ptr = ' ' * 4 218 | GLFW.GetFramebufferSize(window, width_ptr, height_ptr) 219 | width = width_ptr.unpack('L')[0] 220 | height = height_ptr.unpack('L')[0] 221 | size_callback.call(window, width, height ) 222 | 223 | # Make sure that OpenGL 4.3 is supported by the driver 224 | major,minor,*rest = GL.GetString(GL::VERSION).to_s.split(/\.| /) 225 | puts "Supports OpenGL Version #{major}.#{minor} #{rest}" 226 | cs_available = ((major.to_i > 4) || (major.to_i == 4 && minor.to_i >= 3)) 227 | unless cs_available 228 | puts "GL_VERSION major=#{major} minor=#{minor}" 229 | puts "Support for OpenGL 4.3 is required for this demo...exiting" 230 | exit(1) 231 | end 232 | 233 | initGL() 234 | texHandle = genTexture() 235 | $renderHandle = genRenderProg(texHandle) 236 | $computeHandle = genComputeProg(texHandle) 237 | 238 | i = 0 239 | while GLFW.WindowShouldClose(window)== 0 240 | updateTex(i) 241 | i = (i + 1) % 1024 242 | draw() 243 | GLFW.SwapBuffers(window ) 244 | GLFW.PollEvents() 245 | end 246 | end 247 | -------------------------------------------------------------------------------- /sample/GLExcess/scene12.rb: -------------------------------------------------------------------------------- 1 | =begin 2 | GLExcess v1.0 Demo 3 | Copyright (C) 2001-2003 Paolo Martella 4 | 5 | This program is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU General Public License 7 | as published by the Free Software Foundation; either version 2 8 | of the License, or (at your option) any later version. 9 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | 15 | * Original code : Paolo Martella 16 | * Ruby Porting : vaiorabbit 17 | =end 18 | 19 | class Scene12 20 | 21 | def initialize 22 | @texture = Hash.new { |h,k| h[k] = Texture.new } 23 | @need_initialization = true 24 | 25 | @k_time = 0 26 | @k_timer = nil 27 | end 28 | 29 | def initGL 30 | @texture["glxcess"].load("data/glxcess.raw") 31 | @texture["cl"].load("data/cl.raw") 32 | @texture["glxcesss"].load("data/glxcesss.raw") 33 | @texture["crite"].load("data/crite.raw") 34 | @texture["lightmask"].load("data/lightmask.raw") 35 | 36 | GL.MatrixMode(GL::PROJECTION) 37 | GL.LoadIdentity() 38 | GLU.Perspective(45.0, 4.0/3.0, 0.1, 100.0) 39 | GL.MatrixMode(GL::MODELVIEW) 40 | GL.LoadIdentity() 41 | 42 | GL.ShadeModel(GL::FLAT) 43 | GL.ClearColor(0.5, 0.3, 0.2, 0.0) 44 | GL.ClearColor(0.0, 0.0, 0.0, 0.0) 45 | GL.ClearDepth(1.0) 46 | GL.Disable(GL::DEPTH_TEST) 47 | GL.Disable (GL::CULL_FACE) 48 | GL.Hint(GL::PERSPECTIVE_CORRECTION_HINT, GL::NICEST) 49 | GL.PolygonMode(GL::FRONT, GL::FILL) 50 | GL.FrontFace(GL::CCW) 51 | GL.Enable(GL::TEXTURE_2D) 52 | GL.Disable(GL::LIGHTING) 53 | GL.Enable(GL::BLEND) 54 | GL.BlendFunc(GL::SRC_ALPHA,GL::ONE) 55 | end 56 | 57 | def clean 58 | @texture.each { |key,tex| tex.kill } 59 | 60 | @texture = nil 61 | @need_initialization = true 62 | end 63 | 64 | def drawrect(b, h) 65 | GL.Begin(GL::QUADS) 66 | GL.TexCoord2f(0.0,0.0) 67 | GL.Vertex3f(-b/2,-h/2,0.0) 68 | GL.TexCoord2f(1.0,0.0) 69 | GL.Vertex3f(b/2,-h/2,0.0) 70 | GL.TexCoord2f(1.0,1.0) 71 | GL.Vertex3f(b/2,h/2,0.0) 72 | GL.TexCoord2f(0.0,1.0) 73 | GL.Vertex3f(-b/2,h/2,0.0) 74 | GL.End() 75 | end 76 | 77 | def drawrect1(b, h, shifta, shiftb) 78 | GL.Begin(GL::QUADS) 79 | GL.TexCoord2f(0.0+shifta,0.0+shiftb) 80 | GL.Vertex3f(-b/2,-h/2,0.0) 81 | GL.TexCoord2f(1.5+shifta,0.0+shiftb) 82 | GL.Vertex3f(b/2,-h/2,0.0) 83 | GL.TexCoord2f(1.5+shifta,1.5+shiftb) 84 | GL.Vertex3f(b/2,h/2,0.0) 85 | GL.TexCoord2f(0.0+shifta,1.5+shiftb) 86 | GL.Vertex3f(-b/2,h/2,0.0) 87 | GL.End() 88 | end 89 | 90 | def render(globtime) 91 | if (@need_initialization) 92 | initGL() 93 | @need_initialization = false 94 | end 95 | 96 | @k_time = 10 * globtime 97 | @k_timer = -1.0 + (@k_time)/5000.0 98 | 99 | GL.BlendFunc(GL::SRC_ALPHA,GL::ONE_MINUS_SRC_ALPHA) 100 | @texture["cl"].use 101 | GL.LoadIdentity() 102 | GL.Translatef(0,0,-5.0) 103 | @k_timer += 3 104 | GL.PushMatrix() 105 | GL.Color4f(1, 1, 1, 0.25+0.25*Math.sin(@k_timer/13.0)) 106 | GL.Rotatef(20*Math.sin(@k_timer*2.0), 1,0,0) 107 | GL.Rotatef(90*Math.sin(@k_timer), 0,0,1) 108 | drawrect1(8.5,8.5,@k_timer/10.0, 0.25-@k_timer/5.0) 109 | GL.PopMatrix() 110 | 111 | GL.PushMatrix() 112 | GL.Rotatef(@k_timer*10.0, 0,0,1) 113 | GL.Translatef(0,0,2.0*Math.sin(@k_timer/1.0)) 114 | GL.Color4f(1,1,1,0.3+0.3*Math.cos(@k_timer/9.0)) 115 | drawrect1(10.0,10.0,0.5-@k_timer/7.5,0.75+@k_timer/2.5) 116 | GL.PopMatrix() 117 | 118 | GL.PushMatrix() 119 | GL.BlendFunc(GL::ZERO,GL::ONE_MINUS_SRC_COLOR) 120 | GL.Color4f(1,1,1,1) 121 | GL.Translatef(0,0,2.0*Math.sin(@k_timer/1.0)) 122 | GL.Rotatef(@k_timer*20.0,0,0,1) 123 | GL.Translatef(0,0,1+2.0*Math.sin(@k_timer/2.0)*Math.sin(@k_timer/1.0)) 124 | drawrect1(10.0,10.0,0.35-@k_timer/10.0,0.1+@k_timer/25.0) 125 | GL.PopMatrix() 126 | @k_timer-=3 127 | GL.BlendFunc(GL::SRC_ALPHA,GL::ONE) 128 | @texture["glxcess"].use 129 | #///////////////////////////////////////////////////////////////////////////////// 130 | #///////////////////////////////////////////////////////////////////////////////// 131 | #///////////////////////////////////////////////////////////////////////////////// 132 | #///////////////////////////////////////////////////////////////////////////////// 133 | #///////////////////////////////////////////////////////////////////////////////// 134 | #///////////////////////////////////////////////////////////////////////////////// 135 | GL.LoadIdentity() 136 | if (@k_timer<2.501) 137 | GL.Translatef(0,0,-7.0+3.0*Math.sin(@k_timer*3.1415*0.5/2.5)) 138 | else 139 | GL.Translatef(0,0,-4.0) 140 | end 141 | 142 | if(@k_timer<2.5) 143 | GL.PushMatrix() 144 | if (@k_timer<=1.0) 145 | @texture["glxcesss"].use 146 | GL.Color4f(@k_timer,@k_timer,@k_timer,1) 147 | GL.BlendFunc(GL::ZERO,GL::ONE_MINUS_SRC_COLOR) 148 | drawrect(4.2,1.7) 149 | @texture["glxcess"].use 150 | GL.BlendFunc(GL::SRC_ALPHA,GL::ONE) 151 | GL.Color4f(1,1,1,@k_timer) 152 | drawrect(3.5,1.0) 153 | elsif (@k_timer<1.1) 154 | @texture["glxcesss"].use 155 | GL.Color4f(1.0-10.0*(@k_timer-1.0),1.0-10.0*(@k_timer-1.0),1.0-10.0*(@k_timer-1.0),1) 156 | GL.BlendFunc(GL::ZERO,GL::ONE_MINUS_SRC_COLOR) 157 | drawrect(4.2,1.7) 158 | @texture["glxcess"].use 159 | GL.BlendFunc(GL::SRC_ALPHA,GL::ONE) 160 | GL.Color4f(1,1,1,20.0*(@k_timer-1.0)) 161 | GL.Translatef(0,0,15000.0*(@k_timer-1.0)*(@k_timer-1.0)*(@k_timer-1.0)*(@k_timer-1.0)) 162 | drawrect(3.5,1.0) 163 | else 164 | j_tras=(1.0+Math.sin((-@k_timer+1.1)*0.5*3.1415/1.4)) 165 | GL.Translatef(0,0,1.5*j_tras) 166 | GL.Color4f(1,1,1,j_tras) 167 | drawrect(3.5,1.0) 168 | end 169 | GL.PopMatrix() 170 | end 171 | 172 | if (@k_timer>=1.0) 173 | if (@k_timer<1.1) 174 | GL.Color4f(1,1,1,1.0-10.0*(@k_timer-1.0)) 175 | drawrect(3.5,1.0) 176 | else 177 | GL.PushMatrix() 178 | if (@k_timer<2.5) 179 | j_tras=-Math.sin((-@k_timer+1.1)*0.5*3.1415/1.4) 180 | @texture["glxcess"].use 181 | GL.BlendFunc(GL::SRC_ALPHA,GL::ONE) 182 | GL.Color4f(1,1,1,j_tras) 183 | drawrect(3.5,1.0) 184 | else 185 | @texture["glxcesss"].use 186 | GL.Color4f(2.0*(@k_timer-2.5),2.0*(@k_timer-2.5),2.0*(@k_timer-2.5),1) 187 | GL.BlendFunc(GL::ZERO,GL::ONE_MINUS_SRC_COLOR) 188 | drawrect(4.2,1.7) 189 | @texture["glxcess"].use 190 | GL.BlendFunc(GL::SRC_ALPHA,GL::ONE) 191 | GL.Color4f(1,1,1,1) 192 | drawrect(3.5,1.0) 193 | end 194 | GL.PopMatrix() 195 | end 196 | end 197 | 198 | # fade in 199 | if (@k_timer<0.0) 200 | GL.BlendFunc(GL::ZERO, GL::ONE_MINUS_SRC_ALPHA) 201 | GL.Disable(GL::TEXTURE_2D) 202 | GL.Color4f(1,1,1,-@k_timer) 203 | GL.LoadIdentity() 204 | GL.Translatef(0,0,-1.0) 205 | drawrect(1.2,1.2) 206 | GL.BlendFunc(GL::SRC_ALPHA,GL::ONE) 207 | GL.Enable(GL::TEXTURE_2D) 208 | end 209 | 210 | # focus into the center 211 | @texture["lightmask"].use 212 | GL.LoadIdentity() 213 | GL.Translatef(0,0,-1.0) 214 | GL.BlendFunc(GL::ZERO, GL::ONE_MINUS_SRC_COLOR) 215 | GL.Color4f(1,1,1,1) 216 | drawrect(1.85,1.25) 217 | 218 | GL.BlendFunc(GL::SRC_ALPHA, GL::ONE) 219 | if (@k_timer>2.5) 220 | GL.LoadIdentity() 221 | GL.Translatef(0.03,-0.25,-1.0) 222 | @texture["crite"].use 223 | if (@k_timer-2.5<0.75) 224 | GL.Color4f(1,1,1,@k_timer-2.5) 225 | else 226 | GL.Color4f(1,1,1,0.75) 227 | end 228 | GL.Scalef(1,-1,1) 229 | drawrect(1.0, 0.03125) 230 | end 231 | 232 | if (@k_timer>4.0) 233 | GL.BlendFunc(GL::ZERO, GL::ONE_MINUS_SRC_ALPHA) 234 | GL.Disable(GL::TEXTURE_2D) 235 | GL.Color4f(1,1,1,(@k_timer-4.0)/3.25) 236 | GL.LoadIdentity() 237 | GL.Translatef(0,0,-1.0) 238 | drawrect(1.2,1.2) 239 | GL.BlendFunc(GL::SRC_ALPHA,GL::ONE) 240 | GL.Enable(GL::TEXTURE_2D) 241 | end 242 | 243 | if (@k_timer > 7.25) 244 | return false 245 | end 246 | 247 | return true 248 | end 249 | 250 | end 251 | -------------------------------------------------------------------------------- /sample/RedBook/teapots.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) Mark J. Kilgard, 1994. 3 | # 4 | # (c) Copyright 1993, Silicon Graphics, Inc. 5 | # ALL RIGHTS RESERVED 6 | # Permission to use, copy, modify, and distribute this software for 7 | # any purpose and without fee is hereby granted, provided that the above 8 | # copyright notice appear in all copies and that both the copyright notice 9 | # and this permission notice appear in supporting documentation, and that 10 | # the name of Silicon Graphics, Inc. not be used in advertising 11 | # or publicity pertaining to distribution of the software without specific, 12 | # written prior permission. 13 | # 14 | # THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS" 15 | # AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE, 16 | # INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR 17 | # FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON 18 | # GRAPHICS, INC. BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT, 19 | # SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY 20 | # KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION, 21 | # LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF 22 | # THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC. HAS BEEN 23 | # ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON 24 | # ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE 25 | # POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE. 26 | # 27 | # US Government Users Restricted Rights 28 | # Use, duplication, or disclosure by the Government is subject to 29 | # restrictions set forth in FAR 52.227.19(c)(2) or subparagraph 30 | # (c)(1)(ii) of the Rights in Technical Data and Computer Software 31 | # clause at DFARS 252.227-7013 and/or in similar or successor 32 | # clauses in the FAR or the DOD or NASA FAR Supplement. 33 | # Unpublished-- rights reserved under the copyright laws of the 34 | # United States. Contractor/manufacturer is Silicon Graphics, 35 | # Inc., 2011 N. Shoreline Blvd., Mountain View, CA 94039-7311. 36 | # 37 | # OpenGL(TM) is a trademark of Silicon Graphics, Inc. 38 | # 39 | # teapots.c 40 | # This program demonstrates lots of material properties. 41 | # A single light source illuminates the objects. 42 | 43 | require 'opengl' 44 | require 'glfw' 45 | require_relative '../util/setup_dll' 46 | require_relative '../util/WavefrontOBJ' 47 | $teapot = nil 48 | 49 | # Initialize depth buffer, projection matrix, light source, and lighting 50 | # model. Do not specify a material property here. 51 | def myinit 52 | ambient = [0.0, 0.0, 0.0, 1.0] 53 | diffuse = [1.0, 1.0, 1.0, 1.0] 54 | position = [0.0, 3.0, 3.0, 0.0] 55 | 56 | lmodel_ambient = [0.2, 0.2, 0.2, 1.0] 57 | local_view = [0.0] 58 | 59 | GL.Lightfv(GL::LIGHT0, GL::AMBIENT, ambient.pack('F*')) 60 | GL.Lightfv(GL::LIGHT0, GL::DIFFUSE, diffuse.pack('F*')) 61 | GL.Lightfv(GL::LIGHT0, GL::POSITION, position.pack('F*')) 62 | GL.LightModelfv(GL::LIGHT_MODEL_AMBIENT, lmodel_ambient.pack('F*')) 63 | GL.LightModelfv(GL::LIGHT_MODEL_LOCAL_VIEWER, local_view.pack('F*')) 64 | 65 | GL.FrontFace(GL::CW) 66 | GL.Enable(GL::LIGHTING) 67 | GL.Enable(GL::LIGHT0) 68 | GL.Enable(GL::AUTO_NORMAL) 69 | GL.Enable(GL::NORMALIZE) 70 | GL.Enable(GL::DEPTH_TEST) 71 | GL.DepthFunc(GL::LESS) 72 | 73 | $teapot = WavefrontOBJ::Model.new 74 | $teapot.parse('../data/teapot.obj') 75 | $teapot.setup 76 | end 77 | 78 | # Move object into position. Use 3rd through 12th parameters to specify the 79 | # material property. Draw a teapot. 80 | def renderTeapot(x, y, ambr, ambg, ambb, difr, difg, difb, specr, specg, specb, shine) 81 | mat = [] 82 | GL.PushMatrix() 83 | GL.Translatef(x, y, 0.0) 84 | GL.Scalef(0.1, 0.1, 0.1) # Added 85 | mat[0] = ambr 86 | mat[1] = ambg 87 | mat[2] = ambb 88 | mat[3] = 1.0 89 | GL.Materialfv(GL::FRONT, GL::AMBIENT, mat.pack('F*')) 90 | mat[0] = difr 91 | mat[1] = difg 92 | mat[2] = difb 93 | GL.Materialfv(GL::FRONT, GL::DIFFUSE, mat.pack('F*')) 94 | mat[0] = specr 95 | mat[1] = specg 96 | mat[2] = specb 97 | GL.Materialfv(GL::FRONT, GL::SPECULAR, mat.pack('F*')) 98 | GL.Materialf(GL::FRONT, GL::SHININESS, shine * 128.0) 99 | $teapot.render 100 | GL.PopMatrix() 101 | end 102 | 103 | # First column: emerald, jade, obsidian, pearl, ruby, turquoise 104 | # 2nd column: brass, bronze, chrome, copper, gold, silver 105 | # 3rd column: black, cyan, green, red, white, yellow plastic 106 | # 4th column: black, cyan, green, red, white, yellow rubber 107 | display = proc do 108 | GL.Clear(GL::COLOR_BUFFER_BIT | GL::DEPTH_BUFFER_BIT) 109 | renderTeapot(2.0, 17.0, 0.0215, 0.1745, 0.0215, 110 | 0.07568, 0.61424, 0.07568, 0.633, 0.727811, 0.633, 0.6) 111 | renderTeapot(2.0, 14.0, 0.135, 0.2225, 0.1575, 112 | 0.54, 0.89, 0.63, 0.316228, 0.316228, 0.316228, 0.1) 113 | renderTeapot(2.0, 11.0, 0.05375, 0.05, 0.06625, 114 | 0.18275, 0.17, 0.22525, 0.332741, 0.328634, 0.346435, 0.3) 115 | renderTeapot(2.0, 8.0, 0.25, 0.20725, 0.20725, 116 | 1, 0.829, 0.829, 0.296648, 0.296648, 0.296648, 0.088) 117 | renderTeapot(2.0, 5.0, 0.1745, 0.01175, 0.01175, 118 | 0.61424, 0.04136, 0.04136, 0.727811, 0.626959, 0.626959, 0.6) 119 | renderTeapot(2.0, 2.0, 0.1, 0.18725, 0.1745, 120 | 0.396, 0.74151, 0.69102, 0.297254, 0.30829, 0.306678, 0.1) 121 | renderTeapot(6.0, 17.0, 0.329412, 0.223529, 0.027451, 122 | 0.780392, 0.568627, 0.113725, 0.992157, 0.941176, 0.807843, 123 | 0.21794872) 124 | renderTeapot(6.0, 14.0, 0.2125, 0.1275, 0.054, 125 | 0.714, 0.4284, 0.18144, 0.393548, 0.271906, 0.166721, 0.2) 126 | renderTeapot(6.0, 11.0, 0.25, 0.25, 0.25, 127 | 0.4, 0.4, 0.4, 0.774597, 0.774597, 0.774597, 0.6) 128 | renderTeapot(6.0, 8.0, 0.19125, 0.0735, 0.0225, 129 | 0.7038, 0.27048, 0.0828, 0.256777, 0.137622, 0.086014, 0.1) 130 | renderTeapot(6.0, 5.0, 0.24725, 0.1995, 0.0745, 131 | 0.75164, 0.60648, 0.22648, 0.628281, 0.555802, 0.366065, 0.4) 132 | renderTeapot(6.0, 2.0, 0.19225, 0.19225, 0.19225, 133 | 0.50754, 0.50754, 0.50754, 0.508273, 0.508273, 0.508273, 0.4) 134 | renderTeapot(10.0, 17.0, 0.0, 0.0, 0.0, 0.01, 0.01, 0.01, 135 | 0.50, 0.50, 0.50, 0.25) 136 | renderTeapot(10.0, 14.0, 0.0, 0.1, 0.06, 0.0, 0.50980392, 0.50980392, 137 | 0.50196078, 0.50196078, 0.50196078, 0.25) 138 | renderTeapot(10.0, 11.0, 0.0, 0.0, 0.0, 139 | 0.1, 0.35, 0.1, 0.45, 0.55, 0.45, 0.25) 140 | renderTeapot(10.0, 8.0, 0.0, 0.0, 0.0, 0.5, 0.0, 0.0, 141 | 0.7, 0.6, 0.6, 0.25) 142 | renderTeapot(10.0, 5.0, 0.0, 0.0, 0.0, 0.55, 0.55, 0.55, 143 | 0.70, 0.70, 0.70, 0.25) 144 | renderTeapot(10.0, 2.0, 0.0, 0.0, 0.0, 0.5, 0.5, 0.0, 145 | 0.60, 0.60, 0.50, 0.25) 146 | renderTeapot(14.0, 17.0, 0.02, 0.02, 0.02, 0.01, 0.01, 0.01, 147 | 0.4, 0.4, 0.4, 0.078125) 148 | renderTeapot(14.0, 14.0, 0.0, 0.05, 0.05, 0.4, 0.5, 0.5, 149 | 0.04, 0.7, 0.7, 0.078125) 150 | renderTeapot(14.0, 11.0, 0.0, 0.05, 0.0, 0.4, 0.5, 0.4, 151 | 0.04, 0.7, 0.04, 0.078125) 152 | renderTeapot(14.0, 8.0, 0.05, 0.0, 0.0, 0.5, 0.4, 0.4, 153 | 0.7, 0.04, 0.04, 0.078125) 154 | renderTeapot(14.0, 5.0, 0.05, 0.05, 0.05, 0.5, 0.5, 0.5, 155 | 0.7, 0.7, 0.7, 0.078125) 156 | renderTeapot(14.0, 2.0, 0.05, 0.05, 0.0, 0.5, 0.5, 0.4, 157 | 0.7, 0.7, 0.04, 0.078125) 158 | end 159 | 160 | size_callback = GLFW::create_callback(:GLFWwindowsizefun) do |window_handle, w, h| 161 | GL.Viewport(0, 0, w, h) 162 | GL.MatrixMode(GL::PROJECTION) 163 | GL.LoadIdentity() 164 | if (w <= h) 165 | GL.Ortho(0.0, 16.0, 0.0, 16.0 * h.to_f / w, -10.0, 10.0) 166 | else 167 | GL.Ortho(0.0, 16.0 * w.to_f / h, 0.0, 16.0,-10.0, 10.0) 168 | end 169 | GL.MatrixMode(GL::MODELVIEW) 170 | end 171 | 172 | key_callback = GLFW::create_callback(:GLFWkeyfun) do |window_handle, key, scancode, action, mods| 173 | case key 174 | when GLFW::KEY_ESCAPE 175 | GLFW.SetWindowShouldClose(window_handle, 1) 176 | end 177 | end 178 | 179 | if __FILE__ == $0 180 | GLFW.load_lib(SampleUtil.glfw_library_path) 181 | GLFW.Init() 182 | window = GLFW.CreateWindow(500, 500, $0, nil, nil) 183 | GLFW.SetWindowPos(window, 100, 100) 184 | GLFW.MakeContextCurrent(window) 185 | GLFW.SetKeyCallback(window, key_callback) 186 | GLFW.SetWindowSizeCallback(window, size_callback) 187 | 188 | GL.load_lib() 189 | 190 | myinit() 191 | 192 | width_ptr = ' ' * 4 193 | height_ptr = ' ' * 4 194 | GLFW.GetFramebufferSize(window, width_ptr, height_ptr) 195 | width = width_ptr.unpack('L')[0] 196 | height = height_ptr.unpack('L')[0] 197 | size_callback.call(window, width, height) 198 | 199 | while GLFW.WindowShouldClose(window) == 0 200 | display.call() 201 | GLFW.SwapBuffers(window) 202 | GLFW.PollEvents() 203 | end 204 | end 205 | -------------------------------------------------------------------------------- /sample/GLUT/glut_gears.rb: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | =begin 3 | Ref.: https://www.sgi.com/products/software/opengl/examples/glut/mesademos/source/gears.c 4 | Original copyright notice: 5 | /* gears.c */ 6 | 7 | /* 8 | * 3-D gear wheels. This program is in the public domain. 9 | * 10 | * Brian Paul 11 | */ 12 | 13 | /* Conversion to GLUT by Mark J. Kilgard */ 14 | =end 15 | 16 | require 'opengl' 17 | require 'glut' 18 | 19 | =begin 20 | 21 | Draw a gear wheel. You'll probably want to call this function when 22 | building a display list since we do a lot of trig here. 23 | 24 | Input: inner_radius - radius of hole at center 25 | outer_radius - radius at center of teeth 26 | width - width of gear 27 | teeth - number of teeth 28 | tooth_depth - depth of tooth 29 | 30 | =end 31 | 32 | def gear(inner_radius, outer_radius, width, teeth, tooth_depth) 33 | r0 = inner_radius 34 | r1 = outer_radius - tooth_depth / 2.0 35 | r2 = outer_radius + tooth_depth / 2.0 36 | 37 | da = 2.0 * Math::PI / teeth / 4.0 38 | 39 | GL.ShadeModel(GL::FLAT) 40 | 41 | GL.Normal3f(0.0, 0.0, 1.0) 42 | 43 | # draw front face 44 | GL.Begin(GL::QUAD_STRIP) 45 | for i in 0..teeth do 46 | angle = i * 2.0 * Math::PI / teeth 47 | GL.Vertex3f(r0 * Math.cos(angle), r0 * Math.sin(angle), width * 0.5) 48 | GL.Vertex3f(r1 * Math.cos(angle), r1 * Math.sin(angle), width * 0.5) 49 | GL.Vertex3f(r0 * Math.cos(angle), r0 * Math.sin(angle), width * 0.5) 50 | GL.Vertex3f(r1 * Math.cos(angle + 3 * da), r1 * Math.sin(angle + 3 * da), width * 0.5) 51 | end 52 | GL.End() 53 | 54 | # draw front sides of teeth 55 | GL.Begin(GL::QUADS) 56 | da = 2.0 * Math::PI / teeth / 4.0 57 | for i in 0...teeth do 58 | angle = i * 2.0 * Math::PI / teeth 59 | 60 | GL.Vertex3f(r1 * Math.cos(angle), r1 * Math.sin(angle), width * 0.5) 61 | GL.Vertex3f(r2 * Math.cos(angle + da), r2 * Math.sin(angle + da), width * 0.5) 62 | GL.Vertex3f(r2 * Math.cos(angle + 2 * da), r2 * Math.sin(angle + 2 * da), width * 0.5) 63 | GL.Vertex3f(r1 * Math.cos(angle + 3 * da), r1 * Math.sin(angle + 3 * da), width * 0.5) 64 | end 65 | GL.End() 66 | 67 | GL.Normal3f(0.0, 0.0, -1.0) 68 | 69 | # draw back face 70 | GL.Begin(GL::QUAD_STRIP) 71 | for i in 0..teeth do 72 | angle = i * 2.0 * Math::PI / teeth 73 | GL.Vertex3f(r1 * Math.cos(angle), r1 * Math.sin(angle), -width * 0.5) 74 | GL.Vertex3f(r0 * Math.cos(angle), r0 * Math.sin(angle), -width * 0.5) 75 | GL.Vertex3f(r1 * Math.cos(angle + 3 * da), r1 * Math.sin(angle + 3 * da), -width * 0.5) 76 | GL.Vertex3f(r0 * Math.cos(angle), r0 * Math.sin(angle), -width * 0.5) 77 | end 78 | GL.End() 79 | 80 | # draw back sides of teeth 81 | GL.Begin(GL::QUADS) 82 | da = 2.0 * Math::PI / teeth / 4.0 83 | for i in 0...teeth 84 | angle = i * 2.0 * Math::PI / teeth 85 | 86 | GL.Vertex3f(r1 * Math.cos(angle + 3 * da), r1 * Math.sin(angle + 3 * da), -width * 0.5) 87 | GL.Vertex3f(r2 * Math.cos(angle + 2 * da), r2 * Math.sin(angle + 2 * da), -width * 0.5) 88 | GL.Vertex3f(r2 * Math.cos(angle + da), r2 * Math.sin(angle + da), -width * 0.5) 89 | GL.Vertex3f(r1 * Math.cos(angle), r1 * Math.sin(angle), -width * 0.5) 90 | end 91 | GL.End() 92 | 93 | # draw outward faces of teeth 94 | GL.Begin(GL::QUAD_STRIP) 95 | for i in 0...teeth do 96 | angle = i * 2.0 * Math::PI / teeth 97 | 98 | GL.Vertex3f(r1 * Math.cos(angle), r1 * Math.sin(angle), width * 0.5) 99 | GL.Vertex3f(r1 * Math.cos(angle), r1 * Math.sin(angle), -width * 0.5) 100 | u = r2 * Math.cos(angle + da) - r1 * Math.cos(angle) 101 | v = r2 * Math.sin(angle + da) - r1 * Math.sin(angle) 102 | len = Math.sqrt(u * u + v * v) 103 | u /= len 104 | v /= len 105 | GL.Normal3f(v, -u, 0.0) 106 | GL.Vertex3f(r2 * Math.cos(angle + da), r2 * Math.sin(angle + da), width * 0.5) 107 | GL.Vertex3f(r2 * Math.cos(angle + da), r2 * Math.sin(angle + da), -width * 0.5) 108 | GL.Normal3f(Math.cos(angle), Math.sin(angle), 0.0) 109 | GL.Vertex3f(r2 * Math.cos(angle + 2 * da), r2 * Math.sin(angle + 2 * da), width * 0.5) 110 | GL.Vertex3f(r2 * Math.cos(angle + 2 * da), r2 * Math.sin(angle + 2 * da), -width * 0.5) 111 | u = r1 * Math.cos(angle + 3 * da) - r2 * Math.cos(angle + 2 * da) 112 | v = r1 * Math.sin(angle + 3 * da) - r2 * Math.sin(angle + 2 * da) 113 | GL.Normal3f(v, -u, 0.0) 114 | GL.Vertex3f(r1 * Math.cos(angle + 3 * da), r1 * Math.sin(angle + 3 * da), width * 0.5) 115 | GL.Vertex3f(r1 * Math.cos(angle + 3 * da), r1 * Math.sin(angle + 3 * da), -width * 0.5) 116 | GL.Normal3f(Math.cos(angle), Math.sin(angle), 0.0) 117 | end 118 | 119 | GL.Vertex3f(r1 * Math.cos(0), r1 * Math.sin(0), width * 0.5) 120 | GL.Vertex3f(r1 * Math.cos(0), r1 * Math.sin(0), -width * 0.5) 121 | 122 | GL.End() 123 | 124 | GL.ShadeModel(GL::SMOOTH) 125 | 126 | # draw inside radius cylinder 127 | GL.Begin(GL::QUAD_STRIP) 128 | for i in 0..teeth do 129 | angle = i * 2.0 * Math::PI / teeth 130 | GL.Normal3f(-Math.cos(angle), -Math.sin(angle), 0.0) 131 | GL.Vertex3f(r0 * Math.cos(angle), r0 * Math.sin(angle), -width * 0.5) 132 | GL.Vertex3f(r0 * Math.cos(angle), r0 * Math.sin(angle), width * 0.5) 133 | end 134 | GL.End() 135 | end 136 | 137 | $view_rotx = 20.0; $view_roty = 30.0; $view_rotz = 0.0 138 | $gear1 = 0; $gear2 = 0; $gear3 = 0 139 | $angle = 0.0 140 | 141 | $limit = 0 142 | $count = 1 143 | 144 | def draw() 145 | GL.Clear(GL::COLOR_BUFFER_BIT | GL::DEPTH_BUFFER_BIT) 146 | 147 | GL.PushMatrix() 148 | GL.Rotatef($view_rotx, 1.0, 0.0, 0.0) 149 | GL.Rotatef($view_roty, 0.0, 1.0, 0.0) 150 | GL.Rotatef($view_rotz, 0.0, 0.0, 1.0) 151 | 152 | GL.PushMatrix() 153 | GL.Translatef(-3.0, -2.0, 0.0) 154 | GL.Rotatef($angle, 0.0, 0.0, 1.0) 155 | GL.CallList($gear1) 156 | GL.PopMatrix() 157 | 158 | GL.PushMatrix() 159 | GL.Translatef(3.1, -2.0, 0.0) 160 | GL.Rotatef(-2.0 * $angle - 9.0, 0.0, 0.0, 1.0) 161 | GL.CallList($gear2) 162 | GL.PopMatrix() 163 | 164 | GL.PushMatrix() 165 | GL.Translatef(-3.1, 4.2, 0.0) 166 | GL.Rotatef(-2.0 * $angle - 25.0, 0.0, 0.0, 1.0) 167 | GL.CallList($gear3) 168 | GL.PopMatrix() 169 | 170 | GL.PopMatrix() 171 | 172 | GLUT.SwapBuffers() 173 | 174 | $count+=1 175 | exit(0) if $count == $limit 176 | end 177 | 178 | $idle = GLUT.create_callback(:GLUTIdleFunc) do 179 | $angle += 2.0 180 | GLUT.PostRedisplay() 181 | end 182 | 183 | # change view angle, exit upon ESC 184 | def key(k, x, y) 185 | case k 186 | when 'z'.ord; $view_rotz += 5.0 187 | when 'Z'.ord; $view_rotz -= 5.0 188 | when 27; exit(0) # Escape 189 | else; return 190 | end 191 | GLUT.PostRedisplay() 192 | end 193 | 194 | # change view angle 195 | def special(k, x, y) 196 | case k 197 | when GLUT::KEY_UP; $view_rotx += 5.0 198 | when GLUT::KEY_DOWN; $view_rotx -= 5.0 199 | when GLUT::KEY_LEFT; $view_roty += 5.0 200 | when GLUT::KEY_RIGHT; $view_roty -= 5.0 201 | else; return 202 | end 203 | GLUT.PostRedisplay() 204 | end 205 | 206 | def reshape(width, height) 207 | h = height.to_f / width.to_f 208 | 209 | GL.Viewport(0, 0, width.to_i, height.to_i) 210 | GL.MatrixMode(GL::PROJECTION) 211 | GL.LoadIdentity() 212 | GL.Frustum(-1.0, 1.0, -h, h, 5.0, 60.0) 213 | GL.MatrixMode(GL::MODELVIEW) 214 | GL.LoadIdentity() 215 | GL.Translatef(0.0, 0.0, -40.0) 216 | end 217 | 218 | $pos = [5.0, 5.0, 10.0, 0.0].pack('F4') 219 | $red = [0.8, 0.1, 0.0, 1.0].pack('F4') 220 | $green = [0.0, 0.8, 0.2, 1.0].pack('F4') 221 | $blue = [0.2, 0.2, 1.0, 1.0].pack('F4') 222 | 223 | def init() 224 | GL.Lightfv(GL::LIGHT0, GL::POSITION, $pos) 225 | GL.Enable(GL::CULL_FACE) 226 | GL.Enable(GL::LIGHTING) 227 | GL.Enable(GL::LIGHT0) 228 | GL.Enable(GL::DEPTH_TEST) 229 | 230 | # make the gears 231 | $gear1 = GL.GenLists(1) 232 | GL.NewList($gear1, GL::COMPILE) 233 | GL.Materialfv(GL::FRONT, GL::AMBIENT_AND_DIFFUSE, $red) 234 | gear(1.0, 4.0, 1.0, 20, 0.7) 235 | GL.EndList() 236 | 237 | $gear2 = GL.GenLists(1) 238 | GL.NewList($gear2, GL::COMPILE) 239 | GL.Materialfv(GL::FRONT, GL::AMBIENT_AND_DIFFUSE, $green) 240 | gear(0.5, 2.0, 2.0, 10, 0.7) 241 | GL.EndList() 242 | 243 | $gear3 = GL.GenLists(1) 244 | GL.NewList($gear3, GL::COMPILE) 245 | GL.Materialfv(GL::FRONT, GL::AMBIENT_AND_DIFFUSE, $blue) 246 | gear(1.3, 2.0, 0.5, 10, 0.7) 247 | GL.EndList() 248 | 249 | GL.Enable(GL::NORMALIZE) 250 | end 251 | 252 | def visible(vis) 253 | if vis == GLUT::VISIBLE 254 | GLUT.IdleFunc($idle) 255 | else 256 | GLUT.IdleFunc(nil) 257 | end 258 | end 259 | 260 | if __FILE__ == $PROGRAM_NAME 261 | GLUT.load_lib() 262 | GLUT.Init([1].pack('I'), [""].pack('p')) 263 | 264 | $limit = ARGV[0].to_i + 1 if ARGV.size > 0 265 | 266 | GLUT.InitDisplayMode(GLUT::RGB | GLUT::DEPTH | GLUT::DOUBLE) 267 | 268 | GLUT.CreateWindow("Gears") 269 | 270 | GL.load_lib() 271 | 272 | init() 273 | 274 | GLUT.DisplayFunc(GLUT.create_callback(:GLUTDisplayFunc, method(:draw).to_proc)) 275 | GLUT.ReshapeFunc(GLUT.create_callback(:GLUTReshapeFunc, method(:reshape).to_proc)) 276 | GLUT.KeyboardFunc(GLUT.create_callback(:GLUTKeyboardFunc, method(:key).to_proc)) 277 | GLUT.SpecialFunc(GLUT.create_callback(:GLUTSpecialFunc, method(:special).to_proc)) 278 | GLUT.VisibilityFunc(GLUT.create_callback(:GLUTVisibilityFunc, method(:visible).to_proc)) 279 | 280 | GLUT.MainLoop() 281 | end 282 | --------------------------------------------------------------------------------