ruby-glfw 0.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README +1 -0
- data/README.API +73 -0
- data/Rakefile +120 -0
- data/examples/boing.rb +519 -0
- data/examples/gears.rb +327 -0
- data/examples/keytest.rb +117 -0
- data/examples/listmodes.rb +20 -0
- data/examples/mipmaps.rb +104 -0
- data/examples/mipmaps.tga +0 -0
- data/examples/particles.rb +837 -0
- data/examples/pong3d.rb +741 -0
- data/examples/pong3d_field.tga +0 -0
- data/examples/pong3d_instr.tga +0 -0
- data/examples/pong3d_menu.tga +0 -0
- data/examples/pong3d_title.tga +0 -0
- data/examples/pong3d_winner1.tga +0 -0
- data/examples/pong3d_winner2.tga +0 -0
- data/examples/splitview.rb +432 -0
- data/examples/triangle.rb +89 -0
- data/examples/wave.rb +294 -0
- data/ext/glfw/glfw.c +1094 -0
- data/ext/glfw/mkrf_conf.rb +70 -0
- data/glfw-src/Makefile +220 -0
- data/glfw-src/compile.ami +61 -0
- data/glfw-src/compile.bat +217 -0
- data/glfw-src/compile.sh +607 -0
- data/glfw-src/docs/Makefile +57 -0
- data/glfw-src/docs/Reference.pdf +0 -0
- data/glfw-src/docs/UsersGuide.pdf +0 -0
- data/glfw-src/docs/cleanup.bat +22 -0
- data/glfw-src/docs/glfwdoc.sty +80 -0
- data/glfw-src/docs/glfwrm.tex +3034 -0
- data/glfw-src/docs/glfwug.tex +2024 -0
- data/glfw-src/docs/readme.txt +80 -0
- data/glfw-src/examples/Makefile.amigaos.gcc +70 -0
- data/glfw-src/examples/Makefile.amigaos.vbcc +70 -0
- data/glfw-src/examples/Makefile.dos.djgpp +71 -0
- data/glfw-src/examples/Makefile.macosx.gcc +96 -0
- data/glfw-src/examples/Makefile.win32.bcc +75 -0
- data/glfw-src/examples/Makefile.win32.cross-mgw +79 -0
- data/glfw-src/examples/Makefile.win32.cygwin +79 -0
- data/glfw-src/examples/Makefile.win32.lcc +74 -0
- data/glfw-src/examples/Makefile.win32.mgw +75 -0
- data/glfw-src/examples/Makefile.win32.msvc +74 -0
- data/glfw-src/examples/Makefile.win32.ow +74 -0
- data/glfw-src/examples/Makefile.win32.pellesc +74 -0
- data/glfw-src/examples/Makefile.x11.in +54 -0
- data/glfw-src/examples/boing.c +606 -0
- data/glfw-src/examples/bundle.sh +46 -0
- data/glfw-src/examples/gears.c +382 -0
- data/glfw-src/examples/keytest.c +264 -0
- data/glfw-src/examples/listmodes.c +48 -0
- data/glfw-src/examples/mipmaps.c +126 -0
- data/glfw-src/examples/mipmaps.tga +0 -0
- data/glfw-src/examples/mtbench.c +301 -0
- data/glfw-src/examples/mthello.c +48 -0
- data/glfw-src/examples/particles.c +1148 -0
- data/glfw-src/examples/pong3d.c +839 -0
- data/glfw-src/examples/pong3d_field.tga +0 -0
- data/glfw-src/examples/pong3d_instr.tga +0 -0
- data/glfw-src/examples/pong3d_menu.tga +0 -0
- data/glfw-src/examples/pong3d_title.tga +0 -0
- data/glfw-src/examples/pong3d_winner1.tga +0 -0
- data/glfw-src/examples/pong3d_winner2.tga +0 -0
- data/glfw-src/examples/splitview.c +506 -0
- data/glfw-src/examples/triangle.c +108 -0
- data/glfw-src/examples/wave.c +397 -0
- data/glfw-src/images/opengl.gif +0 -0
- data/glfw-src/images/osicert.gif +0 -0
- data/glfw-src/include/GL/glfw.h +486 -0
- data/glfw-src/lib/amigaos/Makefile.amigaos.gcc +128 -0
- data/glfw-src/lib/amigaos/Makefile.amigaos.vbcc +128 -0
- data/glfw-src/lib/amigaos/SDI_compiler.h +94 -0
- data/glfw-src/lib/amigaos/amigaos_enable.c +51 -0
- data/glfw-src/lib/amigaos/amigaos_fullscreen.c +319 -0
- data/glfw-src/lib/amigaos/amigaos_glext.c +61 -0
- data/glfw-src/lib/amigaos/amigaos_init.c +284 -0
- data/glfw-src/lib/amigaos/amigaos_joystick.c +359 -0
- data/glfw-src/lib/amigaos/amigaos_thread.c +494 -0
- data/glfw-src/lib/amigaos/amigaos_time.c +206 -0
- data/glfw-src/lib/amigaos/amigaos_window.c +830 -0
- data/glfw-src/lib/amigaos/platform.h +337 -0
- data/glfw-src/lib/dos/Makefile.dos.djgpp +146 -0
- data/glfw-src/lib/dos/dos_enable.c +51 -0
- data/glfw-src/lib/dos/dos_events.c +173 -0
- data/glfw-src/lib/dos/dos_fullscreen.c +101 -0
- data/glfw-src/lib/dos/dos_glext.c +59 -0
- data/glfw-src/lib/dos/dos_init.c +105 -0
- data/glfw-src/lib/dos/dos_irq.s +246 -0
- data/glfw-src/lib/dos/dos_joystick.c +94 -0
- data/glfw-src/lib/dos/dos_keyboard.c +694 -0
- data/glfw-src/lib/dos/dos_mouse.c +337 -0
- data/glfw-src/lib/dos/dos_thread.c +267 -0
- data/glfw-src/lib/dos/dos_time.c +309 -0
- data/glfw-src/lib/dos/dos_window.c +563 -0
- data/glfw-src/lib/dos/platform.h +341 -0
- data/glfw-src/lib/enable.c +295 -0
- data/glfw-src/lib/fullscreen.c +95 -0
- data/glfw-src/lib/glext.c +201 -0
- data/glfw-src/lib/image.c +629 -0
- data/glfw-src/lib/init.c +108 -0
- data/glfw-src/lib/input.c +280 -0
- data/glfw-src/lib/internal.h +210 -0
- data/glfw-src/lib/joystick.c +101 -0
- data/glfw-src/lib/macosx/Makefile.macosx.gcc +172 -0
- data/glfw-src/lib/macosx/Makefile.macosx.gcc.universal +166 -0
- data/glfw-src/lib/macosx/libglfw.pc.in +11 -0
- data/glfw-src/lib/macosx/macosx_enable.c +42 -0
- data/glfw-src/lib/macosx/macosx_fullscreen.c +126 -0
- data/glfw-src/lib/macosx/macosx_glext.c +52 -0
- data/glfw-src/lib/macosx/macosx_init.c +194 -0
- data/glfw-src/lib/macosx/macosx_joystick.c +50 -0
- data/glfw-src/lib/macosx/macosx_thread.c +414 -0
- data/glfw-src/lib/macosx/macosx_time.c +112 -0
- data/glfw-src/lib/macosx/macosx_window.c +1279 -0
- data/glfw-src/lib/macosx/platform.h +349 -0
- data/glfw-src/lib/stream.c +194 -0
- data/glfw-src/lib/tga.c +405 -0
- data/glfw-src/lib/thread.c +340 -0
- data/glfw-src/lib/time.c +83 -0
- data/glfw-src/lib/win32/Makefile.win32.bcc +265 -0
- data/glfw-src/lib/win32/Makefile.win32.cross-mgw +274 -0
- data/glfw-src/lib/win32/Makefile.win32.cygwin +279 -0
- data/glfw-src/lib/win32/Makefile.win32.lcc +246 -0
- data/glfw-src/lib/win32/Makefile.win32.mgw +243 -0
- data/glfw-src/lib/win32/Makefile.win32.msvc +242 -0
- data/glfw-src/lib/win32/Makefile.win32.ow +242 -0
- data/glfw-src/lib/win32/Makefile.win32.pellesc +242 -0
- data/glfw-src/lib/win32/glfwdll.def +67 -0
- data/glfw-src/lib/win32/glfwdll_mgw1.def +67 -0
- data/glfw-src/lib/win32/glfwdll_mgw2.def +67 -0
- data/glfw-src/lib/win32/glfwdll_pellesc.def +65 -0
- data/glfw-src/lib/win32/libglfw.pc.in +11 -0
- data/glfw-src/lib/win32/platform.h +474 -0
- data/glfw-src/lib/win32/win32_dllmain.c +60 -0
- data/glfw-src/lib/win32/win32_enable.c +155 -0
- data/glfw-src/lib/win32/win32_fullscreen.c +317 -0
- data/glfw-src/lib/win32/win32_glext.c +85 -0
- data/glfw-src/lib/win32/win32_init.c +356 -0
- data/glfw-src/lib/win32/win32_joystick.c +234 -0
- data/glfw-src/lib/win32/win32_thread.c +511 -0
- data/glfw-src/lib/win32/win32_time.c +146 -0
- data/glfw-src/lib/win32/win32_window.c +1714 -0
- data/glfw-src/lib/window.c +727 -0
- data/glfw-src/lib/x11/Makefile.x11.in +243 -0
- data/glfw-src/lib/x11/platform.h +415 -0
- data/glfw-src/lib/x11/x11_enable.c +51 -0
- data/glfw-src/lib/x11/x11_fullscreen.c +524 -0
- data/glfw-src/lib/x11/x11_glext.c +69 -0
- data/glfw-src/lib/x11/x11_init.c +275 -0
- data/glfw-src/lib/x11/x11_joystick.c +371 -0
- data/glfw-src/lib/x11/x11_keysym2unicode.c +902 -0
- data/glfw-src/lib/x11/x11_thread.c +507 -0
- data/glfw-src/lib/x11/x11_time.c +154 -0
- data/glfw-src/lib/x11/x11_window.c +1746 -0
- data/glfw-src/license.txt +21 -0
- data/glfw-src/readme.html +927 -0
- data/glfw-src/support/d/examples/Makefile +59 -0
- data/glfw-src/support/d/examples/boing.d +610 -0
- data/glfw-src/support/d/examples/gears.d +379 -0
- data/glfw-src/support/d/examples/keytest.d +272 -0
- data/glfw-src/support/d/examples/listmodes.d +48 -0
- data/glfw-src/support/d/examples/mipmaps.d +126 -0
- data/glfw-src/support/d/examples/mtbench.d +304 -0
- data/glfw-src/support/d/examples/mthello.d +54 -0
- data/glfw-src/support/d/examples/particles.d +1150 -0
- data/glfw-src/support/d/examples/pong3d.d +840 -0
- data/glfw-src/support/d/examples/splitview.d +486 -0
- data/glfw-src/support/d/examples/triangle.d +108 -0
- data/glfw-src/support/d/examples/wave.d +400 -0
- data/glfw-src/support/d/imports/gl.d +4539 -0
- data/glfw-src/support/d/imports/glfw.d +349 -0
- data/glfw-src/support/d/imports/glu.d +328 -0
- data/glfw-src/support/d/lib/glfwdll.def +64 -0
- data/glfw-src/support/d/lib/glu32.def +56 -0
- data/glfw-src/support/d/lib/makefile +12 -0
- data/glfw-src/support/d/lib/opengl32.def +372 -0
- data/glfw-src/support/d/readme.html +83 -0
- data/glfw-src/support/delphi/examples/Triangle.dpr +105 -0
- data/glfw-src/support/delphi/lib/glfw.pas +437 -0
- data/glfw-src/support/delphi/readme.html +97 -0
- data/glfw-src/support/lua/examples/gears.lua +383 -0
- data/glfw-src/support/lua/examples/test1.lua +68 -0
- data/glfw-src/support/lua/readme.html +128 -0
- data/glfw-src/support/lua/src/luaglfw.c +1179 -0
- data/glfw-src/support/lua/src/luaglfw.h +48 -0
- data/glfw-src/support/lua/src/runlua.c +82 -0
- data/glfw-src/support/masm/examples/fpc.mac +47 -0
- data/glfw-src/support/masm/examples/makeit.bat +66 -0
- data/glfw-src/support/masm/examples/triangle.asm +232 -0
- data/glfw-src/support/masm/include/glfw.inc +326 -0
- data/glfw-src/support/masm/include/glu32.inc +55 -0
- data/glfw-src/support/masm/include/opengl32.inc +372 -0
- data/glfw-src/support/masm/lib/glfwdll.lib +0 -0
- data/glfw-src/support/masm/readme.html +170 -0
- data/glfw-src/support/msvc80/GLFW.sln +26 -0
- data/glfw-src/support/msvc80/GLFW.vcproj +257 -0
- data/glfw-src/support/msvc80/GLFWDLL.vcproj +287 -0
- data/glfw-src/support/visualbasic/bindings/glfw.bas +320 -0
- data/glfw-src/support/visualbasic/bindings/glu32.bas +284 -0
- data/glfw-src/support/visualbasic/bindings/opengl32.bas +999 -0
- data/glfw-src/support/visualbasic/examples/Triangle.bas +101 -0
- data/glfw-src/support/visualbasic/readme.html +164 -0
- data/website/index.html +84 -0
- data/website/style.css +110 -0
- metadata +301 -0
data/README
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
See file website/index.html
|
data/README.API
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
= Usage and API
|
|
2
|
+
|
|
3
|
+
The function names and general usage are equivalent to C (you can read the
|
|
4
|
+
GLFW C API documentation here[http://glfw.sourceforge.net/GLFWUsersGuide26.pdf]), with some differences outlined bellow.
|
|
5
|
+
|
|
6
|
+
= Naming
|
|
7
|
+
|
|
8
|
+
The naming conventions follows those of ruby-opengl bindings - all the
|
|
9
|
+
constants and functions are contained in Glfw module (click for RDoc documentation), in file glfw.so which
|
|
10
|
+
is loaded by writing
|
|
11
|
+
|
|
12
|
+
require 'glfw'
|
|
13
|
+
|
|
14
|
+
You can also add
|
|
15
|
+
|
|
16
|
+
include Glfw
|
|
17
|
+
|
|
18
|
+
which will export the module's functions and constants to the global namespace, so
|
|
19
|
+
instead of writing
|
|
20
|
+
|
|
21
|
+
Glfw.glfwSomeFunction(Glfw::GLFW_SOME_CONSTANT)
|
|
22
|
+
|
|
23
|
+
in full scope, you can then use the C-like syntax:
|
|
24
|
+
|
|
25
|
+
glfwSomeFunction(GLFW_SOME_CONSTANT)
|
|
26
|
+
|
|
27
|
+
Loading the module will call Glfw.glfwInit function, and will generate ruby
|
|
28
|
+
exception should the initialization fail. At the end of your program,
|
|
29
|
+
Glfw.glfwTerminate is automatically called, although you are free to call it
|
|
30
|
+
yourself if you wish.
|
|
31
|
+
|
|
32
|
+
Functions working with boolean states are using ruby's true/false rather then GL_TRUE/GL_FALSE (both for
|
|
33
|
+
input and output).
|
|
34
|
+
|
|
35
|
+
= Callbacks
|
|
36
|
+
|
|
37
|
+
For specifying callback functions just pass ruby Proc object, e.g
|
|
38
|
+
|
|
39
|
+
mouse_callback = lambda do |x,y|
|
|
40
|
+
puts "Mouse moved! current mouse position is #{x} #{y}"
|
|
41
|
+
end
|
|
42
|
+
...
|
|
43
|
+
glfwSetMousePosCallback(mouse_callback)
|
|
44
|
+
|
|
45
|
+
or convert regular function, as
|
|
46
|
+
|
|
47
|
+
def mouse_callback(x,y)
|
|
48
|
+
puts "Mouse moved! current mouse position is #{x} #{y}"
|
|
49
|
+
end
|
|
50
|
+
...
|
|
51
|
+
glfwSetMousePosCallback(method("mouse_callback").to_proc)
|
|
52
|
+
|
|
53
|
+
Passing 'nil' will disable the callback.
|
|
54
|
+
|
|
55
|
+
= GLFW and GLUT or other windowing libraries
|
|
56
|
+
|
|
57
|
+
You can combine GLFW with other GL or graphic libraries as long as you use
|
|
58
|
+
only one of them for window creation/destruction, events callbacks and general
|
|
59
|
+
window state modifications. For example you can write:
|
|
60
|
+
|
|
61
|
+
require 'glfw'
|
|
62
|
+
require 'glut'
|
|
63
|
+
include Glfw,Glut
|
|
64
|
+
...
|
|
65
|
+
glfwCreateWindow(...) # use GLFW to create OpenGL window
|
|
66
|
+
glutSolidSphere(...) # use GLUT to draw sphere
|
|
67
|
+
...
|
|
68
|
+
|
|
69
|
+
= Examples
|
|
70
|
+
|
|
71
|
+
You can find the examples in the 'examples' directory - they are pretty much
|
|
72
|
+
just conversion of the GLFW C examples. The 'particles' example was tuned down
|
|
73
|
+
for compensation of ruby speed - see the file particles.rb for more details.
|
data/Rakefile
ADDED
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
# Copyright (C) 2007 Jan Dvorak <jan.dvorak@kraxnet.cz>
|
|
2
|
+
#
|
|
3
|
+
# This software is provided 'as-is', without any express or implied
|
|
4
|
+
# warranty. In no event will the authors be held liable for any damages
|
|
5
|
+
# arising from the use of this software.
|
|
6
|
+
# Permission is granted to anyone to use this software for any purpose,
|
|
7
|
+
# including commercial applications, and to alter it and redistribute it
|
|
8
|
+
# freely, subject to the following restrictions:
|
|
9
|
+
#
|
|
10
|
+
# 1. The origin of this software must not be misrepresented; you must not
|
|
11
|
+
# claim that you wrote the original software. If you use this software
|
|
12
|
+
# in a product, an acknowledgment in the product documentation would be
|
|
13
|
+
# appreciated but is not required.
|
|
14
|
+
#
|
|
15
|
+
# 2. Altered source versions must be plainly marked as such, and must not be
|
|
16
|
+
# misrepresented as being the original software.
|
|
17
|
+
#
|
|
18
|
+
# 3. This notice may not be removed or altered from any source distribution.
|
|
19
|
+
|
|
20
|
+
require 'rubygems'
|
|
21
|
+
require 'rake'
|
|
22
|
+
require 'rake/clean'
|
|
23
|
+
require 'rake/gempackagetask'
|
|
24
|
+
require 'rake/rdoctask'
|
|
25
|
+
require 'mkrf/rakehelper'
|
|
26
|
+
|
|
27
|
+
CLEAN.include("ext/glfw/Rakefile", "ext/glfw/mkrf.log", "ext/glfw/*.so",
|
|
28
|
+
"ext/glfw/*.bundle", "lib/*.so", "lib/*.bundle", "ext/glfw/*.o{,bj}",
|
|
29
|
+
"ext/glfw/*.lib", "ext/glfw/*.exp", "ext/glfw/*.pdb",
|
|
30
|
+
"pkg","html")
|
|
31
|
+
|
|
32
|
+
setup_extension('glfw', 'glfw')
|
|
33
|
+
|
|
34
|
+
# setup building and cleaning the bundled GLFW library
|
|
35
|
+
case RUBY_PLATFORM
|
|
36
|
+
when /(:?mswin|mingw)/ # windows, MSVC 6
|
|
37
|
+
lib_build = "nmake.exe win32-msvc"
|
|
38
|
+
lib_clean = "nmake.exe win32-clean"
|
|
39
|
+
when /darwin/ # mac
|
|
40
|
+
lib_build = "make macosx-gcc"
|
|
41
|
+
lib_clean = "make macosx-clean"
|
|
42
|
+
else # general posix-x11
|
|
43
|
+
lib_build = "make x11"
|
|
44
|
+
lib_clean = "make x11-clean"
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
desc 'Compiles the bundled GLFW library'
|
|
48
|
+
task :glfwlib do
|
|
49
|
+
Dir.chdir("glfw-src") do
|
|
50
|
+
sh lib_build
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
# full cleanup
|
|
55
|
+
desc 'Cleanup, includes cleaup of the bunded GLFW library'
|
|
56
|
+
task :distclean => [:clean] do
|
|
57
|
+
Dir.chdir("glfw-src") do
|
|
58
|
+
sh lib_clean
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
# setup the build
|
|
63
|
+
case RUBY_PLATFORM
|
|
64
|
+
when /(:?mswin|mingw)/
|
|
65
|
+
# rake on windows doesn't work properly for subdirectories
|
|
66
|
+
# so iterate manually
|
|
67
|
+
begin
|
|
68
|
+
Dir.mkdir("lib")
|
|
69
|
+
rescue
|
|
70
|
+
end
|
|
71
|
+
task :default => [:glfwlib] do
|
|
72
|
+
Dir.chdir("ext\\glfw") do
|
|
73
|
+
sh "ruby mkrf_conf.rb"
|
|
74
|
+
sh "call rake --nosearch"
|
|
75
|
+
sh "copy glfw.so ..\\..\\lib"
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
else
|
|
79
|
+
# other systems
|
|
80
|
+
task :default => [:glfwlib,:glfw]
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
# for gem building
|
|
84
|
+
task :extension => :default
|
|
85
|
+
|
|
86
|
+
# build documentation
|
|
87
|
+
rd = Rake::RDocTask.new do |rdoc|
|
|
88
|
+
rdoc.main = "README.API"
|
|
89
|
+
rdoc.title = "GLFW bindings for Ruby"
|
|
90
|
+
rdoc.rdoc_files.include('README.API', 'ext/glfw/glfw.c')
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
# Define the files that will go into the gem
|
|
94
|
+
gem_files = FileList["{lib,ext,examples,glfw-src,website}/**/*","README"]
|
|
95
|
+
gem_files = gem_files.exclude("**/*.so", "**/*.o{,bj}", "ext/glfw/*.log","ext/glfw/Rakefile")
|
|
96
|
+
|
|
97
|
+
spec = Gem::Specification.new do |s|
|
|
98
|
+
s.name = "ruby-glfw"
|
|
99
|
+
s.version = "0.9"
|
|
100
|
+
s.author = "Jan Dvorak"
|
|
101
|
+
s.email = "jan.dvorak@kraxnet.cz"
|
|
102
|
+
s.homepage = "http://ruby-glfw.rubyforge.org"
|
|
103
|
+
s.platform = Gem::Platform::RUBY
|
|
104
|
+
s.summary = "GLFW library bindings for Ruby"
|
|
105
|
+
s.rubyforge_project = "ruby-glfw"
|
|
106
|
+
s.files = gem_files
|
|
107
|
+
s.extensions << 'Rakefile'
|
|
108
|
+
s.require_path = "lib"
|
|
109
|
+
s.has_rdoc = true
|
|
110
|
+
s.rdoc_options << '--main' << rd.main << '--title' << rd.title
|
|
111
|
+
s.extra_rdoc_files = rd.rdoc_files
|
|
112
|
+
s.add_dependency("mkrf", ">=0.2.0")
|
|
113
|
+
s.add_dependency("rake")
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
# Create a task for creating a ruby gem
|
|
117
|
+
Rake::GemPackageTask.new(spec) do |pkg|
|
|
118
|
+
pkg.gem_spec = spec
|
|
119
|
+
pkg.need_tar = true
|
|
120
|
+
end
|
data/examples/boing.rb
ADDED
|
@@ -0,0 +1,519 @@
|
|
|
1
|
+
#*****************************************************************************
|
|
2
|
+
# Title: GLBoing
|
|
3
|
+
# Desc: Tribute to Amiga Boing.
|
|
4
|
+
# Author: Jim Brooks <gfx@jimbrooks.org>
|
|
5
|
+
# Original Amiga authors were R.J. Mical and Dale Luck.
|
|
6
|
+
# GLFW conversion by Marcus Geelnard
|
|
7
|
+
# Notes: - 360' = 2*PI [radian]
|
|
8
|
+
#
|
|
9
|
+
# - Distances between objects are created by doing a relative
|
|
10
|
+
# Z translations.
|
|
11
|
+
#
|
|
12
|
+
# - Although OpenGL enticingly supports alpha-blending,
|
|
13
|
+
# the shadow of the original Boing didn't affect the color
|
|
14
|
+
# of the grid.
|
|
15
|
+
#
|
|
16
|
+
# - [Marcus] Changed timing scheme from interval driven to frame-
|
|
17
|
+
# time based animation steps (which results in much smoother
|
|
18
|
+
# movement)
|
|
19
|
+
#
|
|
20
|
+
# History of Amiga Boing:
|
|
21
|
+
#
|
|
22
|
+
# Boing was demonstrated on the prototype Amiga (codenamed "Lorraine") in
|
|
23
|
+
# 1985. According to legend, it was written ad-hoc in one night by
|
|
24
|
+
# R. J. Mical and Dale Luck. Because the bouncing ball animation was so fast
|
|
25
|
+
# and smooth, attendees did not believe the Amiga prototype was really doing
|
|
26
|
+
# the rendering. Suspecting a trick, they began looking around the booth for
|
|
27
|
+
# a hidden computer or VCR.
|
|
28
|
+
#****************************************************************************
|
|
29
|
+
# Converted to ruby from GLFW example boing.c
|
|
30
|
+
|
|
31
|
+
require 'opengl'
|
|
32
|
+
require 'glfw'
|
|
33
|
+
include Gl,Glu,Glfw,Math
|
|
34
|
+
|
|
35
|
+
RADIUS = 70.0
|
|
36
|
+
STEP_LONGITUDE = 22.5 # 22.5 makes 8 bands like original Boing
|
|
37
|
+
STEP_LATITUDE = 22.5
|
|
38
|
+
|
|
39
|
+
DIST_BALL = (RADIUS * 2.0 + RADIUS * 0.1)
|
|
40
|
+
|
|
41
|
+
VIEW_SCENE_DIST = (DIST_BALL * 3.0+ 200.0) # distance from viewer to middle of boing area
|
|
42
|
+
GRID_SIZE = (RADIUS * 4.5) # length (width) of grid
|
|
43
|
+
BOUNCE_HEIGHT = (RADIUS * 2.1)
|
|
44
|
+
BOUNCE_WIDTH = (RADIUS * 2.1)
|
|
45
|
+
|
|
46
|
+
SHADOW_OFFSET_X = -20.0
|
|
47
|
+
SHADOW_OFFSET_Y = 10.0
|
|
48
|
+
SHADOW_OFFSET_Z = 0.0
|
|
49
|
+
|
|
50
|
+
WALL_L_OFFSET = 0.0
|
|
51
|
+
WALL_R_OFFSET = 5.0
|
|
52
|
+
|
|
53
|
+
# Animation speed (50.0 mimics the original GLUT demo speed)
|
|
54
|
+
ANIMATION_SPEED = 50.0
|
|
55
|
+
|
|
56
|
+
# Maximum allowed delta time per physics iteration */
|
|
57
|
+
MAX_DELTA_T = 0.02
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
# Vertex type
|
|
61
|
+
class Vertex
|
|
62
|
+
attr_accessor :x,:y,:z
|
|
63
|
+
def initialize
|
|
64
|
+
@x = @y = @z = 0.0
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
# Global vars
|
|
69
|
+
$deg_rot_y = 0.0
|
|
70
|
+
$deg_rot_y_inc = 2.0
|
|
71
|
+
$ball_x = -RADIUS
|
|
72
|
+
$ball_y = -RADIUS
|
|
73
|
+
$ball_x_inc = 1.0
|
|
74
|
+
$ball_y_inc = 2.0
|
|
75
|
+
# Draw ball, or its shadow
|
|
76
|
+
$drawBallHow = :DRAW_BALL
|
|
77
|
+
$t = 0.0
|
|
78
|
+
$t_old = 0.0
|
|
79
|
+
$dt = 0.0
|
|
80
|
+
|
|
81
|
+
#*****************************************************************************
|
|
82
|
+
#* Truncate a degree.
|
|
83
|
+
#*****************************************************************************
|
|
84
|
+
def TruncateDeg(deg)
|
|
85
|
+
if ( deg >= 360.0 )
|
|
86
|
+
return (deg - 360.0)
|
|
87
|
+
else
|
|
88
|
+
return deg
|
|
89
|
+
end
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
#*****************************************************************************
|
|
94
|
+
#* Convert a degree (360-based) into a radian.
|
|
95
|
+
#* 360' = 2 * PI
|
|
96
|
+
#*****************************************************************************
|
|
97
|
+
def deg2rad( deg )
|
|
98
|
+
deg / 360 * (2 * PI)
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
#*****************************************************************************
|
|
102
|
+
#* 360' sin().
|
|
103
|
+
#*****************************************************************************
|
|
104
|
+
def sin_deg( deg )
|
|
105
|
+
sin( deg2rad( deg ) )
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
#*****************************************************************************
|
|
109
|
+
#* 360' cos().
|
|
110
|
+
#*****************************************************************************
|
|
111
|
+
def cos_deg( deg )
|
|
112
|
+
cos( deg2rad( deg ) )
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
#*****************************************************************************
|
|
116
|
+
#* Compute a cross product (for a normal vector).
|
|
117
|
+
#*
|
|
118
|
+
#* c = a x b
|
|
119
|
+
#*****************************************************************************
|
|
120
|
+
def CrossProduct( a,b,c,n )
|
|
121
|
+
u1 = b.x - a.x;
|
|
122
|
+
u2 = b.y - a.y;
|
|
123
|
+
u3 = b.y - a.z;
|
|
124
|
+
|
|
125
|
+
v1 = c.x - a.x;
|
|
126
|
+
v2 = c.y - a.y;
|
|
127
|
+
v3 = c.z - a.z;
|
|
128
|
+
|
|
129
|
+
n.x = u2 * v3 - v2 * v3;
|
|
130
|
+
n.y = u3 * v1 - v3 * u1;
|
|
131
|
+
n.z = u1 * v2 - v1 * u2;
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
#*****************************************************************************
|
|
135
|
+
#* Calculate the angle to be passed to gluPerspective() so that a scene
|
|
136
|
+
#* is visible. This function originates from the OpenGL Red Book.
|
|
137
|
+
#*
|
|
138
|
+
#* Parms : size
|
|
139
|
+
#* The size of the segment when the angle is intersected at "dist"
|
|
140
|
+
#* (ie at the outermost edge of the angle of vision).
|
|
141
|
+
#*
|
|
142
|
+
#* dist
|
|
143
|
+
#* Distance from viewpoint to scene.
|
|
144
|
+
#*****************************************************************************
|
|
145
|
+
def PerspectiveAngle( size,dist )
|
|
146
|
+
radTheta = 2.0 * atan2( size / 2.0, dist )
|
|
147
|
+
degTheta = (180.0 * radTheta) / PI
|
|
148
|
+
end
|
|
149
|
+
|
|
150
|
+
BOING_DEBUG = 0
|
|
151
|
+
|
|
152
|
+
#*****************************************************************************
|
|
153
|
+
#* init()
|
|
154
|
+
#*****************************************************************************
|
|
155
|
+
def init
|
|
156
|
+
#
|
|
157
|
+
# Clear background.
|
|
158
|
+
#
|
|
159
|
+
glClearColor( 0.55, 0.55, 0.55, 0.0 )
|
|
160
|
+
|
|
161
|
+
glShadeModel( GL_FLAT )
|
|
162
|
+
end
|
|
163
|
+
|
|
164
|
+
#*****************************************************************************
|
|
165
|
+
#* display()
|
|
166
|
+
#*****************************************************************************
|
|
167
|
+
def display
|
|
168
|
+
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT )
|
|
169
|
+
glPushMatrix()
|
|
170
|
+
|
|
171
|
+
$drawBallHow = :DRAW_BALL_SHADOW
|
|
172
|
+
DrawBoingBall()
|
|
173
|
+
|
|
174
|
+
DrawGrid()
|
|
175
|
+
|
|
176
|
+
$drawBallHow = :DRAW_BALL;
|
|
177
|
+
DrawBoingBall()
|
|
178
|
+
|
|
179
|
+
glPopMatrix()
|
|
180
|
+
glFlush()
|
|
181
|
+
end
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
#*****************************************************************************
|
|
185
|
+
#* reshape()
|
|
186
|
+
#*****************************************************************************
|
|
187
|
+
reshape = lambda do |w,h|
|
|
188
|
+
glViewport( 0, 0, w, h )
|
|
189
|
+
|
|
190
|
+
glMatrixMode( GL_PROJECTION )
|
|
191
|
+
glLoadIdentity()
|
|
192
|
+
|
|
193
|
+
gluPerspective( PerspectiveAngle( RADIUS * 2, 200 ),
|
|
194
|
+
w.to_f / h.to_f,
|
|
195
|
+
1.0,
|
|
196
|
+
VIEW_SCENE_DIST )
|
|
197
|
+
|
|
198
|
+
glMatrixMode( GL_MODELVIEW )
|
|
199
|
+
glLoadIdentity()
|
|
200
|
+
|
|
201
|
+
gluLookAt( 0.0, 0.0, VIEW_SCENE_DIST,#* eye
|
|
202
|
+
0.0, 0.0, 0.0, #* center of vision
|
|
203
|
+
0.0, -1.0, 0.0 ) #* up vector
|
|
204
|
+
end
|
|
205
|
+
|
|
206
|
+
#*****************************************************************************
|
|
207
|
+
#* Draw the Boing ball.
|
|
208
|
+
#*
|
|
209
|
+
#* The Boing ball is sphere in which each facet is a rectangle.
|
|
210
|
+
#* Facet colors alternate between red and white.
|
|
211
|
+
#* The ball is built by stacking latitudinal circles. Each circle is composed
|
|
212
|
+
#* of a widely-separated set of points, so that each facet is noticably large.
|
|
213
|
+
#*****************************************************************************
|
|
214
|
+
def DrawBoingBall
|
|
215
|
+
glPushMatrix()
|
|
216
|
+
glMatrixMode( GL_MODELVIEW )
|
|
217
|
+
|
|
218
|
+
#
|
|
219
|
+
# Another relative Z translation to separate objects.
|
|
220
|
+
#
|
|
221
|
+
glTranslatef( 0.0, 0.0, DIST_BALL )
|
|
222
|
+
|
|
223
|
+
# Update ball position and rotation (iterate if necessary)
|
|
224
|
+
dt_total = $dt
|
|
225
|
+
while( dt_total > 0.0 )
|
|
226
|
+
dt2 = dt_total > MAX_DELTA_T ? MAX_DELTA_T : dt_total
|
|
227
|
+
dt_total -= dt2
|
|
228
|
+
BounceBall( dt2 )
|
|
229
|
+
$deg_rot_y = TruncateDeg( $deg_rot_y + $deg_rot_y_inc*(dt2*ANIMATION_SPEED) )
|
|
230
|
+
end
|
|
231
|
+
|
|
232
|
+
# Set ball position
|
|
233
|
+
glTranslatef( $ball_x, $ball_y, 0.0 )
|
|
234
|
+
|
|
235
|
+
#
|
|
236
|
+
# Offset the shadow.
|
|
237
|
+
#
|
|
238
|
+
if ( $drawBallHow == :DRAW_BALL_SHADOW )
|
|
239
|
+
glTranslatef( SHADOW_OFFSET_X,
|
|
240
|
+
SHADOW_OFFSET_Y,
|
|
241
|
+
SHADOW_OFFSET_Z )
|
|
242
|
+
end
|
|
243
|
+
|
|
244
|
+
#
|
|
245
|
+
# Tilt the ball.
|
|
246
|
+
#
|
|
247
|
+
glRotatef( -20.0, 0.0, 0.0, 1.0 )
|
|
248
|
+
|
|
249
|
+
#
|
|
250
|
+
# Continually rotate ball around Y axis.
|
|
251
|
+
#
|
|
252
|
+
glRotatef( $deg_rot_y, 0.0, 1.0, 0.0 )
|
|
253
|
+
|
|
254
|
+
#
|
|
255
|
+
# Set OpenGL state for Boing ball.
|
|
256
|
+
#
|
|
257
|
+
glCullFace( GL_FRONT )
|
|
258
|
+
glEnable( GL_CULL_FACE )
|
|
259
|
+
glEnable( GL_NORMALIZE )
|
|
260
|
+
|
|
261
|
+
#
|
|
262
|
+
# Build a faceted latitude slice of the Boing ball,
|
|
263
|
+
# stepping same-sized vertical bands of the sphere.
|
|
264
|
+
#
|
|
265
|
+
0.step(180-1,STEP_LONGITUDE) do |lon_deg|
|
|
266
|
+
#
|
|
267
|
+
# Draw a latitude circle at this longitude.
|
|
268
|
+
#
|
|
269
|
+
DrawBoingBallBand( lon_deg, lon_deg + STEP_LONGITUDE )
|
|
270
|
+
end
|
|
271
|
+
|
|
272
|
+
glPopMatrix()
|
|
273
|
+
end
|
|
274
|
+
|
|
275
|
+
#*****************************************************************************
|
|
276
|
+
#* Bounce the ball.
|
|
277
|
+
#*****************************************************************************
|
|
278
|
+
def BounceBall(dt)
|
|
279
|
+
# Bounce on walls
|
|
280
|
+
if ( $ball_x > (BOUNCE_WIDTH/2 + WALL_R_OFFSET ) )
|
|
281
|
+
$ball_x_inc = -0.5 - 0.75 * rand()
|
|
282
|
+
$deg_rot_y_inc = -$deg_rot_y_inc
|
|
283
|
+
end
|
|
284
|
+
if ( $ball_x < -(BOUNCE_HEIGHT/2 + WALL_L_OFFSET) )
|
|
285
|
+
$ball_x_inc = 0.5 + 0.75 * rand()
|
|
286
|
+
$deg_rot_y_inc = -$deg_rot_y_inc
|
|
287
|
+
end
|
|
288
|
+
|
|
289
|
+
# Bounce on floor / roof
|
|
290
|
+
if ( $ball_y > BOUNCE_HEIGHT/2 )
|
|
291
|
+
$ball_y_inc = -0.75 - 1.0 * rand()
|
|
292
|
+
end
|
|
293
|
+
if ( $ball_y < -(BOUNCE_HEIGHT/2)*0.85 )
|
|
294
|
+
$ball_y_inc = 0.75 + 1.0 * rand()
|
|
295
|
+
end
|
|
296
|
+
|
|
297
|
+
# Update ball position
|
|
298
|
+
$ball_x += $ball_x_inc * (dt*ANIMATION_SPEED)
|
|
299
|
+
$ball_y += $ball_y_inc * (dt*ANIMATION_SPEED)
|
|
300
|
+
|
|
301
|
+
#
|
|
302
|
+
# Simulate the effects of gravity on Y movement.
|
|
303
|
+
#
|
|
304
|
+
if ( $ball_y_inc < 0 )
|
|
305
|
+
sign = -1.0
|
|
306
|
+
else
|
|
307
|
+
sign = 1.0
|
|
308
|
+
end
|
|
309
|
+
|
|
310
|
+
deg = ($ball_y + BOUNCE_HEIGHT/2) * 90 / BOUNCE_HEIGHT
|
|
311
|
+
deg = 80 if ( deg > 80 )
|
|
312
|
+
deg = 10 if ( deg < 10 )
|
|
313
|
+
|
|
314
|
+
$ball_y_inc = sign * 4.0 * sin_deg( deg.to_f )
|
|
315
|
+
end
|
|
316
|
+
|
|
317
|
+
#*****************************************************************************
|
|
318
|
+
#* Draw a faceted latitude band of the Boing ball.
|
|
319
|
+
#*
|
|
320
|
+
#* Parms: long_lo, long_hi
|
|
321
|
+
#* Low and high longitudes of slice, resp.
|
|
322
|
+
#*****************************************************************************
|
|
323
|
+
def DrawBoingBallBand( long_lo, long_hi )
|
|
324
|
+
vert_ne = Vertex.new() # "ne" means south-east, so on
|
|
325
|
+
vert_nw = Vertex.new() #
|
|
326
|
+
vert_sw = Vertex.new() #
|
|
327
|
+
vert_se = Vertex.new() #
|
|
328
|
+
vert_norm = Vertex.new()
|
|
329
|
+
|
|
330
|
+
@@colorToggle ||= false
|
|
331
|
+
|
|
332
|
+
#
|
|
333
|
+
# Iterate thru the points of a latitude circle.
|
|
334
|
+
# A latitude circle is a 2D set of X,Z points.
|
|
335
|
+
#
|
|
336
|
+
0.step(360-STEP_LATITUDE, STEP_LATITUDE) do |lat_deg|
|
|
337
|
+
#
|
|
338
|
+
# Color this polygon with red or white.
|
|
339
|
+
#
|
|
340
|
+
if ( @@colorToggle )
|
|
341
|
+
glColor3f( 0.8, 0.1, 0.1 )
|
|
342
|
+
else
|
|
343
|
+
glColor3f( 0.95, 0.95, 0.95 )
|
|
344
|
+
end
|
|
345
|
+
|
|
346
|
+
@@colorToggle = ! @@colorToggle
|
|
347
|
+
|
|
348
|
+
#
|
|
349
|
+
# Change color if drawing shadow.
|
|
350
|
+
#
|
|
351
|
+
if ( $drawBallHow == :DRAW_BALL_SHADOW )
|
|
352
|
+
glColor3f( 0.35, 0.35, 0.35 )
|
|
353
|
+
end
|
|
354
|
+
|
|
355
|
+
#
|
|
356
|
+
# Assign each Y.
|
|
357
|
+
#
|
|
358
|
+
vert_ne.y = vert_nw.y = cos_deg(long_hi) * RADIUS
|
|
359
|
+
vert_sw.y = vert_se.y = cos_deg(long_lo) * RADIUS
|
|
360
|
+
|
|
361
|
+
#
|
|
362
|
+
# Assign each X,Z with sin,cos values scaled by latitude radius indexed by longitude.
|
|
363
|
+
# Eg, long=0 and long=180 are at the poles, so zero scale is sin(longitude),
|
|
364
|
+
# while long=90 (sin(90)=1) is at equator.
|
|
365
|
+
#
|
|
366
|
+
vert_ne.x = cos_deg( lat_deg ) * (RADIUS * sin_deg( long_lo + STEP_LONGITUDE ))
|
|
367
|
+
vert_se.x = cos_deg( lat_deg ) * (RADIUS * sin_deg( long_lo ))
|
|
368
|
+
vert_nw.x = cos_deg( lat_deg + STEP_LATITUDE ) * (RADIUS * sin_deg( long_lo + STEP_LONGITUDE ))
|
|
369
|
+
vert_sw.x = cos_deg( lat_deg + STEP_LATITUDE ) * (RADIUS * sin_deg( long_lo ))
|
|
370
|
+
|
|
371
|
+
vert_ne.z = sin_deg( lat_deg ) * (RADIUS * sin_deg( long_lo + STEP_LONGITUDE ))
|
|
372
|
+
vert_se.z = sin_deg( lat_deg ) * (RADIUS * sin_deg( long_lo ))
|
|
373
|
+
vert_nw.z = sin_deg( lat_deg + STEP_LATITUDE ) * (RADIUS * sin_deg( long_lo + STEP_LONGITUDE ))
|
|
374
|
+
vert_sw.z = sin_deg( lat_deg + STEP_LATITUDE ) * (RADIUS * sin_deg( long_lo ))
|
|
375
|
+
|
|
376
|
+
#
|
|
377
|
+
# Draw the facet.
|
|
378
|
+
#
|
|
379
|
+
glBegin( GL_POLYGON )
|
|
380
|
+
|
|
381
|
+
CrossProduct( vert_ne, vert_nw, vert_sw, vert_norm )
|
|
382
|
+
glNormal3f( vert_norm.x, vert_norm.y, vert_norm.z )
|
|
383
|
+
|
|
384
|
+
glVertex3f( vert_ne.x, vert_ne.y, vert_ne.z )
|
|
385
|
+
glVertex3f( vert_nw.x, vert_nw.y, vert_nw.z )
|
|
386
|
+
glVertex3f( vert_sw.x, vert_sw.y, vert_sw.z )
|
|
387
|
+
glVertex3f( vert_se.x, vert_se.y, vert_se.z )
|
|
388
|
+
|
|
389
|
+
glEnd()
|
|
390
|
+
|
|
391
|
+
if BOING_DEBUG==1
|
|
392
|
+
printf( "----------------------------------------------------------- \n" );
|
|
393
|
+
printf( "lat = %f long_lo = %f long_hi = %f \n", lat_deg, long_lo, long_hi );
|
|
394
|
+
printf( "vert_ne x = %.8f y = %.8f z = %.8f \n", vert_ne.x, vert_ne.y, vert_ne.z );
|
|
395
|
+
printf( "vert_nw x = %.8f y = %.8f z = %.8f \n", vert_nw.x, vert_nw.y, vert_nw.z );
|
|
396
|
+
printf( "vert_se x = %.8f y = %.8f z = %.8f \n", vert_se.x, vert_se.y, vert_se.z );
|
|
397
|
+
printf( "vert_sw x = %.8f y = %.8f z = %.8f \n", vert_sw.x, vert_sw.y, vert_sw.z );
|
|
398
|
+
end
|
|
399
|
+
end
|
|
400
|
+
|
|
401
|
+
#
|
|
402
|
+
# Toggle color so that next band will opposite red/white colors than this one.
|
|
403
|
+
#
|
|
404
|
+
@@colorToggle = ! @@colorToggle
|
|
405
|
+
|
|
406
|
+
#
|
|
407
|
+
# This circular band is done.
|
|
408
|
+
#
|
|
409
|
+
end
|
|
410
|
+
|
|
411
|
+
#*****************************************************************************
|
|
412
|
+
#* Draw the purple grid of lines, behind the Boing ball.
|
|
413
|
+
#* When the Workbench is dropped to the bottom, Boing shows 12 rows.
|
|
414
|
+
#*****************************************************************************
|
|
415
|
+
def DrawGrid
|
|
416
|
+
rowTotal = 12 # must be divisible by 2
|
|
417
|
+
colTotal = rowTotal # must be same as rowTotal
|
|
418
|
+
widthLine = 2.0 # should be divisible by 2
|
|
419
|
+
sizeCell = GRID_SIZE / rowTotal
|
|
420
|
+
z_offset = -40.0
|
|
421
|
+
|
|
422
|
+
glPushMatrix()
|
|
423
|
+
glDisable( GL_CULL_FACE )
|
|
424
|
+
|
|
425
|
+
#
|
|
426
|
+
# Another relative Z translation to separate objects.
|
|
427
|
+
#
|
|
428
|
+
glTranslatef( 0.0, 0.0, DIST_BALL )
|
|
429
|
+
|
|
430
|
+
#
|
|
431
|
+
# Draw vertical lines (as skinny 3D rectangles).
|
|
432
|
+
#
|
|
433
|
+
0.upto(colTotal) do |col|
|
|
434
|
+
#
|
|
435
|
+
# Compute co-ords of line.
|
|
436
|
+
#
|
|
437
|
+
xl = -GRID_SIZE / 2 + col * sizeCell
|
|
438
|
+
xr = xl + widthLine
|
|
439
|
+
|
|
440
|
+
yt = GRID_SIZE / 2
|
|
441
|
+
yb = -GRID_SIZE / 2 - widthLine
|
|
442
|
+
|
|
443
|
+
glBegin( GL_POLYGON )
|
|
444
|
+
|
|
445
|
+
glColor3f( 0.6, 0.1, 0.6 ) # purple
|
|
446
|
+
|
|
447
|
+
glVertex3f( xr, yt, z_offset ) # NE
|
|
448
|
+
glVertex3f( xl, yt, z_offset ) # NW
|
|
449
|
+
glVertex3f( xl, yb, z_offset ) # SW
|
|
450
|
+
glVertex3f( xr, yb, z_offset ) # SE
|
|
451
|
+
|
|
452
|
+
glEnd()
|
|
453
|
+
end
|
|
454
|
+
|
|
455
|
+
#
|
|
456
|
+
# Draw horizontal lines (as skinny 3D rectangles).
|
|
457
|
+
#
|
|
458
|
+
0.upto(rowTotal) do |row|
|
|
459
|
+
#
|
|
460
|
+
# Compute co-ords of line.
|
|
461
|
+
#
|
|
462
|
+
yt = GRID_SIZE / 2 - row * sizeCell
|
|
463
|
+
yb = yt - widthLine
|
|
464
|
+
|
|
465
|
+
xl = -GRID_SIZE / 2
|
|
466
|
+
xr = GRID_SIZE / 2 + widthLine
|
|
467
|
+
|
|
468
|
+
glBegin( GL_POLYGON )
|
|
469
|
+
|
|
470
|
+
glColor3f( 0.6, 0.1, 0.6 ) # purple
|
|
471
|
+
|
|
472
|
+
glVertex3f( xr, yt, z_offset ) # NE
|
|
473
|
+
glVertex3f( xl, yt, z_offset ) # NW
|
|
474
|
+
glVertex3f( xl, yb, z_offset ) # SW
|
|
475
|
+
glVertex3f( xr, yb, z_offset ) # SE
|
|
476
|
+
|
|
477
|
+
glEnd()
|
|
478
|
+
end
|
|
479
|
+
|
|
480
|
+
glPopMatrix()
|
|
481
|
+
end
|
|
482
|
+
|
|
483
|
+
|
|
484
|
+
#======================================================================
|
|
485
|
+
# main()
|
|
486
|
+
#======================================================================
|
|
487
|
+
|
|
488
|
+
running = true
|
|
489
|
+
|
|
490
|
+
# Init GLFW
|
|
491
|
+
if( glfwOpenWindow( 400,400, 0,0,0,0, 16,0, GLFW_WINDOW ) == false)
|
|
492
|
+
exit
|
|
493
|
+
end
|
|
494
|
+
glfwSetWindowTitle( "Boing (classic Amiga demo)" )
|
|
495
|
+
glfwSetWindowSizeCallback( reshape )
|
|
496
|
+
glfwEnable( GLFW_STICKY_KEYS )
|
|
497
|
+
glfwSwapInterval( 1 )
|
|
498
|
+
glfwSetTime( 0.0 )
|
|
499
|
+
|
|
500
|
+
init()
|
|
501
|
+
|
|
502
|
+
# Main loop
|
|
503
|
+
while running
|
|
504
|
+
# Timing
|
|
505
|
+
$t = glfwGetTime()
|
|
506
|
+
$dt = $t - $t_old
|
|
507
|
+
$t_old = $t
|
|
508
|
+
|
|
509
|
+
# Draw one frame
|
|
510
|
+
display()
|
|
511
|
+
|
|
512
|
+
# Swap buffers
|
|
513
|
+
glfwSwapBuffers()
|
|
514
|
+
|
|
515
|
+
# Check if we are still running
|
|
516
|
+
running = (glfwGetKey( GLFW_KEY_ESC ) == GLFW_RELEASE) &&
|
|
517
|
+
(glfwGetWindowParam( GLFW_OPENED ) == true)
|
|
518
|
+
|
|
519
|
+
end
|