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.
Files changed (206) hide show
  1. data/README +1 -0
  2. data/README.API +73 -0
  3. data/Rakefile +120 -0
  4. data/examples/boing.rb +519 -0
  5. data/examples/gears.rb +327 -0
  6. data/examples/keytest.rb +117 -0
  7. data/examples/listmodes.rb +20 -0
  8. data/examples/mipmaps.rb +104 -0
  9. data/examples/mipmaps.tga +0 -0
  10. data/examples/particles.rb +837 -0
  11. data/examples/pong3d.rb +741 -0
  12. data/examples/pong3d_field.tga +0 -0
  13. data/examples/pong3d_instr.tga +0 -0
  14. data/examples/pong3d_menu.tga +0 -0
  15. data/examples/pong3d_title.tga +0 -0
  16. data/examples/pong3d_winner1.tga +0 -0
  17. data/examples/pong3d_winner2.tga +0 -0
  18. data/examples/splitview.rb +432 -0
  19. data/examples/triangle.rb +89 -0
  20. data/examples/wave.rb +294 -0
  21. data/ext/glfw/glfw.c +1094 -0
  22. data/ext/glfw/mkrf_conf.rb +70 -0
  23. data/glfw-src/Makefile +220 -0
  24. data/glfw-src/compile.ami +61 -0
  25. data/glfw-src/compile.bat +217 -0
  26. data/glfw-src/compile.sh +607 -0
  27. data/glfw-src/docs/Makefile +57 -0
  28. data/glfw-src/docs/Reference.pdf +0 -0
  29. data/glfw-src/docs/UsersGuide.pdf +0 -0
  30. data/glfw-src/docs/cleanup.bat +22 -0
  31. data/glfw-src/docs/glfwdoc.sty +80 -0
  32. data/glfw-src/docs/glfwrm.tex +3034 -0
  33. data/glfw-src/docs/glfwug.tex +2024 -0
  34. data/glfw-src/docs/readme.txt +80 -0
  35. data/glfw-src/examples/Makefile.amigaos.gcc +70 -0
  36. data/glfw-src/examples/Makefile.amigaos.vbcc +70 -0
  37. data/glfw-src/examples/Makefile.dos.djgpp +71 -0
  38. data/glfw-src/examples/Makefile.macosx.gcc +96 -0
  39. data/glfw-src/examples/Makefile.win32.bcc +75 -0
  40. data/glfw-src/examples/Makefile.win32.cross-mgw +79 -0
  41. data/glfw-src/examples/Makefile.win32.cygwin +79 -0
  42. data/glfw-src/examples/Makefile.win32.lcc +74 -0
  43. data/glfw-src/examples/Makefile.win32.mgw +75 -0
  44. data/glfw-src/examples/Makefile.win32.msvc +74 -0
  45. data/glfw-src/examples/Makefile.win32.ow +74 -0
  46. data/glfw-src/examples/Makefile.win32.pellesc +74 -0
  47. data/glfw-src/examples/Makefile.x11.in +54 -0
  48. data/glfw-src/examples/boing.c +606 -0
  49. data/glfw-src/examples/bundle.sh +46 -0
  50. data/glfw-src/examples/gears.c +382 -0
  51. data/glfw-src/examples/keytest.c +264 -0
  52. data/glfw-src/examples/listmodes.c +48 -0
  53. data/glfw-src/examples/mipmaps.c +126 -0
  54. data/glfw-src/examples/mipmaps.tga +0 -0
  55. data/glfw-src/examples/mtbench.c +301 -0
  56. data/glfw-src/examples/mthello.c +48 -0
  57. data/glfw-src/examples/particles.c +1148 -0
  58. data/glfw-src/examples/pong3d.c +839 -0
  59. data/glfw-src/examples/pong3d_field.tga +0 -0
  60. data/glfw-src/examples/pong3d_instr.tga +0 -0
  61. data/glfw-src/examples/pong3d_menu.tga +0 -0
  62. data/glfw-src/examples/pong3d_title.tga +0 -0
  63. data/glfw-src/examples/pong3d_winner1.tga +0 -0
  64. data/glfw-src/examples/pong3d_winner2.tga +0 -0
  65. data/glfw-src/examples/splitview.c +506 -0
  66. data/glfw-src/examples/triangle.c +108 -0
  67. data/glfw-src/examples/wave.c +397 -0
  68. data/glfw-src/images/opengl.gif +0 -0
  69. data/glfw-src/images/osicert.gif +0 -0
  70. data/glfw-src/include/GL/glfw.h +486 -0
  71. data/glfw-src/lib/amigaos/Makefile.amigaos.gcc +128 -0
  72. data/glfw-src/lib/amigaos/Makefile.amigaos.vbcc +128 -0
  73. data/glfw-src/lib/amigaos/SDI_compiler.h +94 -0
  74. data/glfw-src/lib/amigaos/amigaos_enable.c +51 -0
  75. data/glfw-src/lib/amigaos/amigaos_fullscreen.c +319 -0
  76. data/glfw-src/lib/amigaos/amigaos_glext.c +61 -0
  77. data/glfw-src/lib/amigaos/amigaos_init.c +284 -0
  78. data/glfw-src/lib/amigaos/amigaos_joystick.c +359 -0
  79. data/glfw-src/lib/amigaos/amigaos_thread.c +494 -0
  80. data/glfw-src/lib/amigaos/amigaos_time.c +206 -0
  81. data/glfw-src/lib/amigaos/amigaos_window.c +830 -0
  82. data/glfw-src/lib/amigaos/platform.h +337 -0
  83. data/glfw-src/lib/dos/Makefile.dos.djgpp +146 -0
  84. data/glfw-src/lib/dos/dos_enable.c +51 -0
  85. data/glfw-src/lib/dos/dos_events.c +173 -0
  86. data/glfw-src/lib/dos/dos_fullscreen.c +101 -0
  87. data/glfw-src/lib/dos/dos_glext.c +59 -0
  88. data/glfw-src/lib/dos/dos_init.c +105 -0
  89. data/glfw-src/lib/dos/dos_irq.s +246 -0
  90. data/glfw-src/lib/dos/dos_joystick.c +94 -0
  91. data/glfw-src/lib/dos/dos_keyboard.c +694 -0
  92. data/glfw-src/lib/dos/dos_mouse.c +337 -0
  93. data/glfw-src/lib/dos/dos_thread.c +267 -0
  94. data/glfw-src/lib/dos/dos_time.c +309 -0
  95. data/glfw-src/lib/dos/dos_window.c +563 -0
  96. data/glfw-src/lib/dos/platform.h +341 -0
  97. data/glfw-src/lib/enable.c +295 -0
  98. data/glfw-src/lib/fullscreen.c +95 -0
  99. data/glfw-src/lib/glext.c +201 -0
  100. data/glfw-src/lib/image.c +629 -0
  101. data/glfw-src/lib/init.c +108 -0
  102. data/glfw-src/lib/input.c +280 -0
  103. data/glfw-src/lib/internal.h +210 -0
  104. data/glfw-src/lib/joystick.c +101 -0
  105. data/glfw-src/lib/macosx/Makefile.macosx.gcc +172 -0
  106. data/glfw-src/lib/macosx/Makefile.macosx.gcc.universal +166 -0
  107. data/glfw-src/lib/macosx/libglfw.pc.in +11 -0
  108. data/glfw-src/lib/macosx/macosx_enable.c +42 -0
  109. data/glfw-src/lib/macosx/macosx_fullscreen.c +126 -0
  110. data/glfw-src/lib/macosx/macosx_glext.c +52 -0
  111. data/glfw-src/lib/macosx/macosx_init.c +194 -0
  112. data/glfw-src/lib/macosx/macosx_joystick.c +50 -0
  113. data/glfw-src/lib/macosx/macosx_thread.c +414 -0
  114. data/glfw-src/lib/macosx/macosx_time.c +112 -0
  115. data/glfw-src/lib/macosx/macosx_window.c +1279 -0
  116. data/glfw-src/lib/macosx/platform.h +349 -0
  117. data/glfw-src/lib/stream.c +194 -0
  118. data/glfw-src/lib/tga.c +405 -0
  119. data/glfw-src/lib/thread.c +340 -0
  120. data/glfw-src/lib/time.c +83 -0
  121. data/glfw-src/lib/win32/Makefile.win32.bcc +265 -0
  122. data/glfw-src/lib/win32/Makefile.win32.cross-mgw +274 -0
  123. data/glfw-src/lib/win32/Makefile.win32.cygwin +279 -0
  124. data/glfw-src/lib/win32/Makefile.win32.lcc +246 -0
  125. data/glfw-src/lib/win32/Makefile.win32.mgw +243 -0
  126. data/glfw-src/lib/win32/Makefile.win32.msvc +242 -0
  127. data/glfw-src/lib/win32/Makefile.win32.ow +242 -0
  128. data/glfw-src/lib/win32/Makefile.win32.pellesc +242 -0
  129. data/glfw-src/lib/win32/glfwdll.def +67 -0
  130. data/glfw-src/lib/win32/glfwdll_mgw1.def +67 -0
  131. data/glfw-src/lib/win32/glfwdll_mgw2.def +67 -0
  132. data/glfw-src/lib/win32/glfwdll_pellesc.def +65 -0
  133. data/glfw-src/lib/win32/libglfw.pc.in +11 -0
  134. data/glfw-src/lib/win32/platform.h +474 -0
  135. data/glfw-src/lib/win32/win32_dllmain.c +60 -0
  136. data/glfw-src/lib/win32/win32_enable.c +155 -0
  137. data/glfw-src/lib/win32/win32_fullscreen.c +317 -0
  138. data/glfw-src/lib/win32/win32_glext.c +85 -0
  139. data/glfw-src/lib/win32/win32_init.c +356 -0
  140. data/glfw-src/lib/win32/win32_joystick.c +234 -0
  141. data/glfw-src/lib/win32/win32_thread.c +511 -0
  142. data/glfw-src/lib/win32/win32_time.c +146 -0
  143. data/glfw-src/lib/win32/win32_window.c +1714 -0
  144. data/glfw-src/lib/window.c +727 -0
  145. data/glfw-src/lib/x11/Makefile.x11.in +243 -0
  146. data/glfw-src/lib/x11/platform.h +415 -0
  147. data/glfw-src/lib/x11/x11_enable.c +51 -0
  148. data/glfw-src/lib/x11/x11_fullscreen.c +524 -0
  149. data/glfw-src/lib/x11/x11_glext.c +69 -0
  150. data/glfw-src/lib/x11/x11_init.c +275 -0
  151. data/glfw-src/lib/x11/x11_joystick.c +371 -0
  152. data/glfw-src/lib/x11/x11_keysym2unicode.c +902 -0
  153. data/glfw-src/lib/x11/x11_thread.c +507 -0
  154. data/glfw-src/lib/x11/x11_time.c +154 -0
  155. data/glfw-src/lib/x11/x11_window.c +1746 -0
  156. data/glfw-src/license.txt +21 -0
  157. data/glfw-src/readme.html +927 -0
  158. data/glfw-src/support/d/examples/Makefile +59 -0
  159. data/glfw-src/support/d/examples/boing.d +610 -0
  160. data/glfw-src/support/d/examples/gears.d +379 -0
  161. data/glfw-src/support/d/examples/keytest.d +272 -0
  162. data/glfw-src/support/d/examples/listmodes.d +48 -0
  163. data/glfw-src/support/d/examples/mipmaps.d +126 -0
  164. data/glfw-src/support/d/examples/mtbench.d +304 -0
  165. data/glfw-src/support/d/examples/mthello.d +54 -0
  166. data/glfw-src/support/d/examples/particles.d +1150 -0
  167. data/glfw-src/support/d/examples/pong3d.d +840 -0
  168. data/glfw-src/support/d/examples/splitview.d +486 -0
  169. data/glfw-src/support/d/examples/triangle.d +108 -0
  170. data/glfw-src/support/d/examples/wave.d +400 -0
  171. data/glfw-src/support/d/imports/gl.d +4539 -0
  172. data/glfw-src/support/d/imports/glfw.d +349 -0
  173. data/glfw-src/support/d/imports/glu.d +328 -0
  174. data/glfw-src/support/d/lib/glfwdll.def +64 -0
  175. data/glfw-src/support/d/lib/glu32.def +56 -0
  176. data/glfw-src/support/d/lib/makefile +12 -0
  177. data/glfw-src/support/d/lib/opengl32.def +372 -0
  178. data/glfw-src/support/d/readme.html +83 -0
  179. data/glfw-src/support/delphi/examples/Triangle.dpr +105 -0
  180. data/glfw-src/support/delphi/lib/glfw.pas +437 -0
  181. data/glfw-src/support/delphi/readme.html +97 -0
  182. data/glfw-src/support/lua/examples/gears.lua +383 -0
  183. data/glfw-src/support/lua/examples/test1.lua +68 -0
  184. data/glfw-src/support/lua/readme.html +128 -0
  185. data/glfw-src/support/lua/src/luaglfw.c +1179 -0
  186. data/glfw-src/support/lua/src/luaglfw.h +48 -0
  187. data/glfw-src/support/lua/src/runlua.c +82 -0
  188. data/glfw-src/support/masm/examples/fpc.mac +47 -0
  189. data/glfw-src/support/masm/examples/makeit.bat +66 -0
  190. data/glfw-src/support/masm/examples/triangle.asm +232 -0
  191. data/glfw-src/support/masm/include/glfw.inc +326 -0
  192. data/glfw-src/support/masm/include/glu32.inc +55 -0
  193. data/glfw-src/support/masm/include/opengl32.inc +372 -0
  194. data/glfw-src/support/masm/lib/glfwdll.lib +0 -0
  195. data/glfw-src/support/masm/readme.html +170 -0
  196. data/glfw-src/support/msvc80/GLFW.sln +26 -0
  197. data/glfw-src/support/msvc80/GLFW.vcproj +257 -0
  198. data/glfw-src/support/msvc80/GLFWDLL.vcproj +287 -0
  199. data/glfw-src/support/visualbasic/bindings/glfw.bas +320 -0
  200. data/glfw-src/support/visualbasic/bindings/glu32.bas +284 -0
  201. data/glfw-src/support/visualbasic/bindings/opengl32.bas +999 -0
  202. data/glfw-src/support/visualbasic/examples/Triangle.bas +101 -0
  203. data/glfw-src/support/visualbasic/readme.html +164 -0
  204. data/website/index.html +84 -0
  205. data/website/style.css +110 -0
  206. metadata +301 -0
@@ -0,0 +1,74 @@
1
+ ##########################################################################
2
+ # Makefile for GLFW test programs on Windows using Pelles C.
3
+ #-------------------------------------------------------------------------
4
+ # To compile the test files using this makefile, run:
5
+ # pomake /F Makefile.win32.pellesc
6
+ ##########################################################################
7
+
8
+ # Compiler settings
9
+ CC = cc
10
+ CFLAGS = /Ot /I..\include /Ze
11
+ #CFLAGS = /Ot /I..\include /Ze /DGLFW_DLL
12
+
13
+ # Linker settings
14
+ LFLAGS = /LIBPATH:..\lib\win32 glfw.lib opengl32.lib glu32.lib user32.lib kernel32.lib
15
+ #LFLAGS = /LIBPATH:..\lib\win32 glfwdll.lib opengl32.lib glu32.lib kernel32.lib
16
+
17
+ # Subsystem settings
18
+ WINDOWS = /SUBSYSTEM:WINDOWS /ENTRY:_mainCRTStartup
19
+ CONSOLE = /SUBSYSTEM:CONSOLE
20
+
21
+
22
+ # Default: Build all tests
23
+ all: triangle.exe listmodes.exe mthello.exe pong3d.exe mtbench.exe \
24
+ particles.exe splitview.exe mipmaps.exe keytest.exe gears.exe \
25
+ boing.exe wave.exe
26
+
27
+
28
+ # Rule for triangle
29
+ triangle.exe: triangle.c
30
+ $(CC) $(CFLAGS) triangle.c /OUT:$@ $(WINDOWS) $(LFLAGS)
31
+
32
+ # Rule for listmodes
33
+ listmodes.exe: listmodes.c
34
+ $(CC) $(CFLAGS) listmodes.c /OUT:$@ $(CONSOLE) $(LFLAGS)
35
+
36
+ # Rule for mthello
37
+ mthello.exe: mthello.c
38
+ $(CC) $(CFLAGS) mthello.c /OUT:$@ $(CONSOLE) $(LFLAGS)
39
+
40
+ # Rule for pong3d
41
+ pong3d.exe: pong3d.c
42
+ $(CC) $(CFLAGS) pong3d.c /OUT:$@ $(WINDOWS) $(LFLAGS)
43
+
44
+ # Rule for mtbench
45
+ mtbench.exe: mtbench.c
46
+ $(CC) $(CFLAGS) mtbench.c /OUT:$@ $(CONSOLE) $(LFLAGS)
47
+
48
+ # Rule for particles
49
+ particles.exe: particles.c
50
+ $(CC) $(CFLAGS) particles.c /OUT:$@ $(CONSOLE) $(LFLAGS)
51
+
52
+ # Rule for splitview
53
+ splitview.exe: splitview.c
54
+ $(CC) $(CFLAGS) splitview.c /OUT:$@ $(WINDOWS) $(LFLAGS)
55
+
56
+ # Rule for mipmaps
57
+ mipmaps.exe: mipmaps.c
58
+ $(CC) $(CFLAGS) mipmaps.c /OUT:$@ $(WINDOWS) $(LFLAGS)
59
+
60
+ # Rule for keytest
61
+ keytest.exe: keytest.c
62
+ $(CC) $(CFLAGS) keytest.c /OUT:$@ $(CONSOLE) $(LFLAGS)
63
+
64
+ # Rule for gears
65
+ gears.exe: gears.c
66
+ $(CC) $(CFLAGS) gears.c /OUT:$@ $(CONSOLE) $(LFLAGS)
67
+
68
+ # Rule for boing
69
+ boing.exe: boing.c
70
+ $(CC) $(CFLAGS) boing.c /OUT:$@ $(WINDOWS) $(LFLAGS)
71
+
72
+ # Rule for wave
73
+ wave.exe: wave.c
74
+ $(CC) $(CFLAGS) wave.c /OUT:$@ $(WINDOWS) $(LFLAGS)
@@ -0,0 +1,54 @@
1
+
2
+ # Default: Build all tests
3
+ all: triangle listmodes mthello pong3d mtbench particles splitview \
4
+ mipmaps keytest gears boing wave
5
+
6
+
7
+ # Rule for triangle
8
+ triangle: triangle.c
9
+ $(CC) $(CFLAGS) triangle.c $(LFLAGS) -o $@
10
+
11
+ # Rule for listmodes
12
+ listmodes: listmodes.c
13
+ $(CC) $(CFLAGS) listmodes.c $(LFLAGS) -o $@
14
+
15
+ # Rule for mthello
16
+ mthello: mthello.c
17
+ $(CC) $(CFLAGS) mthello.c $(LFLAGS) -o $@
18
+
19
+ # Rule for pong3d
20
+ pong3d: pong3d.c
21
+ $(CC) $(CFLAGS) pong3d.c $(LFLAGS) -o $@
22
+
23
+ # Rule for mtbench
24
+ mtbench: mtbench.c
25
+ $(CC) $(CFLAGS) mtbench.c $(LFLAGS) -o $@
26
+
27
+ # Rule for particles
28
+ particles: particles.c
29
+ $(CC) $(CFLAGS) particles.c $(LFLAGS) -o $@
30
+
31
+ # Rule for splitview
32
+ splitview: splitview.c
33
+ $(CC) $(CFLAGS) splitview.c $(LFLAGS) -o $@
34
+
35
+ # Rule for mipmaps
36
+ mipmaps: mipmaps.c
37
+ $(CC) $(CFLAGS) mipmaps.c $(LFLAGS) -o $@
38
+
39
+ # Rule for keytest
40
+ keytest: keytest.c
41
+ $(CC) $(CFLAGS) keytest.c $(LFLAGS) -o $@
42
+
43
+ # Rule for gears
44
+ gears: gears.c
45
+ $(CC) $(CFLAGS) gears.c $(LFLAGS) -o $@
46
+
47
+ # Rule for boing
48
+ boing: boing.c
49
+ $(CC) $(CFLAGS) boing.c $(LFLAGS) -o $@
50
+
51
+ # Rule for wave
52
+ wave: wave.c
53
+ $(CC) $(CFLAGS) wave.c $(LFLAGS) -o $@
54
+
@@ -0,0 +1,606 @@
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
+
30
+ #include <stdlib.h>
31
+ #include <math.h>
32
+ #include <GL/glfw.h>
33
+
34
+
35
+ /*****************************************************************************
36
+ * Various declarations and macros
37
+ *****************************************************************************/
38
+
39
+ /* Prototypes */
40
+ void init( void );
41
+ void display( void );
42
+ void GLFWCALL reshape( int w, int h );
43
+ void DrawBoingBall( void );
44
+ void BounceBall( double dt );
45
+ void DrawBoingBallBand( GLfloat long_lo, GLfloat long_hi );
46
+ void DrawGrid( void );
47
+
48
+ #define RADIUS 70.0
49
+ #define STEP_LONGITUDE 22.5 /* 22.5 makes 8 bands like original Boing */
50
+ #define STEP_LATITUDE 22.5
51
+
52
+ #define DIST_BALL (RADIUS * 2.0 + RADIUS * 0.1)
53
+
54
+ #define VIEW_SCENE_DIST (DIST_BALL * 3.0+ 200.0)/* distance from viewer to middle of boing area */
55
+ #define GRID_SIZE (RADIUS * 4.5) /* length (width) of grid */
56
+ #define BOUNCE_HEIGHT (RADIUS * 2.1)
57
+ #define BOUNCE_WIDTH (RADIUS * 2.1)
58
+
59
+ #define SHADOW_OFFSET_X -20.0
60
+ #define SHADOW_OFFSET_Y 10.0
61
+ #define SHADOW_OFFSET_Z 0.0
62
+
63
+ #define WALL_L_OFFSET 0.0
64
+ #define WALL_R_OFFSET 5.0
65
+
66
+ /* Animation speed (50.0 mimics the original GLUT demo speed) */
67
+ #define ANIMATION_SPEED 50.0
68
+
69
+ /* Maximum allowed delta time per physics iteration */
70
+ #define MAX_DELTA_T 0.02
71
+
72
+ /* Draw ball, or its shadow */
73
+ typedef enum { DRAW_BALL, DRAW_BALL_SHADOW } DRAW_BALL_ENUM;
74
+
75
+ /* Vertex type */
76
+ typedef struct {float x; float y; float z;} vertex_t;
77
+
78
+ /* Global vars */
79
+ GLfloat deg_rot_y = 0.0;
80
+ GLfloat deg_rot_y_inc = 2.0;
81
+ GLfloat ball_x = -RADIUS;
82
+ GLfloat ball_y = -RADIUS;
83
+ GLfloat ball_x_inc = 1.0;
84
+ GLfloat ball_y_inc = 2.0;
85
+ DRAW_BALL_ENUM drawBallHow;
86
+ double t;
87
+ double t_old = 0.0;
88
+ double dt;
89
+
90
+ /* Random number generator */
91
+ #ifndef RAND_MAX
92
+ #define RAND_MAX 4095
93
+ #endif
94
+
95
+ /* PI */
96
+ #ifndef M_PI
97
+ #define M_PI 3.1415926535897932384626433832795
98
+ #endif
99
+
100
+
101
+ /*****************************************************************************
102
+ * Truncate a degree.
103
+ *****************************************************************************/
104
+ GLfloat TruncateDeg( GLfloat deg )
105
+ {
106
+ if ( deg >= 360.0 )
107
+ return (deg - 360.0);
108
+ else
109
+ return deg;
110
+ }
111
+
112
+ /*****************************************************************************
113
+ * Convert a degree (360-based) into a radian.
114
+ * 360' = 2 * PI
115
+ *****************************************************************************/
116
+ double deg2rad( double deg )
117
+ {
118
+ return deg / 360 * (2 * M_PI);
119
+ }
120
+
121
+ /*****************************************************************************
122
+ * 360' sin().
123
+ *****************************************************************************/
124
+ double sin_deg( double deg )
125
+ {
126
+ return sin( deg2rad( deg ) );
127
+ }
128
+
129
+ /*****************************************************************************
130
+ * 360' cos().
131
+ *****************************************************************************/
132
+ double cos_deg( double deg )
133
+ {
134
+ return cos( deg2rad( deg ) );
135
+ }
136
+
137
+ /*****************************************************************************
138
+ * Compute a cross product (for a normal vector).
139
+ *
140
+ * c = a x b
141
+ *****************************************************************************/
142
+ void CrossProduct( vertex_t a, vertex_t b, vertex_t c, vertex_t *n )
143
+ {
144
+ GLfloat u1, u2, u3;
145
+ GLfloat v1, v2, v3;
146
+
147
+ u1 = b.x - a.x;
148
+ u2 = b.y - a.y;
149
+ u3 = b.y - a.z;
150
+
151
+ v1 = c.x - a.x;
152
+ v2 = c.y - a.y;
153
+ v3 = c.z - a.z;
154
+
155
+ n->x = u2 * v3 - v2 * v3;
156
+ n->y = u3 * v1 - v3 * u1;
157
+ n->z = u1 * v2 - v1 * u2;
158
+ }
159
+
160
+ /*****************************************************************************
161
+ * Calculate the angle to be passed to gluPerspective() so that a scene
162
+ * is visible. This function originates from the OpenGL Red Book.
163
+ *
164
+ * Parms : size
165
+ * The size of the segment when the angle is intersected at "dist"
166
+ * (ie at the outermost edge of the angle of vision).
167
+ *
168
+ * dist
169
+ * Distance from viewpoint to scene.
170
+ *****************************************************************************/
171
+ GLfloat PerspectiveAngle( GLfloat size,
172
+ GLfloat dist )
173
+ {
174
+ GLfloat radTheta, degTheta;
175
+
176
+ radTheta = 2.0 * atan2( size / 2.0, dist );
177
+ degTheta = (180.0 * radTheta) / M_PI;
178
+ return degTheta;
179
+ }
180
+
181
+
182
+
183
+ #define BOING_DEBUG 0
184
+
185
+
186
+ /*****************************************************************************
187
+ * init()
188
+ *****************************************************************************/
189
+ void init( void )
190
+ {
191
+ /*
192
+ * Clear background.
193
+ */
194
+ glClearColor( 0.55, 0.55, 0.55, 0.0 );
195
+
196
+ glShadeModel( GL_FLAT );
197
+ }
198
+
199
+
200
+ /*****************************************************************************
201
+ * display()
202
+ *****************************************************************************/
203
+ void display(void)
204
+ {
205
+ glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
206
+ glPushMatrix();
207
+
208
+ drawBallHow = DRAW_BALL_SHADOW;
209
+ DrawBoingBall();
210
+
211
+ DrawGrid();
212
+
213
+ drawBallHow = DRAW_BALL;
214
+ DrawBoingBall();
215
+
216
+ glPopMatrix();
217
+ glFlush();
218
+ }
219
+
220
+
221
+ /*****************************************************************************
222
+ * reshape()
223
+ *****************************************************************************/
224
+ void GLFWCALL reshape( int w, int h )
225
+ {
226
+ glViewport( 0, 0, (GLsizei)w, (GLsizei)h );
227
+
228
+ glMatrixMode( GL_PROJECTION );
229
+ glLoadIdentity();
230
+
231
+ gluPerspective( PerspectiveAngle( RADIUS * 2, 200 ),
232
+ (GLfloat)w / (GLfloat)h,
233
+ 1.0,
234
+ VIEW_SCENE_DIST );
235
+
236
+ glMatrixMode( GL_MODELVIEW );
237
+ glLoadIdentity();
238
+
239
+ gluLookAt( 0.0, 0.0, VIEW_SCENE_DIST,/* eye */
240
+ 0.0, 0.0, 0.0, /* center of vision */
241
+ 0.0, -1.0, 0.0 ); /* up vector */
242
+ }
243
+
244
+
245
+ /*****************************************************************************
246
+ * Draw the Boing ball.
247
+ *
248
+ * The Boing ball is sphere in which each facet is a rectangle.
249
+ * Facet colors alternate between red and white.
250
+ * The ball is built by stacking latitudinal circles. Each circle is composed
251
+ * of a widely-separated set of points, so that each facet is noticably large.
252
+ *****************************************************************************/
253
+ void DrawBoingBall( void )
254
+ {
255
+ GLfloat lon_deg; /* degree of longitude */
256
+ double dt_total, dt2;
257
+
258
+ glPushMatrix();
259
+ glMatrixMode( GL_MODELVIEW );
260
+
261
+ /*
262
+ * Another relative Z translation to separate objects.
263
+ */
264
+ glTranslatef( 0.0, 0.0, DIST_BALL );
265
+
266
+ /* Update ball position and rotation (iterate if necessary) */
267
+ dt_total = dt;
268
+ while( dt_total > 0.0 )
269
+ {
270
+ dt2 = dt_total > MAX_DELTA_T ? MAX_DELTA_T : dt_total;
271
+ dt_total -= dt2;
272
+ BounceBall( dt2 );
273
+ deg_rot_y = TruncateDeg( deg_rot_y + deg_rot_y_inc*(dt2*ANIMATION_SPEED) );
274
+ }
275
+
276
+ /* Set ball position */
277
+ glTranslatef( ball_x, ball_y, 0.0 );
278
+
279
+ /*
280
+ * Offset the shadow.
281
+ */
282
+ if ( drawBallHow == DRAW_BALL_SHADOW )
283
+ {
284
+ glTranslatef( SHADOW_OFFSET_X,
285
+ SHADOW_OFFSET_Y,
286
+ SHADOW_OFFSET_Z );
287
+ }
288
+
289
+ /*
290
+ * Tilt the ball.
291
+ */
292
+ glRotatef( -20.0, 0.0, 0.0, 1.0 );
293
+
294
+ /*
295
+ * Continually rotate ball around Y axis.
296
+ */
297
+ glRotatef( deg_rot_y, 0.0, 1.0, 0.0 );
298
+
299
+ /*
300
+ * Set OpenGL state for Boing ball.
301
+ */
302
+ glCullFace( GL_FRONT );
303
+ glEnable( GL_CULL_FACE );
304
+ glEnable( GL_NORMALIZE );
305
+
306
+ /*
307
+ * Build a faceted latitude slice of the Boing ball,
308
+ * stepping same-sized vertical bands of the sphere.
309
+ */
310
+ for ( lon_deg = 0;
311
+ lon_deg < 180;
312
+ lon_deg += STEP_LONGITUDE )
313
+ {
314
+ /*
315
+ * Draw a latitude circle at this longitude.
316
+ */
317
+ DrawBoingBallBand( lon_deg,
318
+ lon_deg + STEP_LONGITUDE );
319
+ }
320
+
321
+ glPopMatrix();
322
+
323
+ return;
324
+ }
325
+
326
+
327
+ /*****************************************************************************
328
+ * Bounce the ball.
329
+ *****************************************************************************/
330
+ void BounceBall( double dt )
331
+ {
332
+ GLfloat sign;
333
+ GLfloat deg;
334
+
335
+ /* Bounce on walls */
336
+ if ( ball_x > (BOUNCE_WIDTH/2 + WALL_R_OFFSET ) )
337
+ {
338
+ ball_x_inc = -0.5 - 0.75 * (GLfloat)rand() / (GLfloat)RAND_MAX;
339
+ deg_rot_y_inc = -deg_rot_y_inc;
340
+ }
341
+ if ( ball_x < -(BOUNCE_HEIGHT/2 + WALL_L_OFFSET) )
342
+ {
343
+ ball_x_inc = 0.5 + 0.75 * (GLfloat)rand() / (GLfloat)RAND_MAX;
344
+ deg_rot_y_inc = -deg_rot_y_inc;
345
+ }
346
+
347
+ /* Bounce on floor / roof */
348
+ if ( ball_y > BOUNCE_HEIGHT/2 )
349
+ {
350
+ ball_y_inc = -0.75 - 1.0 * (GLfloat)rand() / (GLfloat)RAND_MAX;
351
+ }
352
+ if ( ball_y < -BOUNCE_HEIGHT/2*0.85 )
353
+ {
354
+ ball_y_inc = 0.75 + 1.0 * (GLfloat)rand() / (GLfloat)RAND_MAX;
355
+ }
356
+
357
+ /* Update ball position */
358
+ ball_x += ball_x_inc * (dt*ANIMATION_SPEED);
359
+ ball_y += ball_y_inc * (dt*ANIMATION_SPEED);
360
+
361
+ /*
362
+ * Simulate the effects of gravity on Y movement.
363
+ */
364
+ if ( ball_y_inc < 0 ) sign = -1.0; else sign = 1.0;
365
+
366
+ deg = (ball_y + BOUNCE_HEIGHT/2) * 90 / BOUNCE_HEIGHT;
367
+ if ( deg > 80 ) deg = 80;
368
+ if ( deg < 10 ) deg = 10;
369
+
370
+ ball_y_inc = sign * 4.0 * sin_deg( deg );
371
+ }
372
+
373
+
374
+ /*****************************************************************************
375
+ * Draw a faceted latitude band of the Boing ball.
376
+ *
377
+ * Parms: long_lo, long_hi
378
+ * Low and high longitudes of slice, resp.
379
+ *****************************************************************************/
380
+ void DrawBoingBallBand( GLfloat long_lo,
381
+ GLfloat long_hi )
382
+ {
383
+ vertex_t vert_ne; /* "ne" means south-east, so on */
384
+ vertex_t vert_nw;
385
+ vertex_t vert_sw;
386
+ vertex_t vert_se;
387
+ vertex_t vert_norm;
388
+ GLfloat lat_deg;
389
+ static int colorToggle = 0;
390
+
391
+ /*
392
+ * Iterate thru the points of a latitude circle.
393
+ * A latitude circle is a 2D set of X,Z points.
394
+ */
395
+ for ( lat_deg = 0;
396
+ lat_deg <= (360 - STEP_LATITUDE);
397
+ lat_deg += STEP_LATITUDE )
398
+ {
399
+ /*
400
+ * Color this polygon with red or white.
401
+ */
402
+ if ( colorToggle )
403
+ glColor3f( 0.8, 0.1, 0.1 );
404
+ else
405
+ glColor3f( 0.95, 0.95, 0.95 );
406
+ #if 0
407
+ if ( lat_deg >= 180 )
408
+ if ( colorToggle )
409
+ glColor3f( 0.1, 0.8, 0.1 );
410
+ else
411
+ glColor3f( 0.5, 0.5, 0.95 );
412
+ #endif
413
+ colorToggle = ! colorToggle;
414
+
415
+ /*
416
+ * Change color if drawing shadow.
417
+ */
418
+ if ( drawBallHow == DRAW_BALL_SHADOW )
419
+ glColor3f( 0.35, 0.35, 0.35 );
420
+
421
+ /*
422
+ * Assign each Y.
423
+ */
424
+ vert_ne.y = vert_nw.y = cos_deg(long_hi) * RADIUS;
425
+ vert_sw.y = vert_se.y = cos_deg(long_lo) * RADIUS;
426
+
427
+ /*
428
+ * Assign each X,Z with sin,cos values scaled by latitude radius indexed by longitude.
429
+ * Eg, long=0 and long=180 are at the poles, so zero scale is sin(longitude),
430
+ * while long=90 (sin(90)=1) is at equator.
431
+ */
432
+ vert_ne.x = cos_deg( lat_deg ) * (RADIUS * sin_deg( long_lo + STEP_LONGITUDE ));
433
+ vert_se.x = cos_deg( lat_deg ) * (RADIUS * sin_deg( long_lo ));
434
+ vert_nw.x = cos_deg( lat_deg + STEP_LATITUDE ) * (RADIUS * sin_deg( long_lo + STEP_LONGITUDE ));
435
+ vert_sw.x = cos_deg( lat_deg + STEP_LATITUDE ) * (RADIUS * sin_deg( long_lo ));
436
+
437
+ vert_ne.z = sin_deg( lat_deg ) * (RADIUS * sin_deg( long_lo + STEP_LONGITUDE ));
438
+ vert_se.z = sin_deg( lat_deg ) * (RADIUS * sin_deg( long_lo ));
439
+ vert_nw.z = sin_deg( lat_deg + STEP_LATITUDE ) * (RADIUS * sin_deg( long_lo + STEP_LONGITUDE ));
440
+ vert_sw.z = sin_deg( lat_deg + STEP_LATITUDE ) * (RADIUS * sin_deg( long_lo ));
441
+
442
+ /*
443
+ * Draw the facet.
444
+ */
445
+ glBegin( GL_POLYGON );
446
+
447
+ CrossProduct( vert_ne, vert_nw, vert_sw, &vert_norm );
448
+ glNormal3f( vert_norm.x, vert_norm.y, vert_norm.z );
449
+
450
+ glVertex3f( vert_ne.x, vert_ne.y, vert_ne.z );
451
+ glVertex3f( vert_nw.x, vert_nw.y, vert_nw.z );
452
+ glVertex3f( vert_sw.x, vert_sw.y, vert_sw.z );
453
+ glVertex3f( vert_se.x, vert_se.y, vert_se.z );
454
+
455
+ glEnd();
456
+
457
+ #if BOING_DEBUG
458
+ printf( "----------------------------------------------------------- \n" );
459
+ printf( "lat = %f long_lo = %f long_hi = %f \n", lat_deg, long_lo, long_hi );
460
+ printf( "vert_ne x = %.8f y = %.8f z = %.8f \n", vert_ne.x, vert_ne.y, vert_ne.z );
461
+ printf( "vert_nw x = %.8f y = %.8f z = %.8f \n", vert_nw.x, vert_nw.y, vert_nw.z );
462
+ printf( "vert_se x = %.8f y = %.8f z = %.8f \n", vert_se.x, vert_se.y, vert_se.z );
463
+ printf( "vert_sw x = %.8f y = %.8f z = %.8f \n", vert_sw.x, vert_sw.y, vert_sw.z );
464
+ #endif
465
+
466
+ }
467
+
468
+ /*
469
+ * Toggle color so that next band will opposite red/white colors than this one.
470
+ */
471
+ colorToggle = ! colorToggle;
472
+
473
+ /*
474
+ * This circular band is done.
475
+ */
476
+ return;
477
+ }
478
+
479
+
480
+ /*****************************************************************************
481
+ * Draw the purple grid of lines, behind the Boing ball.
482
+ * When the Workbench is dropped to the bottom, Boing shows 12 rows.
483
+ *****************************************************************************/
484
+ void DrawGrid( void )
485
+ {
486
+ int row, col;
487
+ const int rowTotal = 12; /* must be divisible by 2 */
488
+ const int colTotal = rowTotal; /* must be same as rowTotal */
489
+ const GLfloat widthLine = 2.0; /* should be divisible by 2 */
490
+ const GLfloat sizeCell = GRID_SIZE / rowTotal;
491
+ const GLfloat z_offset = -40.0;
492
+ GLfloat xl, xr;
493
+ GLfloat yt, yb;
494
+
495
+ glPushMatrix();
496
+ glDisable( GL_CULL_FACE );
497
+
498
+ /*
499
+ * Another relative Z translation to separate objects.
500
+ */
501
+ glTranslatef( 0.0, 0.0, DIST_BALL );
502
+
503
+ /*
504
+ * Draw vertical lines (as skinny 3D rectangles).
505
+ */
506
+ for ( col = 0; col <= colTotal; col++ )
507
+ {
508
+ /*
509
+ * Compute co-ords of line.
510
+ */
511
+ xl = -GRID_SIZE / 2 + col * sizeCell;
512
+ xr = xl + widthLine;
513
+
514
+ yt = GRID_SIZE / 2;
515
+ yb = -GRID_SIZE / 2 - widthLine;
516
+
517
+ glBegin( GL_POLYGON );
518
+
519
+ glColor3f( 0.6, 0.1, 0.6 ); /* purple */
520
+
521
+ glVertex3f( xr, yt, z_offset ); /* NE */
522
+ glVertex3f( xl, yt, z_offset ); /* NW */
523
+ glVertex3f( xl, yb, z_offset ); /* SW */
524
+ glVertex3f( xr, yb, z_offset ); /* SE */
525
+
526
+ glEnd();
527
+ }
528
+
529
+ /*
530
+ * Draw horizontal lines (as skinny 3D rectangles).
531
+ */
532
+ for ( row = 0; row <= rowTotal; row++ )
533
+ {
534
+ /*
535
+ * Compute co-ords of line.
536
+ */
537
+ yt = GRID_SIZE / 2 - row * sizeCell;
538
+ yb = yt - widthLine;
539
+
540
+ xl = -GRID_SIZE / 2;
541
+ xr = GRID_SIZE / 2 + widthLine;
542
+
543
+ glBegin( GL_POLYGON );
544
+
545
+ glColor3f( 0.6, 0.1, 0.6 ); /* purple */
546
+
547
+ glVertex3f( xr, yt, z_offset ); /* NE */
548
+ glVertex3f( xl, yt, z_offset ); /* NW */
549
+ glVertex3f( xl, yb, z_offset ); /* SW */
550
+ glVertex3f( xr, yb, z_offset ); /* SE */
551
+
552
+ glEnd();
553
+ }
554
+
555
+ glPopMatrix();
556
+
557
+ return;
558
+ }
559
+
560
+
561
+ /*======================================================================*
562
+ * main()
563
+ *======================================================================*/
564
+
565
+ int main( void )
566
+ {
567
+ int running;
568
+
569
+ /* Init GLFW */
570
+ glfwInit();
571
+ if( !glfwOpenWindow( 400,400, 0,0,0,0, 16,0, GLFW_WINDOW ) )
572
+ {
573
+ glfwTerminate();
574
+ return 0;
575
+ }
576
+ glfwSetWindowTitle( "Boing (classic Amiga demo)" );
577
+ glfwSetWindowSizeCallback( reshape );
578
+ glfwEnable( GLFW_STICKY_KEYS );
579
+ glfwSwapInterval( 1 );
580
+ glfwSetTime( 0.0 );
581
+
582
+ init();
583
+
584
+ /* Main loop */
585
+ do
586
+ {
587
+ /* Timing */
588
+ t = glfwGetTime();
589
+ dt = t - t_old;
590
+ t_old = t;
591
+
592
+ /* Draw one frame */
593
+ display();
594
+
595
+ /* Swap buffers */
596
+ glfwSwapBuffers();
597
+
598
+ /* Check if we are still running */
599
+ running = !glfwGetKey( GLFW_KEY_ESC ) &&
600
+ glfwGetWindowParam( GLFW_OPENED );
601
+ }
602
+ while( running );
603
+
604
+ glfwTerminate();
605
+ return 0;
606
+ }