3 # Port of http
://glfw
.sourceforge
.net
/tutorials
/lesson08
/lesson08
.html
13 size
:= glfwGetWindowSize
15 # Make sure that height is non
-zero to avoid division by zero
16 if(size height
< 1, size
setHeight(1))
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 # Calculate field of view as a function of time
26 fieldOfView
:= (0.5 * t
) sin
* 30 + 50;
28 # Set up projection matrix
29 glMatrixMode( GL_PROJECTION
) # Select projection matrix
30 glLoadIdentity
# Start with an identity matrix
31 gluPerspective( # Set perspective view
32 fieldOfView
, # Field of view
33 size width
/ size height
, # Window
aspect (assumes square pixels
)
34 1, # Near Z clipping plane
35 100 # Far Z clippling plane
38 # Calculate camera position
39 camera
:= vector((0.3 * t
) cos
* 20, (0.3 * t
) sin
* 20, t sin
+ 4)
41 # Set up modelview matrix
42 glMatrixMode( GL_MODELVIEW
) # Select modelview matrix
43 glLoadIdentity
# Start with an identity matrix
44 gluLookAt( # Set camera position
and orientation
45 camera x
, camera y
, camera z
, # Camera
position (x
,y
,z
)
46 0, 0, 0, # View
point (x
,y
,z
)
47 0, 1, 0 # Up
-vector (x
,y
,z
)
51 glEnable( GL_DEPTH_TEST
)
52 glDepthFunc( GL_LEQUAL
)
55 glColor3f( 0.7, 1, 1 )
57 (-10) to(10) foreach(i
,
58 glVertex3f( -10, 0, i
) # Line along X axis
59 glVertex3f( 10, 0, i
) # -"-
60 glVertex3f( i, 0, -10 ) # Line along Z axis
61 glVertex3f( i, 0, 10 ) # -"-
65 # Create a
GLU quadrics object
66 quadric
:= gluNewQuadric
68 # Draw a blue cone in the center
70 glRotatef( -90, 1, 0, 0 )
72 gluCylinder( quadric
, 1.5, 0, 4, 30, 30 )
75 # Draw four spheres in the corners o the grid
76 glColor3f( 1, 0.2, 0 )
78 glTranslatef( -9, 1, -9 )
79 gluSphere( quadric
, 1, 30, 30 )
82 glTranslatef( 9, 1, -9 )
83 gluSphere( quadric
, 1, 30, 30 )
86 glTranslatef( -9, 1, 9 )
87 gluSphere( quadric
, 1, 30, 30 )
90 glTranslatef( 9, 1, 9 )
91 gluSphere( quadric
, 1, 30, 30 )
94 # Destroy the
GLU quadrics object
95 gluDeleteQuadric( quadric
)
101 640, 480, # Width
and height of window
102 8, 8, 8, # Number of red
, green
, and blue bits
for color buffer
103 8, # Number of bits
for alpha buffer
104 24, # Number of bits
for depth
buffer (Z
-buffer
)
105 0, # Number of bits
for stencil buffer
106 GLFW_WINDOW
# We want a desktop
window (could be GLFW_FULLSCREEN
)
109 glfwSetWindowTitle( "My OpenGL program" )
110 glfwEnable( GLFW_STICKY_KEYS
)
112 while(glfwGetKey(GLFW_KEY_ESC
) == 0 and glfwGetWindowParam(GLFW_OPENED
) != 0,