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
Binary file
Binary file
Binary file
Binary file
@@ -0,0 +1,432 @@
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
+ # (If the code seems a little bit strange here and there, it may be
9
+ # because I am not a friend of orthogonal projections)
10
+ #========================================================================
11
+ # Converted to ruby from GLFW example splitview.c
12
+
13
+ require 'opengl'
14
+ require 'glfw'
15
+ include Gl,Glu,Glfw,Math
16
+
17
+ #========================================================================
18
+ # Global variables
19
+ #========================================================================
20
+
21
+ # Mouse position
22
+ $xpos,$ypos = 0,0
23
+
24
+ # Window size
25
+ $width,$height = 0,0
26
+
27
+ # Active view: 0 = none, 1 = upper left, 2 = upper right, 3 = lower left,
28
+ # 4 = lower right
29
+ $active_view = 0
30
+
31
+ # Rotation around each axis
32
+ $rot_x,$rot_y,$rot_z = 0,0,0
33
+
34
+ # Do redraw?
35
+ $do_redraw = 1
36
+
37
+ #========================================================================
38
+ # DrawTorus() - Draw a solid torus (use a display list for the model)
39
+ #========================================================================
40
+
41
+ TORUS_MAJOR = 1.5
42
+ TORUS_MINOR = 0.5
43
+ TORUS_MAJOR_RES = 32
44
+ TORUS_MINOR_RES = 32
45
+
46
+ def DrawTorus
47
+ @@torus_list ||= 0 # static(class) variable, initialize or no-op if already initialized
48
+ if (@@torus_list==0)
49
+ # Start recording displaylist
50
+ @@torus_list = glGenLists( 1 )
51
+ glNewList( @@torus_list, GL_COMPILE_AND_EXECUTE )
52
+
53
+ # Draw torus
54
+ twopi = 2.0 * PI;
55
+ TORUS_MINOR_RES.times do |i|
56
+ glBegin(GL_QUAD_STRIP)
57
+ 0.upto(TORUS_MAJOR_RES) do |j|
58
+ 1.downto(0) do |k| # inclusive row
59
+ s = (i + k) % TORUS_MINOR_RES + 0.5
60
+ t = j % TORUS_MAJOR_RES
61
+
62
+ # Calculate point on surface
63
+ x = (TORUS_MAJOR+TORUS_MINOR*cos(s*twopi/TORUS_MINOR_RES))*cos(t*twopi/TORUS_MAJOR_RES)
64
+ y = TORUS_MINOR * sin(s * twopi / TORUS_MINOR_RES);
65
+ z = (TORUS_MAJOR+TORUS_MINOR*cos(s*twopi/TORUS_MINOR_RES))*sin(t*twopi/TORUS_MAJOR_RES)
66
+
67
+ # Calculate surface normal
68
+ nx = x - TORUS_MAJOR*cos(t*twopi/TORUS_MAJOR_RES)
69
+ ny = y
70
+ nz = z - TORUS_MAJOR*sin(t*twopi/TORUS_MAJOR_RES)
71
+ scale = 1.0 / sqrt( nx*nx + ny*ny + nz*nz )
72
+ nx *= scale
73
+ ny *= scale
74
+ nz *= scale
75
+
76
+ glNormal3f( nx, ny, nz )
77
+ glVertex3f( x, y, z )
78
+ end
79
+ end
80
+ glEnd()
81
+ end
82
+ # Stop recording displaylist
83
+ glEndList()
84
+ else
85
+ # Playback displaylist
86
+ glCallList( @@torus_list )
87
+ end
88
+ end
89
+
90
+ #========================================================================
91
+ # DrawScene() - Draw the scene (a rotating torus)
92
+ #========================================================================
93
+ def DrawScene
94
+ model_diffuse = [1.0, 0.8, 0.8, 1.0]
95
+ model_specular = [0.6, 0.6, 0.6, 1.0]
96
+ model_shininess = 20.0
97
+
98
+ glPushMatrix()
99
+
100
+ # Rotate the object
101
+ glRotatef( $rot_x*0.5, 1.0, 0.0, 0.0 )
102
+ glRotatef( $rot_y*0.5, 0.0, 1.0, 0.0 )
103
+ glRotatef( $rot_z*0.5, 0.0, 0.0, 1.0 )
104
+
105
+ # Set model color (used for orthogonal views, lighting disabled)
106
+ glColor4fv( model_diffuse )
107
+
108
+ # Set model material (used for perspective view, lighting enabled)
109
+ glMaterialfv( GL_FRONT, GL_DIFFUSE, model_diffuse )
110
+ glMaterialfv( GL_FRONT, GL_SPECULAR, model_specular )
111
+ glMaterialf( GL_FRONT, GL_SHININESS, model_shininess )
112
+
113
+ # Draw torus
114
+ DrawTorus()
115
+
116
+ glPopMatrix()
117
+ end
118
+
119
+ #========================================================================
120
+ # DrawGrid() - Draw a 2D grid (used for orthogonal views)
121
+ #========================================================================
122
+ def DrawGrid(scale,steps)
123
+ glPushMatrix()
124
+
125
+ # Set background to some dark bluish grey
126
+ glClearColor( 0.05, 0.05, 0.2, 0.0)
127
+ glClear( GL_COLOR_BUFFER_BIT )
128
+
129
+ # Setup modelview matrix (flat XY view)
130
+ glLoadIdentity()
131
+ gluLookAt( 0.0, 0.0, 1.0,
132
+ 0.0, 0.0, 0.0,
133
+ 0.0, 1.0, 0.0 )
134
+
135
+ # We don't want to update the Z-buffer
136
+ glDepthMask( GL_FALSE )
137
+
138
+ # Set grid color
139
+ glColor3f( 0.0, 0.5, 0.5 )
140
+
141
+ glBegin( GL_LINES )
142
+
143
+ # Horizontal lines
144
+ x = scale * 0.5 * (steps-1)
145
+ y = -scale * 0.5 * (steps-1)
146
+ steps.times do |i|
147
+ glVertex3f( -x, y, 0.0 )
148
+ glVertex3f( x, y, 0.0 )
149
+ y += scale
150
+ end
151
+
152
+ # Vertical lines
153
+ x = -scale * 0.5 * (steps-1)
154
+ y = scale * 0.5 * (steps-1)
155
+ steps.times do |i|
156
+ glVertex3f( x, -y, 0.0 )
157
+ glVertex3f( x, y, 0.0 )
158
+ x += scale
159
+ end
160
+ glEnd();
161
+
162
+ # Enable Z-buffer writing again
163
+ glDepthMask( GL_TRUE )
164
+
165
+ glPopMatrix()
166
+ end
167
+
168
+ #========================================================================
169
+ # DrawAllViews()
170
+ #========================================================================
171
+ def DrawAllViews
172
+ light_position = [0.0, 8.0, 8.0, 1.0]
173
+ light_diffuse = [1.0, 1.0, 1.0, 1.0]
174
+ light_specular = [1.0, 1.0, 1.0, 1.0]
175
+ light_ambient = [0.2, 0.2, 0.3, 1.0]
176
+
177
+ # Calculate aspect of window
178
+ if( $height > 0 )
179
+ aspect = $width.to_f / $height.to_f
180
+ else
181
+ aspect = 1.0
182
+ end
183
+
184
+ # Clear screen
185
+ glClearColor( 0.0, 0.0, 0.0, 0.0)
186
+ glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT )
187
+
188
+ # Enable scissor test
189
+ glEnable( GL_SCISSOR_TEST )
190
+
191
+ # Enable depth test
192
+ glEnable( GL_DEPTH_TEST )
193
+ glDepthFunc( GL_LEQUAL )
194
+
195
+
196
+ # ** ORTHOGONAL VIEWS **
197
+
198
+ # For orthogonal views, use wireframe rendering
199
+ glPolygonMode( GL_FRONT_AND_BACK, GL_LINE )
200
+
201
+ # Enable line anti-aliasing
202
+ glEnable( GL_LINE_SMOOTH )
203
+ glEnable( GL_BLEND )
204
+ glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA )
205
+
206
+ # Setup orthogonal projection matrix
207
+ glMatrixMode( GL_PROJECTION )
208
+ glLoadIdentity()
209
+ glOrtho( -3.0*aspect, 3.0*aspect, -3.0, 3.0, 1.0, 50.0 )
210
+
211
+ # Upper left view (TOP VIEW)
212
+ glViewport( 0, $height/2, $width/2, $height/2 )
213
+ glScissor( 0, $height/2, $width/2, $height/2 )
214
+ glMatrixMode( GL_MODELVIEW )
215
+ glLoadIdentity()
216
+ gluLookAt( 0.0, 10.0, 1e-3, # Eye-position (above)
217
+ 0.0, 0.0, 0.0, # View-point
218
+ 0.0, 1.0, 0.0 ) # Up-vector
219
+ DrawGrid( 0.5, 12 )
220
+ DrawScene()
221
+
222
+ # Lower left view (FRONT VIEW)
223
+ glViewport( 0, 0, $width/2, $height/2 )
224
+ glScissor( 0, 0, $width/2, $height/2 )
225
+ glMatrixMode( GL_MODELVIEW )
226
+ glLoadIdentity()
227
+ gluLookAt( 0.0, 0.0, 10.0, # Eye-position (in front of)
228
+ 0.0, 0.0, 0.0, # View-point
229
+ 0.0, 1.0, 0.0 ) # Up-vector
230
+ DrawGrid( 0.5, 12 )
231
+ DrawScene()
232
+
233
+ # Lower right view (SIDE VIEW)
234
+ glViewport( $width/2, 0, $width/2, $height/2 )
235
+ glScissor( $width/2, 0, $width/2, $height/2 )
236
+ glMatrixMode( GL_MODELVIEW )
237
+ glLoadIdentity()
238
+ gluLookAt( 10.0, 0.0, 0.0, # Eye-position (to the right)
239
+ 0.0, 0.0, 0.0, # View-point
240
+ 0.0, 1.0, 0.0 ) # Up-vector
241
+ DrawGrid( 0.5, 12 )
242
+ DrawScene()
243
+
244
+ # Disable line anti-aliasing
245
+ glDisable( GL_LINE_SMOOTH )
246
+ glDisable( GL_BLEND )
247
+
248
+ # ** PERSPECTIVE VIEW **
249
+
250
+ # For perspective view, use solid rendering
251
+ glPolygonMode( GL_FRONT_AND_BACK, GL_FILL )
252
+
253
+ # Enable face culling (faster rendering)
254
+ glEnable( GL_CULL_FACE )
255
+ glCullFace( GL_BACK )
256
+ glFrontFace( GL_CW )
257
+
258
+ # Setup perspective projection matrix
259
+ glMatrixMode( GL_PROJECTION )
260
+ glLoadIdentity()
261
+ gluPerspective( 65.0, aspect, 1.0, 50.0 )
262
+
263
+ # Upper right view (PERSPECTIVE VIEW)
264
+ glViewport( $width/2, $height/2, $width/2, $height/2 )
265
+ glScissor( $width/2, $height/2, $width/2, $height/2 )
266
+ glMatrixMode( GL_MODELVIEW )
267
+ glLoadIdentity()
268
+ gluLookAt( 3.0, 1.5, 3.0, # Eye-position
269
+ 0.0, 0.0, 0.0, # View-point
270
+ 0.0, 1.0, 0.0 ) # Up-vector
271
+
272
+ # Configure and enable light source 1
273
+ glLightfv( GL_LIGHT1, GL_POSITION, light_position )
274
+ glLightfv( GL_LIGHT1, GL_AMBIENT, light_ambient )
275
+ glLightfv( GL_LIGHT1, GL_DIFFUSE, light_diffuse )
276
+ glLightfv( GL_LIGHT1, GL_SPECULAR, light_specular )
277
+ glEnable( GL_LIGHT1 )
278
+ glEnable( GL_LIGHTING )
279
+
280
+ # Draw scene
281
+ DrawScene()
282
+
283
+ # Disable lighting
284
+ glDisable( GL_LIGHTING )
285
+
286
+ # Disable face culling
287
+ glDisable( GL_CULL_FACE )
288
+
289
+ # Disable depth test
290
+ glDisable( GL_DEPTH_TEST )
291
+
292
+ # Disable scissor test
293
+ glDisable( GL_SCISSOR_TEST )
294
+
295
+ # Draw a border around the active view
296
+ if( $active_view > 0 && $active_view != 2 )
297
+ glViewport( 0, 0, $width, $height )
298
+ glMatrixMode( GL_PROJECTION )
299
+ glLoadIdentity()
300
+ glOrtho( 0.0, 2.0, 0.0, 2.0, 0.0, 1.0 )
301
+ glMatrixMode( GL_MODELVIEW )
302
+ glLoadIdentity()
303
+ glColor3f( 1.0, 1.0, 0.6 )
304
+ glTranslatef( ($active_view-1)&1, 1-($active_view-1)/2, 0.0 )
305
+ glBegin( GL_LINE_STRIP )
306
+ glVertex2i( 0, 0 )
307
+ glVertex2i( 1, 0 )
308
+ glVertex2i( 1, 1 )
309
+ glVertex2i( 0, 1 )
310
+ glVertex2i( 0, 0 )
311
+ glEnd()
312
+ end
313
+ end
314
+
315
+ #=======================================================================
316
+ # WindowSizeFun() - Window size callback function
317
+ #========================================================================
318
+
319
+ WindowSizeFun = lambda do |w,h|
320
+ $width = w
321
+ $height = h > 0 ? h : 1
322
+ $do_redraw = 1
323
+ end
324
+
325
+ #========================================================================
326
+ # WindowRefreshFun() - Window refresh callback function
327
+ #========================================================================
328
+
329
+ WindowRefreshFun = lambda do
330
+ $do_redraw = 1
331
+ end
332
+
333
+
334
+ #========================================================================
335
+ # MousePosFun() - Mouse position callback function
336
+ #========================================================================
337
+
338
+ MousePosFun = lambda do |x,y|
339
+ case $active_view
340
+ when 1:
341
+ $rot_x += y - $ypos
342
+ $rot_z += x - $xpos
343
+ $do_redraw = 1
344
+ when 3:
345
+ $rot_x += y - $ypos
346
+ $rot_y += x - $xpos
347
+ $do_redraw = 1
348
+ when 4:
349
+ $rot_y += x - $xpos
350
+ $rot_z += y - $ypos
351
+ $do_redraw = 1
352
+ else
353
+ # Do nothing for perspective view, or if no view is selected
354
+ end
355
+ $xpos = x
356
+ $ypos = y
357
+ end
358
+
359
+ #========================================================================
360
+ # MouseButtonFun() - Mouse button callback function
361
+ #========================================================================
362
+
363
+ MouseButtonFun = lambda do |button,action|
364
+ # Button clicked?
365
+ if( ( button == GLFW_MOUSE_BUTTON_LEFT ) && action == GLFW_PRESS )
366
+ # Detect which of the four views was clicked
367
+ $active_view = 1
368
+ if( $xpos >= $width/2 )
369
+ $active_view += 1
370
+ end
371
+ if( $ypos >= $height/2 )
372
+ $active_view += 2
373
+ end
374
+
375
+ # Button released?
376
+ elsif( button == GLFW_MOUSE_BUTTON_LEFT )
377
+ # Deselect any previously selected view
378
+ $active_view = 0
379
+ end
380
+
381
+ $do_redraw = 1
382
+ end
383
+
384
+ #========================================================================
385
+ # main()
386
+ #========================================================================
387
+
388
+ running = true
389
+
390
+ # Open OpenGL window
391
+ if( glfwOpenWindow( 500, 500, 0,0,0,0, 16,0, GLFW_WINDOW ) == false )
392
+ exit
393
+ end
394
+
395
+ # Set window title
396
+ glfwSetWindowTitle( "Split view demo" )
397
+
398
+ # Enable sticky keys
399
+ glfwEnable( GLFW_STICKY_KEYS )
400
+
401
+ # Enable mouse cursor (only needed for fullscreen mode)
402
+ glfwEnable( GLFW_MOUSE_CURSOR )
403
+
404
+ # Disable automatic event polling
405
+ glfwDisable( GLFW_AUTO_POLL_EVENTS )
406
+
407
+ # Set callback functions
408
+ glfwSetWindowSizeCallback( WindowSizeFun )
409
+ glfwSetWindowRefreshCallback( WindowRefreshFun )
410
+ glfwSetMousePosCallback( MousePosFun )
411
+ glfwSetMouseButtonCallback( MouseButtonFun )
412
+
413
+ # Main loop
414
+ while running
415
+ # Only redraw if we need to
416
+ if( $do_redraw )
417
+ # Draw all views
418
+ DrawAllViews()
419
+
420
+ # Swap buffers
421
+ glfwSwapBuffers()
422
+
423
+ $do_redraw = 0
424
+ end
425
+
426
+ # Wait for new events
427
+ glfwWaitEvents()
428
+
429
+ # Check if the ESC key was pressed or the window was closed
430
+ running = (glfwGetKey( GLFW_KEY_ESC ) == GLFW_RELEASE) &&
431
+ (glfwGetWindowParam( GLFW_OPENED ) == true)
432
+ end
@@ -0,0 +1,89 @@
1
+ #========================================================================
2
+ # This is a small test application for GLFW.
3
+ # The program opens a window (640x480), and renders a spinning colored
4
+ # triangle (it is controlled with both the GLFW timer and the mouse). It
5
+ # also calculates the rendering speed (FPS), which is displayed in the
6
+ # window title bar.
7
+ #========================================================================
8
+ # Converted to ruby from GLFW example triangle.c
9
+
10
+ require 'opengl'
11
+ require 'glfw'
12
+ include Gl,Glu,Glfw
13
+
14
+ # main
15
+
16
+ # Open OpenGL window
17
+ if (glfwOpenWindow( 640, 480, 0,0,0,0, 0,0, GLFW_WINDOW ) == false)
18
+ exit
19
+ end
20
+
21
+ # Enable sticky keys
22
+ glfwEnable( GLFW_STICKY_KEYS )
23
+
24
+ # Disable vertical sync (on cards that support it)
25
+ glfwSwapInterval( 0 )
26
+
27
+ # Main loop
28
+ running = true
29
+ frames = 0
30
+ t0 = glfwGetTime()
31
+
32
+ while running == true
33
+ # Get time and mouse position
34
+ t = glfwGetTime()
35
+ x,y = glfwGetMousePos()
36
+
37
+ # Calculate and display FPS (frames per second)
38
+ if( (t-t0) > 1.0 || frames == 0 )
39
+ fps = frames.to_f / (t-t0)
40
+ titlestr = sprintf("Spinning Triangle (%.1f FPS)", fps )
41
+ glfwSetWindowTitle( titlestr )
42
+ t0 = t
43
+ frames = 0
44
+ end
45
+ frames += 1
46
+
47
+ # Get window size (may be different than the requested size)
48
+ width,height = glfwGetWindowSize()
49
+ height = height > 0 ? height : 1
50
+
51
+ # Set viewport
52
+ glViewport( 0, 0, width, height )
53
+
54
+ # Clear color buffer
55
+ glClearColor( 0.0, 0.0, 0.0, 0.0 )
56
+ glClear( GL_COLOR_BUFFER_BIT )
57
+
58
+ # Select and setup the projection matrix
59
+ glMatrixMode( GL_PROJECTION )
60
+ glLoadIdentity()
61
+ gluPerspective( 65.0, width.to_f/height.to_f, 1.0, 100.0 )
62
+
63
+ # Select and setup the modelview matrix
64
+ glMatrixMode( GL_MODELVIEW )
65
+ glLoadIdentity()
66
+ gluLookAt( 0.0, 1.0, 0.0, # Eye-position
67
+ 0.0, 20.0, 0.0, # View-point
68
+ 0.0, 0.0, 1.0 ) # Up-vector
69
+
70
+ # Draw a rotating colorful triangle
71
+ glTranslatef( 0.0, 14.0, 0.0 )
72
+ glRotatef( 0.3*x.to_f + t.to_f*100.0, 0.0, 0.0, 1.0 )
73
+ glBegin( GL_TRIANGLES )
74
+ glColor3f( 1.0, 0.0, 0.0 )
75
+ glVertex3f( -5.0, 0.0, -4.0 )
76
+ glColor3f( 0.0, 1.0, 0.0 )
77
+ glVertex3f( 5.0, 0.0, -4.0 )
78
+ glColor3f( 0.0, 0.0, 1.0 )
79
+ glVertex3f( 0.0, 0.0, 6.0 )
80
+ glEnd()
81
+
82
+ # Swap buffers
83
+ glfwSwapBuffers()
84
+
85
+ # Check if the ESC key was pressed or the window was closed
86
+ running = ( glfwGetKey( GLFW_KEY_ESC ) == GLFW_RELEASE &&
87
+ glfwGetWindowParam( GLFW_OPENED ) == true )
88
+ end
89
+