SlideShare a Scribd company logo
CHAPTER
FIFTYFOUR
USING RINGOPENGL AND RINGFREEGLUT FOR 3D GRAPHICS
In this chapter we will learn about using RingOpenGL
54.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
54.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
485
Ring Documentation, Release 1.5.1
• 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? 486
Ring Documentation, Release 1.5.1
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 487
Ring Documentation, Release 1.5.1
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 488
Ring Documentation, Release 1.5.1
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 489
Ring Documentation, Release 1.5.1
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 490
Ring Documentation, Release 1.5.1
// 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 491
Ring Documentation, Release 1.5.1
// 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 492
Ring Documentation, Release 1.5.1
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 493
Ring Documentation, Release 1.5.1
// (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 494

More Related Content

PDF
The Ring programming language version 1.8 book - Part 60 of 202
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.7 book - Part 58 of 196
PDF
The Ring programming language version 1.10 book - Part 65 of 212
PDF
The Ring programming language version 1.5.3 book - Part 64 of 184
PDF
The Ring programming language version 1.5.4 book - Part 54 of 185
PDF
The Ring programming language version 1.10 book - Part 66 of 212
The Ring programming language version 1.8 book - Part 60 of 202
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.7 book - Part 58 of 196
The Ring programming language version 1.10 book - Part 65 of 212
The Ring programming language version 1.5.3 book - Part 64 of 184
The Ring programming language version 1.5.4 book - Part 54 of 185
The Ring programming language version 1.10 book - Part 66 of 212

What's hot (20)

PDF
The Ring programming language version 1.6 book - Part 73 of 189
PDF
The Ring programming language version 1.7 book - Part 59 of 196
PDF
The Ring programming language version 1.5.2 book - Part 54 of 181
PDF
The Ring programming language version 1.5.1 book - Part 53 of 180
PDF
The Ring programming language version 1.8 book - Part 61 of 202
PDF
551 pd fsam_fayed_ring_doc_1.5.2
PDF
The Ring programming language version 1.6 book - Part 57 of 189
PDF
The Ring programming language version 1.6 book - Part 59 of 189
PDF
The Ring programming language version 1.5.3 book - Part 65 of 184
PDF
Debug sunday #2 ui practice #2
PDF
The Ring programming language version 1.9 book - Part 64 of 210
PDF
Refactoring Strategies: Beyond the Basics
PDF
The Ring programming language version 1.7 book - Part 63 of 196
PDF
Design Patterns in Game Programming
PPTX
Open gl polygon code review
PDF
The Ring programming language version 1.5.4 book - Part 70 of 185
PDF
The Ring programming language version 1.9 book - Part 65 of 210
PDF
The Ring programming language version 1.8 book - Part 77 of 202
PDF
Programação de Jogos - Design Patterns
The Ring programming language version 1.6 book - Part 73 of 189
The Ring programming language version 1.7 book - Part 59 of 196
The Ring programming language version 1.5.2 book - Part 54 of 181
The Ring programming language version 1.5.1 book - Part 53 of 180
The Ring programming language version 1.8 book - Part 61 of 202
551 pd fsam_fayed_ring_doc_1.5.2
The Ring programming language version 1.6 book - Part 57 of 189
The Ring programming language version 1.6 book - Part 59 of 189
The Ring programming language version 1.5.3 book - Part 65 of 184
Debug sunday #2 ui practice #2
The Ring programming language version 1.9 book - Part 64 of 210
Refactoring Strategies: Beyond the Basics
The Ring programming language version 1.7 book - Part 63 of 196
Design Patterns in Game Programming
Open gl polygon code review
The Ring programming language version 1.5.4 book - Part 70 of 185
The Ring programming language version 1.9 book - Part 65 of 210
The Ring programming language version 1.8 book - Part 77 of 202
Programação de Jogos - Design Patterns
Ad

Similar to The Ring programming language version 1.5.1 book - Part 52 of 180 (20)

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.7 book - Part 62 of 196
PDF
The Ring programming language version 1.5.4 book - Part 58 of 185
PDF
The Ring programming language version 1.5.2 book - Part 57 of 181
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 56 of 180
PDF
The Ring programming language version 1.10 book - Part 68 of 212
PDF
The Ring programming language version 1.5.1 book - Part 54 of 180
PDF
The Ring programming language version 1.5.4 book - Part 55 of 185
PDF
The Ring programming language version 1.5.3 book - Part 68 of 184
PDF
The Ring programming language version 1.10 book - Part 67 of 212
PDF
The Ring programming language version 1.5.2 book - Part 8 of 181
PDF
The Ring programming language version 1.9 book - Part 67 of 210
PDF
The Ring programming language version 1.10 book - Part 16 of 212
PDF
The Ring programming language version 1.9 book - Part 68 of 210
PDF
The Ring programming language version 1.7 book - Part 60 of 196
PDF
The Ring programming language version 1.5.1 book - Part 55 of 180
PDF
The Ring programming language version 1.6 book - Part 58 of 189
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.7 book - Part 62 of 196
The Ring programming language version 1.5.4 book - Part 58 of 185
The Ring programming language version 1.5.2 book - Part 57 of 181
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 56 of 180
The Ring programming language version 1.10 book - Part 68 of 212
The Ring programming language version 1.5.1 book - Part 54 of 180
The Ring programming language version 1.5.4 book - Part 55 of 185
The Ring programming language version 1.5.3 book - Part 68 of 184
The Ring programming language version 1.10 book - Part 67 of 212
The Ring programming language version 1.5.2 book - Part 8 of 181
The Ring programming language version 1.9 book - Part 67 of 210
The Ring programming language version 1.10 book - Part 16 of 212
The Ring programming language version 1.9 book - Part 68 of 210
The Ring programming language version 1.7 book - Part 60 of 196
The Ring programming language version 1.5.1 book - Part 55 of 180
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)

PDF
NewMind AI Weekly Chronicles - August'25 Week I
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PPTX
Big Data Technologies - Introduction.pptx
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PPTX
Programs and apps: productivity, graphics, security and other tools
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Approach and Philosophy of On baking technology
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
Encapsulation theory and applications.pdf
PPT
Teaching material agriculture food technology
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
KodekX | Application Modernization Development
PDF
Unlocking AI with Model Context Protocol (MCP)
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PDF
Machine learning based COVID-19 study performance prediction
NewMind AI Weekly Chronicles - August'25 Week I
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
“AI and Expert System Decision Support & Business Intelligence Systems”
Big Data Technologies - Introduction.pptx
Per capita expenditure prediction using model stacking based on satellite ima...
Programs and apps: productivity, graphics, security and other tools
20250228 LYD VKU AI Blended-Learning.pptx
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Approach and Philosophy of On baking technology
Chapter 3 Spatial Domain Image Processing.pdf
Diabetes mellitus diagnosis method based random forest with bat algorithm
Encapsulation theory and applications.pdf
Teaching material agriculture food technology
Understanding_Digital_Forensics_Presentation.pptx
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
KodekX | Application Modernization Development
Unlocking AI with Model Context Protocol (MCP)
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
Machine learning based COVID-19 study performance prediction

The Ring programming language version 1.5.1 book - Part 52 of 180

  • 1. CHAPTER FIFTYFOUR USING RINGOPENGL AND RINGFREEGLUT FOR 3D GRAPHICS In this chapter we will learn about using RingOpenGL 54.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 54.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 485
  • 2. Ring Documentation, Release 1.5.1 • 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? 486
  • 3. Ring Documentation, Release 1.5.1 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 487
  • 4. Ring Documentation, Release 1.5.1 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 488
  • 5. Ring Documentation, Release 1.5.1 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 489
  • 6. Ring Documentation, Release 1.5.1 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 490
  • 7. Ring Documentation, Release 1.5.1 // 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 491
  • 8. Ring Documentation, Release 1.5.1 // 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 492
  • 9. Ring Documentation, Release 1.5.1 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 493
  • 10. Ring Documentation, Release 1.5.1 // (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 494