1 # Port of http
://glfw
.sourceforge
.net
/tutorials
/lesson07
/lesson07
.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 # 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
)
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
54 glTranslatef( -5, 0, 0 )
56 gluSphere( quadric
, 2, 30, 30 )
59 # Draw a green cylinder
61 glRotatef( 38 * t
, 1, 0, 0 )
63 gluCylinder( quadric
, 2, 2, 4, 30, 30 )
68 glTranslatef( 5, 0, 0 )
69 glRotatef( 20 * t
, 1, 0, 0 )
71 gluCylinder( quadric
, 2, 0, 4, 30, 30 )
74 # Destroy the
GLU quadrics object
75 gluDeleteQuadric( quadric
)
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,