1 # Port of http
://glfw
.sourceforge
.net
/tutorials
/lesson08
/lesson08
.html
11 size
:= glfwGetWindowSize
13 # Make sure that height is non
-zero to avoid division by zero
14 if(size height
< 1, size
setHeight(1))
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
)
49 glEnable( GL_DEPTH_TEST
)
50 glDepthFunc( GL_LEQUAL
)
53 glColor3f( 0.7, 1, 1 )
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 ) # -"-
63 # Create a
GLU quadrics object
64 quadric
:= gluNewQuadric
66 # Draw a blue cone in the center
68 glRotatef( -90, 1, 0, 0 )
70 gluCylinder( quadric
, 1.5, 0, 4, 30, 30 )
73 # Draw four spheres in the corners o the grid
74 glColor3f( 1, 0.2, 0 )
76 glTranslatef( -9, 1, -9 )
77 gluSphere( quadric
, 1, 30, 30 )
80 glTranslatef( 9, 1, -9 )
81 gluSphere( quadric
, 1, 30, 30 )
84 glTranslatef( -9, 1, 9 )
85 gluSphere( quadric
, 1, 30, 30 )
88 glTranslatef( 9, 1, 9 )
89 gluSphere( quadric
, 1, 30, 30 )
92 # Destroy the
GLU quadrics object
93 gluDeleteQuadric( quadric
)
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,