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,51 @@
1
+ //========================================================================
2
+ // GLFW - An OpenGL framework
3
+ // File: x11_enable.c
4
+ // Platform: X11 (Unix)
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
+ //**** Platform implementation functions ****
36
+ //************************************************************************
37
+
38
+ //========================================================================
39
+ // _glfwPlatformEnableSystemKeys() - Enable system keys
40
+ // _glfwPlatformDisableSystemKeys() - Disable system keys
41
+ //========================================================================
42
+
43
+ void _glfwPlatformEnableSystemKeys( void )
44
+ {
45
+ // Not supported under X11 (yet)
46
+ }
47
+
48
+ void _glfwPlatformDisableSystemKeys( void )
49
+ {
50
+ // Not supported under X11 (yet)
51
+ }
@@ -0,0 +1,524 @@
1
+ //========================================================================
2
+ // GLFW - An OpenGL framework
3
+ // File: x11_fullscreen.c
4
+ // Platform: X11 (Unix)
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 (I don't think this is necessary for X11??)
47
+ if( bpp == 32 )
48
+ bpp = 24;
49
+
50
+ // Convert "bits per pixel" to red, green & blue sizes
51
+ *r = *g = *b = bpp / 3;
52
+ delta = bpp - (*r * 3);
53
+ if( delta >= 1 )
54
+ {
55
+ *g = *g + 1;
56
+ }
57
+ if( delta == 2 )
58
+ {
59
+ *r = *r + 1;
60
+ }
61
+ }
62
+
63
+
64
+ //========================================================================
65
+ // Finds the video mode closest in size to the specified desired size
66
+ //========================================================================
67
+
68
+ int _glfwGetClosestVideoMode( int screen, int *width, int *height, int *rate )
69
+ {
70
+ #if defined( _GLFW_HAS_XRANDR )
71
+ int i, match, bestmatch;
72
+ int sizecount, bestsize;
73
+ int ratecount, bestrate;
74
+ short *ratelist;
75
+ XRRScreenConfiguration *sc;
76
+ XRRScreenSize *sizelist;
77
+
78
+ if( _glfwLibrary.XRandR.Available )
79
+ {
80
+ sc = XRRGetScreenInfo( _glfwLibrary.Dpy,
81
+ RootWindow( _glfwLibrary.Dpy, screen ) );
82
+
83
+ sizelist = XRRConfigSizes( sc, &sizecount );
84
+
85
+ // Find the best matching mode
86
+ bestsize = -1;
87
+ bestmatch = 999999;
88
+ for( i = 0; i < sizecount; i++ )
89
+ {
90
+ match = (*width - sizelist[i].width) *
91
+ (*width - sizelist[i].width) +
92
+ (*height - sizelist[i].height) *
93
+ (*height - sizelist[i].height);
94
+ if( match < bestmatch )
95
+ {
96
+ bestmatch = match;
97
+ bestsize = i;
98
+ }
99
+ }
100
+
101
+ if( bestsize != -1 )
102
+ {
103
+ // Report width & height of best matching mode
104
+ *width = sizelist[bestsize].width;
105
+ *height = sizelist[bestsize].height;
106
+
107
+ if( *rate > 0 )
108
+ {
109
+ ratelist = XRRConfigRates( sc, bestsize, &ratecount );
110
+
111
+ bestrate = -1;
112
+ bestmatch = 999999;
113
+ for( i = 0; i < ratecount; i++ )
114
+ {
115
+ match = abs( ratelist[i] - *rate );
116
+ if( match < bestmatch )
117
+ {
118
+ bestmatch = match;
119
+ bestrate = ratelist[i];
120
+ }
121
+ }
122
+
123
+ if( bestrate != -1 )
124
+ {
125
+ *rate = bestrate;
126
+ }
127
+ }
128
+ }
129
+
130
+ // Free modelist
131
+ XRRFreeScreenConfigInfo( sc );
132
+
133
+ if( bestsize != -1 )
134
+ {
135
+ return bestsize;
136
+ }
137
+ }
138
+ #elif defined( _GLFW_HAS_XF86VIDMODE )
139
+ XF86VidModeModeInfo **modelist;
140
+ int modecount, i, bestmode, bestmatch, match;
141
+
142
+ // Use the XF86VidMode extension to control video resolution
143
+ if( _glfwLibrary.XF86VidMode.Available )
144
+ {
145
+ // Get a list of all available display modes
146
+ XF86VidModeGetAllModeLines( _glfwLibrary.Dpy, screen,
147
+ &modecount, &modelist );
148
+
149
+ // Find the best matching mode
150
+ bestmode = -1;
151
+ bestmatch = 999999;
152
+ for( i = 0; i < modecount; i++ )
153
+ {
154
+ match = (*width - modelist[i]->hdisplay) *
155
+ (*width - modelist[i]->hdisplay) +
156
+ (*height - modelist[i]->vdisplay) *
157
+ (*height - modelist[i]->vdisplay);
158
+ if( match < bestmatch )
159
+ {
160
+ bestmatch = match;
161
+ bestmode = i;
162
+ }
163
+ }
164
+
165
+ if( bestmode != -1 )
166
+ {
167
+ // Report width & height of best matching mode
168
+ *width = modelist[ bestmode ]->hdisplay;
169
+ *h = modelist[ bestmode ]->vdisplay;
170
+ }
171
+
172
+ // Free modelist
173
+ XFree( modelist );
174
+
175
+ if( bestmode != -1 )
176
+ {
177
+ return bestmode;
178
+ }
179
+ }
180
+ #endif
181
+
182
+ // Default: Simply use the screen resolution
183
+ *width = DisplayWidth( _glfwLibrary.Dpy, screen );
184
+ *height = DisplayHeight( _glfwLibrary.Dpy, screen );
185
+
186
+ return 0;
187
+ }
188
+
189
+
190
+ //========================================================================
191
+ // Change the current video mode
192
+ //========================================================================
193
+
194
+ void _glfwSetVideoModeMODE( int screen, int mode, int rate )
195
+ {
196
+ #if defined( _GLFW_HAS_XRANDR )
197
+ XRRScreenConfiguration *sc;
198
+ Window root;
199
+
200
+ if( _glfwLibrary.XRandR.Available )
201
+ {
202
+ root = RootWindow( _glfwLibrary.Dpy, screen );
203
+ sc = XRRGetScreenInfo( _glfwLibrary.Dpy, root );
204
+
205
+ // Remember old size and flag that we have changed the mode
206
+ if( !_glfwWin.FS.ModeChanged )
207
+ {
208
+ _glfwWin.FS.OldSizeID = XRRConfigCurrentConfiguration( sc, &_glfwWin.FS.OldRotation );
209
+ _glfwWin.FS.OldWidth = DisplayWidth( _glfwLibrary.Dpy, screen );
210
+ _glfwWin.FS.OldHeight = DisplayHeight( _glfwLibrary.Dpy, screen );
211
+
212
+ _glfwWin.FS.ModeChanged = GL_TRUE;
213
+ }
214
+
215
+ if( rate > 0 )
216
+ {
217
+ // Set desired configuration
218
+ XRRSetScreenConfigAndRate( _glfwLibrary.Dpy,
219
+ sc,
220
+ root,
221
+ mode,
222
+ RR_Rotate_0,
223
+ (short) rate,
224
+ CurrentTime );
225
+ }
226
+ else
227
+ {
228
+ // Set desired configuration
229
+ XRRSetScreenConfig( _glfwLibrary.Dpy,
230
+ sc,
231
+ root,
232
+ mode,
233
+ RR_Rotate_0,
234
+ CurrentTime );
235
+ }
236
+
237
+ XRRFreeScreenConfigInfo( sc );
238
+ }
239
+ #elif defined( _GLFW_HAS_XF86VIDMODE )
240
+ XF86VidModeModeInfo **modelist;
241
+ int modecount;
242
+
243
+ // Use the XF86VidMode extension to control video resolution
244
+ if( _glfwLibrary.XF86VidMode.Available )
245
+ {
246
+ // Get a list of all available display modes
247
+ XF86VidModeGetAllModeLines( _glfwLibrary.Dpy, screen,
248
+ &modecount, &modelist );
249
+
250
+ // Unlock mode switch if necessary
251
+ if( _glfwWin.FS.ModeChanged )
252
+ {
253
+ XF86VidModeLockModeSwitch( _glfwLibrary.Dpy, screen, 0 );
254
+ }
255
+
256
+ // Change the video mode to the desired mode
257
+ XF86VidModeSwitchToMode( _glfwLibrary.Dpy, screen,
258
+ modelist[ mode ] );
259
+
260
+ // Set viewport to upper left corner (where our window will be)
261
+ XF86VidModeSetViewPort( _glfwLibrary.Dpy, screen, 0, 0 );
262
+
263
+ // Lock mode switch
264
+ XF86VidModeLockModeSwitch( _glfwLibrary.Dpy, screen, 1 );
265
+
266
+ // Remember old mode and flag that we have changed the mode
267
+ if( !_glfwWin.FS.ModeChanged )
268
+ {
269
+ _glfwWin.FS.OldMode = *modelist[ 0 ];
270
+ _glfwWin.FS.ModeChanged = GL_TRUE;
271
+ }
272
+
273
+ // Free mode list
274
+ XFree( modelist );
275
+ }
276
+ #endif
277
+ }
278
+
279
+
280
+ //========================================================================
281
+ // Change the current video mode
282
+ //========================================================================
283
+
284
+ void _glfwSetVideoMode( int screen, int *width, int *height, int *rate )
285
+ {
286
+ int bestmode;
287
+
288
+ // Find a best match mode
289
+ bestmode = _glfwGetClosestVideoMode( screen, width, height, rate );
290
+
291
+ // Change mode
292
+ _glfwSetVideoModeMODE( screen, bestmode, *rate );
293
+ }
294
+
295
+
296
+
297
+ //************************************************************************
298
+ //**** Platform implementation functions ****
299
+ //************************************************************************
300
+
301
+ struct _glfwResolution {
302
+ int width;
303
+ int height;
304
+ };
305
+
306
+ //========================================================================
307
+ // List available video modes
308
+ //========================================================================
309
+
310
+ int _glfwPlatformGetVideoModes( GLFWvidmode *list, int maxcount )
311
+ {
312
+ int count, k, l, r, g, b, rgba, gl;
313
+ int depth, screen;
314
+ Display *dpy;
315
+ XVisualInfo *vislist, dummy;
316
+ int viscount, rgbcount, rescount;
317
+ int *rgbarray;
318
+ struct _glfwResolution *resarray;
319
+ #if defined( _GLFW_HAS_XRANDR )
320
+ XRRScreenConfiguration *sc;
321
+ XRRScreenSize *sizelist;
322
+ int sizecount;
323
+ #elif defined( _GLFW_HAS_XF86VIDMODE )
324
+ XF86VidModeModeInfo **modelist;
325
+ int modecount, width, height;
326
+ #endif
327
+
328
+ // Get display and screen
329
+ dpy = _glfwLibrary.Dpy;
330
+ screen = DefaultScreen( dpy );
331
+
332
+ // Get list of visuals
333
+ vislist = XGetVisualInfo( dpy, 0, &dummy, &viscount );
334
+ if( vislist == NULL )
335
+ {
336
+ return 0;
337
+ }
338
+
339
+ rgbarray = (int*) malloc( sizeof(int) * viscount );
340
+ rgbcount = 0;
341
+
342
+ // Build RGB array
343
+ for( k = 0; k < viscount; k++ )
344
+ {
345
+ // Does the visual support OpenGL & true color?
346
+ glXGetConfig( dpy, &vislist[k], GLX_USE_GL, &gl );
347
+ glXGetConfig( dpy, &vislist[k], GLX_RGBA, &rgba );
348
+ if( gl && rgba )
349
+ {
350
+ // Get color depth for this visual
351
+ depth = vislist[k].depth;
352
+
353
+ // Convert to RGB
354
+ _glfwBPP2RGB( depth, &r, &g, &b );
355
+ depth = (r<<16) | (g<<8) | b;
356
+
357
+ // Is this mode unique?
358
+ for( l = 0; l < rgbcount; l++ )
359
+ {
360
+ if( depth == rgbarray[ l ] )
361
+ {
362
+ break;
363
+ }
364
+ }
365
+ if( l >= rgbcount )
366
+ {
367
+ rgbarray[ rgbcount ] = depth;
368
+ rgbcount++;
369
+ }
370
+ }
371
+ }
372
+
373
+ rescount = 0;
374
+ resarray = NULL;
375
+
376
+ // Build resolution array
377
+ #if defined( _GLFW_HAS_XRANDR )
378
+ if( _glfwLibrary.XRandR.Available )
379
+ {
380
+ sc = XRRGetScreenInfo( dpy, RootWindow( dpy, screen ) );
381
+ sizelist = XRRConfigSizes( sc, &sizecount );
382
+
383
+ resarray = (struct _glfwResolution*) malloc( sizeof(struct _glfwResolution) * sizecount );
384
+
385
+ for( k = 0; k < sizecount; k++ )
386
+ {
387
+ resarray[ rescount ].width = sizelist[ k ].width;
388
+ resarray[ rescount ].height = sizelist[ k ].height;
389
+ rescount++;
390
+ }
391
+
392
+ XRRFreeScreenConfigInfo( sc );
393
+ }
394
+ #elif defined( _GLFW_HAS_XF86VIDMODE )
395
+ if( _glfwLibrary.XF86VidMode.Available )
396
+ {
397
+ XF86VidModeGetAllModeLines( dpy, screen, &modecount, &modelist );
398
+
399
+ resarray = (struct _glfwResolution*) malloc( sizeof(struct _glfwResolution) * modecount );
400
+
401
+ for( k = 0; k < modecount; k++ )
402
+ {
403
+ width = modelist[ k ]->hdisplay;
404
+ height = modelist[ k ]->vdisplay;
405
+
406
+ // Is this mode unique?
407
+ for( l = 0; l < rescount; l++ )
408
+ {
409
+ if( width == resarray[ l ].width && height == resarray[ l ].height )
410
+ {
411
+ break;
412
+ }
413
+ }
414
+ if( l >= rescount )
415
+ {
416
+ resarray[ rescount ].width = width;
417
+ resarray[ rescount ].height = height;
418
+ rescount++;
419
+ }
420
+ }
421
+
422
+ XFree( modelist );
423
+ }
424
+ #endif
425
+
426
+ if( !resarray )
427
+ {
428
+ rescount = 1;
429
+ resarray = (struct _glfwResolution*) malloc( sizeof(struct _glfwResolution) * rescount );
430
+
431
+ resarray[ 0 ].width = DisplayWidth( dpy, screen );
432
+ resarray[ 0 ].height = DisplayHeight( dpy, screen );
433
+ }
434
+
435
+ // Build permutations of colors and resolutions
436
+ count = 0;
437
+ for( k = 0; k < rgbcount && count < maxcount; k++ )
438
+ {
439
+ for( l = 0; l < rescount && count < maxcount; l++ )
440
+ {
441
+ list[count].Width = resarray[ l ].width;
442
+ list[count].Height = resarray[ l ].height;
443
+ list[count].RedBits = (rgbarray[ k ] >> 16) & 255;
444
+ list[count].GreenBits = (rgbarray[ k ] >> 8) & 255;
445
+ list[count].BlueBits = rgbarray[ k ] & 255;
446
+ count++;
447
+ }
448
+ }
449
+
450
+ // Free visuals list
451
+ XFree( vislist );
452
+
453
+ free( resarray );
454
+ free( rgbarray );
455
+
456
+ return count;
457
+ }
458
+
459
+
460
+ //========================================================================
461
+ // Get the desktop video mode
462
+ //========================================================================
463
+
464
+ void _glfwPlatformGetDesktopMode( GLFWvidmode *mode )
465
+ {
466
+ Display *dpy;
467
+ int bpp, screen;
468
+ #if defined( _GLFW_HAS_XF86VIDMODE )
469
+ XF86VidModeModeInfo **modelist;
470
+ int modecount;
471
+ #endif
472
+
473
+ // Get display and screen
474
+ dpy = _glfwLibrary.Dpy;
475
+ screen = DefaultScreen( dpy );
476
+
477
+ // Get display depth
478
+ bpp = DefaultDepth( dpy, screen );
479
+
480
+ // Convert BPP to RGB bits
481
+ _glfwBPP2RGB( bpp, &mode->RedBits, &mode->GreenBits, &mode->BlueBits );
482
+
483
+ #if defined( _GLFW_HAS_XRANDR )
484
+ if( _glfwLibrary.XRandR.Available )
485
+ {
486
+ if( _glfwWin.FS.ModeChanged )
487
+ {
488
+ mode->Width = _glfwWin.FS.OldWidth;
489
+ mode->Height = _glfwWin.FS.OldHeight;
490
+ return;
491
+ }
492
+ }
493
+ #elif defined( _GLFW_HAS_XF86VIDMODE )
494
+ if( _glfwLibrary.XF86VidMode.Available )
495
+ {
496
+ if( _glfwWin.FS.ModeChanged )
497
+ {
498
+ // The old (desktop) mode is stored in _glfwWin.FS.OldMode
499
+ mode->Width = _glfwWin.FS.OldMode.hdisplay;
500
+ mode->Height = _glfwWin.FS.OldMode.vdisplay;
501
+ }
502
+ else
503
+ {
504
+ // Use the XF86VidMode extension to get list of video modes
505
+ XF86VidModeGetAllModeLines( dpy, screen, &modecount,
506
+ &modelist );
507
+
508
+ // The first mode in the list is the current (desktio) mode
509
+ mode->Width = modelist[ 0 ]->hdisplay;
510
+ mode->Height = modelist[ 0 ]->vdisplay;
511
+
512
+ // Free list
513
+ XFree( modelist );
514
+ }
515
+
516
+ return;
517
+ }
518
+ #endif
519
+
520
+ // Get current display width and height
521
+ mode->Width = DisplayWidth( dpy, screen );
522
+ mode->Height = DisplayHeight( dpy, screen );
523
+ }
524
+