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,486 @@
1
+ //========================================================================
2
+ // This is a small test application for GLFW.
3
+ // The program uses a "split window" view, rendering four views of the
4
+ // same scene in one window (e.g. uesful for 3D modelling software). This
5
+ // demo uses scissors to separete the four different rendering areas from
6
+ // each other.
7
+ //
8
+ // This code was ported straight from C, so it may not be a school book
9
+ // example of D programming, but it shows how to use GLFW callbacks in D.
10
+ //========================================================================
11
+
12
+ import std.math;
13
+ import std.string;
14
+ import glfw;
15
+
16
+
17
+
18
+ //========================================================================
19
+ // Global variables
20
+ //========================================================================
21
+
22
+ // Mouse position
23
+ int xpos = 0, ypos = 0;
24
+
25
+ // Window size
26
+ int width, height;
27
+
28
+ // Active view: 0 = none, 1 = upper left, 2 = upper right, 3 = lower left,
29
+ // 4 = lower right
30
+ int active_view = 0;
31
+
32
+ // Rotation around each axis
33
+ int rot_x = 0, rot_y = 0, rot_z = 0;
34
+
35
+
36
+ //========================================================================
37
+ // DrawTorus() - Draw a solid torus (use a display list for the model)
38
+ //========================================================================
39
+
40
+ const double TORUS_MAJOR = 1.5;
41
+ const double TORUS_MINOR = 0.5;
42
+ const int TORUS_MAJOR_RES = 32;
43
+ const int TORUS_MINOR_RES = 32;
44
+
45
+ void DrawTorus()
46
+ {
47
+ static GLuint torus_list = 0;
48
+ int i, j, k;
49
+ double s, t, x, y, z, nx, ny, nz, scale, twopi;
50
+
51
+ if( !torus_list )
52
+ {
53
+ // Start recording displaylist
54
+ torus_list = glGenLists( 1 );
55
+ glNewList( torus_list, GL_COMPILE_AND_EXECUTE );
56
+
57
+ // Draw torus
58
+ twopi = 2.0 * PI;
59
+ for( i = 0; i < TORUS_MINOR_RES; i++ )
60
+ {
61
+ glBegin( GL_QUAD_STRIP );
62
+ for( j = 0; j <= TORUS_MAJOR_RES; j++ )
63
+ {
64
+ for( k = 1; k >= 0; k-- )
65
+ {
66
+ s = (i + k) % TORUS_MINOR_RES + 0.5;
67
+ t = j % TORUS_MAJOR_RES;
68
+
69
+ // Calculate point on surface
70
+ x = (TORUS_MAJOR+TORUS_MINOR*cos(s*twopi/TORUS_MINOR_RES))*cos(t*twopi/TORUS_MAJOR_RES);
71
+ y = TORUS_MINOR * sin(s * twopi / TORUS_MINOR_RES);
72
+ z = (TORUS_MAJOR+TORUS_MINOR*cos(s*twopi/TORUS_MINOR_RES))*sin(t*twopi/TORUS_MAJOR_RES);
73
+
74
+ // Calculate surface normal
75
+ nx = x - TORUS_MAJOR*cos(t*twopi/TORUS_MAJOR_RES);
76
+ ny = y;
77
+ nz = z - TORUS_MAJOR*sin(t*twopi/TORUS_MAJOR_RES);
78
+ scale = 1.0 / sqrt( nx*nx + ny*ny + nz*nz );
79
+ nx *= scale;
80
+ ny *= scale;
81
+ nz *= scale;
82
+
83
+ glNormal3f( cast(float)nx, cast(float)ny, cast(float)nz );
84
+ glVertex3f( cast(float)x, cast(float)y, cast(float)z );
85
+ }
86
+ }
87
+ glEnd();
88
+ }
89
+
90
+ // Stop recording displaylist
91
+ glEndList();
92
+ }
93
+ else
94
+ {
95
+ // Playback displaylist
96
+ glCallList( torus_list );
97
+ }
98
+ }
99
+
100
+
101
+ //========================================================================
102
+ // DrawScene() - Draw the scene (a rotating torus)
103
+ //========================================================================
104
+
105
+ void DrawScene()
106
+ {
107
+ const GLfloat[4] model_diffuse = [1.0f, 0.8f, 0.8f, 1.0f];
108
+ const GLfloat[4] model_specular = [0.6f, 0.6f, 0.6f, 1.0f];
109
+ const GLfloat model_shininess = 20.0f;
110
+
111
+ glPushMatrix();
112
+
113
+ // Rotate the object
114
+ glRotatef( cast(GLfloat)rot_x*0.5f, 1.0f, 0.0f, 0.0f );
115
+ glRotatef( cast(GLfloat)rot_y*0.5f, 0.0f, 1.0f, 0.0f );
116
+ glRotatef( cast(GLfloat)rot_z*0.5f, 0.0f, 0.0f, 1.0f );
117
+
118
+ // Set model color (used for orthogonal views, lighting disabled)
119
+ glColor4fv( model_diffuse );
120
+
121
+ // Set model material (used for perspective view, lighting enabled)
122
+ glMaterialfv( GL_FRONT, GL_DIFFUSE, model_diffuse );
123
+ glMaterialfv( GL_FRONT, GL_SPECULAR, model_specular );
124
+ glMaterialf( GL_FRONT, GL_SHININESS, model_shininess );
125
+
126
+ // Draw torus
127
+ DrawTorus();
128
+
129
+ glPopMatrix();
130
+ }
131
+
132
+
133
+ //========================================================================
134
+ // DrawGrid() - Draw a 2D grid (used for orthogonal views)
135
+ //========================================================================
136
+
137
+ void DrawGrid( float scale, int steps )
138
+ {
139
+ int i;
140
+ float x, y;
141
+
142
+ glPushMatrix();
143
+
144
+ // Set background to some dark bluish grey
145
+ glClearColor( 0.05f, 0.05f, 0.2f, 0.0f );
146
+ glClear( GL_COLOR_BUFFER_BIT );
147
+
148
+ // Setup modelview matrix (flat XY view)
149
+ glLoadIdentity();
150
+ gluLookAt( 0.0, 0.0, 1.0,
151
+ 0.0, 0.0, 0.0,
152
+ 0.0, 1.0, 0.0 );
153
+
154
+ // We don't want to update the Z-buffer
155
+ glDepthMask( GL_FALSE );
156
+
157
+ // Set grid color
158
+ glColor3f( 0.0f, 0.5f, 0.5f );
159
+
160
+ glBegin( GL_LINES );
161
+
162
+ // Horizontal lines
163
+ x = scale * 0.5f * cast(float)(steps-1);
164
+ y = -scale * 0.5f * cast(float)(steps-1);
165
+ for( i = 0; i < steps; i ++ )
166
+ {
167
+ glVertex3f( -x, y, 0.0f );
168
+ glVertex3f( x, y, 0.0f );
169
+ y += scale;
170
+ }
171
+
172
+ // Vertical lines
173
+ x = -scale * 0.5f * cast(float)(steps-1);
174
+ y = scale * 0.5f * cast(float)(steps-1);
175
+ for( i = 0; i < steps; i ++ )
176
+ {
177
+ glVertex3f( x, -y, 0.0f );
178
+ glVertex3f( x, y, 0.0f );
179
+ x += scale;
180
+ }
181
+
182
+ glEnd();
183
+
184
+ // Enable Z-buffer writing again
185
+ glDepthMask( GL_TRUE );
186
+
187
+ glPopMatrix();
188
+ }
189
+
190
+
191
+ //========================================================================
192
+ // DrawAllViews()
193
+ //========================================================================
194
+
195
+ void DrawAllViews()
196
+ {
197
+ const GLfloat[4] light_position = [0.0f, 8.0f, 8.0f, 1.0f];
198
+ const GLfloat[4] light_diffuse = [1.0f, 1.0f, 1.0f, 1.0f];
199
+ const GLfloat[4] light_specular = [1.0f, 1.0f, 1.0f, 1.0f];
200
+ const GLfloat[4] light_ambient = [0.2f, 0.2f, 0.3f, 1.0f];
201
+ double aspect;
202
+
203
+ // Calculate aspect of window
204
+ if( height > 0 )
205
+ {
206
+ aspect = cast(double)width / cast(double)height;
207
+ }
208
+ else
209
+ {
210
+ aspect = 1.0;
211
+ }
212
+
213
+ // Clear screen
214
+ glClearColor( 0.0f, 0.0f, 0.0f, 0.0f);
215
+ glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
216
+
217
+ // Enable scissor test
218
+ glEnable( GL_SCISSOR_TEST );
219
+
220
+ // Enable depth test
221
+ glEnable( GL_DEPTH_TEST );
222
+ glDepthFunc( GL_LEQUAL );
223
+
224
+
225
+ // ** ORTHOGONAL VIEWS **
226
+
227
+ // For orthogonal views, use wireframe rendering
228
+ glPolygonMode( GL_FRONT_AND_BACK, GL_LINE );
229
+
230
+ // Enable line anti-aliasing
231
+ glEnable( GL_LINE_SMOOTH );
232
+ glEnable( GL_BLEND );
233
+ glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
234
+
235
+ // Setup orthogonal projection matrix
236
+ glMatrixMode( GL_PROJECTION );
237
+ glLoadIdentity();
238
+ glOrtho( -3.0*aspect, 3.0*aspect, -3.0, 3.0, 1.0, 50.0 );
239
+
240
+ // Upper left view (TOP VIEW)
241
+ glViewport( 0, height/2, width/2, height/2 );
242
+ glScissor( 0, height/2, width/2, height/2 );
243
+ glMatrixMode( GL_MODELVIEW );
244
+ glLoadIdentity();
245
+ gluLookAt( 0.0f, 10.0f, 1e-3f, // Eye-position (above)
246
+ 0.0f, 0.0f, 0.0f, // View-point
247
+ 0.0f, 1.0f, 0.0f ); // Up-vector
248
+ DrawGrid( 0.5, 12 );
249
+ DrawScene();
250
+
251
+ // Lower left view (FRONT VIEW)
252
+ glViewport( 0, 0, width/2, height/2 );
253
+ glScissor( 0, 0, width/2, height/2 );
254
+ glMatrixMode( GL_MODELVIEW );
255
+ glLoadIdentity();
256
+ gluLookAt( 0.0f, 0.0f, 10.0f, // Eye-position (in front of)
257
+ 0.0f, 0.0f, 0.0f, // View-point
258
+ 0.0f, 1.0f, 0.0f ); // Up-vector
259
+ DrawGrid( 0.5, 12 );
260
+ DrawScene();
261
+
262
+ // Lower right view (SIDE VIEW)
263
+ glViewport( width/2, 0, width/2, height/2 );
264
+ glScissor( width/2, 0, width/2, height/2 );
265
+ glMatrixMode( GL_MODELVIEW );
266
+ glLoadIdentity();
267
+ gluLookAt( 10.0f, 0.0f, 0.0f, // Eye-position (to the right)
268
+ 0.0f, 0.0f, 0.0f, // View-point
269
+ 0.0f, 1.0f, 0.0f ); // Up-vector
270
+ DrawGrid( 0.5, 12 );
271
+ DrawScene();
272
+
273
+ // Disable line anti-aliasing
274
+ glDisable( GL_LINE_SMOOTH );
275
+ glDisable( GL_BLEND );
276
+
277
+
278
+ // ** PERSPECTIVE VIEW **
279
+
280
+ // For perspective view, use solid rendering
281
+ glPolygonMode( GL_FRONT_AND_BACK, GL_FILL );
282
+
283
+ // Enable face culling (faster rendering)
284
+ glEnable( GL_CULL_FACE );
285
+ glCullFace( GL_BACK );
286
+ glFrontFace( GL_CW );
287
+
288
+ // Setup perspective projection matrix
289
+ glMatrixMode( GL_PROJECTION );
290
+ glLoadIdentity();
291
+ gluPerspective( 65.0f, aspect, 1.0f, 50.0f );
292
+
293
+ // Upper right view (PERSPECTIVE VIEW)
294
+ glViewport( width/2, height/2, width/2, height/2 );
295
+ glScissor( width/2, height/2, width/2, height/2 );
296
+ glMatrixMode( GL_MODELVIEW );
297
+ glLoadIdentity();
298
+ gluLookAt( 3.0f, 1.5f, 3.0f, // Eye-position
299
+ 0.0f, 0.0f, 0.0f, // View-point
300
+ 0.0f, 1.0f, 0.0f ); // Up-vector
301
+
302
+ // Configure and enable light source 1
303
+ glLightfv( GL_LIGHT1, GL_POSITION, light_position );
304
+ glLightfv( GL_LIGHT1, GL_AMBIENT, light_ambient );
305
+ glLightfv( GL_LIGHT1, GL_DIFFUSE, light_diffuse );
306
+ glLightfv( GL_LIGHT1, GL_SPECULAR, light_specular );
307
+ glEnable( GL_LIGHT1 );
308
+ glEnable( GL_LIGHTING );
309
+
310
+ // Draw scene
311
+ DrawScene();
312
+
313
+ // Disable lighting
314
+ glDisable( GL_LIGHTING );
315
+
316
+ // Disable face culling
317
+ glDisable( GL_CULL_FACE );
318
+
319
+ // Disable depth test
320
+ glDisable( GL_DEPTH_TEST );
321
+
322
+ // Disable scissor test
323
+ glDisable( GL_SCISSOR_TEST );
324
+
325
+
326
+ // Draw a border around the active view
327
+ if( active_view > 0 && active_view != 2 )
328
+ {
329
+ glViewport( 0, 0, width, height );
330
+ glMatrixMode( GL_PROJECTION );
331
+ glLoadIdentity();
332
+ glOrtho( 0.0, 2.0, 0.0, 2.0, 0.0, 1.0 );
333
+ glMatrixMode( GL_MODELVIEW );
334
+ glLoadIdentity();
335
+ glColor3f( 1.0f, 1.0f, 0.6f );
336
+ glTranslatef( (active_view-1)&1, 1-(active_view-1)/2, 0.0f );
337
+ glBegin( GL_LINE_STRIP );
338
+ glVertex2i( 0, 0 );
339
+ glVertex2i( 1, 0 );
340
+ glVertex2i( 1, 1 );
341
+ glVertex2i( 0, 1 );
342
+ glVertex2i( 0, 0 );
343
+ glEnd();
344
+ }
345
+ }
346
+
347
+
348
+ //========================================================================
349
+ // WindowSizeFun() - Window size callback function
350
+ //========================================================================
351
+
352
+ extern (Windows)
353
+ {
354
+ void WindowSizeFun( int w, int h )
355
+ {
356
+ width = w;
357
+ height = h > 0 ? h : 1;
358
+ }
359
+ }
360
+
361
+ //========================================================================
362
+ // MousePosFun() - Mouse position callback function
363
+ //========================================================================
364
+
365
+ extern (Windows)
366
+ {
367
+ void MousePosFun( int x, int y )
368
+ {
369
+ // Depending on which view was selected, rotate around different axes
370
+ switch( active_view )
371
+ {
372
+ case 1:
373
+ rot_x += y - ypos;
374
+ rot_z += x - xpos;
375
+ break;
376
+ case 3:
377
+ rot_x += y - ypos;
378
+ rot_y += x - xpos;
379
+ break;
380
+ case 4:
381
+ rot_y += x - xpos;
382
+ rot_z += y - ypos;
383
+ break;
384
+ default:
385
+ // Do nothing for perspective view, or if no view is selected
386
+ break;
387
+ }
388
+
389
+ // Remember mouse position
390
+ xpos = x;
391
+ ypos = y;
392
+ }
393
+ }
394
+
395
+
396
+ //========================================================================
397
+ // MouseButtonFun() - Mouse button callback function
398
+ //========================================================================
399
+
400
+ extern (Windows)
401
+ {
402
+ void MouseButtonFun( int button, int action )
403
+ {
404
+ // Button clicked?
405
+ if( ( button == GLFW_MOUSE_BUTTON_LEFT ) && action == GLFW_PRESS )
406
+ {
407
+ // Detect which of the four views was clicked
408
+ active_view = 1;
409
+ if( xpos >= width/2 )
410
+ {
411
+ active_view += 1;
412
+ }
413
+ if( ypos >= height/2 )
414
+ {
415
+ active_view += 2;
416
+ }
417
+ }
418
+
419
+ // Button released?
420
+ else if( button == GLFW_MOUSE_BUTTON_LEFT )
421
+ {
422
+ // Deselect any previously selected view
423
+ active_view = 0;
424
+ }
425
+ }
426
+ }
427
+
428
+
429
+ //========================================================================
430
+ // main()
431
+ //========================================================================
432
+
433
+ int main()
434
+ {
435
+ int running;
436
+
437
+ // Initialise GLFW
438
+ glfwInit();
439
+
440
+ // Open OpenGL window
441
+ if( !glfwOpenWindow( 500, 500, 0,0,0,0, 16,0, GLFW_WINDOW ) )
442
+ {
443
+ glfwTerminate();
444
+ return 0;
445
+ }
446
+
447
+ // Set window title
448
+ glfwSetWindowTitle( "Split view demo\0" );
449
+
450
+ // Enable sticky keys
451
+ glfwEnable( GLFW_STICKY_KEYS );
452
+
453
+ // Enable mouse cursor (only needed for fullscreen mode)
454
+ glfwEnable( GLFW_MOUSE_CURSOR );
455
+
456
+ // Disable automatic event polling
457
+ glfwDisable( GLFW_AUTO_POLL_EVENTS );
458
+
459
+ // Set callback functions
460
+ glfwSetWindowSizeCallback( &WindowSizeFun );
461
+ glfwSetMousePosCallback( &MousePosFun );
462
+ glfwSetMouseButtonCallback( &MouseButtonFun );
463
+
464
+ // Main loop
465
+ do
466
+ {
467
+ // Draw all views
468
+ DrawAllViews();
469
+
470
+ // Swap buffers
471
+ glfwSwapBuffers();
472
+
473
+ // Wait for new events
474
+ glfwWaitEvents();
475
+
476
+ // Check if the ESC key was pressed or the window was closed
477
+ running = !glfwGetKey( GLFW_KEY_ESC ) &&
478
+ glfwGetWindowParam( GLFW_OPENED );
479
+ }
480
+ while( running );
481
+
482
+ // Close OpenGL window and terminate GLFW
483
+ glfwTerminate();
484
+
485
+ return 0;
486
+ }