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,405 @@
1
+ //========================================================================
2
+ // GLFW - An OpenGL framework
3
+ // File: tga.c
4
+ // Platform: Any
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
+ //========================================================================
32
+ // Description:
33
+ //
34
+ // TGA format image file loader. This module supports version 1 Targa
35
+ // images, with these restrictions:
36
+ // - Pixel format may only be 8, 24 or 32 bits
37
+ // - Colormaps must be no longer than 256 entries
38
+ //
39
+ //========================================================================
40
+
41
+
42
+ #include "internal.h"
43
+
44
+
45
+ //************************************************************************
46
+ //**** GLFW internal functions & declarations ****
47
+ //************************************************************************
48
+
49
+ //========================================================================
50
+ // TGA file header information
51
+ //========================================================================
52
+
53
+ typedef struct {
54
+ int idlen; // 1 byte
55
+ int cmaptype; // 1 byte
56
+ int imagetype; // 1 byte
57
+ int cmapfirstidx; // 2 bytes
58
+ int cmaplen; // 2 bytes
59
+ int cmapentrysize; // 1 byte
60
+ int xorigin; // 2 bytes
61
+ int yorigin; // 2 bytes
62
+ int width; // 2 bytes
63
+ int height; // 2 bytes
64
+ int bitsperpixel; // 1 byte
65
+ int imageinfo; // 1 byte
66
+ int _alphabits; // (derived from imageinfo)
67
+ int _origin; // (derived from imageinfo)
68
+ } _tga_header_t;
69
+
70
+ #define _TGA_CMAPTYPE_NONE 0
71
+ #define _TGA_CMAPTYPE_PRESENT 1
72
+
73
+ #define _TGA_IMAGETYPE_NONE 0
74
+ #define _TGA_IMAGETYPE_CMAP 1
75
+ #define _TGA_IMAGETYPE_TC 2
76
+ #define _TGA_IMAGETYPE_GRAY 3
77
+ #define _TGA_IMAGETYPE_CMAP_RLE 9
78
+ #define _TGA_IMAGETYPE_TC_RLE 10
79
+ #define _TGA_IMAGETYPE_GRAY_RLE 11
80
+
81
+ #define _TGA_IMAGEINFO_ALPHA_MASK 0x0f
82
+ #define _TGA_IMAGEINFO_ALPHA_SHIFT 0
83
+ #define _TGA_IMAGEINFO_ORIGIN_MASK 0x30
84
+ #define _TGA_IMAGEINFO_ORIGIN_SHIFT 4
85
+
86
+ #define _TGA_ORIGIN_BL 0
87
+ #define _TGA_ORIGIN_BR 1
88
+ #define _TGA_ORIGIN_UL 2
89
+ #define _TGA_ORIGIN_UR 3
90
+
91
+
92
+ //========================================================================
93
+ // _glfwReadTGAHeader() - Read TGA file header (and check that it is
94
+ // valid)
95
+ //========================================================================
96
+
97
+ static int _glfwReadTGAHeader( _GLFWstream *s, _tga_header_t *h )
98
+ {
99
+ unsigned char buf[ 18 ];
100
+ int pos;
101
+
102
+ // Read TGA file header from file
103
+ pos = _glfwTellStream( s );
104
+ _glfwReadStream( s, buf, 18 );
105
+
106
+ // Interpret header (endian independent parsing)
107
+ h->idlen = (int) buf[0];
108
+ h->cmaptype = (int) buf[1];
109
+ h->imagetype = (int) buf[2];
110
+ h->cmapfirstidx = (int) buf[3] | (((int) buf[4]) << 8);
111
+ h->cmaplen = (int) buf[5] | (((int) buf[6]) << 8);
112
+ h->cmapentrysize = (int) buf[7];
113
+ h->xorigin = (int) buf[8] | (((int) buf[9]) << 8);
114
+ h->yorigin = (int) buf[10] | (((int) buf[11]) << 8);
115
+ h->width = (int) buf[12] | (((int) buf[13]) << 8);
116
+ h->height = (int) buf[14] | (((int) buf[15]) << 8);
117
+ h->bitsperpixel = (int) buf[16];
118
+ h->imageinfo = (int) buf[17];
119
+
120
+ // Extract alphabits and origin information
121
+ h->_alphabits = (int) (h->imageinfo & _TGA_IMAGEINFO_ALPHA_MASK) >>
122
+ _TGA_IMAGEINFO_ALPHA_SHIFT;
123
+ h->_origin = (int) (h->imageinfo & _TGA_IMAGEINFO_ORIGIN_MASK) >>
124
+ _TGA_IMAGEINFO_ORIGIN_SHIFT;
125
+
126
+ // Validate TGA header (is this a TGA file?)
127
+ if( (h->cmaptype == 0 || h->cmaptype == 1) &&
128
+ ((h->imagetype >= 1 && h->imagetype <= 3) ||
129
+ (h->imagetype >= 9 && h->imagetype <= 11)) &&
130
+ (h->bitsperpixel == 8 || h->bitsperpixel == 24 ||
131
+ h->bitsperpixel == 32) )
132
+ {
133
+ // Skip the ID field
134
+ _glfwSeekStream( s, h->idlen, SEEK_CUR );
135
+
136
+ // Indicate that the TGA header was valid
137
+ return GL_TRUE;
138
+ }
139
+ else
140
+ {
141
+ // Restore file position
142
+ _glfwSeekStream( s, pos, SEEK_SET );
143
+
144
+ // Indicate that the TGA header was invalid
145
+ return GL_FALSE;
146
+ }
147
+ }
148
+
149
+ //========================================================================
150
+ // _glfwReadTGA_RLE() - Read Run-Length Encoded data
151
+ //========================================================================
152
+
153
+ static void _glfwReadTGA_RLE( unsigned char *buf, int size, int bpp,
154
+ _GLFWstream *s )
155
+ {
156
+ int repcount, bytes, k, n;
157
+ unsigned char pixel[ 4 ];
158
+ char c;
159
+
160
+ // Dummy check
161
+ if( bpp > 4 )
162
+ {
163
+ return;
164
+ }
165
+
166
+ while( size > 0 )
167
+ {
168
+ // Get repetition count
169
+ _glfwReadStream( s, &c, 1 );
170
+ repcount = (unsigned int) c;
171
+ bytes = ((repcount & 127) + 1) * bpp;
172
+ if( size < bytes )
173
+ {
174
+ bytes = size;
175
+ }
176
+
177
+ // Run-Length packet?
178
+ if( repcount & 128 )
179
+ {
180
+ _glfwReadStream( s, pixel, bpp );
181
+ for( n = 0; n < (repcount & 127) + 1; n ++ )
182
+ {
183
+ for( k = 0; k < bpp; k ++ )
184
+ {
185
+ *buf ++ = pixel[ k ];
186
+ }
187
+ }
188
+ }
189
+ else
190
+ {
191
+ // It's a Raw packet
192
+ _glfwReadStream( s, buf, bytes );
193
+ buf += bytes;
194
+ }
195
+
196
+ size -= bytes;
197
+ }
198
+ }
199
+
200
+
201
+ //========================================================================
202
+ // _glfwReadTGA() - Read a TGA image from a file
203
+ //========================================================================
204
+
205
+ int _glfwReadTGA( _GLFWstream *s, GLFWimage *img, int flags )
206
+ {
207
+ _tga_header_t h;
208
+ unsigned char *cmap, *pix, tmp, *src, *dst;
209
+ int cmapsize, pixsize, pixsize2;
210
+ int bpp, bpp2, k, m, n, swapx, swapy;
211
+
212
+ // Read TGA header
213
+ if( !_glfwReadTGAHeader( s, &h ) )
214
+ {
215
+ return 0;
216
+ }
217
+
218
+ // Is there a colormap?
219
+ cmapsize = (h.cmaptype == _TGA_CMAPTYPE_PRESENT ? 1 : 0) * h.cmaplen *
220
+ ((h.cmapentrysize+7) / 8);
221
+ if( cmapsize > 0 )
222
+ {
223
+ // Is it a colormap that we can handle?
224
+ if( (h.cmapentrysize != 24 && h.cmapentrysize != 32) ||
225
+ h.cmaplen == 0 || h.cmaplen > 256 )
226
+ {
227
+ return 0;
228
+ }
229
+
230
+ // Allocate memory for colormap
231
+ cmap = (unsigned char *) malloc( cmapsize );
232
+ if( cmap == NULL )
233
+ {
234
+ return 0;
235
+ }
236
+
237
+ // Read colormap from file
238
+ _glfwReadStream( s, cmap, cmapsize );
239
+ }
240
+ else
241
+ {
242
+ cmap = NULL;
243
+ }
244
+
245
+ // Size of pixel data
246
+ pixsize = h.width * h.height * ((h.bitsperpixel + 7) / 8);
247
+
248
+ // Bytes per pixel (pixel data - unexpanded)
249
+ bpp = (h.bitsperpixel + 7) / 8;
250
+
251
+ // Bytes per pixel (expanded pixels - not colormap indeces)
252
+ if( cmap )
253
+ {
254
+ bpp2 = (h.cmapentrysize + 7) / 8;
255
+ }
256
+ else
257
+ {
258
+ bpp2 = bpp;
259
+ }
260
+
261
+ // For colormaped images, the RGB/RGBA image data may use more memory
262
+ // than the stored pixel data
263
+ pixsize2 = h.width * h.height * bpp2;
264
+
265
+ // Allocate memory for pixel data
266
+ pix = (unsigned char *) malloc( pixsize2 );
267
+ if( pix == NULL )
268
+ {
269
+ if( cmap )
270
+ {
271
+ free( cmap );
272
+ }
273
+ return 0;
274
+ }
275
+
276
+ // Read pixel data from file
277
+ if( h.imagetype >= _TGA_IMAGETYPE_CMAP_RLE )
278
+ {
279
+ _glfwReadTGA_RLE( pix, pixsize, bpp, s );
280
+ }
281
+ else
282
+ {
283
+ _glfwReadStream( s, pix, pixsize );
284
+ }
285
+
286
+ // If the image origin is not what we want, re-arrange the pixels
287
+ switch( h._origin )
288
+ {
289
+ default:
290
+ case _TGA_ORIGIN_UL:
291
+ swapx = 0;
292
+ swapy = 1;
293
+ break;
294
+
295
+ case _TGA_ORIGIN_BL:
296
+ swapx = 0;
297
+ swapy = 0;
298
+ break;
299
+
300
+ case _TGA_ORIGIN_UR:
301
+ swapx = 1;
302
+ swapy = 1;
303
+ break;
304
+
305
+ case _TGA_ORIGIN_BR:
306
+ swapx = 1;
307
+ swapy = 0;
308
+ break;
309
+ }
310
+ if( (swapy && !(flags & GLFW_ORIGIN_UL_BIT)) ||
311
+ (!swapy && (flags & GLFW_ORIGIN_UL_BIT)) )
312
+ {
313
+ src = pix;
314
+ dst = &pix[ (h.height-1)*h.width*bpp ];
315
+ for( n = 0; n < h.height/2; n ++ )
316
+ {
317
+ for( m = 0; m < h.width ; m ++ )
318
+ {
319
+ for( k = 0; k < bpp; k ++ )
320
+ {
321
+ tmp = *src;
322
+ *src ++ = *dst;
323
+ *dst ++ = tmp;
324
+ }
325
+ }
326
+ dst -= 2*h.width*bpp;
327
+ }
328
+ }
329
+ if( swapx )
330
+ {
331
+ src = pix;
332
+ dst = &pix[ (h.width-1)*bpp ];
333
+ for( n = 0; n < h.height; n ++ )
334
+ {
335
+ for( m = 0; m < h.width/2 ; m ++ )
336
+ {
337
+ for( k = 0; k < bpp; k ++ )
338
+ {
339
+ tmp = *src;
340
+ *src ++ = *dst;
341
+ *dst ++ = tmp;
342
+ }
343
+ dst -= 2*bpp;
344
+ }
345
+ src += ((h.width+1)/2)*bpp;
346
+ dst += ((3*h.width+1)/2)*bpp;
347
+ }
348
+ }
349
+
350
+ // Convert BGR/BGRA to RGB/RGBA, and optionally colormap indeces to
351
+ // RGB/RGBA values
352
+ if( cmap )
353
+ {
354
+ // Convert colormap pixel format (BGR -> RGB or BGRA -> RGBA)
355
+ if( bpp2 == 3 || bpp2 == 4 )
356
+ {
357
+ for( n = 0; n < h.cmaplen; n ++ )
358
+ {
359
+ tmp = cmap[ n*bpp2 ];
360
+ cmap[ n*bpp2 ] = cmap[ n*bpp2 + 2 ];
361
+ cmap[ n*bpp2 + 2 ] = tmp;
362
+ }
363
+ }
364
+
365
+ // Convert pixel data to RGB/RGBA data
366
+ for( m = h.width * h.height - 1; m >= 0; m -- )
367
+ {
368
+ n = pix[ m ];
369
+ for( k = 0; k < bpp2; k ++ )
370
+ {
371
+ pix[ m*bpp2 + k ] = cmap[ n*bpp2 + k ];
372
+ }
373
+ }
374
+
375
+ // Free memory for colormap (it's not needed anymore)
376
+ free( cmap );
377
+ }
378
+ else
379
+ {
380
+ // Convert image pixel format (BGR -> RGB or BGRA -> RGBA)
381
+ if( bpp2 == 3 || bpp2 == 4 )
382
+ {
383
+ src = pix;
384
+ dst = &pix[ 2 ];
385
+ for( n = 0; n < h.height * h.width; n ++ )
386
+ {
387
+ tmp = *src;
388
+ *src = *dst;
389
+ *dst = tmp;
390
+ src += bpp2;
391
+ dst += bpp2;
392
+ }
393
+ }
394
+ }
395
+
396
+ // Fill out GLFWimage struct (the Format field will be set by
397
+ // glfwReadImage)
398
+ img->Width = h.width;
399
+ img->Height = h.height;
400
+ img->BytesPerPixel = bpp2;
401
+ img->Data = pix;
402
+
403
+ return 1;
404
+ }
405
+
@@ -0,0 +1,340 @@
1
+ //========================================================================
2
+ // GLFW - An OpenGL framework
3
+ // File: thread.c
4
+ // Platform: Any
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
+ // _glfwGetThreadPointer() - Find pointer to thread with a matching ID
41
+ //========================================================================
42
+
43
+ _GLFWthread * _glfwGetThreadPointer( int ID )
44
+ {
45
+ _GLFWthread *t;
46
+
47
+ for( t = &_glfwThrd.First; t != NULL; t = t->Next )
48
+ {
49
+ if( t->ID == ID )
50
+ {
51
+ break;
52
+ }
53
+ }
54
+
55
+ return t;
56
+ }
57
+
58
+
59
+ //========================================================================
60
+ // _glfwAppendThread() - Append thread to thread list
61
+ //========================================================================
62
+
63
+ void _glfwAppendThread( _GLFWthread * t )
64
+ {
65
+ _GLFWthread *t_tmp;
66
+
67
+ t_tmp = &_glfwThrd.First;
68
+ while( t_tmp->Next != NULL )
69
+ {
70
+ t_tmp = t_tmp->Next;
71
+ }
72
+ t_tmp->Next = t;
73
+ t->Previous = t_tmp;
74
+ t->Next = NULL;
75
+ }
76
+
77
+
78
+ //========================================================================
79
+ // _glfwRemoveThread() - Remove thread from thread list
80
+ //========================================================================
81
+
82
+ void _glfwRemoveThread( _GLFWthread * t )
83
+ {
84
+ if( t->Previous != NULL )
85
+ {
86
+ t->Previous->Next = t->Next;
87
+ }
88
+ if( t->Next != NULL )
89
+ {
90
+ t->Next->Previous = t->Previous;
91
+ }
92
+ free( (void *) t );
93
+ }
94
+
95
+
96
+
97
+ //************************************************************************
98
+ //**** GLFW user functions ****
99
+ //************************************************************************
100
+
101
+ //========================================================================
102
+ // glfwCreateThread() - Create a new thread
103
+ //========================================================================
104
+
105
+ GLFWAPI GLFWthread GLFWAPIENTRY glfwCreateThread( GLFWthreadfun fun,
106
+ void *arg )
107
+ {
108
+ // Is GLFW initialized?
109
+ if( !_glfwInitialized )
110
+ {
111
+ return -1;
112
+ }
113
+
114
+ // Return the GLFW thread ID
115
+ return _glfwPlatformCreateThread( fun, arg );
116
+ }
117
+
118
+
119
+ //========================================================================
120
+ // glfwDestroyThread() - Kill a thread. NOTE: THIS IS A VERY DANGEROUS
121
+ // OPERATION, AND SHOULD NOT BE USED EXCEPT IN EXTREME SITUATIONS!
122
+ //========================================================================
123
+
124
+ GLFWAPI void GLFWAPIENTRY glfwDestroyThread( GLFWthread ID )
125
+ {
126
+ // Is GLFW initialized?
127
+ if( !_glfwInitialized )
128
+ {
129
+ return;
130
+ }
131
+
132
+ // Is it a valid thread? (killing the main thread is not allowed)
133
+ if( ID < 1 )
134
+ {
135
+ return;
136
+ }
137
+
138
+ _glfwPlatformDestroyThread( ID );
139
+ }
140
+
141
+
142
+ //========================================================================
143
+ // glfwWaitThread() - Wait for a thread to die
144
+ //========================================================================
145
+
146
+ GLFWAPI int GLFWAPIENTRY glfwWaitThread( GLFWthread ID, int waitmode )
147
+ {
148
+ // Is GLFW initialized?
149
+ if( !_glfwInitialized )
150
+ {
151
+ return GL_TRUE;
152
+ }
153
+
154
+ // Is it a valid thread? (waiting for the main thread is not allowed)
155
+ if( ID < 1 )
156
+ {
157
+ return GL_TRUE;
158
+ }
159
+
160
+ return _glfwPlatformWaitThread( ID, waitmode );
161
+ }
162
+
163
+
164
+ //========================================================================
165
+ // glfwGetThreadID() - Return the thread ID for the current thread
166
+ //========================================================================
167
+
168
+ GLFWAPI GLFWthread GLFWAPIENTRY glfwGetThreadID( void )
169
+ {
170
+ // Is GLFW initialized?
171
+ if( !_glfwInitialized )
172
+ {
173
+ return 0;
174
+ }
175
+
176
+ return _glfwPlatformGetThreadID();
177
+ }
178
+
179
+
180
+ //========================================================================
181
+ // glfwCreateMutex() - Create a mutual exclusion object
182
+ //========================================================================
183
+
184
+ GLFWAPI GLFWmutex GLFWAPIENTRY glfwCreateMutex( void )
185
+ {
186
+ // Is GLFW initialized?
187
+ if( !_glfwInitialized )
188
+ {
189
+ return (GLFWmutex) 0;
190
+ }
191
+
192
+ return _glfwPlatformCreateMutex();
193
+ }
194
+
195
+
196
+ //========================================================================
197
+ // glfwDestroyMutex() - Destroy a mutual exclusion object
198
+ //========================================================================
199
+
200
+ GLFWAPI void GLFWAPIENTRY glfwDestroyMutex( GLFWmutex mutex )
201
+ {
202
+ // Initialized & valid mutex (no real way of assuring this)?
203
+ if( !_glfwInitialized || !mutex )
204
+ {
205
+ return;
206
+ }
207
+
208
+ _glfwPlatformDestroyMutex( mutex );
209
+ }
210
+
211
+
212
+ //========================================================================
213
+ // glfwLockMutex() - Request access to a mutex
214
+ //========================================================================
215
+
216
+ GLFWAPI void GLFWAPIENTRY glfwLockMutex( GLFWmutex mutex )
217
+ {
218
+ // Initialized & valid mutex (no real way of assuring this)?
219
+ if( !_glfwInitialized && !mutex )
220
+ {
221
+ return;
222
+ }
223
+
224
+ _glfwPlatformLockMutex( mutex );
225
+ }
226
+
227
+
228
+ //========================================================================
229
+ // glfwUnlockMutex() - Release a mutex
230
+ //========================================================================
231
+
232
+ GLFWAPI void GLFWAPIENTRY glfwUnlockMutex( GLFWmutex mutex )
233
+ {
234
+ // Initialized & valid mutex (no real way of assuring this)?
235
+ if( !_glfwInitialized && !mutex )
236
+ {
237
+ return;
238
+ }
239
+
240
+ _glfwPlatformUnlockMutex( mutex );
241
+ }
242
+
243
+
244
+ //========================================================================
245
+ // glfwCreateCond() - Create a new condition variable object
246
+ //========================================================================
247
+
248
+ GLFWAPI GLFWcond GLFWAPIENTRY glfwCreateCond( void )
249
+ {
250
+ // Is GLFW initialized?
251
+ if( !_glfwInitialized )
252
+ {
253
+ return (GLFWcond) 0;
254
+ }
255
+
256
+ return _glfwPlatformCreateCond();
257
+ }
258
+
259
+
260
+ //========================================================================
261
+ // glfwDestroyCond() - Destroy a condition variable object
262
+ //========================================================================
263
+
264
+ GLFWAPI void GLFWAPIENTRY glfwDestroyCond( GLFWcond cond )
265
+ {
266
+ // Initialized & valid condition variable?
267
+ if( !_glfwInitialized || !cond )
268
+ {
269
+ return;
270
+ }
271
+
272
+ _glfwPlatformDestroyCond( cond );
273
+ }
274
+
275
+
276
+ //========================================================================
277
+ // glfwWaitCond() - Wait for a condition to be raised
278
+ //========================================================================
279
+
280
+ GLFWAPI void GLFWAPIENTRY glfwWaitCond( GLFWcond cond, GLFWmutex mutex,
281
+ double timeout )
282
+ {
283
+ // Initialized & valid condition variable and mutex?
284
+ if( !_glfwInitialized || !cond || !mutex )
285
+ {
286
+ return;
287
+ }
288
+
289
+ _glfwPlatformWaitCond( cond, mutex, timeout );
290
+ }
291
+
292
+
293
+ //========================================================================
294
+ // glfwSignalCond() - Signal a condition to one waiting thread
295
+ //========================================================================
296
+
297
+ GLFWAPI void GLFWAPIENTRY glfwSignalCond( GLFWcond cond )
298
+ {
299
+ // Initialized & valid condition variable?
300
+ if( !_glfwInitialized || !cond )
301
+ {
302
+ return;
303
+ }
304
+
305
+ _glfwPlatformSignalCond( cond );
306
+ }
307
+
308
+
309
+ //========================================================================
310
+ // glfwBroadcastCond() - Broadcast a condition to all waiting threads
311
+ //========================================================================
312
+
313
+ GLFWAPI void GLFWAPIENTRY glfwBroadcastCond( GLFWcond cond )
314
+ {
315
+ // Initialized & valid condition variable?
316
+ if( !_glfwInitialized || !cond )
317
+ {
318
+ return;
319
+ }
320
+
321
+ _glfwPlatformBroadcastCond( cond );
322
+ }
323
+
324
+
325
+ //========================================================================
326
+ // glfwGetNumberOfProcessors() - Return the number of processors in the
327
+ // system. This information can be useful for determining the optimal
328
+ // number of threads to use for performing a certain task.
329
+ //========================================================================
330
+
331
+ GLFWAPI int GLFWAPIENTRY glfwGetNumberOfProcessors( void )
332
+ {
333
+ // Is GLFW initialized?
334
+ if( !_glfwInitialized )
335
+ {
336
+ return 0;
337
+ }
338
+
339
+ return _glfwPlatformGetNumberOfProcessors();
340
+ }