Making Samples executable. #!/usr/bin/env io and chmod a+x *.io
[io/quag.git] / addons / GLFW / samples / lesson07.io
blobf4964adc2a67e61cb55c99596532738b85dad606
1 #!/usr/bin/env io
3 # Port of http://glfw.sourceforge.net/tutorials/lesson07/lesson07.html
5 appendProto(GLFW)
6 appendProto(OpenGL)
8 draw := method(
9 # Get current time
10 t := glfwGetTime()
12 # Get window size
13 size := glfwGetWindowSize
15 # Make sure that height is non-zero to avoid division by zero
16 if(size height < 1, size setHeight(1))
18 # Set viewport
19 glViewport( 0, 0, size width, size height )
21 # Clear color and depth buffers
22 glClearColor( 0, 0, 0, 0 )
23 glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT )
25 # Set up projection matrix
26 glMatrixMode( GL_PROJECTION ) # Select projection matrix
27 glLoadIdentity # Start with an identity matrix
28 gluPerspective( # Set perspective view
29 65, # Field of view = 65 degrees
30 size width / size height, # Window aspect (assumes square pixels)
31 1, # Near Z clipping plane
32 100 # Far Z clippling plane
35 # Set up modelview matrix
36 glMatrixMode( GL_MODELVIEW ) # Select modelview matrix
37 glLoadIdentity # Start with an identity matrix
38 gluLookAt( # Set camera position and orientation
39 0, 0, 10, # Camera position (x,y,z)
40 0, 0, 0, # View point (x,y,z)
41 0, 1, 0 # Up-vector (x,y,z)
44 # Enable Z buffering
45 glEnable( GL_DEPTH_TEST )
46 glDepthFunc( GL_LEQUAL )
48 # Rotate the entire scene
49 glRotatef( 15 * t, 0, 1, 0 )
51 # Create a GLU quadrics object
52 quadric := gluNewQuadric
54 # Draw a red sphere
55 glPushMatrix
56 glTranslatef( -5, 0, 0 )
57 glColor3f( 1, 0, 0 )
58 gluSphere( quadric, 2, 30, 30 )
59 glPopMatrix
61 # Draw a green cylinder
62 glPushMatrix
63 glRotatef( 38 * t, 1, 0, 0 )
64 glColor3f( 0, 1, 0 )
65 gluCylinder( quadric, 2, 2, 4, 30, 30 )
66 glPopMatrix
68 # Draw a blue cone
69 glPushMatrix
70 glTranslatef( 5, 0, 0 )
71 glRotatef( 20 * t, 1, 0, 0 )
72 glColor3f( 0, 0, 1 )
73 gluCylinder( quadric, 2, 0, 4, 30, 30 )
74 glPopMatrix
76 # Destroy the GLU quadrics object
77 gluDeleteQuadric( quadric )
80 glfwInit
82 glfwOpenWindow(
83 640, 480, # Width and height of window
84 8, 8, 8, # Number of red, green, and blue bits for color buffer
85 8, # Number of bits for alpha buffer
86 24, # Number of bits for depth buffer (Z-buffer)
87 0, # Number of bits for stencil buffer
88 GLFW_WINDOW # We want a desktop window (could be GLFW_FULLSCREEN)
91 glfwSetWindowTitle( "My OpenGL program" )
92 glfwEnable( GLFW_STICKY_KEYS )
94 while(glfwGetKey(GLFW_KEY_ESC) == 0 and glfwGetWindowParam(GLFW_OPENED) != 0,
95 draw
96 glfwSwapBuffers
99 glfwTerminate