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,60 @@
1
+ //========================================================================
2
+ // GLFW - An OpenGL framework
3
+ // File: win32_dllmain.c
4
+ // Platform: Windows
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
+ #if defined(GLFW_BUILD_DLL)
35
+
36
+ //========================================================================
37
+ // DllMain()
38
+ //========================================================================
39
+
40
+ int WINAPI DllMain( HINSTANCE hinst, unsigned long reason, void *x )
41
+ {
42
+ // NOTE: Some compilers complains about hinst and x never being used -
43
+ // never mind that (we don't want to use them)!
44
+
45
+ switch( reason )
46
+ {
47
+ case DLL_PROCESS_ATTACH:
48
+ // Initializations
49
+ //glfwInit(); // We don't want to do that now!
50
+ break;
51
+ case DLL_PROCESS_DETACH:
52
+ // Do some cleanup
53
+ glfwTerminate();
54
+ break;
55
+ };
56
+
57
+ return 1;
58
+ }
59
+
60
+ #endif // GLFW_BUILD_DLL
@@ -0,0 +1,155 @@
1
+ //========================================================================
2
+ // GLFW - An OpenGL framework
3
+ // File: win32_enable.c
4
+ // Platform: Windows
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
+ //**** GLFW internal functions ****
36
+ //************************************************************************
37
+
38
+ //========================================================================
39
+ // _glfwLLKeyboardProc() - Low level keyboard callback function (used to
40
+ // disable system keys under Windows NT).
41
+ //========================================================================
42
+
43
+ LRESULT CALLBACK _glfwLLKeyboardProc( int nCode, WPARAM wParam,
44
+ LPARAM lParam )
45
+ {
46
+ BOOL syskeys = 0;
47
+ PKBDLLHOOKSTRUCT p;
48
+
49
+ // We are only looking for keyboard events - interpret lParam as a
50
+ // pointer to a KBDLLHOOKSTRUCT
51
+ p = (PKBDLLHOOKSTRUCT) lParam;
52
+
53
+ // If nCode == HC_ACTION, then we have a keyboard event
54
+ if( nCode == HC_ACTION )
55
+ {
56
+ switch( wParam )
57
+ {
58
+ case WM_KEYDOWN:
59
+ case WM_SYSKEYDOWN:
60
+ case WM_KEYUP:
61
+ case WM_SYSKEYUP:
62
+ // Detect: ALT+TAB, ALT+ESC, ALT+F4, CTRL+ESC,
63
+ // LWIN, RWIN, APPS (mysterious menu key)
64
+ syskeys = ( p->vkCode == VK_TAB &&
65
+ p->flags & LLKHF_ALTDOWN ) ||
66
+ ( p->vkCode == VK_ESCAPE &&
67
+ p->flags & LLKHF_ALTDOWN ) ||
68
+ ( p->vkCode == VK_F4 &&
69
+ p->flags & LLKHF_ALTDOWN ) ||
70
+ ( p->vkCode == VK_ESCAPE &&
71
+ (GetKeyState(VK_CONTROL) & 0x8000)) ||
72
+ p->vkCode == VK_LWIN ||
73
+ p->vkCode == VK_RWIN ||
74
+ p->vkCode == VK_APPS;
75
+ break;
76
+
77
+ default:
78
+ break;
79
+ }
80
+ }
81
+
82
+ // Was it a system key combination (e.g. ALT+TAB)?
83
+ if( syskeys )
84
+ {
85
+ // Pass the key event to our window message loop
86
+ if( _glfwWin.Opened )
87
+ {
88
+ PostMessage( _glfwWin.Wnd, (UINT) wParam, p->vkCode, 0 );
89
+ }
90
+
91
+ // We've taken care of it - don't let the system know about this
92
+ // key event
93
+ return 1;
94
+ }
95
+ else
96
+ {
97
+ // It's a harmless key press, let the system deal with it
98
+ return CallNextHookEx( _glfwWin.KeyboardHook, nCode, wParam,
99
+ lParam );
100
+ }
101
+ }
102
+
103
+
104
+
105
+ //************************************************************************
106
+ //**** Platform implementation functions ****
107
+ //************************************************************************
108
+
109
+ //========================================================================
110
+ // _glfwPlatformEnableSystemKeys() - Enable system keys
111
+ // _glfwPlatformDisableSystemKeys() - Disable system keys
112
+ //========================================================================
113
+
114
+ void _glfwPlatformEnableSystemKeys( void )
115
+ {
116
+ BOOL bOld;
117
+
118
+ // Use different methods depending on operating system version
119
+ if( _glfwLibrary.Sys.WinVer >= _GLFW_WIN_NT4 )
120
+ {
121
+ if( _glfwWin.KeyboardHook != NULL )
122
+ {
123
+ UnhookWindowsHookEx( _glfwWin.KeyboardHook );
124
+ _glfwWin.KeyboardHook = NULL;
125
+ }
126
+ }
127
+ else
128
+ {
129
+ (void) SystemParametersInfo( SPI_SETSCREENSAVERRUNNING, FALSE,
130
+ &bOld, 0 );
131
+ }
132
+ }
133
+
134
+ void _glfwPlatformDisableSystemKeys( void )
135
+ {
136
+ BOOL bOld;
137
+
138
+ // Use different methods depending on operating system version
139
+ if( _glfwLibrary.Sys.WinVer >= _GLFW_WIN_NT4 )
140
+ {
141
+ // Under Windows NT, install a low level keyboard hook
142
+ _glfwWin.KeyboardHook = SetWindowsHookEx( WH_KEYBOARD_LL,
143
+ _glfwLLKeyboardProc,
144
+ _glfwLibrary.Instance,
145
+ 0 );
146
+ }
147
+ else
148
+ {
149
+ // Under Windows 95/98/ME, fool Windows that a screensaver
150
+ // is running => prevents ALT+TAB, CTRL+ESC and CTRL+ALT+DEL
151
+ (void) SystemParametersInfo( SPI_SETSCREENSAVERRUNNING, TRUE,
152
+ &bOld, 0 );
153
+ }
154
+ }
155
+
@@ -0,0 +1,317 @@
1
+ //========================================================================
2
+ // GLFW - An OpenGL framework
3
+ // File: win32_fullscreen.c
4
+ // Platform: Windows
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
+ //**** GLFW internal functions ****
36
+ //************************************************************************
37
+
38
+ //========================================================================
39
+ // _glfwBPP2RGB() - Convert BPP to RGB bits (based on "best guess")
40
+ //========================================================================
41
+
42
+ static void _glfwBPP2RGB( int bpp, int *r, int *g, int *b )
43
+ {
44
+ int delta;
45
+
46
+ // Special case: BPP = 32
47
+ if( bpp == 32 ) bpp = 24;
48
+
49
+ // Convert "bits per pixel" to red, green & blue sizes
50
+ *r = *g = *b = bpp / 3;
51
+ delta = bpp - (*r * 3);
52
+ if( delta >= 1 )
53
+ {
54
+ *g = *g + 1;
55
+ }
56
+ if( delta == 2 )
57
+ {
58
+ *r = *r + 1;
59
+ }
60
+ }
61
+
62
+
63
+ //========================================================================
64
+ // _glfwGetClosestVideoModeBPP()
65
+ //========================================================================
66
+
67
+ int _glfwGetClosestVideoModeBPP( int *w, int *h, int *bpp, int *refresh )
68
+ {
69
+ int mode, bestmode, match, bestmatch, rr, bestrr, success;
70
+ DEVMODE dm;
71
+
72
+ // Find best match
73
+ bestmatch = 0x7fffffff;
74
+ bestrr = 0x7fffffff;
75
+ mode = bestmode = 0;
76
+ do
77
+ {
78
+ dm.dmSize = sizeof( DEVMODE );
79
+ success = EnumDisplaySettings( NULL, mode, &dm );
80
+ if( success )
81
+ {
82
+ match = dm.dmBitsPerPel - *bpp;
83
+ if( match < 0 ) match = -match;
84
+ match = ( match << 25 ) |
85
+ ( (dm.dmPelsWidth - *w) *
86
+ (dm.dmPelsWidth - *w) +
87
+ (dm.dmPelsHeight - *h) *
88
+ (dm.dmPelsHeight - *h) );
89
+ if( match < bestmatch )
90
+ {
91
+ bestmatch = match;
92
+ bestmode = mode;
93
+ bestrr = (dm.dmDisplayFrequency - *refresh) *
94
+ (dm.dmDisplayFrequency - *refresh);
95
+ }
96
+ else if( match == bestmatch && *refresh > 0 )
97
+ {
98
+ rr = (dm.dmDisplayFrequency - *refresh) *
99
+ (dm.dmDisplayFrequency - *refresh);
100
+ if( rr < bestrr )
101
+ {
102
+ bestmatch = match;
103
+ bestmode = mode;
104
+ bestrr = rr;
105
+ }
106
+ }
107
+ }
108
+ mode ++;
109
+ }
110
+ while( success );
111
+
112
+ // Get the parameters for the best matching display mode
113
+ dm.dmSize = sizeof( DEVMODE );
114
+ (void) EnumDisplaySettings( NULL, bestmode, &dm );
115
+
116
+ // Fill out actual width and height
117
+ *w = dm.dmPelsWidth;
118
+ *h = dm.dmPelsHeight;
119
+
120
+ // Return bits per pixel
121
+ *bpp = dm.dmBitsPerPel;
122
+
123
+ // Return vertical refresh rate
124
+ *refresh = dm.dmDisplayFrequency;
125
+
126
+ return bestmode;
127
+ }
128
+
129
+
130
+ //========================================================================
131
+ // _glfwGetClosestVideoMode()
132
+ //========================================================================
133
+
134
+ int _glfwGetClosestVideoMode( int *w, int *h, int *r, int *g, int *b,
135
+ int *refresh )
136
+ {
137
+ int bpp, bestmode;
138
+
139
+ // Colorbits = sum of red/green/blue bits
140
+ bpp = *r + *g + *b;
141
+
142
+ // If colorbits < 15 (e.g. 0) or >= 24, default to 32 bpp
143
+ if( bpp < 15 || bpp >= 24 )
144
+ {
145
+ bpp = 32;
146
+ }
147
+
148
+ // Find best match
149
+ bestmode = _glfwGetClosestVideoModeBPP( w, h, &bpp, refresh );
150
+
151
+ // Convert "bits per pixel" to red, green & blue sizes
152
+ _glfwBPP2RGB( bpp, r, g, b );
153
+
154
+ return bestmode;
155
+ }
156
+
157
+
158
+ //========================================================================
159
+ // Change the current video mode
160
+ //========================================================================
161
+
162
+ void _glfwSetVideoModeMODE( int mode )
163
+ {
164
+ DEVMODE dm;
165
+ int success;
166
+
167
+ // Get the parameters for the best matching display mode
168
+ dm.dmSize = sizeof( DEVMODE );
169
+ (void) EnumDisplaySettings( NULL, mode, &dm );
170
+
171
+ // Set which fields we want to specify
172
+ dm.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT | DM_BITSPERPEL;
173
+
174
+ // Do we have a prefered refresh rate?
175
+ if( _glfwWin.DesiredRefreshRate > 0 )
176
+ {
177
+ dm.dmFields = dm.dmFields | DM_DISPLAYFREQUENCY;
178
+ dm.dmDisplayFrequency = _glfwWin.DesiredRefreshRate;
179
+ }
180
+
181
+ // Change display setting
182
+ dm.dmSize = sizeof( DEVMODE );
183
+ success = ChangeDisplaySettings( &dm, CDS_FULLSCREEN );
184
+
185
+ // If the mode change was not possible, query the current display
186
+ // settings (we'll use the desktop resolution for fullscreen mode)
187
+ if( success == DISP_CHANGE_SUCCESSFUL )
188
+ {
189
+ _glfwWin.ModeID = mode;
190
+ }
191
+ else
192
+ {
193
+ _glfwWin.ModeID = ENUM_REGISTRY_SETTINGS;
194
+ EnumDisplaySettings( NULL, ENUM_REGISTRY_SETTINGS, &dm );
195
+ }
196
+
197
+ // Set the window size to that of the display mode
198
+ _glfwWin.Width = dm.dmPelsWidth;
199
+ _glfwWin.Height = dm.dmPelsHeight;
200
+ }
201
+
202
+
203
+ //========================================================================
204
+ // _glfwSetVideoMode() - Change the current video mode
205
+ //========================================================================
206
+
207
+ void _glfwSetVideoMode( int *w, int *h, int r, int g, int b, int refresh )
208
+ {
209
+ int bestmode;
210
+
211
+ // Find a best match mode
212
+ bestmode = _glfwGetClosestVideoMode( w, h, &r, &g, &b, &refresh );
213
+
214
+ // Change mode
215
+ _glfwSetVideoModeMODE( bestmode );
216
+ }
217
+
218
+
219
+ //************************************************************************
220
+ //**** GLFW user functions ****
221
+ //************************************************************************
222
+
223
+ //========================================================================
224
+ // _glfwPlatformGetVideoModes() - Get a list of available video modes
225
+ //========================================================================
226
+
227
+ int _glfwPlatformGetVideoModes( GLFWvidmode *list, int maxcount )
228
+ {
229
+ int count, success, mode, i, j;
230
+ int m1, m2, bpp, r, g, b;
231
+ DEVMODE dm;
232
+
233
+ // Loop through all video modes and extract all the UNIQUE modes
234
+ count = 0;
235
+ mode = 0;
236
+ do
237
+ {
238
+ // Get video mode properties
239
+ dm.dmSize = sizeof( DEVMODE );
240
+ success = EnumDisplaySettings( NULL, mode, &dm );
241
+
242
+ // Is it a valid mode? (only list depths >= 15 bpp)
243
+ if( success && dm.dmBitsPerPel >= 15 )
244
+ {
245
+ // Convert to RGB, and back to bpp ("mask out" alpha bits etc)
246
+ _glfwBPP2RGB( dm.dmBitsPerPel, &r, &g, &b );
247
+ bpp = r + g + b;
248
+
249
+ // Mode "code" for this mode
250
+ m1 = (bpp << 25) | (dm.dmPelsWidth * dm.dmPelsHeight);
251
+
252
+ // Insert mode in list (sorted), and avoid duplicates
253
+ for( i = 0; i < count; i ++ )
254
+ {
255
+ // Mode "code" for already listed mode
256
+ bpp = list[i].RedBits + list[i].GreenBits +
257
+ list[i].BlueBits;
258
+ m2 = (bpp << 25) | (list[i].Width * list[i].Height);
259
+ if( m1 <= m2 )
260
+ {
261
+ break;
262
+ }
263
+ }
264
+
265
+ // New entry at the end of the list?
266
+ if( i >= count )
267
+ {
268
+ list[count].Width = dm.dmPelsWidth;
269
+ list[count].Height = dm.dmPelsHeight;
270
+ list[count].RedBits = r;
271
+ list[count].GreenBits = g;
272
+ list[count].BlueBits = b;
273
+ count ++;
274
+ }
275
+ // Insert new entry in the list?
276
+ else if( m1 < m2 )
277
+ {
278
+ for( j = count; j > i; j -- )
279
+ {
280
+ list[j] = list[j-1];
281
+ }
282
+ list[i].Width = dm.dmPelsWidth;
283
+ list[i].Height = dm.dmPelsHeight;
284
+ list[i].RedBits = r;
285
+ list[i].GreenBits = g;
286
+ list[i].BlueBits = b;
287
+ count ++;
288
+ }
289
+ }
290
+ mode ++;
291
+ }
292
+ while( success && (count < maxcount) );
293
+
294
+ return count;
295
+ }
296
+
297
+
298
+ //========================================================================
299
+ // _glfwPlatformGetDesktopMode() - Get the desktop video mode
300
+ //========================================================================
301
+
302
+ void _glfwPlatformGetDesktopMode( GLFWvidmode *mode )
303
+ {
304
+ DEVMODE dm;
305
+
306
+ // Get desktop display mode
307
+ dm.dmSize = sizeof( DEVMODE );
308
+ (void) EnumDisplaySettings( NULL, ENUM_REGISTRY_SETTINGS, &dm );
309
+
310
+ // Return desktop mode parameters
311
+ mode->Width = dm.dmPelsWidth;
312
+ mode->Height = dm.dmPelsHeight;
313
+ _glfwBPP2RGB( dm.dmBitsPerPel, &mode->RedBits, &mode->GreenBits,
314
+ &mode->BlueBits );
315
+ }
316
+
317
+