3 # Port of http
://glfw
.sourceforge
.net
/tutorials
/lesson07
/lesson07
.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 # Set up projection matrix
26 glMatrixMode( GL_PROJECTION
) # Select projection matrix
27 glLoadIdentity
# Start with an identity matrix
28 gluPerspective( # Set perspective view
29 65, # Field of view
= 65 degrees
30 size width
/ size height
, # Window
aspect (assumes square pixels
)
31 1, # Near Z clipping plane
32 100 # Far Z clippling plane
35 # Set up modelview matrix
36 glMatrixMode( GL_MODELVIEW
) # Select modelview matrix
37 glLoadIdentity
# Start with an identity matrix
38 gluLookAt( # Set camera position
and orientation
39 0, 0, 10, # Camera
position (x
,y
,z
)
40 0, 0, 0, # View
point (x
,y
,z
)
41 0, 1, 0 # Up
-vector (x
,y
,z
)
45 glEnable( GL_DEPTH_TEST
)
46 glDepthFunc( GL_LEQUAL
)
48 # Rotate the entire scene
49 glRotatef( 15 * t
, 0, 1, 0 )
51 # Create a
GLU quadrics object
52 quadric
:= gluNewQuadric
56 glTranslatef( -5, 0, 0 )
58 gluSphere( quadric
, 2, 30, 30 )
61 # Draw a green cylinder
63 glRotatef( 38 * t
, 1, 0, 0 )
65 gluCylinder( quadric
, 2, 2, 4, 30, 30 )
70 glTranslatef( 5, 0, 0 )
71 glRotatef( 20 * t
, 1, 0, 0 )
73 gluCylinder( quadric
, 2, 0, 4, 30, 30 )
76 # Destroy the
GLU quadrics object
77 gluDeleteQuadric( quadric
)
83 640, 480, # Width
and height of window
84 8, 8, 8, # Number of red
, green
, and blue bits
for color buffer
85 8, # Number of bits
for alpha buffer
86 24, # Number of bits
for depth
buffer (Z
-buffer
)
87 0, # Number of bits
for stencil buffer
88 GLFW_WINDOW
# We want a desktop
window (could be GLFW_FULLSCREEN
)
91 glfwSetWindowTitle( "My OpenGL program" )
92 glfwEnable( GLFW_STICKY_KEYS
)
94 while(glfwGetKey(GLFW_KEY_ESC
) == 0 and glfwGetWindowParam(GLFW_OPENED
) != 0,