Change parser to do C style () for operators: 1+2*3 == 1+(2)*3
[io/jrb1.git] / addons / GLFW / samples / lesson08.io
blob31925f4d9b77f551b69b447c4319cd63e425df12
1 # Port of http://glfw.sourceforge.net/tutorials/lesson08/lesson08.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 # Calculate field of view as a function of time
24 fieldOfView := (0.5 * t) sin * 30 + 50;
26 # Set up projection matrix
27 glMatrixMode( GL_PROJECTION ) # Select projection matrix
28 glLoadIdentity # Start with an identity matrix
29 gluPerspective( # Set perspective view
30 fieldOfView, # Field of view
31 size width / size height, # Window aspect (assumes square pixels)
32 1, # Near Z clipping plane
33 100 # Far Z clippling plane
36 # Calculate camera position
37 camera := vector((0.3 * t) cos * 20, (0.3 * t) sin * 20, t sin + 4)
39 # Set up modelview matrix
40 glMatrixMode( GL_MODELVIEW ) # Select modelview matrix
41 glLoadIdentity # Start with an identity matrix
42 gluLookAt( # Set camera position and orientation
43 camera x, camera y, camera z, # Camera position (x,y,z)
44 0, 0, 0, # View point (x,y,z)
45 0, 1, 0 # Up-vector (x,y,z)
48 # Enable Z buffering
49 glEnable( GL_DEPTH_TEST )
50 glDepthFunc( GL_LEQUAL )
52 # Draw a grid
53 glColor3f( 0.7, 1, 1 )
54 glBegin( GL_LINES )
55 (-10) to(10) foreach(i,
56 glVertex3f( -10, 0, i ) # Line along X axis
57 glVertex3f( 10, 0, i ) # -"-
58 glVertex3f( i, 0, -10 ) # Line along Z axis
59 glVertex3f( i, 0, 10 ) # -"-
61 glEnd
63 # Create a GLU quadrics object
64 quadric := gluNewQuadric
66 # Draw a blue cone in the center
67 glPushMatrix
68 glRotatef( -90, 1, 0, 0 )
69 glColor3f( 0, 0, 1 )
70 gluCylinder( quadric, 1.5, 0, 4, 30, 30 )
71 glPopMatrix
73 # Draw four spheres in the corners o the grid
74 glColor3f( 1, 0.2, 0 )
75 glPushMatrix
76 glTranslatef( -9, 1, -9 )
77 gluSphere( quadric, 1, 30, 30 )
78 glPopMatrix
79 glPushMatrix
80 glTranslatef( 9, 1, -9 )
81 gluSphere( quadric, 1, 30, 30 )
82 glPopMatrix
83 glPushMatrix
84 glTranslatef( -9, 1, 9 )
85 gluSphere( quadric, 1, 30, 30 )
86 glPopMatrix
87 glPushMatrix
88 glTranslatef( 9, 1, 9 )
89 gluSphere( quadric, 1, 30, 30 )
90 glPopMatrix
92 # Destroy the GLU quadrics object
93 gluDeleteQuadric( quadric )
96 glfwInit
98 glfwOpenWindow(
99 640, 480, # Width and height of window
100 8, 8, 8, # Number of red, green, and blue bits for color buffer
101 8, # Number of bits for alpha buffer
102 24, # Number of bits for depth buffer (Z-buffer)
103 0, # Number of bits for stencil buffer
104 GLFW_WINDOW # We want a desktop window (could be GLFW_FULLSCREEN)
107 glfwSetWindowTitle( "My OpenGL program" )
108 glfwEnable( GLFW_STICKY_KEYS )
110 while(glfwGetKey(GLFW_KEY_ESC) == 0 and glfwGetWindowParam(GLFW_OPENED) != 0,
111 draw
112 glfwSwapBuffers
115 glfwTerminate