SlideShare a Scribd company logo
Ring Documentation, Release 1.5.2
• OpenGL 4.4
• OpenGL 4.5
• OpenGL 4.6
For example, if you want to use OpenGL 2.1 then load RingOpenGL 2.1 library
load "opengl21lib.ring"
54.3 What is RingFreeGLUT?
RingFreeGLUT contains the Ring binding to the FreeGLUT library
You can learn about FreeGLUT from : http://freeglut.sourceforge.net/
To use the RingFreeGLUT library, Just load the library
load "freeglut.ring"
54.4 The First Window using RingFreeGLUT
Example:
load "freeglut.ring"
func main
glutInit()
glutInitDisplayMode(GLUT_SINGLE)
glutInitWindowSize(800, 600)
glutInitWindowPosition(100, 10)
glutCreateWindow("RingFreeGLUT - Test 1")
glutDisplayFunc(:displayCode)
glutMainLoop()
func displaycode
Screen Shot
54.3. What is RingFreeGLUT? 495
Ring Documentation, Release 1.5.2
54.5 Drawing using RingOpenGL
Example:
load "freeglut.ring"
load "opengl21lib.ring"
func main
glutInit()
glutInitDisplayMode(GLUT_SINGLE)
glutInitWindowSize(800, 600)
glutInitWindowPosition(100, 10)
glutCreateWindow("RingFreeGLUT - Test 2")
glutDisplayFunc(:displayCode)
glutMainLoop()
func displaycode
glClear(GL_COLOR_BUFFER_BIT)
glColor3f(0,255,0)
glBegin(GL_POLYGON)
glVertex3f(0.0, 0.0, 0.0)
54.5. Drawing using RingOpenGL 496
Ring Documentation, Release 1.5.2
glVertex3f(0.5, 0.0, 0.0)
glVertex3f(0.5, 0.5, 0.0)
glVertex3f(0.0, 0.5, 0.0)
glEnd()
glColor3f(255,0,0)
glBegin(GL_POLYGON)
glVertex3f(0.0, 0.0, 0.0)
glVertex3f(0.5, 0.0, 0.0)
glVertex3f(-0.5,- 1, 0.0)
glVertex3f(0.0, -1, 0.0)
glEnd()
glColor3f(0,0,255)
glBegin(GL_POLYGON)
glVertex3f(0.0, 0.0, 0.0)
glVertex3f(-0.5, 0.0, 0.0)
glVertex3f(-0.5,- 0.5, 0.0)
glVertex3f(0.0, -0.5, 0.0)
glEnd()
glFlush()
Screen Shot
54.5. Drawing using RingOpenGL 497
Ring Documentation, Release 1.5.2
54.6 The First Triangle
Example:
load "freeglut.ring"
load "opengl21lib.ring"
func main
glutInit()
glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA)
glutInitWindowSize(320,320)
glutInitWindowPosition(100, 10)
glutCreateWindow("RingFreeGLUT - Test 3")
glutDisplayFunc(:renderScene)
glutMainLoop()
func renderScene
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
glBegin(GL_TRIANGLES)
glVertex3f(-0.5,-0.5,0.0)
glVertex3f(0.5,0.0,0.0)
glVertex3f(0.0,0.5,0.0)
glEnd()
glutSwapBuffers()
Screen Shot
54.6. The First Triangle 498
Ring Documentation, Release 1.5.2
54.7 Window Resize Event
Example:
load "freeglut.ring"
load "opengl21lib.ring"
func main
// init GLUT and create window
glutInit()
glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA)
glutInitWindowPosition(100,100)
glutInitWindowSize(320,320)
glutCreateWindow("RingFreeGLUT - Test 4")
glutDisplayFunc(:renderScene)
glutReshapeFunc(:changeSize)
glutMainLoop()
func renderScene
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
glBegin(GL_TRIANGLES)
glVertex3f(-2,-2,-5.0)
glVertex3f(2,0.0,-5.0)
glVertex3f(0.0,2,-5.0)
glEnd()
glutSwapBuffers()
func changesize
h = glutEventHeight()
w = glutEventWidth()
// 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,ratio,1,100)
54.7. Window Resize Event 499
Ring Documentation, Release 1.5.2
// Get Back to the Modelview
glMatrixMode(GL_MODELVIEW)
54.8 Triangle Rotation
Example:
load "freeglut.ring"
load "opengl21lib.ring"
angle = 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 5")
glutDisplayFunc(:renderScene)
glutReshapeFunc(:changeSize)
glutIdleFunc(:renderScene)
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)
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()
54.8. Triangle Rotation 500
Ring Documentation, Release 1.5.2
// 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,ratio,1,100)
// Get Back to the Modelview
glMatrixMode(GL_MODELVIEW)
Screen Shot
54.9 Keyboard Events and Colors
Example:
load "freeglut.ring"
load "opengl21lib.ring"
54.9. Keyboard Events and Colors 501
Ring Documentation, Release 1.5.2
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
54.9. Keyboard Events and Colors 502
Ring Documentation, Release 1.5.2
// (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
54.9. Keyboard Events and Colors 503
Ring Documentation, Release 1.5.2
54.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)
54.10. The Camera 504

More Related Content

PDF
The Ring programming language version 1.6 book - Part 56 of 189
PDF
The Ring programming language version 1.5.1 book - Part 52 of 180
PDF
The Ring programming language version 1.8 book - Part 60 of 202
PDF
The Ring programming language version 1.10 book - Part 65 of 212
PDF
The Ring programming language version 1.7 book - Part 58 of 196
PDF
The Ring programming language version 1.10 book - Part 66 of 212
PDF
The Ring programming language version 1.9 book - Part 76 of 210
PDF
The Ring programming language version 1.8 book - Part 61 of 202
The Ring programming language version 1.6 book - Part 56 of 189
The Ring programming language version 1.5.1 book - Part 52 of 180
The Ring programming language version 1.8 book - Part 60 of 202
The Ring programming language version 1.10 book - Part 65 of 212
The Ring programming language version 1.7 book - Part 58 of 196
The Ring programming language version 1.10 book - Part 66 of 212
The Ring programming language version 1.9 book - Part 76 of 210
The Ring programming language version 1.8 book - Part 61 of 202

What's hot (20)

PDF
The Ring programming language version 1.5.3 book - Part 64 of 184
PDF
The Ring programming language version 1.7 book - Part 59 of 196
PDF
The Ring programming language version 1.5.1 book - Part 53 of 180
PDF
The Ring programming language version 1.5.3 book - Part 65 of 184
PDF
The Ring programming language version 1.5.4 book - Part 54 of 185
PDF
The Ring programming language version 1.5.2 book - Part 54 of 181
PDF
The Ring programming language version 1.6 book - Part 57 of 189
PDF
The Ring programming language version 1.9 book - Part 65 of 210
PDF
The Ring programming language version 1.6 book - Part 73 of 189
PDF
The Ring programming language version 1.9 book - Part 64 of 210
PDF
The Ring programming language version 1.3 book - Part 49 of 88
PDF
The Ring programming language version 1.5.1 book - Part 58 of 180
PDF
The Ring programming language version 1.5.2 book - Part 62 of 181
PDF
The Ring programming language version 1.7 book - Part 60 of 196
PDF
551 pd fsam_fayed_ring_doc_1.5.2
PDF
The Ring programming language version 1.5.3 book - Part 73 of 184
PDF
The Ring programming language version 1.6 book - Part 59 of 189
PDF
The Ring programming language version 1.10 book - Part 68 of 212
PDF
The Ring programming language version 1.5.3 book - Part 76 of 184
PDF
The Ring programming language version 1.2 book - Part 42 of 84
The Ring programming language version 1.5.3 book - Part 64 of 184
The Ring programming language version 1.7 book - Part 59 of 196
The Ring programming language version 1.5.1 book - Part 53 of 180
The Ring programming language version 1.5.3 book - Part 65 of 184
The Ring programming language version 1.5.4 book - Part 54 of 185
The Ring programming language version 1.5.2 book - Part 54 of 181
The Ring programming language version 1.6 book - Part 57 of 189
The Ring programming language version 1.9 book - Part 65 of 210
The Ring programming language version 1.6 book - Part 73 of 189
The Ring programming language version 1.9 book - Part 64 of 210
The Ring programming language version 1.3 book - Part 49 of 88
The Ring programming language version 1.5.1 book - Part 58 of 180
The Ring programming language version 1.5.2 book - Part 62 of 181
The Ring programming language version 1.7 book - Part 60 of 196
551 pd fsam_fayed_ring_doc_1.5.2
The Ring programming language version 1.5.3 book - Part 73 of 184
The Ring programming language version 1.6 book - Part 59 of 189
The Ring programming language version 1.10 book - Part 68 of 212
The Ring programming language version 1.5.3 book - Part 76 of 184
The Ring programming language version 1.2 book - Part 42 of 84
Ad

Similar to The Ring programming language version 1.5.2 book - Part 53 of 181 (19)

PDF
The Ring programming language version 1.7 book - Part 62 of 196
PDF
The Ring programming language version 1.6 book - Part 10 of 189
PDF
The Ring programming language version 1.7 book - Part 11 of 196
PDF
The Ring programming language version 1.6 book - Part 60 of 189
PDF
The Ring programming language version 1.8 book - Part 64 of 202
PDF
The Ring programming language version 1.5.1 book - Part 54 of 180
PDF
The Ring programming language version 1.5.1 book - Part 56 of 180
PDF
The Ring programming language version 1.5.2 book - Part 57 of 181
PDF
The Ring programming language version 1.5.4 book - Part 55 of 185
PDF
The Ring programming language version 1.5.4 book - Part 58 of 185
PDF
The Ring programming language version 1.10 book - Part 67 of 212
PDF
The Ring programming language version 1.9 book - Part 67 of 210
PDF
The Ring programming language version 1.5.2 book - Part 8 of 181
PDF
The Ring programming language version 1.5.3 book - Part 67 of 184
PDF
The Ring programming language version 1.5.1 book - Part 55 of 180
PDF
The Ring programming language version 1.8 book - Part 62 of 202
PDF
The Ring programming language version 1.5.3 book - Part 68 of 184
PDF
The Ring programming language version 1.10 book - Part 16 of 212
PDF
The Ring programming language version 1.6 book - Part 58 of 189
The Ring programming language version 1.7 book - Part 62 of 196
The Ring programming language version 1.6 book - Part 10 of 189
The Ring programming language version 1.7 book - Part 11 of 196
The Ring programming language version 1.6 book - Part 60 of 189
The Ring programming language version 1.8 book - Part 64 of 202
The Ring programming language version 1.5.1 book - Part 54 of 180
The Ring programming language version 1.5.1 book - Part 56 of 180
The Ring programming language version 1.5.2 book - Part 57 of 181
The Ring programming language version 1.5.4 book - Part 55 of 185
The Ring programming language version 1.5.4 book - Part 58 of 185
The Ring programming language version 1.10 book - Part 67 of 212
The Ring programming language version 1.9 book - Part 67 of 210
The Ring programming language version 1.5.2 book - Part 8 of 181
The Ring programming language version 1.5.3 book - Part 67 of 184
The Ring programming language version 1.5.1 book - Part 55 of 180
The Ring programming language version 1.8 book - Part 62 of 202
The Ring programming language version 1.5.3 book - Part 68 of 184
The Ring programming language version 1.10 book - Part 16 of 212
The Ring programming language version 1.6 book - Part 58 of 189
Ad

More from Mahmoud Samir Fayed (20)

PDF
The Ring programming language version 1.10 book - Part 212 of 212
PDF
The Ring programming language version 1.10 book - Part 211 of 212
PDF
The Ring programming language version 1.10 book - Part 210 of 212
PDF
The Ring programming language version 1.10 book - Part 208 of 212
PDF
The Ring programming language version 1.10 book - Part 207 of 212
PDF
The Ring programming language version 1.10 book - Part 205 of 212
PDF
The Ring programming language version 1.10 book - Part 206 of 212
PDF
The Ring programming language version 1.10 book - Part 204 of 212
PDF
The Ring programming language version 1.10 book - Part 203 of 212
PDF
The Ring programming language version 1.10 book - Part 202 of 212
PDF
The Ring programming language version 1.10 book - Part 201 of 212
PDF
The Ring programming language version 1.10 book - Part 200 of 212
PDF
The Ring programming language version 1.10 book - Part 199 of 212
PDF
The Ring programming language version 1.10 book - Part 198 of 212
PDF
The Ring programming language version 1.10 book - Part 197 of 212
PDF
The Ring programming language version 1.10 book - Part 196 of 212
PDF
The Ring programming language version 1.10 book - Part 195 of 212
PDF
The Ring programming language version 1.10 book - Part 194 of 212
PDF
The Ring programming language version 1.10 book - Part 193 of 212
PDF
The Ring programming language version 1.10 book - Part 192 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 210 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 205 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 203 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 200 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 197 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 194 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

Recently uploaded (20)

PPTX
sap open course for s4hana steps from ECC to s4
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PPT
Teaching material agriculture food technology
PDF
Machine learning based COVID-19 study performance prediction
PPTX
Spectroscopy.pptx food analysis technology
PPTX
MYSQL Presentation for SQL database connectivity
PDF
Approach and Philosophy of On baking technology
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
NewMind AI Weekly Chronicles - August'25 Week I
sap open course for s4hana steps from ECC to s4
Advanced methodologies resolving dimensionality complications for autism neur...
Diabetes mellitus diagnosis method based random forest with bat algorithm
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Teaching material agriculture food technology
Machine learning based COVID-19 study performance prediction
Spectroscopy.pptx food analysis technology
MYSQL Presentation for SQL database connectivity
Approach and Philosophy of On baking technology
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
The Rise and Fall of 3GPP – Time for a Sabbatical?
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Chapter 3 Spatial Domain Image Processing.pdf
Mobile App Security Testing_ A Comprehensive Guide.pdf
The AUB Centre for AI in Media Proposal.docx
NewMind AI Weekly Chronicles - August'25 Week I

The Ring programming language version 1.5.2 book - Part 53 of 181

  • 1. Ring Documentation, Release 1.5.2 • OpenGL 4.4 • OpenGL 4.5 • OpenGL 4.6 For example, if you want to use OpenGL 2.1 then load RingOpenGL 2.1 library load "opengl21lib.ring" 54.3 What is RingFreeGLUT? RingFreeGLUT contains the Ring binding to the FreeGLUT library You can learn about FreeGLUT from : http://freeglut.sourceforge.net/ To use the RingFreeGLUT library, Just load the library load "freeglut.ring" 54.4 The First Window using RingFreeGLUT Example: load "freeglut.ring" func main glutInit() glutInitDisplayMode(GLUT_SINGLE) glutInitWindowSize(800, 600) glutInitWindowPosition(100, 10) glutCreateWindow("RingFreeGLUT - Test 1") glutDisplayFunc(:displayCode) glutMainLoop() func displaycode Screen Shot 54.3. What is RingFreeGLUT? 495
  • 2. Ring Documentation, Release 1.5.2 54.5 Drawing using RingOpenGL Example: load "freeglut.ring" load "opengl21lib.ring" func main glutInit() glutInitDisplayMode(GLUT_SINGLE) glutInitWindowSize(800, 600) glutInitWindowPosition(100, 10) glutCreateWindow("RingFreeGLUT - Test 2") glutDisplayFunc(:displayCode) glutMainLoop() func displaycode glClear(GL_COLOR_BUFFER_BIT) glColor3f(0,255,0) glBegin(GL_POLYGON) glVertex3f(0.0, 0.0, 0.0) 54.5. Drawing using RingOpenGL 496
  • 3. Ring Documentation, Release 1.5.2 glVertex3f(0.5, 0.0, 0.0) glVertex3f(0.5, 0.5, 0.0) glVertex3f(0.0, 0.5, 0.0) glEnd() glColor3f(255,0,0) glBegin(GL_POLYGON) glVertex3f(0.0, 0.0, 0.0) glVertex3f(0.5, 0.0, 0.0) glVertex3f(-0.5,- 1, 0.0) glVertex3f(0.0, -1, 0.0) glEnd() glColor3f(0,0,255) glBegin(GL_POLYGON) glVertex3f(0.0, 0.0, 0.0) glVertex3f(-0.5, 0.0, 0.0) glVertex3f(-0.5,- 0.5, 0.0) glVertex3f(0.0, -0.5, 0.0) glEnd() glFlush() Screen Shot 54.5. Drawing using RingOpenGL 497
  • 4. Ring Documentation, Release 1.5.2 54.6 The First Triangle Example: load "freeglut.ring" load "opengl21lib.ring" func main glutInit() glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA) glutInitWindowSize(320,320) glutInitWindowPosition(100, 10) glutCreateWindow("RingFreeGLUT - Test 3") glutDisplayFunc(:renderScene) glutMainLoop() func renderScene glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) glBegin(GL_TRIANGLES) glVertex3f(-0.5,-0.5,0.0) glVertex3f(0.5,0.0,0.0) glVertex3f(0.0,0.5,0.0) glEnd() glutSwapBuffers() Screen Shot 54.6. The First Triangle 498
  • 5. Ring Documentation, Release 1.5.2 54.7 Window Resize Event Example: load "freeglut.ring" load "opengl21lib.ring" func main // init GLUT and create window glutInit() glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA) glutInitWindowPosition(100,100) glutInitWindowSize(320,320) glutCreateWindow("RingFreeGLUT - Test 4") glutDisplayFunc(:renderScene) glutReshapeFunc(:changeSize) glutMainLoop() func renderScene glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) glBegin(GL_TRIANGLES) glVertex3f(-2,-2,-5.0) glVertex3f(2,0.0,-5.0) glVertex3f(0.0,2,-5.0) glEnd() glutSwapBuffers() func changesize h = glutEventHeight() w = glutEventWidth() // 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,ratio,1,100) 54.7. Window Resize Event 499
  • 6. Ring Documentation, Release 1.5.2 // Get Back to the Modelview glMatrixMode(GL_MODELVIEW) 54.8 Triangle Rotation Example: load "freeglut.ring" load "opengl21lib.ring" angle = 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 5") glutDisplayFunc(:renderScene) glutReshapeFunc(:changeSize) glutIdleFunc(:renderScene) 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) 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() 54.8. Triangle Rotation 500
  • 7. Ring Documentation, Release 1.5.2 // 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,ratio,1,100) // Get Back to the Modelview glMatrixMode(GL_MODELVIEW) Screen Shot 54.9 Keyboard Events and Colors Example: load "freeglut.ring" load "opengl21lib.ring" 54.9. Keyboard Events and Colors 501
  • 8. Ring Documentation, Release 1.5.2 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 54.9. Keyboard Events and Colors 502
  • 9. Ring Documentation, Release 1.5.2 // (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 54.9. Keyboard Events and Colors 503
  • 10. Ring Documentation, Release 1.5.2 54.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) 54.10. The Camera 504