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
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
<html>
|
|
2
|
+
|
|
3
|
+
<head>
|
|
4
|
+
<title>GLFW Readme file for Delphi</title>
|
|
5
|
+
</head>
|
|
6
|
+
<body>
|
|
7
|
+
|
|
8
|
+
<!-- TITLE -------------------------------------------------------------->
|
|
9
|
+
<center>
|
|
10
|
+
<font face="bookman old style,arial" size=+4><b>GLFW v2.5</b></font><br>
|
|
11
|
+
<font face="bookman old style,arial" size=+3>for Delphi</font>
|
|
12
|
+
</center>
|
|
13
|
+
|
|
14
|
+
<!-- CONTENTS ----------------------------------------------------------->
|
|
15
|
+
<p>
|
|
16
|
+
<center>
|
|
17
|
+
<table border=0><tr><td>
|
|
18
|
+
<b>
|
|
19
|
+
<ol>
|
|
20
|
+
<li><a href="#sec1">Introduction</li></a>
|
|
21
|
+
<li><a href="#sec2">Using GLFW from Delphi</li></a>
|
|
22
|
+
<li><a href="#sec3">The author</li></a>
|
|
23
|
+
<li><a href="#sec4">Acknowledgements</li></a>
|
|
24
|
+
</ol>
|
|
25
|
+
</b>
|
|
26
|
+
</td></tr></table>
|
|
27
|
+
</center>
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
<!----------------------------------------------------------------------->
|
|
31
|
+
<p><hr>
|
|
32
|
+
<!----------------------------------------------------------------------->
|
|
33
|
+
|
|
34
|
+
<a name="sec1">
|
|
35
|
+
<p><h2>1. Introduction</h2>
|
|
36
|
+
|
|
37
|
+
<p>This folder contains Delphi bindings for the GLFW v2.5.x Windows DLL,
|
|
38
|
+
and Delphi example programs. For further information on how to use GLFW
|
|
39
|
+
you should read the GLFW documentation.
|
|
40
|
+
|
|
41
|
+
<!----------------------------------------------------------------------->
|
|
42
|
+
<p><hr>
|
|
43
|
+
<!----------------------------------------------------------------------->
|
|
44
|
+
|
|
45
|
+
<a name="sec2">
|
|
46
|
+
<p><h2>2. Using GLFW from Delphi</h2>
|
|
47
|
+
|
|
48
|
+
<p>Since the general syntax of Pascal does not differ much from the C
|
|
49
|
+
language syntax, using GLFW from Delphi is very similar to using GLFW from
|
|
50
|
+
C/C++. This should make it easy to follow the GLFW documentation, which
|
|
51
|
+
was primarily written for C/C++ users.
|
|
52
|
+
|
|
53
|
+
<p>On the more practical side, you will need to copy the GLFW DLL file
|
|
54
|
+
(support\win32dll\glfw.dll) to your Windows system folder (e.g.
|
|
55
|
+
C:\Windows\system for Windows 9x/ME, or C:\WinNT\system32 for Windows NT),
|
|
56
|
+
and/or to the same directory as you keep the executable for your GLFW
|
|
57
|
+
based program.
|
|
58
|
+
|
|
59
|
+
<p>You also have to copy the GLFW binding file for Delphi
|
|
60
|
+
(support\delphi\lib\glfw.pas) to your Delphi\Lib directory.
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
<!----------------------------------------------------------------------->
|
|
64
|
+
<p><hr>
|
|
65
|
+
<!----------------------------------------------------------------------->
|
|
66
|
+
|
|
67
|
+
<a name="sec3">
|
|
68
|
+
<p><h2>3. The maintainer</h2>
|
|
69
|
+
|
|
70
|
+
<p>My name is Camilla Berglund,
|
|
71
|
+
<a href="mailto:elmindreda@users.sourceforge.net">elmindreda@users.sourceforge.net</a>.
|
|
72
|
+
Please visit our
|
|
73
|
+
<a href="http://sourceforge.net/projects/glfw/">support forums</a>
|
|
74
|
+
if you have any problems with GLFW or any questions concerning GLFW.
|
|
75
|
+
|
|
76
|
+
<p>The GLFW web site can be found here:
|
|
77
|
+
<a href="http://glfw.sourceforge.net/">http://glfw.sourceforge.net/</a>.
|
|
78
|
+
It contains the latest version of GLFW, news and other information that is
|
|
79
|
+
useful for OpenGL development.
|
|
80
|
+
|
|
81
|
+
<!----------------------------------------------------------------------->
|
|
82
|
+
<p><hr>
|
|
83
|
+
<!----------------------------------------------------------------------->
|
|
84
|
+
|
|
85
|
+
<a name="sec4">
|
|
86
|
+
<p><h2>4. Acknowledgements</h2>
|
|
87
|
+
|
|
88
|
+
<p>Many thanks to <b>Jarrod Davis</b>, who contributed the original
|
|
89
|
+
Delphi binding file (glfw.pas) and the conversion of the Triangle example
|
|
90
|
+
program!
|
|
91
|
+
|
|
92
|
+
<!----------------------------------------------------------------------->
|
|
93
|
+
<p><hr>
|
|
94
|
+
<!----------------------------------------------------------------------->
|
|
95
|
+
|
|
96
|
+
</body>
|
|
97
|
+
</html>
|
|
@@ -0,0 +1,383 @@
|
|
|
1
|
+
--------------------------------------------------------------------------
|
|
2
|
+
-- 3-D gear wheels. This program is in the public domain.
|
|
3
|
+
--
|
|
4
|
+
-- Command line options:
|
|
5
|
+
-- -info print GL implementation information
|
|
6
|
+
-- -exit automatically exit after 30 seconds
|
|
7
|
+
--
|
|
8
|
+
--
|
|
9
|
+
-- Brian Paul
|
|
10
|
+
--
|
|
11
|
+
--
|
|
12
|
+
-- Marcus Geelnard:
|
|
13
|
+
-- - Conversion to GLFW
|
|
14
|
+
-- - Time based rendering (frame rate independent)
|
|
15
|
+
-- - Slightly modified camera that should work better for stereo viewing
|
|
16
|
+
-- - Ported to Lua (thanks to David Medlock for the original Lua port)
|
|
17
|
+
--------------------------------------------------------------------------
|
|
18
|
+
|
|
19
|
+
local t0 = 0.0
|
|
20
|
+
local t = 0
|
|
21
|
+
local dt = 0
|
|
22
|
+
|
|
23
|
+
local Frames = 0
|
|
24
|
+
local autoexit = 0
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
--------------------------------------------------------------------------
|
|
28
|
+
-- Draw a gear wheel. You'll probably want to call this function when
|
|
29
|
+
-- building a display list since we do a lot of trig here.
|
|
30
|
+
--
|
|
31
|
+
-- Input: inner_radius - radius of hole at center
|
|
32
|
+
-- outer_radius - radius at center of teeth
|
|
33
|
+
-- width - width of gear
|
|
34
|
+
-- teeth - number of teeth
|
|
35
|
+
-- tooth_depth - depth of tooth
|
|
36
|
+
--------------------------------------------------------------------------
|
|
37
|
+
local function gear(inner_radius, outer_radius, width, teeth, tooth_depth)
|
|
38
|
+
|
|
39
|
+
local PI = 3.141592654
|
|
40
|
+
local r0 = inner_radius
|
|
41
|
+
local r1 = outer_radius - ( tooth_depth / 2.0 )
|
|
42
|
+
local r2 = outer_radius + ( tooth_depth / 2.0 )
|
|
43
|
+
local da = 2.0 * PI / teeth / 4.0
|
|
44
|
+
|
|
45
|
+
gl.ShadeModel("FLAT")
|
|
46
|
+
|
|
47
|
+
gl.Normal(0.0, 0.0, 1.0)
|
|
48
|
+
|
|
49
|
+
local cos = math.cos;
|
|
50
|
+
local sin = math.sin;
|
|
51
|
+
local sqrt = math.sqrt;
|
|
52
|
+
|
|
53
|
+
-- draw front face
|
|
54
|
+
gl.Begin("QUAD_STRIP");
|
|
55
|
+
for i = 0, teeth do
|
|
56
|
+
angle = i * 2.0 * PI / teeth
|
|
57
|
+
gl.Vertex(r0 * cos(angle), r0 * sin(angle), width * 0.5)
|
|
58
|
+
gl.Vertex(r1 * cos(angle), r1 * sin(angle), width * 0.5)
|
|
59
|
+
if (i < teeth) then
|
|
60
|
+
gl.Vertex(r0 * cos(angle), r0 * sin(angle), width * 0.5)
|
|
61
|
+
gl.Vertex(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da), width * 0.5)
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
gl.End()
|
|
65
|
+
|
|
66
|
+
-- draw front sides of teeth
|
|
67
|
+
gl.Begin("QUADS")
|
|
68
|
+
da = 2.0 * PI / teeth / 4.0;
|
|
69
|
+
for i = 0,teeth-1 do
|
|
70
|
+
angle = i * 2.0 * PI / teeth
|
|
71
|
+
|
|
72
|
+
gl.Vertex(r1 * cos(angle), r1 * sin(angle), width * 0.5)
|
|
73
|
+
gl.Vertex(r2 * cos(angle + da), r2 * sin(angle + da), width * 0.5)
|
|
74
|
+
gl.Vertex(r2 * cos(angle + 2 * da), r2 * sin(angle + 2 * da), width * 0.5)
|
|
75
|
+
gl.Vertex(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da), width * 0.5)
|
|
76
|
+
end
|
|
77
|
+
gl.End()
|
|
78
|
+
|
|
79
|
+
gl.Normal(0.0, 0.0, -1.0)
|
|
80
|
+
|
|
81
|
+
-- draw back face
|
|
82
|
+
gl.Begin("QUAD_STRIP")
|
|
83
|
+
for i = 0,teeth do
|
|
84
|
+
angle = i * 2.0 * PI / teeth
|
|
85
|
+
gl.Vertex(r1 * cos(angle), r1 * sin(angle), -width * 0.5)
|
|
86
|
+
gl.Vertex(r0 * cos(angle), r0 * sin(angle), -width * 0.5)
|
|
87
|
+
if (i < teeth) then
|
|
88
|
+
gl.Vertex(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da), -width * 0.5)
|
|
89
|
+
gl.Vertex(r0 * cos(angle), r0 * sin(angle), -width * 0.5)
|
|
90
|
+
end
|
|
91
|
+
end
|
|
92
|
+
gl.End()
|
|
93
|
+
|
|
94
|
+
-- draw back sides of teeth
|
|
95
|
+
gl.Begin("QUADS")
|
|
96
|
+
da = 2.0 * PI / teeth / 4.0
|
|
97
|
+
for i = 0, teeth-1 do
|
|
98
|
+
angle = i * 2.0 * PI / teeth
|
|
99
|
+
|
|
100
|
+
gl.Vertex(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da), -width * 0.5)
|
|
101
|
+
gl.Vertex(r2 * cos(angle + 2 * da), r2 * sin(angle + 2 * da), -width * 0.5)
|
|
102
|
+
gl.Vertex(r2 * cos(angle + da), r2 * sin(angle + da), -width * 0.5)
|
|
103
|
+
gl.Vertex(r1 * cos(angle), r1 * sin(angle), -width * 0.5)
|
|
104
|
+
end
|
|
105
|
+
gl.End()
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
-- draw outward faces of teeth
|
|
109
|
+
gl.Begin("QUAD_STRIP")
|
|
110
|
+
for i = 0, teeth-1 do
|
|
111
|
+
angle = i * 2.0 * PI / teeth
|
|
112
|
+
|
|
113
|
+
gl.Vertex(r1 * cos(angle), r1 * sin(angle), width * 0.5)
|
|
114
|
+
gl.Vertex(r1 * cos(angle), r1 * sin(angle), -width * 0.5)
|
|
115
|
+
u = r2 * cos(angle + da) - r1 * cos(angle)
|
|
116
|
+
v = r2 * sin(angle + da) - r1 * sin(angle)
|
|
117
|
+
len = sqrt(u * u + v * v)
|
|
118
|
+
u = u / len
|
|
119
|
+
v = v / len
|
|
120
|
+
gl.Normal(v, -u, 0.0)
|
|
121
|
+
gl.Vertex(r2 * cos(angle + da), r2 * sin(angle + da), width * 0.5)
|
|
122
|
+
gl.Vertex(r2 * cos(angle + da), r2 * sin(angle + da), -width * 0.5)
|
|
123
|
+
gl.Normal(cos(angle), sin(angle), 0.0)
|
|
124
|
+
gl.Vertex(r2 * cos(angle + 2 * da), r2 * sin(angle + 2 * da), width * 0.5)
|
|
125
|
+
gl.Vertex(r2 * cos(angle + 2 * da), r2 * sin(angle + 2 * da), -width * 0.5)
|
|
126
|
+
u = r1 * cos(angle + 3 * da) - r2 * cos(angle + 2 * da)
|
|
127
|
+
v = r1 * sin(angle + 3 * da) - r2 * sin(angle + 2 * da)
|
|
128
|
+
gl.Normal(v, -u, 0.0)
|
|
129
|
+
gl.Vertex(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da), width * 0.5)
|
|
130
|
+
gl.Vertex(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da), -width * 0.5)
|
|
131
|
+
gl.Normal(cos(angle), sin(angle), 0.0)
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
gl.Vertex(r1 * cos(0), r1 * sin(0), width * 0.5)
|
|
135
|
+
gl.Vertex(r1 * cos(0), r1 * sin(0), -width * 0.5)
|
|
136
|
+
|
|
137
|
+
gl.End()
|
|
138
|
+
|
|
139
|
+
gl.ShadeModel("SMOOTH");
|
|
140
|
+
|
|
141
|
+
-- draw inside radius cylinder
|
|
142
|
+
gl.Begin("QUAD_STRIP")
|
|
143
|
+
for i = 0,teeth do
|
|
144
|
+
angle = i * 2.0 * PI / teeth
|
|
145
|
+
gl.Normal(-cos(angle), -sin(angle), 0.0)
|
|
146
|
+
gl.Vertex(r0 * cos(angle), r0 * sin(angle), -width * 0.5)
|
|
147
|
+
gl.Vertex(r0 * cos(angle), r0 * sin(angle), width * 0.5)
|
|
148
|
+
end
|
|
149
|
+
gl.End()
|
|
150
|
+
|
|
151
|
+
end
|
|
152
|
+
|
|
153
|
+
local running = true
|
|
154
|
+
local view = { rotx = 20.0 ; roty = 30.0 ; rotz = 0.0 }
|
|
155
|
+
local gear1, gear2, gear3
|
|
156
|
+
local angle = 0.0
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
--------------------------------------------------------------------------
|
|
160
|
+
-- OpenGL draw function & timing
|
|
161
|
+
--------------------------------------------------------------------------
|
|
162
|
+
local function draw()
|
|
163
|
+
gl.Clear("DEPTH_BUFFER_BIT,COLOR_BUFFER_BIT")
|
|
164
|
+
|
|
165
|
+
gl.MatrixMode( "MODELVIEW" );
|
|
166
|
+
|
|
167
|
+
gl.PushMatrix()
|
|
168
|
+
gl.Rotate(view.rotx, 1.0, 0.0, 0.0)
|
|
169
|
+
gl.Rotate(view.roty, 0.0, 1.0, 0.0)
|
|
170
|
+
gl.Rotate(view.rotz, 0.0, 0.0, 1.0)
|
|
171
|
+
|
|
172
|
+
gl.PushMatrix()
|
|
173
|
+
gl.Translate(-3.0, -2.0, 0.0)
|
|
174
|
+
gl.Rotate(angle, 0.0, 0.0, 1.0)
|
|
175
|
+
gl.CallList(gear1)
|
|
176
|
+
gl.PopMatrix()
|
|
177
|
+
|
|
178
|
+
gl.PushMatrix()
|
|
179
|
+
gl.Translate(3.1, -2.0, 0.0)
|
|
180
|
+
gl.Rotate(-2.0 * angle - 9.0, 0.0, 0.0, 1.0)
|
|
181
|
+
gl.CallList(gear2)
|
|
182
|
+
gl.PopMatrix()
|
|
183
|
+
|
|
184
|
+
gl.PushMatrix()
|
|
185
|
+
gl.Translate(-3.1, 4.2, 0.0)
|
|
186
|
+
gl.Rotate(-2.0 * angle - 25.0, 0.0, 0.0, 1.0)
|
|
187
|
+
gl.CallList(gear3)
|
|
188
|
+
gl.PopMatrix()
|
|
189
|
+
|
|
190
|
+
gl.PopMatrix()
|
|
191
|
+
|
|
192
|
+
Frames = Frames + 1;
|
|
193
|
+
|
|
194
|
+
do
|
|
195
|
+
t_new = glfw.GetTime()
|
|
196
|
+
dt = t_new - t;
|
|
197
|
+
t = t_new;
|
|
198
|
+
|
|
199
|
+
if (t - t0 >= 5.0) then
|
|
200
|
+
seconds = t - t0;
|
|
201
|
+
fps = Frames / seconds;
|
|
202
|
+
print(Frames, " frames in ", seconds, " seconds = ", fps, " FPS")
|
|
203
|
+
t0 = t;
|
|
204
|
+
Frames = 0;
|
|
205
|
+
if (t >= 0.999 * autoexit) and autoexit then running = 0 end
|
|
206
|
+
end
|
|
207
|
+
end
|
|
208
|
+
end
|
|
209
|
+
|
|
210
|
+
|
|
211
|
+
--------------------------------------------------------------------------
|
|
212
|
+
-- Initialize OpenGL
|
|
213
|
+
--------------------------------------------------------------------------
|
|
214
|
+
local function init(args)
|
|
215
|
+
pos = {5.0, 5.0, 10.0, 0.0}
|
|
216
|
+
red = {0.8, 0.1, 0.0, 1.0}
|
|
217
|
+
green = {0.0, 0.8, 0.2, 1.0}
|
|
218
|
+
blue = {0.2, 0.2, 1.0, 1.0}
|
|
219
|
+
|
|
220
|
+
gl.Light("LIGHT0", "POSITION", pos)
|
|
221
|
+
gl.Enable("CULL_FACE")
|
|
222
|
+
gl.Enable("LIGHTING")
|
|
223
|
+
gl.Enable("LIGHT0")
|
|
224
|
+
gl.Enable("DEPTH_TEST")
|
|
225
|
+
gl.DepthFunc("LEQUAL")
|
|
226
|
+
|
|
227
|
+
-- make the gears
|
|
228
|
+
gear1 = gl.GenLists(1)
|
|
229
|
+
gl.NewList(gear1, "COMPILE");
|
|
230
|
+
gl.Material("FRONT", "AMBIENT_AND_DIFFUSE", red);
|
|
231
|
+
gear(1.0, 4.0, 1.0, 20, 0.7);
|
|
232
|
+
gl.EndList()
|
|
233
|
+
|
|
234
|
+
gear2 = gl.GenLists(1)
|
|
235
|
+
gl.NewList(gear2, "COMPILE")
|
|
236
|
+
gl.Material("FRONT", "AMBIENT_AND_DIFFUSE", green)
|
|
237
|
+
gear(0.5, 2.0, 2.0, 10, 0.7)
|
|
238
|
+
gl.EndList()
|
|
239
|
+
|
|
240
|
+
gear3 = gl.GenLists(1);
|
|
241
|
+
gl.NewList(gear3, "COMPILE")
|
|
242
|
+
gl.Material("FRONT", "AMBIENT_AND_DIFFUSE", blue)
|
|
243
|
+
gear(1.3, 2.0, 0.5, 10, 0.7)
|
|
244
|
+
gl.EndList()
|
|
245
|
+
|
|
246
|
+
gl.Enable("NORMALIZE")
|
|
247
|
+
|
|
248
|
+
if args then
|
|
249
|
+
for parm in args do
|
|
250
|
+
if parm == "-exit" then
|
|
251
|
+
autoexit = 30
|
|
252
|
+
print("Auto Exit after ", autoexit ," seconds." );
|
|
253
|
+
end
|
|
254
|
+
end
|
|
255
|
+
end
|
|
256
|
+
end
|
|
257
|
+
|
|
258
|
+
|
|
259
|
+
--------------------------------------------------------------------------
|
|
260
|
+
-- update animation parameters
|
|
261
|
+
--------------------------------------------------------------------------
|
|
262
|
+
local function animate()
|
|
263
|
+
angle = angle + 100.0*dt
|
|
264
|
+
end
|
|
265
|
+
|
|
266
|
+
|
|
267
|
+
--------------------------------------------------------------------------
|
|
268
|
+
-- new window size
|
|
269
|
+
--------------------------------------------------------------------------
|
|
270
|
+
function reshape( width, height )
|
|
271
|
+
local h = height / width
|
|
272
|
+
|
|
273
|
+
local znear = 5.0
|
|
274
|
+
local zfar = 30.0
|
|
275
|
+
local xmax = znear * 0.5
|
|
276
|
+
|
|
277
|
+
gl.Viewport( 0, 0, width, height )
|
|
278
|
+
gl.MatrixMode( "PROJECTION" );
|
|
279
|
+
gl.LoadIdentity()
|
|
280
|
+
gl.Frustum( -xmax, xmax, -xmax*h, xmax*h, znear, zfar )
|
|
281
|
+
gl.MatrixMode( "MODELVIEW" );
|
|
282
|
+
gl.LoadIdentity()
|
|
283
|
+
gl.Translate( 0.0, 0.0, -20.0 )
|
|
284
|
+
gl.Enable( "DEPTH_TEST" );
|
|
285
|
+
end
|
|
286
|
+
|
|
287
|
+
|
|
288
|
+
--------------------------------------------------------------------------
|
|
289
|
+
-- change view angle, exit upon ESC
|
|
290
|
+
--------------------------------------------------------------------------
|
|
291
|
+
function key( k, action )
|
|
292
|
+
if action ~= glfw.PRESS then return end
|
|
293
|
+
|
|
294
|
+
-- 'Z'?
|
|
295
|
+
if k == 90 then
|
|
296
|
+
if glfw.GetKey( glfw.KEY_LSHIFT ) == glfw.PRESS then
|
|
297
|
+
view.rotz = view.rotz - 5.0
|
|
298
|
+
else
|
|
299
|
+
view.rotz = view.rotz + 5.0
|
|
300
|
+
end
|
|
301
|
+
return
|
|
302
|
+
end
|
|
303
|
+
|
|
304
|
+
if k == glfw.KEY_ESC then
|
|
305
|
+
running = false
|
|
306
|
+
return
|
|
307
|
+
end
|
|
308
|
+
|
|
309
|
+
if k == glfw.KEY_UP then
|
|
310
|
+
view.rotx = view.rotx + 5.0
|
|
311
|
+
return
|
|
312
|
+
end
|
|
313
|
+
|
|
314
|
+
if k == glfw.KEY_DOWN then
|
|
315
|
+
view.rotx = view.rotx - 5.0
|
|
316
|
+
return
|
|
317
|
+
end
|
|
318
|
+
|
|
319
|
+
if k == glfw.KEY_LEFT then
|
|
320
|
+
view.roty = view.roty + 5.0
|
|
321
|
+
return
|
|
322
|
+
end
|
|
323
|
+
|
|
324
|
+
if k == glfw.KEY_RIGHT then
|
|
325
|
+
view.roty = view.roty - 5.0
|
|
326
|
+
return
|
|
327
|
+
end
|
|
328
|
+
end
|
|
329
|
+
|
|
330
|
+
|
|
331
|
+
--------------------------------------------------------------------------
|
|
332
|
+
-- main()
|
|
333
|
+
--------------------------------------------------------------------------
|
|
334
|
+
local function main()
|
|
335
|
+
-- Init GLFW
|
|
336
|
+
if glfw.Init() ~= glfw.TRUE then
|
|
337
|
+
return
|
|
338
|
+
end
|
|
339
|
+
|
|
340
|
+
-- Open window
|
|
341
|
+
if glfw.OpenWindow( 640,480,0,0,0,0,24,0,glfw.WINDOW ) ~= glfw.TRUE then
|
|
342
|
+
glfw.Terminate()
|
|
343
|
+
return
|
|
344
|
+
end
|
|
345
|
+
|
|
346
|
+
glfw.SetWindowTitle( "Gears" );
|
|
347
|
+
glfw.Enable( glfw.KEY_REPEAT );
|
|
348
|
+
glfw.SwapInterval( 0 );
|
|
349
|
+
|
|
350
|
+
-- Special args?
|
|
351
|
+
init(args);
|
|
352
|
+
|
|
353
|
+
-- Set callback functions
|
|
354
|
+
glfw.SetWindowSizeCallback( "reshape" );
|
|
355
|
+
glfw.SetKeyCallback( "key" );
|
|
356
|
+
|
|
357
|
+
while running do
|
|
358
|
+
-- Draw gears
|
|
359
|
+
draw()
|
|
360
|
+
|
|
361
|
+
-- Update animation
|
|
362
|
+
animate()
|
|
363
|
+
|
|
364
|
+
-- Swap buffers
|
|
365
|
+
glfw.SwapBuffers()
|
|
366
|
+
|
|
367
|
+
-- Was the window closed?
|
|
368
|
+
if glfw.GetWindowParam( glfw.OPENED ) ~= glfw.TRUE then
|
|
369
|
+
running = false
|
|
370
|
+
end
|
|
371
|
+
|
|
372
|
+
end
|
|
373
|
+
|
|
374
|
+
-- Terminate GLFW
|
|
375
|
+
glfw.Terminate()
|
|
376
|
+
|
|
377
|
+
-- Exit program
|
|
378
|
+
return
|
|
379
|
+
end
|
|
380
|
+
|
|
381
|
+
|
|
382
|
+
-- execute!
|
|
383
|
+
main()
|