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,309 @@
1
+ //========================================================================
2
+ // GLFW - An OpenGL framework
3
+ // File: dos_time.c
4
+ // Platform: DOS
5
+ // API version: 2.6
6
+ // WWW: http://glfw.sourceforge.net
7
+ //------------------------------------------------------------------------
8
+ // Copyright (c) 2002-2006 Camilla Berglund
9
+ //
10
+ // This software is provided 'as-is', without any express or implied
11
+ // warranty. In no event will the authors be held liable for any damages
12
+ // arising from the use of this software.
13
+ //
14
+ // Permission is granted to anyone to use this software for any purpose,
15
+ // including commercial applications, and to alter it and redistribute it
16
+ // freely, subject to the following restrictions:
17
+ //
18
+ // 1. The origin of this software must not be misrepresented; you must not
19
+ // claim that you wrote the original software. If you use this software
20
+ // in a product, an acknowledgment in the product documentation would
21
+ // be appreciated but is not required.
22
+ //
23
+ // 2. Altered source versions must be plainly marked as such, and must not
24
+ // be misrepresented as being the original software.
25
+ //
26
+ // 3. This notice may not be removed or altered from any source
27
+ // distribution.
28
+ //
29
+ //========================================================================
30
+
31
+ #include "internal.h"
32
+
33
+
34
+ // We use the __i386 define later in the code. Check if there are any
35
+ // other defines that hint that we are compiling for 32-bit x86.
36
+ #ifndef __i386
37
+ #if defined(__i386__) || defined(i386) || defined(X86) || defined(_M_IX86)
38
+ #define __i386
39
+ #endif
40
+ #endif // __i386
41
+
42
+ // Should we use inline x86 assembler?
43
+ #if defined(__i386) && defined(__GNUC__)
44
+ #define _USE_X86_ASM
45
+ #endif
46
+
47
+
48
+
49
+ //************************************************************************
50
+ //**** GLFW internal functions ****
51
+ //************************************************************************
52
+
53
+ // Functions for accessing upper and lower parts of 64-bit integers
54
+ // (Note: These are endian dependent, but ONLY used on x86 platforms!)
55
+ #define _HIGH(x) ((unsigned int*)&x)[1]
56
+ #define _LOW(x) *((unsigned int*)&x)
57
+
58
+
59
+ //========================================================================
60
+ // _glfwCPUID() - Execute x86 CPUID instruction
61
+ //========================================================================
62
+
63
+ #ifdef _USE_X86_ASM
64
+
65
+ static int _glfwCPUID( unsigned int ID, unsigned int *a, unsigned int *b,
66
+ unsigned int *c, unsigned int *d )
67
+ {
68
+ int has_cpuid;
69
+ unsigned int local_a, local_b, local_c, local_d;
70
+
71
+ // Inline assembly - GCC version
72
+ #if defined(__i386) && defined(__GNUC__)
73
+
74
+ // Detect CPUID support
75
+ asm(
76
+ "pushf\n\t"
77
+ "pop %%eax\n\t"
78
+ "movl %%eax,%%ebx\n\t"
79
+ "xorl $0x00200000,%%eax\n\t"
80
+ "push %%eax\n\t"
81
+ "popf\n\t"
82
+ "pushf\n\t"
83
+ "pop %%eax\n\t"
84
+ "xorl %%eax,%%ebx\n\t"
85
+ "movl %%eax,%0\n\t"
86
+ : "=m" (has_cpuid)
87
+ :
88
+ : "%eax", "%ebx"
89
+ );
90
+ if( !has_cpuid )
91
+ {
92
+ return GL_FALSE;
93
+ }
94
+
95
+ // Execute CPUID
96
+ asm(
97
+ "movl %4,%%eax\n\t"
98
+ "cpuid\n\t"
99
+ "movl %%eax,%0\n\t"
100
+ "movl %%ebx,%1\n\t"
101
+ "movl %%ecx,%2\n\t"
102
+ "movl %%edx,%3\n\t"
103
+ : "=m" (local_a), "=m" (local_b), "=m" (local_c), "=m" (local_d)
104
+ : "m" (ID)
105
+ : "%eax", "%ebx", "%ecx", "%edx"
106
+ );
107
+
108
+ #endif
109
+
110
+ // Common code for all compilers
111
+ *a = local_a;
112
+ *b = local_b;
113
+ *c = local_c;
114
+ *d = local_d;
115
+ return GL_TRUE;
116
+ }
117
+
118
+ #endif // _USE_X86_ASM
119
+
120
+
121
+ //========================================================================
122
+ // _glfwHasRDTSC() - Check for RDTSC availability AND usefulness
123
+ //========================================================================
124
+
125
+ static int _glfwHasRDTSC( void )
126
+ {
127
+ #ifdef _USE_X86_ASM
128
+
129
+ unsigned int cpu_name1, cpu_name2, cpu_name3;
130
+ unsigned int cpu_signature, cpu_brandID;
131
+ unsigned int max_base, feature_flags;
132
+ unsigned int dummy;
133
+
134
+ // Get processor vendor string (will return 0 if CPUID is not
135
+ // supported)
136
+ if( !_glfwCPUID( 0, &max_base, &cpu_name1, &cpu_name3, &cpu_name2 ) )
137
+ {
138
+ return GL_FALSE;
139
+ }
140
+
141
+ // Does the processor support base CPUID function 1?
142
+ if( max_base < 1 )
143
+ {
144
+ return GL_FALSE;
145
+ }
146
+
147
+ // Get CPU capabilities, CPU Brand ID & CPU Signature
148
+ _glfwCPUID( 1, &cpu_signature, &cpu_brandID, &dummy, &feature_flags );
149
+
150
+ // Is RDTSC supported?
151
+ if( !(feature_flags & 0x00000010) )
152
+ {
153
+ return GL_FALSE;
154
+ }
155
+
156
+ return GL_TRUE;
157
+
158
+ #else
159
+
160
+ // Not a supported compiler
161
+ return GL_FALSE;
162
+
163
+ #endif
164
+ }
165
+
166
+
167
+ //------------------------------------------------------------------------
168
+ // _RDTSC() - Get CPU cycle count using the RDTSC instruction
169
+ //------------------------------------------------------------------------
170
+
171
+ #if defined(__i386) && defined(__GNUC__)
172
+
173
+ // Read 64-bit processor Time Stamp Counter - GCC version
174
+ #define _RDTSC( hi, lo ) \
175
+ asm( \
176
+ "rdtsc\n\t" \
177
+ "movl %%edx,%0\n\t" \
178
+ "movl %%eax,%1" \
179
+ : "=m" (hi), "=m" (lo) \
180
+ : \
181
+ : "%edx", "%eax" \
182
+ );
183
+
184
+ #else
185
+
186
+ #define _RDTSC( hi, lo ) {hi=lo=0;}
187
+
188
+ #endif
189
+
190
+
191
+
192
+
193
+ //========================================================================
194
+ // _glfwInitTimer() - Initialize timer
195
+ //========================================================================
196
+
197
+ int _glfwInitTimer( void )
198
+ {
199
+ clock_t t, t1, t2;
200
+ long long c1, c2;
201
+
202
+ // Do we have RDTSC?
203
+ _glfwTimer.HasRDTSC = _glfwHasRDTSC();
204
+ if( _glfwTimer.HasRDTSC )
205
+ {
206
+ // Measure the CPU clock with the raw DOS clock (18.2 Hz)
207
+ t = clock();
208
+ while( (t1=clock()) == t );
209
+ _RDTSC( _HIGH(c1), _LOW(c1) );
210
+ t = t1+CLOCKS_PER_SEC/3;
211
+ while( (t2=clock()) < t );
212
+ _RDTSC( _HIGH(c2), _LOW(c2) );
213
+
214
+ // Calculate CPU clock period
215
+ _glfwTimer.Period = (double)(t2-t1) /
216
+ (CLOCKS_PER_SEC * (double)(c2-c1));
217
+ _RDTSC( _HIGH(_glfwTimer.t0), _LOW(_glfwTimer.t0) );
218
+ }
219
+ else
220
+ {
221
+ // Use the raw DOS clock (18.2 Hz)
222
+ _glfwTimer.Period = 1.0 / CLOCKS_PER_SEC;
223
+ _glfwTimer.t0 = clock();
224
+ }
225
+
226
+ return 1;
227
+ }
228
+
229
+
230
+ //========================================================================
231
+ // _glfwTerminateTimer() - Terminate timer
232
+ //========================================================================
233
+
234
+ void _glfwTerminateTimer( void )
235
+ {
236
+ // Nothing to do here
237
+ }
238
+
239
+
240
+ //************************************************************************
241
+ //**** Platform implementation functions ****
242
+ //************************************************************************
243
+
244
+ //========================================================================
245
+ // _glfwPlatformGetTime() - Return timer value in seconds
246
+ //========================================================================
247
+
248
+ double _glfwPlatformGetTime( void )
249
+ {
250
+ long long t_now;
251
+
252
+ // Get current clock count
253
+ if( _glfwTimer.HasRDTSC )
254
+ {
255
+ _RDTSC( _HIGH(t_now), _LOW(t_now) );
256
+ }
257
+ else
258
+ {
259
+ t_now = (long long) clock();
260
+ }
261
+
262
+ // Convert to seconds
263
+ return (t_now-_glfwTimer.t0) * _glfwTimer.Period;
264
+ }
265
+
266
+
267
+ //========================================================================
268
+ // _glfwPlatformSetTime() - Set timer value in seconds
269
+ //========================================================================
270
+
271
+ void _glfwPlatformSetTime( double t )
272
+ {
273
+ long long t_now;
274
+
275
+ // Get current clock count
276
+ if( _glfwTimer.HasRDTSC )
277
+ {
278
+ _RDTSC( _HIGH(t_now), _LOW(t_now) );
279
+ }
280
+ else
281
+ {
282
+ t_now = (long long) clock();
283
+ }
284
+
285
+ // Set timer
286
+ _glfwTimer.t0 = t_now - (long long)(t/_glfwTimer.Period);
287
+ }
288
+
289
+
290
+ //========================================================================
291
+ // _glfwPlatformSleep() - Put a thread to sleep for a specified amount of
292
+ // time
293
+ //========================================================================
294
+
295
+ void _glfwPlatformSleep( double time )
296
+ {
297
+ // TODO: Proper threaded version
298
+ if( time > 0 )
299
+ {
300
+ if( time < 0.001 )
301
+ {
302
+ delay( 1 );
303
+ }
304
+ else
305
+ {
306
+ delay( (unsigned int)(time*1000.0+0.5) );
307
+ }
308
+ }
309
+ }
@@ -0,0 +1,563 @@
1
+ //========================================================================
2
+ // GLFW - An OpenGL framework
3
+ // File: dos_window.c
4
+ // Platform: DOS
5
+ // API version: 2.6
6
+ // WWW: http://glfw.sourceforge.net
7
+ //------------------------------------------------------------------------
8
+ // Copyright (c) 2002-2006 Camilla Berglund
9
+ //
10
+ // This software is provided 'as-is', without any express or implied
11
+ // warranty. In no event will the authors be held liable for any damages
12
+ // arising from the use of this software.
13
+ //
14
+ // Permission is granted to anyone to use this software for any purpose,
15
+ // including commercial applications, and to alter it and redistribute it
16
+ // freely, subject to the following restrictions:
17
+ //
18
+ // 1. The origin of this software must not be misrepresented; you must not
19
+ // claim that you wrote the original software. If you use this software
20
+ // in a product, an acknowledgment in the product documentation would
21
+ // be appreciated but is not required.
22
+ //
23
+ // 2. Altered source versions must be plainly marked as such, and must not
24
+ // be misrepresented as being the original software.
25
+ //
26
+ // 3. This notice may not be removed or altered from any source
27
+ // distribution.
28
+ //
29
+ //========================================================================
30
+
31
+ #include "internal.h"
32
+
33
+
34
+
35
+ //************************************************************************
36
+ //**** GLFW internal functions ****
37
+ //************************************************************************
38
+
39
+ //========================================================================
40
+ // _glfwRedirectOutput() - Standard output redirection
41
+ //========================================================================
42
+
43
+ static void _glfwRedirectOutput( void )
44
+ {
45
+ // Generate temporary names
46
+ tmpnam( _glfwWin.OutName );
47
+ tmpnam( _glfwWin.ErrName );
48
+
49
+ // Open temporary output files
50
+ _glfwWin.hOut = open( _glfwWin.OutName, O_WRONLY | O_CREAT | O_TEXT |
51
+ O_TRUNC, S_IREAD | S_IWRITE );
52
+ _glfwWin.hErr = open( _glfwWin.ErrName, O_WRONLY | O_CREAT | O_TEXT |
53
+ O_TRUNC, S_IREAD | S_IWRITE );
54
+
55
+ // Redirect stdout
56
+ if( _glfwWin.hOut > 0 )
57
+ {
58
+ _glfwWin.hOutOld = dup( STDOUT_FILENO );
59
+ fflush( stdout );
60
+ dup2( _glfwWin.hOut, STDOUT_FILENO );
61
+ }
62
+
63
+ // Redirect stderr
64
+ if( _glfwWin.hErr > 0 )
65
+ {
66
+ _glfwWin.hErrOld = dup( STDERR_FILENO );
67
+ fflush( stderr );
68
+ dup2( _glfwWin.hErr, STDERR_FILENO );
69
+ }
70
+ }
71
+
72
+
73
+ //========================================================================
74
+ // _glfwRestoreOutput() - Standard output redirection
75
+ //========================================================================
76
+
77
+ static void _glfwRestoreOutput( void )
78
+ {
79
+ FILE *f;
80
+ char *str = alloca( 512 );
81
+
82
+ // Dump from temporary file to stdout
83
+ if( _glfwWin.hOut > 0)
84
+ {
85
+ // Restore old stdout
86
+ dup2( _glfwWin.hOutOld, STDOUT_FILENO );
87
+ close( _glfwWin.hOut );
88
+ close( _glfwWin.hOutOld );
89
+ _glfwWin.hOut = 0;
90
+
91
+ // Dump file to stdout
92
+ f = fopen( _glfwWin.OutName, "rt" );
93
+ while( fgets( str, 512, f ) )
94
+ {
95
+ fputs( str, stdout );
96
+ }
97
+ fclose( f );
98
+
99
+ // Remove temporary file
100
+ remove( _glfwWin.OutName );
101
+ }
102
+
103
+ // Dump from temporary file to stderr
104
+ if( _glfwWin.hOut > 0)
105
+ {
106
+ // Restore old stderr
107
+ dup2( _glfwWin.hErrOld, STDERR_FILENO );
108
+ close( _glfwWin.hErr );
109
+ close( _glfwWin.hErrOld );
110
+ _glfwWin.hErr = 0;
111
+
112
+ // Dump file to stderr
113
+ f = fopen( _glfwWin.ErrName, "rt" );
114
+ while( fgets( str, 512, f ) )
115
+ {
116
+ fputs( str, stderr );
117
+ }
118
+ fclose( f );
119
+
120
+ // Remove temporary file
121
+ remove( _glfwWin.ErrName );
122
+ }
123
+ }
124
+
125
+
126
+ //========================================================================
127
+ // _glfwTranslateChar() - Translates a DOS key code to Unicode
128
+ //========================================================================
129
+
130
+ static int _glfwTranslateChar( int keycode )
131
+ {
132
+ // Unicode?
133
+ if( (keycode >= 32 && keycode <= 126) || keycode >= 160 )
134
+ {
135
+ return keycode;
136
+ }
137
+
138
+ return -1;
139
+ }
140
+
141
+
142
+ //========================================================================
143
+ // _glfwTranslateKey() - Translates a DOS key code to GLFW coding
144
+ //========================================================================
145
+
146
+ static int _glfwTranslateKey( int keycode )
147
+ {
148
+ // ISO 8859-1?
149
+ if( ((keycode>=32) && (keycode<=126)) ||
150
+ ((keycode>=160) && (keycode<=254)) )
151
+ {
152
+ return keycode;
153
+ }
154
+
155
+ // Special keys?
156
+ if( keycode < 0 )
157
+ {
158
+ return -keycode;
159
+ }
160
+
161
+ return -1;
162
+ }
163
+
164
+
165
+
166
+ //************************************************************************
167
+ //**** Platform implementation functions ****
168
+ //************************************************************************
169
+
170
+ //========================================================================
171
+ // _glfwPlatformOpenWindow() - Here is where the window is created, and
172
+ // the OpenGL rendering context is created
173
+ //========================================================================
174
+
175
+ int _glfwPlatformOpenWindow( int width, int height, int redbits,
176
+ int greenbits, int bluebits, int alphabits, int depthbits,
177
+ int stencilbits, int mode, int accumredbits, int accumgreenbits,
178
+ int accumbluebits, int accumalphabits, int auxbuffers, int stereo,
179
+ int refreshrate )
180
+ {
181
+ GLint params[2];
182
+
183
+ // Clear window resources
184
+ _glfwWin.Visual = NULL;
185
+ _glfwWin.Context = NULL;
186
+ _glfwWin.Buffer = NULL;
187
+ _glfwWin.hOut = 0;
188
+ _glfwWin.hErr = 0;
189
+
190
+ // For now, we only support 640x480, 800x600 and 1024x768
191
+ if( (width*height) < (700*500) )
192
+ {
193
+ width = 640;
194
+ height = 480;
195
+ }
196
+ else if( (width*height) < (900*700) )
197
+ {
198
+ width = 800;
199
+ height = 600;
200
+ }
201
+ else
202
+ {
203
+ width = 1024;
204
+ height = 768;
205
+ }
206
+
207
+ // For now, we only support 5,6,5 and 8,8,8 color formats
208
+ if( (redbits+greenbits+bluebits) < 20 )
209
+ {
210
+ redbits = 5;
211
+ greenbits = 6;
212
+ bluebits = 5;
213
+ }
214
+ else
215
+ {
216
+ redbits = 8;
217
+ greenbits = 8;
218
+ bluebits = 8;
219
+ }
220
+
221
+ // For now, we always set refresh rate = 0 (default)
222
+ refreshrate = 0;
223
+
224
+ // stdout/stderr redirection
225
+ _glfwRedirectOutput();
226
+
227
+ // Create visual
228
+ _glfwWin.Visual = DMesaCreateVisual(
229
+ width, height,
230
+ redbits+greenbits+bluebits,
231
+ refreshrate,
232
+ GL_TRUE, // Double buffer
233
+ GL_TRUE, // RGB mode
234
+ alphabits?GL_TRUE:GL_FALSE, // Alpha buffer?
235
+ depthbits,
236
+ stencilbits,
237
+ (accumredbits+accumgreenbits+
238
+ accumbluebits+accumalphabits)>>2
239
+ );
240
+ if( _glfwWin.Visual == NULL )
241
+ {
242
+ printf("Unable to create visual\n");
243
+ _glfwPlatformCloseWindow();
244
+ return GL_FALSE;
245
+ }
246
+
247
+ // Create context
248
+ _glfwWin.Context = DMesaCreateContext( _glfwWin.Visual, NULL );
249
+ if( _glfwWin.Context == NULL )
250
+ {
251
+ printf("Unable to create context\n");
252
+ _glfwPlatformCloseWindow();
253
+ return GL_FALSE;
254
+ }
255
+
256
+ // Create buffer
257
+ _glfwWin.Buffer = DMesaCreateBuffer( _glfwWin.Visual, 0, 0,
258
+ width, height );
259
+ if( _glfwWin.Buffer == NULL )
260
+ {
261
+ printf("Unable to create buffer\n");
262
+ _glfwPlatformCloseWindow();
263
+ return GL_FALSE;
264
+ }
265
+
266
+ // Make current context
267
+ if( !DMesaMakeCurrent( _glfwWin.Context, _glfwWin.Buffer ) )
268
+ {
269
+ printf("Unable to make current context\n");
270
+ _glfwPlatformCloseWindow();
271
+ return GL_FALSE;
272
+ }
273
+
274
+ // Start DOS event handler
275
+ if( !_glfwInitEvents() )
276
+ {
277
+ printf("Unable to start event handler\n");
278
+ _glfwPlatformCloseWindow();
279
+ return GL_FALSE;
280
+ }
281
+
282
+ // Start keyboard handler
283
+ if( !_glfwInitKeyboard() )
284
+ {
285
+ printf("Unable to start keyboard driver\n");
286
+ _glfwPlatformCloseWindow();
287
+ return GL_FALSE;
288
+ }
289
+
290
+ // Start mouse handler
291
+ if( !_glfwInitMouse() )
292
+ {
293
+ printf("***Warning: Unable to start mouse driver\n");
294
+ }
295
+
296
+ // Remember actual screen/window size
297
+ _glfwWin.Width = width;
298
+ _glfwWin.Height = height;
299
+
300
+ return GL_TRUE;
301
+ }
302
+
303
+
304
+ //========================================================================
305
+ // _glfwPlatformCloseWindow() - Properly kill the window/video display
306
+ //========================================================================
307
+
308
+ void _glfwPlatformCloseWindow( void )
309
+ {
310
+ // Terminate mouse handler
311
+ _glfwTerminateMouse();
312
+
313
+ // Terminate keyboard handler
314
+ _glfwTerminateKeyboard();
315
+
316
+ // Terminate event handler
317
+ _glfwTerminateEvents();
318
+
319
+ // Destroy buffer
320
+ if( _glfwWin.Buffer != NULL )
321
+ {
322
+ DMesaDestroyBuffer( _glfwWin.Buffer );
323
+ _glfwWin.Buffer = NULL;
324
+ }
325
+
326
+ // Destroy context
327
+ if( _glfwWin.Context != NULL )
328
+ {
329
+ DMesaDestroyContext( _glfwWin.Context );
330
+ _glfwWin.Context = NULL;
331
+ }
332
+
333
+ // Destroy visual
334
+ if( _glfwWin.Visual != NULL )
335
+ {
336
+ DMesaDestroyVisual( _glfwWin.Visual );
337
+ _glfwWin.Visual = NULL;
338
+ }
339
+
340
+ // stdout/stderr redirection
341
+ _glfwRestoreOutput();
342
+ }
343
+
344
+
345
+ //========================================================================
346
+ // _glfwPlatformSetWindowTitle() - Set the window title.
347
+ //========================================================================
348
+
349
+ void _glfwPlatformSetWindowTitle( const char *title )
350
+ {
351
+ // Nothing to do here...
352
+ }
353
+
354
+
355
+ //========================================================================
356
+ // _glfwPlatformSetWindowSize() - Set the window size.
357
+ //========================================================================
358
+
359
+ void _glfwPlatformSetWindowSize( int width, int height )
360
+ {
361
+ // TODO
362
+ }
363
+
364
+
365
+ //========================================================================
366
+ // _glfwPlatformSetWindowPos() - Set the window position.
367
+ //========================================================================
368
+
369
+ void _glfwPlatformSetWindowPos( int x, int y )
370
+ {
371
+ // Nothing to do here...
372
+ }
373
+
374
+
375
+ //========================================================================
376
+ // _glfwPlatformIconfyWindow() - Window iconification
377
+ //========================================================================
378
+
379
+ void _glfwPlatformIconifyWindow( void )
380
+ {
381
+ // Nothing to do here...
382
+ }
383
+
384
+
385
+ //========================================================================
386
+ // _glfwPlatformRestoreWindow() - Window un-iconification
387
+ //========================================================================
388
+
389
+ void _glfwPlatformRestoreWindow( void )
390
+ {
391
+ // Nothing to do here...
392
+ }
393
+
394
+
395
+ //========================================================================
396
+ // _glfwPlatformSwapBuffers() - Swap buffers (double-buffering) and poll
397
+ // any new events.
398
+ //========================================================================
399
+
400
+ void _glfwPlatformSwapBuffers( void )
401
+ {
402
+ DMesaSwapBuffers( _glfwWin.Buffer );
403
+ }
404
+
405
+
406
+ //========================================================================
407
+ // _glfwPlatformSwapInterval() - Set double buffering swap interval
408
+ //========================================================================
409
+
410
+ void _glfwPlatformSwapInterval( int interval )
411
+ {
412
+ // TODO
413
+ }
414
+
415
+
416
+ //========================================================================
417
+ // _glfwPlatformRefreshWindowParams()
418
+ //========================================================================
419
+
420
+ void _glfwPlatformRefreshWindowParams( void )
421
+ {
422
+ GLint x;
423
+ GLboolean b;
424
+
425
+ // Fill out information
426
+ _glfwWin.Accelerated = GL_TRUE;
427
+ glGetIntegerv( GL_RED_BITS, &x );
428
+ _glfwWin.RedBits = x;
429
+ glGetIntegerv( GL_GREEN_BITS, &x );
430
+ _glfwWin.GreenBits = x;
431
+ glGetIntegerv( GL_BLUE_BITS, &x );
432
+ _glfwWin.BlueBits = x;
433
+ glGetIntegerv( GL_ALPHA_BITS, &x );
434
+ _glfwWin.AlphaBits = x;
435
+ glGetIntegerv( GL_DEPTH_BITS, &x );
436
+ _glfwWin.DepthBits = x;
437
+ glGetIntegerv( GL_STENCIL_BITS, &x );
438
+ _glfwWin.StencilBits = x;
439
+ glGetIntegerv( GL_ACCUM_RED_BITS, &x );
440
+ _glfwWin.AccumRedBits = x;
441
+ glGetIntegerv( GL_ACCUM_GREEN_BITS, &x );
442
+ _glfwWin.AccumGreenBits = x;
443
+ glGetIntegerv( GL_ACCUM_BLUE_BITS, &x );
444
+ _glfwWin.AccumBlueBits = x;
445
+ glGetIntegerv( GL_ACCUM_ALPHA_BITS, &x );
446
+ _glfwWin.AccumAlphaBits = x;
447
+ glGetIntegerv( GL_AUX_BUFFERS, &x );
448
+ _glfwWin.AuxBuffers = x;
449
+ glGetBooleanv( GL_AUX_BUFFERS, &b );
450
+ _glfwWin.Stereo = b ? GL_TRUE : GL_FALSE;
451
+ _glfwWin.RefreshRate = 0;
452
+ }
453
+
454
+
455
+ //========================================================================
456
+ // _glfwPlatformPollEvents() - Poll for new window and input events
457
+ //========================================================================
458
+
459
+ void _glfwPlatformPollEvents( void )
460
+ {
461
+ _GLFWdosevent event;
462
+ struct key_event *key;
463
+ struct mousemove_event *mousemove;
464
+ struct mousewheel_event *mousewheel;
465
+ struct mousebutton_event *mousebutton;
466
+
467
+ // Empty the event queue
468
+ while( _glfwGetNextEvent( &event ) )
469
+ {
470
+ switch( event.Type )
471
+ {
472
+ // Keyboard event?
473
+ case _GLFW_DOS_KEY_EVENT:
474
+ key = &event.Key;
475
+ _glfwInputKey( _glfwTranslateKey( key->KeyNoMod ),
476
+ key->Action );
477
+ _glfwInputChar( _glfwTranslateChar( key->Key ),
478
+ key->Action );
479
+ break;
480
+
481
+ // Mouse move event?
482
+ case _GLFW_DOS_MOUSE_MOVE_EVENT:
483
+ mousemove = &event.MouseMove;
484
+ _glfwInput.MousePosX += mousemove->DeltaX;
485
+ _glfwInput.MousePosY += mousemove->DeltaY;
486
+
487
+ // Call user callback function
488
+ if( _glfwWin.MousePosCallback )
489
+ {
490
+ _glfwWin.MousePosCallback( _glfwInput.MousePosX,
491
+ _glfwInput.MousePosY );
492
+ }
493
+ break;
494
+
495
+ // Mouse wheel event?
496
+ case _GLFW_DOS_MOUSE_WHEEL_EVENT:
497
+ mousewheel = &event.MouseWheel;
498
+ _glfwInput.WheelPos += mousewheel->WheelDelta;
499
+
500
+ // Call user callback function
501
+ if( _glfwWin.MouseWheelCallback )
502
+ {
503
+ _glfwWin.MouseWheelCallback( _glfwInput.WheelPos );
504
+ }
505
+ break;
506
+
507
+ // Mouse button event?
508
+ case _GLFW_DOS_MOUSE_BUTTON_EVENT:
509
+ mousebutton = &event.MouseButton;
510
+ _glfwInputMouseClick( mousebutton->Button,
511
+ mousebutton->Action );
512
+ break;
513
+
514
+ default:
515
+ break;
516
+ }
517
+
518
+ }
519
+ }
520
+
521
+
522
+ //========================================================================
523
+ // _glfwPlatformWaitEvents() - Wait for new window and input events
524
+ //========================================================================
525
+
526
+ void _glfwPlatformWaitEvents( void )
527
+ {
528
+ // Wait for new events
529
+ _glfwWaitNextEvent;
530
+
531
+ // Poll new events
532
+ _glfwPlatformPollEvents();
533
+ }
534
+
535
+
536
+ //========================================================================
537
+ // _glfwPlatformHideMouseCursor() - Hide mouse cursor (lock it)
538
+ //========================================================================
539
+
540
+ void _glfwPlatformHideMouseCursor( void )
541
+ {
542
+ // TODO
543
+ }
544
+
545
+
546
+ //========================================================================
547
+ // _glfwPlatformShowMouseCursor() - Show mouse cursor (unlock it)
548
+ //========================================================================
549
+
550
+ void _glfwPlatformShowMouseCursor( void )
551
+ {
552
+ // TODO
553
+ }
554
+
555
+
556
+ //========================================================================
557
+ // _glfwPlatformSetMouseCursorPos() - Set physical mouse cursor position
558
+ //========================================================================
559
+
560
+ void _glfwPlatformSetMouseCursorPos( int x, int y )
561
+ {
562
+ // TODO
563
+ }