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