SlideShare a Scribd company logo
Ring Documentation, Release 1.7
You can add the source code (*.ring) and Images/Sound Files to the assets folder.
You will find the Flappy Bird 3000 Game ready for building.
The execution starts from the start.ring file
load "game2.ring"
56.3 Building the project
Move to the ring/android/ringlibsdl/project folder
We can build using the next command (We need to do this for one time only).
ndk-build
Then we can create the package (*.apk) using the next command.
56.3. Building the project 542
Ring Documentation, Release 1.7
ant debug
56.3. Building the project 543
CHAPTER
FIFTYSEVEN
USING RINGOPENGL AND RINGFREEGLUT FOR 3D GRAPHICS
In this chapter we will learn about using RingOpenGL
57.1 Samples Source (Authors)
The samples in this chapter are based on C Tutorials
from
1. http://www.lighthouse3d.com/tutorials/glut-tutorial/
2. http://www.wikihow.com/Make-a-Cube-in-OpenGL
57.2 What is RingOpenGL?
RingOpenGL contains the Ring binding to the OpenGL library
You can learn about OpenGL from : https://www.opengl.org/
RingOpenGL comes with support for the next versions
• OpenGL 1.1
• OpenGL 1.2
• OpenGL 1.3
• OpenGL 1.4
• OpenGL 1.5
• OpenGL 2.0
• OpenGL 2.1
• OpenGL 3.0
• OpenGL 3.2
• OpenGL 3.3
• OpenGL 4.0
• OpenGL 4.1
• OpenGL 4.2
• OpenGL 4.3
544
Ring Documentation, Release 1.7
• 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"
57.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"
57.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
57.3. What is RingFreeGLUT? 545
Ring Documentation, Release 1.7
57.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)
57.5. Drawing using RingOpenGL 546
Ring Documentation, Release 1.7
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
57.5. Drawing using RingOpenGL 547
Ring Documentation, Release 1.7
57.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
57.6. The First Triangle 548
Ring Documentation, Release 1.7
57.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)
57.7. Window Resize Event 549
Ring Documentation, Release 1.7
// Get Back to the Modelview
glMatrixMode(GL_MODELVIEW)
57.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()
57.8. Triangle Rotation 550
Ring Documentation, Release 1.7
// 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
57.9 Keyboard Events and Colors
Example:
load "freeglut.ring"
load "opengl21lib.ring"
57.9. Keyboard Events and Colors 551

More Related Content

PDF
The Ring programming language version 1.5.2 book - Part 53 of 181
PDF
The Ring programming language version 1.6 book - Part 56 of 189
PDF
The Ring programming language version 1.9 book - Part 76 of 210
PDF
The Ring programming language version 1.5.3 book - Part 73 of 184
PDF
The Ring programming language version 1.5.4 book - Part 63 of 185
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.3 book - Part 49 of 88
The Ring programming language version 1.5.2 book - Part 53 of 181
The Ring programming language version 1.6 book - Part 56 of 189
The Ring programming language version 1.9 book - Part 76 of 210
The Ring programming language version 1.5.3 book - Part 73 of 184
The Ring programming language version 1.5.4 book - Part 63 of 185
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.3 book - Part 49 of 88

What's hot (15)

PDF
The Ring programming language version 1.9 book - Part 63 of 210
PDF
The Ring programming language version 1.2 book - Part 43 of 84
PDF
The Ring programming language version 1.5.2 book - Part 58 of 181
PDF
The Ring programming language version 1.2 book - Part 42 of 84
PDF
The Ring programming language version 1.10 book - Part 65 of 212
PDF
The Ring programming language version 1.6 book - Part 73 of 189
PDF
The Ring programming language version 1.5.3 book - Part 76 of 184
PDF
The Ring programming language version 1.10 book - Part 13 of 212
PDF
The Ring programming language version 1.6 book - Part 64 of 189
PDF
OpenStack, The Open Source Cloud Operating System
PDF
The Ring programming language version 1.10 book - Part 74 of 212
PDF
The Ring programming language version 1.3 book - Part 45 of 88
PDF
The Ring programming language version 1.10 book - Part 73 of 212
PDF
The Ring programming language version 1.5.2 book - Part 59 of 181
PDF
UberFire Quick Intro and Overview (early beta Jul 2013)
The Ring programming language version 1.9 book - Part 63 of 210
The Ring programming language version 1.2 book - Part 43 of 84
The Ring programming language version 1.5.2 book - Part 58 of 181
The Ring programming language version 1.2 book - Part 42 of 84
The Ring programming language version 1.10 book - Part 65 of 212
The Ring programming language version 1.6 book - Part 73 of 189
The Ring programming language version 1.5.3 book - Part 76 of 184
The Ring programming language version 1.10 book - Part 13 of 212
The Ring programming language version 1.6 book - Part 64 of 189
OpenStack, The Open Source Cloud Operating System
The Ring programming language version 1.10 book - Part 74 of 212
The Ring programming language version 1.3 book - Part 45 of 88
The Ring programming language version 1.10 book - Part 73 of 212
The Ring programming language version 1.5.2 book - Part 59 of 181
UberFire Quick Intro and Overview (early beta Jul 2013)
Ad

Similar to The Ring programming language version 1.7 book - Part 58 of 196 (20)

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.8 book - Part 77 of 202
PDF
The Ring programming language version 1.7 book - Part 75 of 196
PDF
The Ring programming language version 1.3 book - Part 8 of 88
PDF
The Ring programming language version 1.5.1 book - Part 7 of 180
PDF
The Ring programming language version 1.5.4 book - Part 8 of 185
PDF
The Ring programming language version 1.5.2 book - Part 10 of 181
PDF
The Ring programming language version 1.5.3 book - Part 8 of 184
PDF
The Ring programming language version 1.5.3 book - Part 63 of 184
PDF
The Ring programming language version 1.10 book - Part 72 of 212
PDF
The Ring programming language version 1.9 book - Part 89 of 210
PDF
The Ring programming language version 1.8 book - Part 12 of 202
PDF
The Ring programming language version 1.9 book - Part 14 of 210
PPTX
OpenGL_summer2012.ccccccccccccccccccpptx
PDF
The Ring programming language version 1.8 book - Part 85 of 202
PDF
The Ring programming language version 1.8 book - Part 51 of 202
PDF
The Ring programming language version 1.7 book - Part 8 of 196
PDF
The Ring programming language version 1.7 book - Part 59 of 196
PDF
The Ring programming language version 1.3 book - Part 7 of 88
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.8 book - Part 77 of 202
The Ring programming language version 1.7 book - Part 75 of 196
The Ring programming language version 1.3 book - Part 8 of 88
The Ring programming language version 1.5.1 book - Part 7 of 180
The Ring programming language version 1.5.4 book - Part 8 of 185
The Ring programming language version 1.5.2 book - Part 10 of 181
The Ring programming language version 1.5.3 book - Part 8 of 184
The Ring programming language version 1.5.3 book - Part 63 of 184
The Ring programming language version 1.10 book - Part 72 of 212
The Ring programming language version 1.9 book - Part 89 of 210
The Ring programming language version 1.8 book - Part 12 of 202
The Ring programming language version 1.9 book - Part 14 of 210
OpenGL_summer2012.ccccccccccccccccccpptx
The Ring programming language version 1.8 book - Part 85 of 202
The Ring programming language version 1.8 book - Part 51 of 202
The Ring programming language version 1.7 book - Part 8 of 196
The Ring programming language version 1.7 book - Part 59 of 196
The Ring programming language version 1.3 book - Part 7 of 88
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)

PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PPTX
Spectroscopy.pptx food analysis technology
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
Spectral efficient network and resource selection model in 5G networks
DOCX
The AUB Centre for AI in Media Proposal.docx
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
Encapsulation theory and applications.pdf
PPTX
Cloud computing and distributed systems.
PPTX
MYSQL Presentation for SQL database connectivity
PDF
Encapsulation_ Review paper, used for researhc scholars
PPTX
sap open course for s4hana steps from ECC to s4
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
Spectroscopy.pptx food analysis technology
Understanding_Digital_Forensics_Presentation.pptx
Spectral efficient network and resource selection model in 5G networks
The AUB Centre for AI in Media Proposal.docx
Digital-Transformation-Roadmap-for-Companies.pptx
Encapsulation theory and applications.pdf
Cloud computing and distributed systems.
MYSQL Presentation for SQL database connectivity
Encapsulation_ Review paper, used for researhc scholars
sap open course for s4hana steps from ECC to s4
Unlocking AI with Model Context Protocol (MCP)
Mobile App Security Testing_ A Comprehensive Guide.pdf
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...

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

  • 1. Ring Documentation, Release 1.7 You can add the source code (*.ring) and Images/Sound Files to the assets folder. You will find the Flappy Bird 3000 Game ready for building. The execution starts from the start.ring file load "game2.ring" 56.3 Building the project Move to the ring/android/ringlibsdl/project folder We can build using the next command (We need to do this for one time only). ndk-build Then we can create the package (*.apk) using the next command. 56.3. Building the project 542
  • 2. Ring Documentation, Release 1.7 ant debug 56.3. Building the project 543
  • 3. CHAPTER FIFTYSEVEN USING RINGOPENGL AND RINGFREEGLUT FOR 3D GRAPHICS In this chapter we will learn about using RingOpenGL 57.1 Samples Source (Authors) The samples in this chapter are based on C Tutorials from 1. http://www.lighthouse3d.com/tutorials/glut-tutorial/ 2. http://www.wikihow.com/Make-a-Cube-in-OpenGL 57.2 What is RingOpenGL? RingOpenGL contains the Ring binding to the OpenGL library You can learn about OpenGL from : https://www.opengl.org/ RingOpenGL comes with support for the next versions • OpenGL 1.1 • OpenGL 1.2 • OpenGL 1.3 • OpenGL 1.4 • OpenGL 1.5 • OpenGL 2.0 • OpenGL 2.1 • OpenGL 3.0 • OpenGL 3.2 • OpenGL 3.3 • OpenGL 4.0 • OpenGL 4.1 • OpenGL 4.2 • OpenGL 4.3 544
  • 4. Ring Documentation, Release 1.7 • 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" 57.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" 57.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 57.3. What is RingFreeGLUT? 545
  • 5. Ring Documentation, Release 1.7 57.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) 57.5. Drawing using RingOpenGL 546
  • 6. Ring Documentation, Release 1.7 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 57.5. Drawing using RingOpenGL 547
  • 7. Ring Documentation, Release 1.7 57.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 57.6. The First Triangle 548
  • 8. Ring Documentation, Release 1.7 57.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) 57.7. Window Resize Event 549
  • 9. Ring Documentation, Release 1.7 // Get Back to the Modelview glMatrixMode(GL_MODELVIEW) 57.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() 57.8. Triangle Rotation 550
  • 10. Ring Documentation, Release 1.7 // 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 57.9 Keyboard Events and Colors Example: load "freeglut.ring" load "opengl21lib.ring" 57.9. Keyboard Events and Colors 551