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/examples/gears.rb
ADDED
|
@@ -0,0 +1,327 @@
|
|
|
1
|
+
# 3-D gear wheels. This program is in the public domain.
|
|
2
|
+
#
|
|
3
|
+
# Command line options:
|
|
4
|
+
# -info print GL implementation information
|
|
5
|
+
# -exit automatically exit after 30 seconds
|
|
6
|
+
#
|
|
7
|
+
#
|
|
8
|
+
# Brian Paul
|
|
9
|
+
#
|
|
10
|
+
#
|
|
11
|
+
# Marcus Geelnard:
|
|
12
|
+
# - Conversion to GLFW
|
|
13
|
+
# - Time based rendering (frame rate independent)
|
|
14
|
+
# - Slightly modified camera that should work better for stereo viewing
|
|
15
|
+
#
|
|
16
|
+
# Converted to ruby from GLFW example gears.c
|
|
17
|
+
|
|
18
|
+
require 'opengl'
|
|
19
|
+
require 'glfw'
|
|
20
|
+
include Gl,Glu,Glfw,Math
|
|
21
|
+
|
|
22
|
+
$running = true
|
|
23
|
+
$t0 = 0.0
|
|
24
|
+
$t = 0.0
|
|
25
|
+
$dt = 0.0
|
|
26
|
+
|
|
27
|
+
$frames = 0
|
|
28
|
+
$autoexit = 0
|
|
29
|
+
|
|
30
|
+
#
|
|
31
|
+
# Draw a gear wheel. You'll probably want to call this function when
|
|
32
|
+
# building a display list since we do a lot of trig here.
|
|
33
|
+
#
|
|
34
|
+
# Input: inner_radius - radius of hole at center
|
|
35
|
+
# outer_radius - radius at center of teeth
|
|
36
|
+
# width - width of gear
|
|
37
|
+
# teeth - number of teeth
|
|
38
|
+
# tooth_depth - depth of tooth
|
|
39
|
+
#
|
|
40
|
+
def gear(inner_radius,outer_radius,width,teeth,tooth_depth)
|
|
41
|
+
r0 = inner_radius
|
|
42
|
+
r1 = outer_radius - tooth_depth / 2.0
|
|
43
|
+
r2 = outer_radius + tooth_depth / 2.0
|
|
44
|
+
|
|
45
|
+
da = 2.0 * PI / teeth / 4.0
|
|
46
|
+
|
|
47
|
+
glShadeModel(GL_FLAT)
|
|
48
|
+
|
|
49
|
+
glNormal3f(0.0, 0.0, 1.0)
|
|
50
|
+
|
|
51
|
+
# draw front face
|
|
52
|
+
glBegin(GL_QUAD_STRIP)
|
|
53
|
+
0.upto(teeth) do |i|
|
|
54
|
+
angle = i * 2.0 * PI / teeth
|
|
55
|
+
glVertex3f(r0 * cos(angle), r0 * sin(angle), width * 0.5)
|
|
56
|
+
glVertex3f(r1 * cos(angle), r1 * sin(angle), width * 0.5)
|
|
57
|
+
if (i < teeth)
|
|
58
|
+
glVertex3f(r0 * cos(angle), r0 * sin(angle), width * 0.5)
|
|
59
|
+
glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da), width * 0.5)
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
glEnd()
|
|
63
|
+
|
|
64
|
+
# draw front sides of teeth
|
|
65
|
+
glBegin(GL_QUADS)
|
|
66
|
+
da = 2.0 * PI / teeth / 4.0
|
|
67
|
+
teeth.times do |i|
|
|
68
|
+
angle = i * 2.0 * PI / teeth
|
|
69
|
+
|
|
70
|
+
glVertex3f(r1 * cos(angle), r1 * sin(angle), width * 0.5)
|
|
71
|
+
glVertex3f(r2 * cos(angle + da), r2 * sin(angle + da), width * 0.5)
|
|
72
|
+
glVertex3f(r2 * cos(angle + 2 * da), r2 * sin(angle + 2 * da), width * 0.5)
|
|
73
|
+
glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da), width * 0.5)
|
|
74
|
+
end
|
|
75
|
+
glEnd()
|
|
76
|
+
|
|
77
|
+
glNormal3f(0.0, 0.0, -1.0)
|
|
78
|
+
|
|
79
|
+
# draw back face
|
|
80
|
+
glBegin(GL_QUAD_STRIP)
|
|
81
|
+
0.upto(teeth) do |i|
|
|
82
|
+
angle = i * 2.0 * PI / teeth
|
|
83
|
+
glVertex3f(r1 * cos(angle), r1 * sin(angle), -width * 0.5)
|
|
84
|
+
glVertex3f(r0 * cos(angle), r0 * sin(angle), -width * 0.5)
|
|
85
|
+
if (i < teeth)
|
|
86
|
+
glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da), -width * 0.5)
|
|
87
|
+
glVertex3f(r0 * cos(angle), r0 * sin(angle), -width * 0.5)
|
|
88
|
+
end
|
|
89
|
+
end
|
|
90
|
+
glEnd()
|
|
91
|
+
|
|
92
|
+
# draw back sides of teeth */
|
|
93
|
+
glBegin(GL_QUADS)
|
|
94
|
+
da = 2.0 * PI / teeth / 4.0
|
|
95
|
+
teeth.times do |i|
|
|
96
|
+
angle = i * 2.0 * PI / teeth
|
|
97
|
+
|
|
98
|
+
glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da), -width * 0.5)
|
|
99
|
+
glVertex3f(r2 * cos(angle + 2 * da), r2 * sin(angle + 2 * da), -width * 0.5)
|
|
100
|
+
glVertex3f(r2 * cos(angle + da), r2 * sin(angle + da), -width * 0.5)
|
|
101
|
+
glVertex3f(r1 * cos(angle), r1 * sin(angle), -width * 0.5)
|
|
102
|
+
end
|
|
103
|
+
glEnd()
|
|
104
|
+
|
|
105
|
+
# draw outward faces of teeth
|
|
106
|
+
glBegin(GL_QUAD_STRIP)
|
|
107
|
+
teeth.times do |i|
|
|
108
|
+
angle = i * 2.0 * PI / teeth
|
|
109
|
+
|
|
110
|
+
glVertex3f(r1 * cos(angle), r1 * sin(angle), width * 0.5)
|
|
111
|
+
glVertex3f(r1 * cos(angle), r1 * sin(angle), -width * 0.5)
|
|
112
|
+
u = r2 * cos(angle + da) - r1 * cos(angle)
|
|
113
|
+
v = r2 * sin(angle + da) - r1 * sin(angle)
|
|
114
|
+
len = sqrt(u * u + v * v)
|
|
115
|
+
u /= len
|
|
116
|
+
v /= len
|
|
117
|
+
glNormal3f(v, -u, 0.0)
|
|
118
|
+
glVertex3f(r2 * cos(angle + da), r2 * sin(angle + da), width * 0.5)
|
|
119
|
+
glVertex3f(r2 * cos(angle + da), r2 * sin(angle + da), -width * 0.5)
|
|
120
|
+
glNormal3f(cos(angle), sin(angle), 0.0)
|
|
121
|
+
glVertex3f(r2 * cos(angle + 2 * da), r2 * sin(angle + 2 * da), width * 0.5)
|
|
122
|
+
glVertex3f(r2 * cos(angle + 2 * da), r2 * sin(angle + 2 * da), -width * 0.5)
|
|
123
|
+
u = r1 * cos(angle + 3 * da) - r2 * cos(angle + 2 * da)
|
|
124
|
+
v = r1 * sin(angle + 3 * da) - r2 * sin(angle + 2 * da)
|
|
125
|
+
glNormal3f(v, -u, 0.0)
|
|
126
|
+
glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da), width * 0.5)
|
|
127
|
+
glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da), -width * 0.5)
|
|
128
|
+
glNormal3f(cos(angle), sin(angle), 0.0)
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
glVertex3f(r1 * cos(0), r1 * sin(0), width * 0.5)
|
|
132
|
+
glVertex3f(r1 * cos(0), r1 * sin(0), -width * 0.5)
|
|
133
|
+
|
|
134
|
+
glEnd()
|
|
135
|
+
|
|
136
|
+
glShadeModel(GL_SMOOTH)
|
|
137
|
+
|
|
138
|
+
# draw inside radius cylinder
|
|
139
|
+
glBegin(GL_QUAD_STRIP);
|
|
140
|
+
0.upto(teeth) do |i|
|
|
141
|
+
angle = i * 2.0 * PI / teeth
|
|
142
|
+
glNormal3f(-cos(angle), -sin(angle), 0.0)
|
|
143
|
+
glVertex3f(r0 * cos(angle), r0 * sin(angle), -width * 0.5)
|
|
144
|
+
glVertex3f(r0 * cos(angle), r0 * sin(angle), width * 0.5)
|
|
145
|
+
end
|
|
146
|
+
glEnd()
|
|
147
|
+
end
|
|
148
|
+
|
|
149
|
+
$view_rotx = 20.0
|
|
150
|
+
$view_roty = 30.0
|
|
151
|
+
$view_rotz = 0.0
|
|
152
|
+
$gear1 = 0
|
|
153
|
+
$gear2 = 0
|
|
154
|
+
$gear3 = 0
|
|
155
|
+
$angle = 0.0
|
|
156
|
+
|
|
157
|
+
# OpenGL draw function & timing
|
|
158
|
+
def draw
|
|
159
|
+
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
|
|
160
|
+
|
|
161
|
+
glPushMatrix()
|
|
162
|
+
glRotatef($view_rotx, 1.0, 0.0, 0.0)
|
|
163
|
+
glRotatef($view_roty, 0.0, 1.0, 0.0)
|
|
164
|
+
glRotatef($view_rotz, 0.0, 0.0, 1.0)
|
|
165
|
+
|
|
166
|
+
glPushMatrix()
|
|
167
|
+
glTranslatef(-3.0, -2.0, 0.0)
|
|
168
|
+
glRotatef($angle, 0.0, 0.0, 1.0)
|
|
169
|
+
glCallList($gear1)
|
|
170
|
+
glPopMatrix()
|
|
171
|
+
|
|
172
|
+
glPushMatrix()
|
|
173
|
+
glTranslatef(3.1, -2.0, 0.0)
|
|
174
|
+
glRotatef(-2.0 * $angle - 9.0, 0.0, 0.0, 1.0)
|
|
175
|
+
glCallList($gear2)
|
|
176
|
+
glPopMatrix()
|
|
177
|
+
|
|
178
|
+
glPushMatrix()
|
|
179
|
+
glTranslatef(-3.1, 4.2, 0.0)
|
|
180
|
+
glRotatef(-2.0 * $angle - 25.0, 0.0, 0.0, 1.0)
|
|
181
|
+
glCallList($gear3)
|
|
182
|
+
glPopMatrix()
|
|
183
|
+
|
|
184
|
+
glPopMatrix()
|
|
185
|
+
|
|
186
|
+
$frames+=1
|
|
187
|
+
|
|
188
|
+
t_new = glfwGetTime()
|
|
189
|
+
$dt = t_new - $t
|
|
190
|
+
$t = t_new
|
|
191
|
+
|
|
192
|
+
if ($t - $t0 >= 5.0)
|
|
193
|
+
seconds = $t - $t0
|
|
194
|
+
fps = $frames / seconds.to_f
|
|
195
|
+
printf("%d frames in %6.3f seconds = %6.3f FPS\n", $frames, seconds, fps)
|
|
196
|
+
$stdout.flush
|
|
197
|
+
$t0 = $t
|
|
198
|
+
$frames = 0
|
|
199
|
+
if (($t >= 0.999 * $autoexit) && ($autoexit!=0))
|
|
200
|
+
$running = false
|
|
201
|
+
end
|
|
202
|
+
end
|
|
203
|
+
end
|
|
204
|
+
|
|
205
|
+
# update animation parameters
|
|
206
|
+
def animate
|
|
207
|
+
$angle += 100.0*$dt
|
|
208
|
+
end
|
|
209
|
+
|
|
210
|
+
key = lambda do |k,action|
|
|
211
|
+
if (action != GLFW_PRESS)
|
|
212
|
+
next
|
|
213
|
+
end
|
|
214
|
+
|
|
215
|
+
case k
|
|
216
|
+
when ?Z
|
|
217
|
+
if( glfwGetKey( GLFW_KEY_LSHIFT ) == GLFW_PRESS)
|
|
218
|
+
$view_rotz -= 5.0;
|
|
219
|
+
else
|
|
220
|
+
$view_rotz += 5.0;
|
|
221
|
+
end
|
|
222
|
+
when GLFW_KEY_ESC: $running = false
|
|
223
|
+
when GLFW_KEY_UP: $view_rotx += 5.0
|
|
224
|
+
when GLFW_KEY_DOWN: $view_rotx -= 5.0
|
|
225
|
+
when GLFW_KEY_LEFT: $view_roty += 5.0
|
|
226
|
+
when GLFW_KEY_RIGHT: $view_roty -= 5.0
|
|
227
|
+
end
|
|
228
|
+
end
|
|
229
|
+
|
|
230
|
+
# new window size
|
|
231
|
+
reshape = lambda do |width,height|
|
|
232
|
+
h = height.to_f / width.to_f
|
|
233
|
+
|
|
234
|
+
znear = 5.0
|
|
235
|
+
zfar = 30.0
|
|
236
|
+
xmax = znear * 0.5
|
|
237
|
+
|
|
238
|
+
glViewport( 0, 0, width, height )
|
|
239
|
+
glMatrixMode( GL_PROJECTION )
|
|
240
|
+
glLoadIdentity()
|
|
241
|
+
glFrustum( -xmax, xmax, -xmax*h, xmax*h, znear, zfar )
|
|
242
|
+
glMatrixMode( GL_MODELVIEW )
|
|
243
|
+
glLoadIdentity()
|
|
244
|
+
glTranslatef( 0.0, 0.0, -20.0 )
|
|
245
|
+
end
|
|
246
|
+
|
|
247
|
+
def init
|
|
248
|
+
pos = [5.0, 5.0, 10.0, 0.0]
|
|
249
|
+
red = [0.8, 0.1, 0.0, 1.0]
|
|
250
|
+
green = [0.0, 0.8, 0.2, 1.0]
|
|
251
|
+
blue = [0.2, 0.2, 1.0, 1.0]
|
|
252
|
+
|
|
253
|
+
glLightfv(GL_LIGHT0, GL_POSITION, pos)
|
|
254
|
+
glEnable(GL_CULL_FACE)
|
|
255
|
+
glEnable(GL_LIGHTING)
|
|
256
|
+
glEnable(GL_LIGHT0)
|
|
257
|
+
glEnable(GL_DEPTH_TEST)
|
|
258
|
+
|
|
259
|
+
# make the gears
|
|
260
|
+
$gear1 = glGenLists(1)
|
|
261
|
+
glNewList($gear1, GL_COMPILE)
|
|
262
|
+
glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, red)
|
|
263
|
+
gear(1.0, 4.0, 1.0, 20, 0.7)
|
|
264
|
+
glEndList()
|
|
265
|
+
|
|
266
|
+
$gear2 = glGenLists(1)
|
|
267
|
+
glNewList($gear2, GL_COMPILE)
|
|
268
|
+
glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, green)
|
|
269
|
+
gear(0.5, 2.0, 2.0, 10, 0.7)
|
|
270
|
+
glEndList()
|
|
271
|
+
|
|
272
|
+
$gear3 = glGenLists(1)
|
|
273
|
+
glNewList($gear3, GL_COMPILE)
|
|
274
|
+
glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, blue)
|
|
275
|
+
gear(1.3, 2.0, 0.5, 10, 0.7)
|
|
276
|
+
glEndList()
|
|
277
|
+
|
|
278
|
+
glEnable(GL_NORMALIZE)
|
|
279
|
+
|
|
280
|
+
ARGV.each do |arg|
|
|
281
|
+
case arg
|
|
282
|
+
when "-info"
|
|
283
|
+
puts "GL_RENDERER = #{glGetString(GL_RENDERER)}"
|
|
284
|
+
puts "GL_VERSION = #{glGetString(GL_VERSION)}"
|
|
285
|
+
puts "GL_VENDOR = #{glGetString(GL_VENDOR)}"
|
|
286
|
+
puts "GL_EXTENSIONS = #{glGetString(GL_EXTENSIONS)}"
|
|
287
|
+
when "-exit"
|
|
288
|
+
$autoexit = 30
|
|
289
|
+
puts "Auto Exit after #{$autoexit} seconds."
|
|
290
|
+
end
|
|
291
|
+
end
|
|
292
|
+
end
|
|
293
|
+
|
|
294
|
+
|
|
295
|
+
# program entry
|
|
296
|
+
|
|
297
|
+
# Init GLFW and open window
|
|
298
|
+
if( glfwOpenWindow( 300,300, 0,0,0,0, 16,0, GLFW_WINDOW ) == false)
|
|
299
|
+
exit
|
|
300
|
+
end
|
|
301
|
+
|
|
302
|
+
glfwSetWindowTitle( "Gears" )
|
|
303
|
+
glfwEnable( GLFW_KEY_REPEAT )
|
|
304
|
+
glfwSwapInterval( 0 )
|
|
305
|
+
|
|
306
|
+
init()
|
|
307
|
+
# Set callback functions
|
|
308
|
+
glfwSetWindowSizeCallback( reshape )
|
|
309
|
+
glfwSetKeyCallback( key )
|
|
310
|
+
|
|
311
|
+
# Main loop
|
|
312
|
+
while $running
|
|
313
|
+
# Draw gears
|
|
314
|
+
draw()
|
|
315
|
+
|
|
316
|
+
# Update animation
|
|
317
|
+
animate()
|
|
318
|
+
|
|
319
|
+
# Swap buffers
|
|
320
|
+
glfwSwapBuffers()
|
|
321
|
+
|
|
322
|
+
# Was the window closed?
|
|
323
|
+
if( glfwGetWindowParam( GLFW_OPENED ) == false)
|
|
324
|
+
$running = false
|
|
325
|
+
end
|
|
326
|
+
end
|
|
327
|
+
|
data/examples/keytest.rb
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
#========================================================================
|
|
2
|
+
# This is a small test application for GLFW.
|
|
3
|
+
# Keyboard input test.
|
|
4
|
+
#========================================================================
|
|
5
|
+
# Converted to ruby from GLFW example keytest.c
|
|
6
|
+
|
|
7
|
+
require 'opengl'
|
|
8
|
+
require 'glfw'
|
|
9
|
+
include Gl,Glu,Glfw
|
|
10
|
+
|
|
11
|
+
$running = true
|
|
12
|
+
$keyrepeat = false
|
|
13
|
+
$systemkeys = true
|
|
14
|
+
|
|
15
|
+
keyfun = lambda do |key,action|
|
|
16
|
+
if action != GLFW_PRESS
|
|
17
|
+
next
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
case key
|
|
21
|
+
when GLFW_KEY_ESC
|
|
22
|
+
puts "ESC => quit program"
|
|
23
|
+
$running = false
|
|
24
|
+
when GLFW_KEY_F1..GLFW_KEY_F25
|
|
25
|
+
puts "F#{1 + key - GLFW_KEY_F1}"
|
|
26
|
+
when GLFW_KEY_UP: puts "UP"
|
|
27
|
+
when GLFW_KEY_DOWN: puts "DOWN"
|
|
28
|
+
when GLFW_KEY_LEFT: puts "LEFT"
|
|
29
|
+
when GLFW_KEY_RIGHT: puts "RIGHT"
|
|
30
|
+
when GLFW_KEY_LSHIFT: puts "LSHIFT"
|
|
31
|
+
when GLFW_KEY_RSHIFT: puts "RSHIFT"
|
|
32
|
+
when GLFW_KEY_LCTRL: puts "LCTRL"
|
|
33
|
+
when GLFW_KEY_RCTRL: puts "RCTRL"
|
|
34
|
+
when GLFW_KEY_LALT: puts "LALT"
|
|
35
|
+
when GLFW_KEY_RALT: puts "RALT"
|
|
36
|
+
when GLFW_KEY_TAB: puts "TAB"
|
|
37
|
+
when GLFW_KEY_ENTER: puts "ENTER"
|
|
38
|
+
when GLFW_KEY_BACKSPACE: puts "BACKSPACE"
|
|
39
|
+
when GLFW_KEY_INSERT: puts "INSERT"
|
|
40
|
+
when GLFW_KEY_DEL: puts "DEL"
|
|
41
|
+
when GLFW_KEY_PAGEUP: puts "PAGEUP"
|
|
42
|
+
when GLFW_KEY_PAGEDOWN: puts "PAGEDOWN"
|
|
43
|
+
when GLFW_KEY_HOME: puts "HOME"
|
|
44
|
+
when GLFW_KEY_END: puts "END"
|
|
45
|
+
when GLFW_KEY_KP_0..GLFW_KEY_KP_9
|
|
46
|
+
puts "KEYPAD #{key - GLFW_KEY_KP_0}"
|
|
47
|
+
when GLFW_KEY_KP_DIVIDE: puts "KEYPAD DIVIDE"
|
|
48
|
+
when GLFW_KEY_KP_MULTIPLY: puts "KEYPAD MULTIPLY"
|
|
49
|
+
when GLFW_KEY_KP_SUBTRACT: puts "KEYPAD SUBTRACT"
|
|
50
|
+
when GLFW_KEY_KP_ADD: puts "KEYPAD ADD"
|
|
51
|
+
when GLFW_KEY_KP_DECIMAL: puts "KEYPAD DECIMAL"
|
|
52
|
+
when GLFW_KEY_KP_EQUAL: puts "KEYPAD ="
|
|
53
|
+
when GLFW_KEY_KP_ENTER: puts "KEYPAD ENTER"
|
|
54
|
+
when GLFW_KEY_SPACE: puts "SPACE"
|
|
55
|
+
when ?R
|
|
56
|
+
if ($keyrepeat==false)
|
|
57
|
+
glfwEnable(GLFW_KEY_REPEAT)
|
|
58
|
+
else
|
|
59
|
+
glfwDisable(GLFW_KEY_REPEAT)
|
|
60
|
+
end
|
|
61
|
+
$keyrepeat = !$keyrepeat
|
|
62
|
+
puts "R => Key repeat: #{$keyrepeat ? 'ON' : 'OFF'}"
|
|
63
|
+
when ?S
|
|
64
|
+
if ($systemkeys==false)
|
|
65
|
+
glfwEnable(GLFW_SYSTEM_KEYS)
|
|
66
|
+
else
|
|
67
|
+
glfwDisable(GLFW_SYSTEM_KEYS)
|
|
68
|
+
end
|
|
69
|
+
$systemkeys = !$systemkeys
|
|
70
|
+
puts "S => System keys: #{$systemkeys ? 'ON' : 'OFF'}"
|
|
71
|
+
else
|
|
72
|
+
if (key>0 && key<256)
|
|
73
|
+
puts key.chr
|
|
74
|
+
else
|
|
75
|
+
puts "???"
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
$stdout.flush
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
# main
|
|
83
|
+
|
|
84
|
+
# Open OpenGL window
|
|
85
|
+
if (glfwOpenWindow( 250,100, 0,0,0,0, 0,0, GLFW_WINDOW ) == false)
|
|
86
|
+
exit
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
# Set key callback function
|
|
90
|
+
glfwSetKeyCallback( keyfun )
|
|
91
|
+
|
|
92
|
+
# Set tile
|
|
93
|
+
glfwSetWindowTitle( "Press some keys!" )
|
|
94
|
+
|
|
95
|
+
# Main loop
|
|
96
|
+
$running = true
|
|
97
|
+
while $running
|
|
98
|
+
# Get time and mouse position
|
|
99
|
+
t = glfwGetTime()
|
|
100
|
+
|
|
101
|
+
# Get window size (may be different than the requested size)
|
|
102
|
+
width,height = glfwGetWindowSize()
|
|
103
|
+
height = height > 0 ? height : 1
|
|
104
|
+
|
|
105
|
+
# Set viewport
|
|
106
|
+
glViewport( 0, 0, width, height )
|
|
107
|
+
|
|
108
|
+
# Clear color buffer
|
|
109
|
+
glClearColor( 0.5+0.5*Math.sin(3.0*t), 0.0, 0.0, 0.0)
|
|
110
|
+
glClear( GL_COLOR_BUFFER_BIT )
|
|
111
|
+
|
|
112
|
+
# Swap buffers
|
|
113
|
+
glfwSwapBuffers()
|
|
114
|
+
|
|
115
|
+
# Check if the window was closed
|
|
116
|
+
$running = ($running && glfwGetWindowParam( GLFW_OPENED ) == true)
|
|
117
|
+
end
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
#========================================================================
|
|
2
|
+
# This is a small test application for GLFW.
|
|
3
|
+
# The program lists all available fullscreen video modes.
|
|
4
|
+
#========================================================================
|
|
5
|
+
# Converted to ruby from GLFW example listmodes.c
|
|
6
|
+
|
|
7
|
+
require 'opengl'
|
|
8
|
+
require 'glfw'
|
|
9
|
+
include Gl,Glu,Glfw
|
|
10
|
+
|
|
11
|
+
dtmode = glfwGetDesktopMode()
|
|
12
|
+
puts "Desktop mode: #{dtmode.Width} x #{dtmode.Height} x #{dtmode.RedBits+dtmode.GreenBits+dtmode.BlueBits}\n\n"
|
|
13
|
+
|
|
14
|
+
modes = glfwGetVideoModes()
|
|
15
|
+
puts "Available modes:"
|
|
16
|
+
(modes.size).times do |i|
|
|
17
|
+
printf( "%3d: %d x %d x %d\n", i,
|
|
18
|
+
modes[i].Width, modes[i].Height,
|
|
19
|
+
modes[i].RedBits+modes[i].GreenBits+modes[i].BlueBits)
|
|
20
|
+
end
|