ruby-glfw 0.9

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