3 # Port of http
://glfw
.sourceforge
.net
/tutorials
/lesson06
/lesson06
.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 cube about the x
and the y axis
49 glRotatef( 45 * t
, 1, 0, 0 )
50 glRotatef( 32 * t
, 0, 1, 0 )
52 # Draw the cube
: six sides with six different colors
54 glColor3f( 1, 0, 0 ) # Front side
55 glVertex3f( 2.5, -2.5, -2.5 )
56 glVertex3f( -2.5, -2.5, -2.5 )
57 glVertex3f( -2.5, 2.5, -2.5 )
58 glVertex3f( 2.5, 2.5, -2.5 )
59 glColor3f( 1, 1, 0 ) # Back side
60 glVertex3f( -2.5, -2.5, 2.5 )
61 glVertex3f( 2.5, -2.5, 2.5 )
62 glVertex3f( 2.5, 2.5, 2.5 )
63 glVertex3f( -2.5, 2.5, 2.5 )
64 glColor3f( 0, 1, 0 ) # Top
65 glVertex3f( 2.5, 2.5, -2.5 )
66 glVertex3f( -2.5, 2.5, -2.5 )
67 glVertex3f( -2.5, 2.5, 2.5 )
68 glVertex3f( 2.5, 2.5, 2.5 )
69 glColor3f( 0, 1, 1 ) # Bottom
70 glVertex3f( -2.5, -2.5, -2.5 )
71 glVertex3f( 2.5, -2.5, -2.5 )
72 glVertex3f( 2.5, -2.5, 2.5 )
73 glVertex3f( -2.5, -2.5, 2.5 )
74 glColor3f( 0, 0, 1 ) # Left
75 glVertex3f( -2.5, -2.5, -2.5 )
76 glVertex3f( -2.5, -2.5, 2.5 )
77 glVertex3f( -2.5, 2.5, 2.5 )
78 glVertex3f( -2.5, 2.5, -2.5 )
79 glColor3f( 1, 0, 1 ) # Right
80 glVertex3f( 2.5, -2.5, 2.5 )
81 glVertex3f( 2.5, -2.5, -2.5 )
82 glVertex3f( 2.5, 2.5, -2.5 )
83 glVertex3f( 2.5, 2.5, 2.5 )
90 640, 480, # Width
and height of window
91 8, 8, 8, # Number of red
, green
, and blue bits
for color buffer
92 8, # Number of bits
for alpha buffer
93 24, # Number of bits
for depth
buffer (Z
-buffer
)
94 0, # Number of bits
for stencil buffer
95 GLFW_WINDOW
# We want a desktop
window (could be GLFW_FULLSCREEN
)
98 glfwSetWindowTitle( "My OpenGL program" )
99 glfwEnable( GLFW_STICKY_KEYS
)
101 while(glfwGetKey(GLFW_KEY_ESC
) == 0 and glfwGetWindowParam(GLFW_OPENED
) != 0,