SlideShare a Scribd company logo
1 of 10
Download to read offline
Ring Documentation, Release 1.7
angle = 0
red=1.0
blue=1.0
green=1.0
func main
// init GLUT and create window
glutInit()
glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA)
glutInitWindowPosition(100,100)
glutInitWindowSize(320,320)
glutCreateWindow("RingFreeGLUT - Test 6")
glutDisplayFunc(:renderScene)
glutReshapeFunc(:changeSize)
glutIdleFunc(:renderScene)
// here are the new entries
glutKeyboardFunc(:processNormalKeys)
glutSpecialFunc(:processSpecialKeys)
glutMainLoop()
func renderScene
// Clear Color and Depth Buffers
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
// Reset transformations
glLoadIdentity()
// Set the camera
gluLookAt( 0.0, 0.0, 10.0,
0.0, 0.0, 0.0,
0.0, 1.0, 0.0)
glRotatef(angle, 0.0, 1.0, 0.0)
glColor3f(red,green,blue);
glBegin(GL_TRIANGLES)
glVertex3f(-2.0,-2.0, 0.0)
glVertex3f( 2.0, 0.0, 0.0)
glVertex3f( 0.0, 2.0, 0.0)
glEnd()
angle+=0.1
glutSwapBuffers();
func changesize
h = glutEventHeight()
w = glutEventWidth()
// Prevent a divide by zero, when window is too short
57.9. Keyboard Events and Colors 552
Ring Documentation, Release 1.7
// (you cant make a window of zero width).
if (h = 0)
h = 1
ok
ratio = w * 1.0 / h
// Use the Projection Matrix
glMatrixMode(GL_PROJECTION)
// Reset Matrix
glLoadIdentity()
// Set the viewport to be the entire window
glViewport(0, 0, w, h)
// Set the correct perspective.
gluPerspective(45,ratio,1,100)
// Get Back to the Modelview
glMatrixMode(GL_MODELVIEW)
func processNormalKeys
key = GLUTEventKey()
if key = 27
shutdown()
ok
func processSpecialKeys
key = GLUTEventKey()
switch key
on GLUT_KEY_F1
red = 1.0
green = 0.0
blue = 0.0
on GLUT_KEY_F2
red = 0.0
green = 1.0
blue = 0.0
on GLUT_KEY_F3
red = 0.0
green = 0.0
blue = 1.0
off
Screen Shot
57.9. Keyboard Events and Colors 553
Ring Documentation, Release 1.7
57.10 The Camera
Example:
load "freeglut.ring"
load "opengl21lib.ring"
// angle of rotation for the camera direction
angle=0.0
// actual vector representing the camera's direction
lx=0.0
lz=-1.0
// XZ position of the camera
x=0.0
z=5.0
func drawSnowMan
glColor3f(1.0, 1.0, 1.0)
// Draw Body
glTranslatef(0.0 ,0.75, 0.0)
glutSolidSphere(0.75,20,20)
// Draw Head
glTranslatef(0.0, 1.0, 0.0)
glutSolidSphere(0.25,20,20)
// Draw Eyes
glPushMatrix()
glColor3f(0.0,0.0,0.0)
glTranslatef(0.05, 0.10, 0.18)
57.10. The Camera 554
Ring Documentation, Release 1.7
glutSolidSphere(0.05,10,10)
glTranslatef(-0.1, 0.0, 0.0)
glutSolidSphere(0.05,10,10)
glPopMatrix()
// Draw Nose
glColor3f(1.0, 0.5 , 0.5)
glutSolidCone(0.08,0.5,10,2)
func changeSize
w = glutEventWidth()
h = glutEventHeight()
// Prevent a divide by zero, when window is too short
// (you cant make a window of zero width).
if h = 0
h = 1
ok
ratio = w * 1.0 / h
// Use the Projection Matrix
glMatrixMode(GL_PROJECTION)
// Reset Matrix
glLoadIdentity()
// Set the viewport to be the entire window
glViewport(0, 0, w, h)
// Set the correct perspective.
gluPerspective(45.0, ratio, 0.1, 100.0);
// Get Back to the Modelview
glMatrixMode(GL_MODELVIEW)
func processNormalKeys
key = glutEventKey()
if key = 27
shutdown()
ok
func renderScene
// Clear Color and Depth Buffers
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
// Reset transformations
glLoadIdentity()
// Set the camera
57.10. The Camera 555
Ring Documentation, Release 1.7
gluLookAt( x, 1.0, z,
x+lx, 1.0, z+lz,
0.0, 1.0, 0.0)
// Draw ground
glColor3f(0.9, 0.9, 0.9)
glBegin(GL_QUADS)
glVertex3f(-100.0, 0.0, -100.0)
glVertex3f(-100.0, 0.0, 100.0)
glVertex3f( 100.0, 0.0, 100.0)
glVertex3f( 100.0, 0.0, -100.0)
glEnd()
// Draw 36 SnowMen
for i = -3 to 2
for j=-3 to 2
glPushMatrix()
glTranslatef(i*10.0,0,j * 10.0)
drawSnowMan()
glPopMatrix()
next
next
glutSwapBuffers()
func processSpecialKeys
key = glutEventKey()
fraction = 0.1
switch key
on GLUT_KEY_LEFT
angle -= 0.01
lx = sin(angle)
lz = -cos(angle)
on GLUT_KEY_RIGHT
angle += 0.01
lx = sin(angle)
lz = -cos(angle)
on GLUT_KEY_UP
x += lx * fraction
z += lz * fraction
on GLUT_KEY_DOWN
x -= lx * fraction
z -= lz * fraction
off
func main
// init GLUT and create window
glutInit()
glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA)
57.10. The Camera 556
Ring Documentation, Release 1.7
glutInitWindowPosition(100,100)
glutInitWindowSize(320,320)
glutCreateWindow("RingFreeGLUT - Test 7")
// register callbacks
glutDisplayFunc(:renderScene)
glutReshapeFunc(:changeSize)
glutIdleFunc(:renderScene)
glutKeyboardFunc(:processNormalKeys)
glutSpecialFunc(:processSpecialKeys)
// OpenGL init
glEnable(GL_DEPTH_TEST)
// enter GLUT event processing cycle
glutMainLoop()
Screen Shot
Another Example:
load "freeglut.ring"
load "opengl21lib.ring"
// angle of rotation for the camera direction
angle = 0.0
// actual vector representing the camera's direction
lx=0.0 lz=-1.0
// XZ position of the camera
x=0.0 z=5.0
// the key states. These variables will be zero
//when no key is being presses
deltaAngle = 0.0
57.10. The Camera 557
Ring Documentation, Release 1.7
deltaMove = 0
func changeSize
w = glutEventWidth()
h = glutEventHeight()
// Prevent a divide by zero, when window is too short
// (you cant make a window of zero width).
if h = 0
h = 1
ok
ratio = w * 1.0 / h
// Use the Projection Matrix
glMatrixMode(GL_PROJECTION)
// Reset Matrix
glLoadIdentity()
// Set the viewport to be the entire window
glViewport(0, 0, w, h)
// Set the correct perspective.
gluPerspective(45.0, ratio, 0.1, 100.0)
// Get Back to the Modelview
glMatrixMode(GL_MODELVIEW)
func drawSnowMan
glColor3f(1.0, 1.0, 1.0)
// Draw Body
glTranslatef(0.0 ,0.75, 0.0)
glutSolidSphere(0.75,20,20)
// Draw Head
glTranslatef(0.0, 1.0, 0.0)
glutSolidSphere(0.25,20,20)
// Draw Eyes
glPushMatrix()
glColor3f(0.0,0.0,0.0)
glTranslatef(0.05, 0.10, 0.18)
glutSolidSphere(0.05,10,10)
glTranslatef(-0.1, 0.0, 0.0)
glutSolidSphere(0.05,10,10)
glPopMatrix()
// Draw Nose
glColor3f(1.0, 0.5 , 0.5)
glRotatef(0.0,1.0, 0.0, 0.0)
glutSolidCone(0.08,0.5,10,2)
57.10. The Camera 558
Ring Documentation, Release 1.7
func computePos deltaMove
x += deltaMove * lx * 0.1
z += deltaMove * lz * 0.1
func computeDir deltaAngle
angle += deltaAngle
lx = sin(angle)
lz = -cos(angle)
func renderScene
if deltaMove
computePos(deltaMove)
ok
if deltaAngle
computeDir(deltaAngle)
ok
// Clear Color and Depth Buffers
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
// Reset transformations
glLoadIdentity()
// Set the camera
gluLookAt( x, 1.0, z,
x+lx, 1.0, z+lz,
0.0, 1.0, 0.0)
// Draw ground
glColor3f(0.9, 0.9, 0.9)
glBegin(GL_QUADS)
glVertex3f(-100.0, 0.0, -100.0)
glVertex3f(-100.0, 0.0, 100.0)
glVertex3f( 100.0, 0.0, 100.0)
glVertex3f( 100.0, 0.0, -100.0)
glEnd()
// Draw 36 SnowMen
for i = -3 to 2
for j=-3 to 2
glPushMatrix()
glTranslatef(i*10.0,0,j * 10.0)
drawSnowMan()
glPopMatrix()
next
next
glutSwapBuffers()
func pressKey
key = glutEventKey()
xx = glutEventX()
57.10. The Camera 559
Ring Documentation, Release 1.7
yy = glutEventY()
switch key
on GLUT_KEY_LEFT
deltaAngle = -0.01
on GLUT_KEY_RIGHT
deltaAngle = 0.01
on GLUT_KEY_UP
deltaMove = 0.5
on GLUT_KEY_DOWN
deltaMove = -0.5
off
func releaseKey
key = glutEventKey()
switch key
on GLUT_KEY_LEFT
deltaAngle = 0.0
on GLUT_KEY_RIGHT
deltaAngle = 0.0
on GLUT_KEY_UP
deltaMove = 0
on GLUT_KEY_DOWN
deltaMove = 0
off
func main
// init GLUT and create window
glutInit()
glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA)
glutInitWindowPosition(100,100)
glutInitWindowSize(320,320)
glutCreateWindow("RingFreeGLUT - Test 8")
// register callbacks
glutDisplayFunc(:renderScene)
glutReshapeFunc(:changeSize)
glutIdleFunc(:renderScene)
glutSpecialFunc(:pressKey)
// here are the new entries
glutIgnoreKeyRepeat(1)
glutSpecialUpFunc(:releaseKey)
// OpenGL init
glEnable(GL_DEPTH_TEST)
// enter GLUT event processing cycle
glutMainLoop()
57.10. The Camera 560
Ring Documentation, Release 1.7
57.11 Mouse Events
Example:
load "freeglut.ring"
load "opengl21lib.ring"
// angle of rotation for the camera direction
angle = 0.0
// actual vector representing the camera's direction
lx=0.0 lz=-1.0
// XZ position of the camera
x=0.0 z=5.0
// the key states. These variables will be zero
//when no key is being presses
deltaAngle = 0.0
deltaMove = 0.0
xOrigin = -1
func changeSize
w = glutEventWidth()
h = glutEventHeight()
// Prevent a divide by zero, when window is too short
// (you cant make a window of zero width).
if h = 0
h = 1
ok
ratio = w * 1.0 / h
// Use the Projection Matrix
glMatrixMode(GL_PROJECTION)
// Reset Matrix
glLoadIdentity()
// Set the viewport to be the entire window
glViewport(0, 0, w, h)
// Set the correct perspective.
gluPerspective(45.0, ratio, 0.1, 100.0)
// Get Back to the Modelview
glMatrixMode(GL_MODELVIEW)
func drawSnowMan
glColor3f(1.0, 1.0, 1.0)
// Draw Body
glTranslatef(0.0 ,0.75, 0.0)
glutSolidSphere(0.75,20,20)
57.11. Mouse Events 561

More Related Content

What's hot

The Ring programming language version 1.10 book - Part 66 of 212
The Ring programming language version 1.10 book - Part 66 of 212The Ring programming language version 1.10 book - Part 66 of 212
The Ring programming language version 1.10 book - Part 66 of 212Mahmoud Samir Fayed
 
The Ring programming language version 1.9 book - Part 65 of 210
The Ring programming language version 1.9 book - Part 65 of 210The Ring programming language version 1.9 book - Part 65 of 210
The Ring programming language version 1.9 book - Part 65 of 210Mahmoud Samir Fayed
 
The Ring programming language version 1.7 book - Part 60 of 196
The Ring programming language version 1.7 book - Part 60 of 196The Ring programming language version 1.7 book - Part 60 of 196
The Ring programming language version 1.7 book - Part 60 of 196Mahmoud Samir Fayed
 
The Ring programming language version 1.8 book - Part 62 of 202
The Ring programming language version 1.8 book - Part 62 of 202The Ring programming language version 1.8 book - Part 62 of 202
The Ring programming language version 1.8 book - Part 62 of 202Mahmoud Samir Fayed
 
The Ring programming language version 1.5.3 book - Part 65 of 184
The Ring programming language version 1.5.3 book - Part 65 of 184The Ring programming language version 1.5.3 book - Part 65 of 184
The Ring programming language version 1.5.3 book - Part 65 of 184Mahmoud Samir Fayed
 
The Ring programming language version 1.5.1 book - Part 53 of 180
The Ring programming language version 1.5.1 book - Part 53 of 180The Ring programming language version 1.5.1 book - Part 53 of 180
The Ring programming language version 1.5.1 book - Part 53 of 180Mahmoud Samir Fayed
 
The Ring programming language version 1.10 book - Part 67 of 212
The Ring programming language version 1.10 book - Part 67 of 212The Ring programming language version 1.10 book - Part 67 of 212
The Ring programming language version 1.10 book - Part 67 of 212Mahmoud Samir Fayed
 
The Ring programming language version 1.9 book - Part 64 of 210
The Ring programming language version 1.9 book - Part 64 of 210The Ring programming language version 1.9 book - Part 64 of 210
The Ring programming language version 1.9 book - Part 64 of 210Mahmoud Samir Fayed
 
The Ring programming language version 1.7 book - Part 62 of 196
The Ring programming language version 1.7 book - Part 62 of 196The Ring programming language version 1.7 book - Part 62 of 196
The Ring programming language version 1.7 book - Part 62 of 196Mahmoud Samir Fayed
 
The Ring programming language version 1.6 book - Part 56 of 189
The Ring programming language version 1.6 book - Part 56 of 189The Ring programming language version 1.6 book - Part 56 of 189
The Ring programming language version 1.6 book - Part 56 of 189Mahmoud Samir Fayed
 
The Ring programming language version 1.5.2 book - Part 53 of 181
The Ring programming language version 1.5.2 book - Part 53 of 181The Ring programming language version 1.5.2 book - Part 53 of 181
The Ring programming language version 1.5.2 book - Part 53 of 181Mahmoud Samir Fayed
 
The Ring programming language version 1.9 book - Part 67 of 210
The Ring programming language version 1.9 book - Part 67 of 210The Ring programming language version 1.9 book - Part 67 of 210
The Ring programming language version 1.9 book - Part 67 of 210Mahmoud Samir Fayed
 
The Ring programming language version 1.5.3 book - Part 64 of 184
The Ring programming language version 1.5.3 book - Part 64 of 184The Ring programming language version 1.5.3 book - Part 64 of 184
The Ring programming language version 1.5.3 book - Part 64 of 184Mahmoud Samir Fayed
 
The Ring programming language version 1.9 book - Part 66 of 210
The Ring programming language version 1.9 book - Part 66 of 210The Ring programming language version 1.9 book - Part 66 of 210
The Ring programming language version 1.9 book - Part 66 of 210Mahmoud Samir Fayed
 
The Ring programming language version 1.6 book - Part 58 of 189
The Ring programming language version 1.6 book - Part 58 of 189The Ring programming language version 1.6 book - Part 58 of 189
The Ring programming language version 1.6 book - Part 58 of 189Mahmoud Samir Fayed
 
The Ring programming language version 1.8 book - Part 60 of 202
The Ring programming language version 1.8 book - Part 60 of 202The Ring programming language version 1.8 book - Part 60 of 202
The Ring programming language version 1.8 book - Part 60 of 202Mahmoud Samir Fayed
 
The Ring programming language version 1.8 book - Part 12 of 202
The Ring programming language version 1.8 book - Part 12 of 202The Ring programming language version 1.8 book - Part 12 of 202
The Ring programming language version 1.8 book - Part 12 of 202Mahmoud Samir Fayed
 
The Ring programming language version 1.9 book - Part 14 of 210
The Ring programming language version 1.9 book - Part 14 of 210The Ring programming language version 1.9 book - Part 14 of 210
The Ring programming language version 1.9 book - Part 14 of 210Mahmoud Samir Fayed
 
The Ring programming language version 1.5 book - Part 10 of 31
The Ring programming language version 1.5 book - Part 10 of 31The Ring programming language version 1.5 book - Part 10 of 31
The Ring programming language version 1.5 book - Part 10 of 31Mahmoud Samir Fayed
 

What's hot (20)

The Ring programming language version 1.10 book - Part 66 of 212
The Ring programming language version 1.10 book - Part 66 of 212The Ring programming language version 1.10 book - Part 66 of 212
The Ring programming language version 1.10 book - Part 66 of 212
 
The Ring programming language version 1.9 book - Part 65 of 210
The Ring programming language version 1.9 book - Part 65 of 210The Ring programming language version 1.9 book - Part 65 of 210
The Ring programming language version 1.9 book - Part 65 of 210
 
The Ring programming language version 1.7 book - Part 60 of 196
The Ring programming language version 1.7 book - Part 60 of 196The Ring programming language version 1.7 book - Part 60 of 196
The Ring programming language version 1.7 book - Part 60 of 196
 
The Ring programming language version 1.8 book - Part 62 of 202
The Ring programming language version 1.8 book - Part 62 of 202The Ring programming language version 1.8 book - Part 62 of 202
The Ring programming language version 1.8 book - Part 62 of 202
 
The Ring programming language version 1.5.3 book - Part 65 of 184
The Ring programming language version 1.5.3 book - Part 65 of 184The Ring programming language version 1.5.3 book - Part 65 of 184
The Ring programming language version 1.5.3 book - Part 65 of 184
 
The Ring programming language version 1.5.1 book - Part 53 of 180
The Ring programming language version 1.5.1 book - Part 53 of 180The Ring programming language version 1.5.1 book - Part 53 of 180
The Ring programming language version 1.5.1 book - Part 53 of 180
 
The Ring programming language version 1.10 book - Part 67 of 212
The Ring programming language version 1.10 book - Part 67 of 212The Ring programming language version 1.10 book - Part 67 of 212
The Ring programming language version 1.10 book - Part 67 of 212
 
Working with Callbacks
Working with CallbacksWorking with Callbacks
Working with Callbacks
 
The Ring programming language version 1.9 book - Part 64 of 210
The Ring programming language version 1.9 book - Part 64 of 210The Ring programming language version 1.9 book - Part 64 of 210
The Ring programming language version 1.9 book - Part 64 of 210
 
The Ring programming language version 1.7 book - Part 62 of 196
The Ring programming language version 1.7 book - Part 62 of 196The Ring programming language version 1.7 book - Part 62 of 196
The Ring programming language version 1.7 book - Part 62 of 196
 
The Ring programming language version 1.6 book - Part 56 of 189
The Ring programming language version 1.6 book - Part 56 of 189The Ring programming language version 1.6 book - Part 56 of 189
The Ring programming language version 1.6 book - Part 56 of 189
 
The Ring programming language version 1.5.2 book - Part 53 of 181
The Ring programming language version 1.5.2 book - Part 53 of 181The Ring programming language version 1.5.2 book - Part 53 of 181
The Ring programming language version 1.5.2 book - Part 53 of 181
 
The Ring programming language version 1.9 book - Part 67 of 210
The Ring programming language version 1.9 book - Part 67 of 210The Ring programming language version 1.9 book - Part 67 of 210
The Ring programming language version 1.9 book - Part 67 of 210
 
The Ring programming language version 1.5.3 book - Part 64 of 184
The Ring programming language version 1.5.3 book - Part 64 of 184The Ring programming language version 1.5.3 book - Part 64 of 184
The Ring programming language version 1.5.3 book - Part 64 of 184
 
The Ring programming language version 1.9 book - Part 66 of 210
The Ring programming language version 1.9 book - Part 66 of 210The Ring programming language version 1.9 book - Part 66 of 210
The Ring programming language version 1.9 book - Part 66 of 210
 
The Ring programming language version 1.6 book - Part 58 of 189
The Ring programming language version 1.6 book - Part 58 of 189The Ring programming language version 1.6 book - Part 58 of 189
The Ring programming language version 1.6 book - Part 58 of 189
 
The Ring programming language version 1.8 book - Part 60 of 202
The Ring programming language version 1.8 book - Part 60 of 202The Ring programming language version 1.8 book - Part 60 of 202
The Ring programming language version 1.8 book - Part 60 of 202
 
The Ring programming language version 1.8 book - Part 12 of 202
The Ring programming language version 1.8 book - Part 12 of 202The Ring programming language version 1.8 book - Part 12 of 202
The Ring programming language version 1.8 book - Part 12 of 202
 
The Ring programming language version 1.9 book - Part 14 of 210
The Ring programming language version 1.9 book - Part 14 of 210The Ring programming language version 1.9 book - Part 14 of 210
The Ring programming language version 1.9 book - Part 14 of 210
 
The Ring programming language version 1.5 book - Part 10 of 31
The Ring programming language version 1.5 book - Part 10 of 31The Ring programming language version 1.5 book - Part 10 of 31
The Ring programming language version 1.5 book - Part 10 of 31
 

Similar to The Ring programming language version 1.7 book - Part 59 of 196

The Ring programming language version 1.5.1 book - Part 54 of 180
The Ring programming language version 1.5.1 book - Part 54 of 180The Ring programming language version 1.5.1 book - Part 54 of 180
The Ring programming language version 1.5.1 book - Part 54 of 180Mahmoud Samir Fayed
 
The Ring programming language version 1.5.2 book - Part 55 of 181
The Ring programming language version 1.5.2 book - Part 55 of 181The Ring programming language version 1.5.2 book - Part 55 of 181
The Ring programming language version 1.5.2 book - Part 55 of 181Mahmoud Samir Fayed
 
The Ring programming language version 1.5.4 book - Part 54 of 185
The Ring programming language version 1.5.4 book - Part 54 of 185The Ring programming language version 1.5.4 book - Part 54 of 185
The Ring programming language version 1.5.4 book - Part 54 of 185Mahmoud Samir Fayed
 
The Ring programming language version 1.8 book - Part 64 of 202
The Ring programming language version 1.8 book - Part 64 of 202The Ring programming language version 1.8 book - Part 64 of 202
The Ring programming language version 1.8 book - Part 64 of 202Mahmoud Samir Fayed
 
The Ring programming language version 1.8 book - Part 63 of 202
The Ring programming language version 1.8 book - Part 63 of 202The Ring programming language version 1.8 book - Part 63 of 202
The Ring programming language version 1.8 book - Part 63 of 202Mahmoud Samir Fayed
 
The Ring programming language version 1.5.2 book - Part 8 of 181
The Ring programming language version 1.5.2 book - Part 8 of 181The Ring programming language version 1.5.2 book - Part 8 of 181
The Ring programming language version 1.5.2 book - Part 8 of 181Mahmoud Samir Fayed
 
The Ring programming language version 1.5.1 book - Part 55 of 180
The Ring programming language version 1.5.1 book - Part 55 of 180The Ring programming language version 1.5.1 book - Part 55 of 180
The Ring programming language version 1.5.1 book - Part 55 of 180Mahmoud Samir Fayed
 
The Ring programming language version 1.5.1 book - Part 56 of 180
The Ring programming language version 1.5.1 book - Part 56 of 180The Ring programming language version 1.5.1 book - Part 56 of 180
The Ring programming language version 1.5.1 book - Part 56 of 180Mahmoud Samir Fayed
 
The Ring programming language version 1.5.1 book - Part 52 of 180
The Ring programming language version 1.5.1 book - Part 52 of 180The Ring programming language version 1.5.1 book - Part 52 of 180
The Ring programming language version 1.5.1 book - Part 52 of 180Mahmoud Samir Fayed
 
Tutorial Open GL (Listing Code)
Tutorial Open GL (Listing Code)Tutorial Open GL (Listing Code)
Tutorial Open GL (Listing Code)Aila Gema Safitri
 
Intro to Computer Graphics.ppt
Intro to Computer Graphics.pptIntro to Computer Graphics.ppt
Intro to Computer Graphics.pptadil104135
 

Similar to The Ring programming language version 1.7 book - Part 59 of 196 (12)

The Ring programming language version 1.5.1 book - Part 54 of 180
The Ring programming language version 1.5.1 book - Part 54 of 180The Ring programming language version 1.5.1 book - Part 54 of 180
The Ring programming language version 1.5.1 book - Part 54 of 180
 
The Ring programming language version 1.5.2 book - Part 55 of 181
The Ring programming language version 1.5.2 book - Part 55 of 181The Ring programming language version 1.5.2 book - Part 55 of 181
The Ring programming language version 1.5.2 book - Part 55 of 181
 
The Ring programming language version 1.5.4 book - Part 54 of 185
The Ring programming language version 1.5.4 book - Part 54 of 185The Ring programming language version 1.5.4 book - Part 54 of 185
The Ring programming language version 1.5.4 book - Part 54 of 185
 
The Ring programming language version 1.8 book - Part 64 of 202
The Ring programming language version 1.8 book - Part 64 of 202The Ring programming language version 1.8 book - Part 64 of 202
The Ring programming language version 1.8 book - Part 64 of 202
 
The Ring programming language version 1.8 book - Part 63 of 202
The Ring programming language version 1.8 book - Part 63 of 202The Ring programming language version 1.8 book - Part 63 of 202
The Ring programming language version 1.8 book - Part 63 of 202
 
The Ring programming language version 1.5.2 book - Part 8 of 181
The Ring programming language version 1.5.2 book - Part 8 of 181The Ring programming language version 1.5.2 book - Part 8 of 181
The Ring programming language version 1.5.2 book - Part 8 of 181
 
The Ring programming language version 1.5.1 book - Part 55 of 180
The Ring programming language version 1.5.1 book - Part 55 of 180The Ring programming language version 1.5.1 book - Part 55 of 180
The Ring programming language version 1.5.1 book - Part 55 of 180
 
The Ring programming language version 1.5.1 book - Part 56 of 180
The Ring programming language version 1.5.1 book - Part 56 of 180The Ring programming language version 1.5.1 book - Part 56 of 180
The Ring programming language version 1.5.1 book - Part 56 of 180
 
The Ring programming language version 1.5.1 book - Part 52 of 180
The Ring programming language version 1.5.1 book - Part 52 of 180The Ring programming language version 1.5.1 book - Part 52 of 180
The Ring programming language version 1.5.1 book - Part 52 of 180
 
Tutorial Open GL (Listing Code)
Tutorial Open GL (Listing Code)Tutorial Open GL (Listing Code)
Tutorial Open GL (Listing Code)
 
opengl.ppt
opengl.pptopengl.ppt
opengl.ppt
 
Intro to Computer Graphics.ppt
Intro to Computer Graphics.pptIntro to Computer Graphics.ppt
Intro to Computer Graphics.ppt
 

More from Mahmoud Samir Fayed

The Ring programming language version 1.10 book - Part 212 of 212
The Ring programming language version 1.10 book - Part 212 of 212The Ring programming language version 1.10 book - Part 212 of 212
The Ring programming language version 1.10 book - Part 212 of 212Mahmoud Samir Fayed
 
The Ring programming language version 1.10 book - Part 211 of 212
The Ring programming language version 1.10 book - Part 211 of 212The Ring programming language version 1.10 book - Part 211 of 212
The Ring programming language version 1.10 book - Part 211 of 212Mahmoud Samir Fayed
 
The Ring programming language version 1.10 book - Part 210 of 212
The Ring programming language version 1.10 book - Part 210 of 212The Ring programming language version 1.10 book - Part 210 of 212
The Ring programming language version 1.10 book - Part 210 of 212Mahmoud Samir Fayed
 
The Ring programming language version 1.10 book - Part 208 of 212
The Ring programming language version 1.10 book - Part 208 of 212The Ring programming language version 1.10 book - Part 208 of 212
The Ring programming language version 1.10 book - Part 208 of 212Mahmoud Samir Fayed
 
The Ring programming language version 1.10 book - Part 207 of 212
The Ring programming language version 1.10 book - Part 207 of 212The Ring programming language version 1.10 book - Part 207 of 212
The Ring programming language version 1.10 book - Part 207 of 212Mahmoud Samir Fayed
 
The Ring programming language version 1.10 book - Part 205 of 212
The Ring programming language version 1.10 book - Part 205 of 212The Ring programming language version 1.10 book - Part 205 of 212
The Ring programming language version 1.10 book - Part 205 of 212Mahmoud Samir Fayed
 
The Ring programming language version 1.10 book - Part 206 of 212
The Ring programming language version 1.10 book - Part 206 of 212The Ring programming language version 1.10 book - Part 206 of 212
The Ring programming language version 1.10 book - Part 206 of 212Mahmoud Samir Fayed
 
The Ring programming language version 1.10 book - Part 204 of 212
The Ring programming language version 1.10 book - Part 204 of 212The Ring programming language version 1.10 book - Part 204 of 212
The Ring programming language version 1.10 book - Part 204 of 212Mahmoud Samir Fayed
 
The Ring programming language version 1.10 book - Part 203 of 212
The Ring programming language version 1.10 book - Part 203 of 212The Ring programming language version 1.10 book - Part 203 of 212
The Ring programming language version 1.10 book - Part 203 of 212Mahmoud Samir Fayed
 
The Ring programming language version 1.10 book - Part 202 of 212
The Ring programming language version 1.10 book - Part 202 of 212The Ring programming language version 1.10 book - Part 202 of 212
The Ring programming language version 1.10 book - Part 202 of 212Mahmoud Samir Fayed
 
The Ring programming language version 1.10 book - Part 201 of 212
The Ring programming language version 1.10 book - Part 201 of 212The Ring programming language version 1.10 book - Part 201 of 212
The Ring programming language version 1.10 book - Part 201 of 212Mahmoud Samir Fayed
 
The Ring programming language version 1.10 book - Part 200 of 212
The Ring programming language version 1.10 book - Part 200 of 212The Ring programming language version 1.10 book - Part 200 of 212
The Ring programming language version 1.10 book - Part 200 of 212Mahmoud Samir Fayed
 
The Ring programming language version 1.10 book - Part 199 of 212
The Ring programming language version 1.10 book - Part 199 of 212The Ring programming language version 1.10 book - Part 199 of 212
The Ring programming language version 1.10 book - Part 199 of 212Mahmoud Samir Fayed
 
The Ring programming language version 1.10 book - Part 198 of 212
The Ring programming language version 1.10 book - Part 198 of 212The Ring programming language version 1.10 book - Part 198 of 212
The Ring programming language version 1.10 book - Part 198 of 212Mahmoud Samir Fayed
 
The Ring programming language version 1.10 book - Part 197 of 212
The Ring programming language version 1.10 book - Part 197 of 212The Ring programming language version 1.10 book - Part 197 of 212
The Ring programming language version 1.10 book - Part 197 of 212Mahmoud Samir Fayed
 
The Ring programming language version 1.10 book - Part 196 of 212
The Ring programming language version 1.10 book - Part 196 of 212The Ring programming language version 1.10 book - Part 196 of 212
The Ring programming language version 1.10 book - Part 196 of 212Mahmoud Samir Fayed
 
The Ring programming language version 1.10 book - Part 195 of 212
The Ring programming language version 1.10 book - Part 195 of 212The Ring programming language version 1.10 book - Part 195 of 212
The Ring programming language version 1.10 book - Part 195 of 212Mahmoud Samir Fayed
 
The Ring programming language version 1.10 book - Part 194 of 212
The Ring programming language version 1.10 book - Part 194 of 212The Ring programming language version 1.10 book - Part 194 of 212
The Ring programming language version 1.10 book - Part 194 of 212Mahmoud Samir Fayed
 
The Ring programming language version 1.10 book - Part 193 of 212
The Ring programming language version 1.10 book - Part 193 of 212The Ring programming language version 1.10 book - Part 193 of 212
The Ring programming language version 1.10 book - Part 193 of 212Mahmoud Samir Fayed
 
The Ring programming language version 1.10 book - Part 192 of 212
The Ring programming language version 1.10 book - Part 192 of 212The Ring programming language version 1.10 book - Part 192 of 212
The Ring programming language version 1.10 book - Part 192 of 212Mahmoud Samir Fayed
 

More from Mahmoud Samir Fayed (20)

The Ring programming language version 1.10 book - Part 212 of 212
The Ring programming language version 1.10 book - Part 212 of 212The Ring programming language version 1.10 book - Part 212 of 212
The Ring programming language version 1.10 book - Part 212 of 212
 
The Ring programming language version 1.10 book - Part 211 of 212
The Ring programming language version 1.10 book - Part 211 of 212The Ring programming language version 1.10 book - Part 211 of 212
The Ring programming language version 1.10 book - Part 211 of 212
 
The Ring programming language version 1.10 book - Part 210 of 212
The Ring programming language version 1.10 book - Part 210 of 212The Ring programming language version 1.10 book - Part 210 of 212
The Ring programming language version 1.10 book - Part 210 of 212
 
The Ring programming language version 1.10 book - Part 208 of 212
The Ring programming language version 1.10 book - Part 208 of 212The Ring programming language version 1.10 book - Part 208 of 212
The Ring programming language version 1.10 book - Part 208 of 212
 
The Ring programming language version 1.10 book - Part 207 of 212
The Ring programming language version 1.10 book - Part 207 of 212The Ring programming language version 1.10 book - Part 207 of 212
The Ring programming language version 1.10 book - Part 207 of 212
 
The Ring programming language version 1.10 book - Part 205 of 212
The Ring programming language version 1.10 book - Part 205 of 212The Ring programming language version 1.10 book - Part 205 of 212
The Ring programming language version 1.10 book - Part 205 of 212
 
The Ring programming language version 1.10 book - Part 206 of 212
The Ring programming language version 1.10 book - Part 206 of 212The Ring programming language version 1.10 book - Part 206 of 212
The Ring programming language version 1.10 book - Part 206 of 212
 
The Ring programming language version 1.10 book - Part 204 of 212
The Ring programming language version 1.10 book - Part 204 of 212The Ring programming language version 1.10 book - Part 204 of 212
The Ring programming language version 1.10 book - Part 204 of 212
 
The Ring programming language version 1.10 book - Part 203 of 212
The Ring programming language version 1.10 book - Part 203 of 212The Ring programming language version 1.10 book - Part 203 of 212
The Ring programming language version 1.10 book - Part 203 of 212
 
The Ring programming language version 1.10 book - Part 202 of 212
The Ring programming language version 1.10 book - Part 202 of 212The Ring programming language version 1.10 book - Part 202 of 212
The Ring programming language version 1.10 book - Part 202 of 212
 
The Ring programming language version 1.10 book - Part 201 of 212
The Ring programming language version 1.10 book - Part 201 of 212The Ring programming language version 1.10 book - Part 201 of 212
The Ring programming language version 1.10 book - Part 201 of 212
 
The Ring programming language version 1.10 book - Part 200 of 212
The Ring programming language version 1.10 book - Part 200 of 212The Ring programming language version 1.10 book - Part 200 of 212
The Ring programming language version 1.10 book - Part 200 of 212
 
The Ring programming language version 1.10 book - Part 199 of 212
The Ring programming language version 1.10 book - Part 199 of 212The Ring programming language version 1.10 book - Part 199 of 212
The Ring programming language version 1.10 book - Part 199 of 212
 
The Ring programming language version 1.10 book - Part 198 of 212
The Ring programming language version 1.10 book - Part 198 of 212The Ring programming language version 1.10 book - Part 198 of 212
The Ring programming language version 1.10 book - Part 198 of 212
 
The Ring programming language version 1.10 book - Part 197 of 212
The Ring programming language version 1.10 book - Part 197 of 212The Ring programming language version 1.10 book - Part 197 of 212
The Ring programming language version 1.10 book - Part 197 of 212
 
The Ring programming language version 1.10 book - Part 196 of 212
The Ring programming language version 1.10 book - Part 196 of 212The Ring programming language version 1.10 book - Part 196 of 212
The Ring programming language version 1.10 book - Part 196 of 212
 
The Ring programming language version 1.10 book - Part 195 of 212
The Ring programming language version 1.10 book - Part 195 of 212The Ring programming language version 1.10 book - Part 195 of 212
The Ring programming language version 1.10 book - Part 195 of 212
 
The Ring programming language version 1.10 book - Part 194 of 212
The Ring programming language version 1.10 book - Part 194 of 212The Ring programming language version 1.10 book - Part 194 of 212
The Ring programming language version 1.10 book - Part 194 of 212
 
The Ring programming language version 1.10 book - Part 193 of 212
The Ring programming language version 1.10 book - Part 193 of 212The Ring programming language version 1.10 book - Part 193 of 212
The Ring programming language version 1.10 book - Part 193 of 212
 
The Ring programming language version 1.10 book - Part 192 of 212
The Ring programming language version 1.10 book - Part 192 of 212The Ring programming language version 1.10 book - Part 192 of 212
The Ring programming language version 1.10 book - Part 192 of 212
 

Recently uploaded

"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024The Digital Insurer
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Wonjun Hwang
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 

Recently uploaded (20)

"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 

The Ring programming language version 1.7 book - Part 59 of 196

  • 1. Ring Documentation, Release 1.7 angle = 0 red=1.0 blue=1.0 green=1.0 func main // init GLUT and create window glutInit() glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA) glutInitWindowPosition(100,100) glutInitWindowSize(320,320) glutCreateWindow("RingFreeGLUT - Test 6") glutDisplayFunc(:renderScene) glutReshapeFunc(:changeSize) glutIdleFunc(:renderScene) // here are the new entries glutKeyboardFunc(:processNormalKeys) glutSpecialFunc(:processSpecialKeys) glutMainLoop() func renderScene // Clear Color and Depth Buffers glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) // Reset transformations glLoadIdentity() // Set the camera gluLookAt( 0.0, 0.0, 10.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0) glRotatef(angle, 0.0, 1.0, 0.0) glColor3f(red,green,blue); glBegin(GL_TRIANGLES) glVertex3f(-2.0,-2.0, 0.0) glVertex3f( 2.0, 0.0, 0.0) glVertex3f( 0.0, 2.0, 0.0) glEnd() angle+=0.1 glutSwapBuffers(); func changesize h = glutEventHeight() w = glutEventWidth() // Prevent a divide by zero, when window is too short 57.9. Keyboard Events and Colors 552
  • 2. Ring Documentation, Release 1.7 // (you cant make a window of zero width). if (h = 0) h = 1 ok ratio = w * 1.0 / h // Use the Projection Matrix glMatrixMode(GL_PROJECTION) // Reset Matrix glLoadIdentity() // Set the viewport to be the entire window glViewport(0, 0, w, h) // Set the correct perspective. gluPerspective(45,ratio,1,100) // Get Back to the Modelview glMatrixMode(GL_MODELVIEW) func processNormalKeys key = GLUTEventKey() if key = 27 shutdown() ok func processSpecialKeys key = GLUTEventKey() switch key on GLUT_KEY_F1 red = 1.0 green = 0.0 blue = 0.0 on GLUT_KEY_F2 red = 0.0 green = 1.0 blue = 0.0 on GLUT_KEY_F3 red = 0.0 green = 0.0 blue = 1.0 off Screen Shot 57.9. Keyboard Events and Colors 553
  • 3. Ring Documentation, Release 1.7 57.10 The Camera Example: load "freeglut.ring" load "opengl21lib.ring" // angle of rotation for the camera direction angle=0.0 // actual vector representing the camera's direction lx=0.0 lz=-1.0 // XZ position of the camera x=0.0 z=5.0 func drawSnowMan glColor3f(1.0, 1.0, 1.0) // Draw Body glTranslatef(0.0 ,0.75, 0.0) glutSolidSphere(0.75,20,20) // Draw Head glTranslatef(0.0, 1.0, 0.0) glutSolidSphere(0.25,20,20) // Draw Eyes glPushMatrix() glColor3f(0.0,0.0,0.0) glTranslatef(0.05, 0.10, 0.18) 57.10. The Camera 554
  • 4. Ring Documentation, Release 1.7 glutSolidSphere(0.05,10,10) glTranslatef(-0.1, 0.0, 0.0) glutSolidSphere(0.05,10,10) glPopMatrix() // Draw Nose glColor3f(1.0, 0.5 , 0.5) glutSolidCone(0.08,0.5,10,2) func changeSize w = glutEventWidth() h = glutEventHeight() // Prevent a divide by zero, when window is too short // (you cant make a window of zero width). if h = 0 h = 1 ok ratio = w * 1.0 / h // Use the Projection Matrix glMatrixMode(GL_PROJECTION) // Reset Matrix glLoadIdentity() // Set the viewport to be the entire window glViewport(0, 0, w, h) // Set the correct perspective. gluPerspective(45.0, ratio, 0.1, 100.0); // Get Back to the Modelview glMatrixMode(GL_MODELVIEW) func processNormalKeys key = glutEventKey() if key = 27 shutdown() ok func renderScene // Clear Color and Depth Buffers glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) // Reset transformations glLoadIdentity() // Set the camera 57.10. The Camera 555
  • 5. Ring Documentation, Release 1.7 gluLookAt( x, 1.0, z, x+lx, 1.0, z+lz, 0.0, 1.0, 0.0) // Draw ground glColor3f(0.9, 0.9, 0.9) glBegin(GL_QUADS) glVertex3f(-100.0, 0.0, -100.0) glVertex3f(-100.0, 0.0, 100.0) glVertex3f( 100.0, 0.0, 100.0) glVertex3f( 100.0, 0.0, -100.0) glEnd() // Draw 36 SnowMen for i = -3 to 2 for j=-3 to 2 glPushMatrix() glTranslatef(i*10.0,0,j * 10.0) drawSnowMan() glPopMatrix() next next glutSwapBuffers() func processSpecialKeys key = glutEventKey() fraction = 0.1 switch key on GLUT_KEY_LEFT angle -= 0.01 lx = sin(angle) lz = -cos(angle) on GLUT_KEY_RIGHT angle += 0.01 lx = sin(angle) lz = -cos(angle) on GLUT_KEY_UP x += lx * fraction z += lz * fraction on GLUT_KEY_DOWN x -= lx * fraction z -= lz * fraction off func main // init GLUT and create window glutInit() glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA) 57.10. The Camera 556
  • 6. Ring Documentation, Release 1.7 glutInitWindowPosition(100,100) glutInitWindowSize(320,320) glutCreateWindow("RingFreeGLUT - Test 7") // register callbacks glutDisplayFunc(:renderScene) glutReshapeFunc(:changeSize) glutIdleFunc(:renderScene) glutKeyboardFunc(:processNormalKeys) glutSpecialFunc(:processSpecialKeys) // OpenGL init glEnable(GL_DEPTH_TEST) // enter GLUT event processing cycle glutMainLoop() Screen Shot Another Example: load "freeglut.ring" load "opengl21lib.ring" // angle of rotation for the camera direction angle = 0.0 // actual vector representing the camera's direction lx=0.0 lz=-1.0 // XZ position of the camera x=0.0 z=5.0 // the key states. These variables will be zero //when no key is being presses deltaAngle = 0.0 57.10. The Camera 557
  • 7. Ring Documentation, Release 1.7 deltaMove = 0 func changeSize w = glutEventWidth() h = glutEventHeight() // Prevent a divide by zero, when window is too short // (you cant make a window of zero width). if h = 0 h = 1 ok ratio = w * 1.0 / h // Use the Projection Matrix glMatrixMode(GL_PROJECTION) // Reset Matrix glLoadIdentity() // Set the viewport to be the entire window glViewport(0, 0, w, h) // Set the correct perspective. gluPerspective(45.0, ratio, 0.1, 100.0) // Get Back to the Modelview glMatrixMode(GL_MODELVIEW) func drawSnowMan glColor3f(1.0, 1.0, 1.0) // Draw Body glTranslatef(0.0 ,0.75, 0.0) glutSolidSphere(0.75,20,20) // Draw Head glTranslatef(0.0, 1.0, 0.0) glutSolidSphere(0.25,20,20) // Draw Eyes glPushMatrix() glColor3f(0.0,0.0,0.0) glTranslatef(0.05, 0.10, 0.18) glutSolidSphere(0.05,10,10) glTranslatef(-0.1, 0.0, 0.0) glutSolidSphere(0.05,10,10) glPopMatrix() // Draw Nose glColor3f(1.0, 0.5 , 0.5) glRotatef(0.0,1.0, 0.0, 0.0) glutSolidCone(0.08,0.5,10,2) 57.10. The Camera 558
  • 8. Ring Documentation, Release 1.7 func computePos deltaMove x += deltaMove * lx * 0.1 z += deltaMove * lz * 0.1 func computeDir deltaAngle angle += deltaAngle lx = sin(angle) lz = -cos(angle) func renderScene if deltaMove computePos(deltaMove) ok if deltaAngle computeDir(deltaAngle) ok // Clear Color and Depth Buffers glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) // Reset transformations glLoadIdentity() // Set the camera gluLookAt( x, 1.0, z, x+lx, 1.0, z+lz, 0.0, 1.0, 0.0) // Draw ground glColor3f(0.9, 0.9, 0.9) glBegin(GL_QUADS) glVertex3f(-100.0, 0.0, -100.0) glVertex3f(-100.0, 0.0, 100.0) glVertex3f( 100.0, 0.0, 100.0) glVertex3f( 100.0, 0.0, -100.0) glEnd() // Draw 36 SnowMen for i = -3 to 2 for j=-3 to 2 glPushMatrix() glTranslatef(i*10.0,0,j * 10.0) drawSnowMan() glPopMatrix() next next glutSwapBuffers() func pressKey key = glutEventKey() xx = glutEventX() 57.10. The Camera 559
  • 9. Ring Documentation, Release 1.7 yy = glutEventY() switch key on GLUT_KEY_LEFT deltaAngle = -0.01 on GLUT_KEY_RIGHT deltaAngle = 0.01 on GLUT_KEY_UP deltaMove = 0.5 on GLUT_KEY_DOWN deltaMove = -0.5 off func releaseKey key = glutEventKey() switch key on GLUT_KEY_LEFT deltaAngle = 0.0 on GLUT_KEY_RIGHT deltaAngle = 0.0 on GLUT_KEY_UP deltaMove = 0 on GLUT_KEY_DOWN deltaMove = 0 off func main // init GLUT and create window glutInit() glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA) glutInitWindowPosition(100,100) glutInitWindowSize(320,320) glutCreateWindow("RingFreeGLUT - Test 8") // register callbacks glutDisplayFunc(:renderScene) glutReshapeFunc(:changeSize) glutIdleFunc(:renderScene) glutSpecialFunc(:pressKey) // here are the new entries glutIgnoreKeyRepeat(1) glutSpecialUpFunc(:releaseKey) // OpenGL init glEnable(GL_DEPTH_TEST) // enter GLUT event processing cycle glutMainLoop() 57.10. The Camera 560
  • 10. Ring Documentation, Release 1.7 57.11 Mouse Events Example: load "freeglut.ring" load "opengl21lib.ring" // angle of rotation for the camera direction angle = 0.0 // actual vector representing the camera's direction lx=0.0 lz=-1.0 // XZ position of the camera x=0.0 z=5.0 // the key states. These variables will be zero //when no key is being presses deltaAngle = 0.0 deltaMove = 0.0 xOrigin = -1 func changeSize w = glutEventWidth() h = glutEventHeight() // Prevent a divide by zero, when window is too short // (you cant make a window of zero width). if h = 0 h = 1 ok ratio = w * 1.0 / h // Use the Projection Matrix glMatrixMode(GL_PROJECTION) // Reset Matrix glLoadIdentity() // Set the viewport to be the entire window glViewport(0, 0, w, h) // Set the correct perspective. gluPerspective(45.0, ratio, 0.1, 100.0) // Get Back to the Modelview glMatrixMode(GL_MODELVIEW) func drawSnowMan glColor3f(1.0, 1.0, 1.0) // Draw Body glTranslatef(0.0 ,0.75, 0.0) glutSolidSphere(0.75,20,20) 57.11. Mouse Events 561