You are on page 1of 10

Ring Documentation, Release 1.5.

glLoadIdentity()

// Rotate when user changes rotate_x and rotate_y


glRotatef( rotate_x, 1.0, 0.0, 0.0 )
glRotatef( rotate_y, 0.0, 1.0, 0.0 )

//Multi-colored side - FRONT


glBegin(GL_POLYGON)

glColor3f( 1.0, 0.0, 0.0 ) glVertex3f( 0.5, -0.5, -0.5 ) # P1 is red


glColor3f( 0.0, 1.0, 0.0 ) glVertex3f( 0.5, 0.5, -0.5 ) # P2 is green
glColor3f( 0.0, 0.0, 1.0 ) glVertex3f( -0.5, 0.5, -0.5 ) # P3 is blue
glColor3f( 1.0, 0.0, 1.0 ) glVertex3f( -0.5, -0.5, -0.5 ) # P4 is purple

glEnd()

// White side - BACK


glBegin(GL_POLYGON)
glColor3f( 1.0, 1.0, 1.0 )
glVertex3f( 0.5, -0.5, 0.5 )
glVertex3f( 0.5, 0.5, 0.5 )
glVertex3f( -0.5, 0.5, 0.5 )
glVertex3f( -0.5, -0.5, 0.5 )
glEnd()

// Purple side - RIGHT


glBegin(GL_POLYGON)
glColor3f( 1.0, 0.0, 1.0 )
glVertex3f( 0.5, -0.5, -0.5 )
glVertex3f( 0.5, 0.5, -0.5 )
glVertex3f( 0.5, 0.5, 0.5 )
glVertex3f( 0.5, -0.5, 0.5 )
glEnd()

// Green side - LEFT


glBegin(GL_POLYGON)
glColor3f( 0.0, 1.0, 0.0 )
glVertex3f( -0.5, -0.5, 0.5 )
glVertex3f( -0.5, 0.5, 0.5 )
glVertex3f( -0.5, 0.5, -0.5 )
glVertex3f( -0.5, -0.5, -0.5 )
glEnd()

// Blue side - TOP


glBegin(GL_POLYGON)
glColor3f( 0.0, 0.0, 1.0 )
glVertex3f( 0.5, 0.5, 0.5 )
glVertex3f( 0.5, 0.5, -0.5 )
glVertex3f( -0.5, 0.5, -0.5 )
glVertex3f( -0.5, 0.5, 0.5 )
glEnd()

// Red side - BOTTOM


glBegin(GL_POLYGON)
glColor3f( 1.0, 0.0, 0.0 )
glVertex3f( 0.5, -0.5, -0.5 )
glVertex3f( 0.5, -0.5, 0.5 )
glVertex3f( -0.5, -0.5, 0.5 )

4.11. RingOpenGL Extension 55


Ring Documentation, Release 1.5.2

glVertex3f( -0.5, -0.5, -0.5 )


glEnd()

glFlush()
glutSwapBuffers()

// ----------------------------------------------------------
// specialKeys() Callback Function
// ----------------------------------------------------------
func specialKeys

key = glutEventKey()

// Right arrow - increase rotation by 5 degree


switch Key

on GLUT_KEY_RIGHT
rotate_y += 5

// Left arrow - decrease rotation by 5 degree


on GLUT_KEY_LEFT
rotate_y -= 5

on GLUT_KEY_UP
rotate_x += 5

on GLUT_KEY_DOWN
rotate_x -= 5

off

// Request display update


glutPostRedisplay()

// ----------------------------------------------------------
// main() function
// ----------------------------------------------------------
func main

// Initialize GLUT and process user parameters


glutInit()

// Request double buffered true color window with Z-buffer


glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH)

// Create window
glutCreateWindow("Awesome Cube")

// Enable Z-buffer depth test


glEnable(GL_DEPTH_TEST)

// Callback functions
glutDisplayFunc(:display)
glutSpecialFunc(:specialKeys)

4.11. RingOpenGL Extension 56


Ring Documentation, Release 1.5.2

// Pass control to GLUT for events


glutMainLoop()

// Return to OS

Screen Shot:

4.12 Better Code Generator for Extensions

The Code Generator is updated to support <constant> type, So we can have constants other than numbers, for example
: Strings and Pointers.
When we have pointers we can determine the pointer type. To use this feature, before <constant> and </constant> we
can use
$nDefaultConstantType = C_CONSTANT_TYPE_POINTER
$cDefaultConstantPointerType = "void *"

The next example from the RingFreeGLUT extension


<runcode>
$nDefaultConstantType = C_CONSTANT_TYPE_POINTER
$cDefaultConstantPointerType = "void"
</runcode>
<constant>
GLUT_STROKE_ROMAN
GLUT_STROKE_MONO_ROMAN
GLUT_BITMAP_9_BY_15
GLUT_BITMAP_8_BY_13
GLUT_BITMAP_TIMES_ROMAN_10
GLUT_BITMAP_TIMES_ROMAN_24
GLUT_BITMAP_HELVETICA_10
GLUT_BITMAP_HELVETICA_12

4.12. Better Code Generator for Extensions 57


Ring Documentation, Release 1.5.2

GLUT_BITMAP_HELVETICA_18
</constant>

4.13 Better Documentation Generator for Extensions

The documentation generator for extensions is updated to generate a list of constants in the generated documentation
The previous versions provides the functions prototype only, Now we have the list of constants too.

4.14 Ring VM - Tracing Functions

In Ring 1.5 the next functions are added to Ring VM


• RingVM_SetTrace(cCode)
• RingVM_TraceData() –> aDataList
• RingVM_TraceEvent() –> nTraceEvent
• RingVM_TraceFunc() –> cCode
• RingVM_ScopesCount() –> nScopes
• RingVM_EvalInScope(nScope,cCode)
• RingVM_PassError()
• RingVM_HideErrorMsg(lStatus)
• RingVM_CallFunc(cFuncName)
Example:
load "tracelib.ring"

ringvm_settrace("mytrace()")

see "Hello, world!" + nl


see "Welcome" + nl
see "How are you?" +nl
mytest()
new myclass { mymethod() }

func mytest
see "Message from mytest" + nl

func mytrace
see "====== The Trace function is Active ======" + nl +
"Trace Function Name : " + ringvm_TraceFunc() + nl +
"Trace Event : "
switch ringvm_TraceEvent()
on TRACEEVENT_NEWLINE see "New Line"
on TRACEEVENT_NEWFUNC see "New Function"
on TRACEEVENT_RETURN see "Return"
on TRACEEVENT_ERROR see "Error"
on TRACEEVENT_BEFORECFUNC see "Before C Function"
on TRACEEVENT_AFTERCFUNC see "After C Function"
off

4.13. Better Documentation Generator for Extensions 58


Ring Documentation, Release 1.5.2

see nl +
"Line Number : " + ringvm_tracedata()[TRACEDATA_LINENUMBER] + nl +
"File Name : " + ringvm_tracedata()[TRACEDATA_FILENAME] + nl +
"Function Name : " + ringvm_tracedata()[TRACEDATA_FUNCNAME] + nl +
"Method or Function : "
if ringvm_tracedata()[TRACEDATA_METHODORFUNC] =
TRACEDATA_METHODORFUNC_METHOD
see "Method"
else
if ringvm_tracedata()[TRACEDATA_FUNCNAME] = NULL
see "Command"
else
see "Function"
ok
ok
see nl + Copy("=",42) + nl

class myclass
func mymethod
see "Message from mymethod" + nl

Output:
====== The Trace function is Active ======
Trace Function Name : mytrace()
Trace Event : After C Function
Line Number : 3
File Name : test1.ring
Function Name : ringvm_settrace
Method or Function : Function
==========================================
====== The Trace function is Active ======
Trace Function Name : mytrace()
Trace Event : New Line
Line Number : 5
File Name : test1.ring
Function Name :
Method or Function : Command
==========================================
Hello, world!
====== The Trace function is Active ======
Trace Function Name : mytrace()
Trace Event : New Line
Line Number : 6
File Name : test1.ring
Function Name :
Method or Function : Command
==========================================
Welcome
====== The Trace function is Active ======
Trace Function Name : mytrace()
Trace Event : New Line
Line Number : 7
File Name : test1.ring
Function Name :
Method or Function : Command
==========================================
How are you?

4.14. Ring VM - Tracing Functions 59


Ring Documentation, Release 1.5.2

====== The Trace function is Active ======


Trace Function Name : mytrace()
Trace Event : New Line
Line Number : 8
File Name : test1.ring
Function Name :
Method or Function : Command
==========================================
====== The Trace function is Active ======
Trace Function Name : mytrace()
Trace Event : New Function
Line Number : 8
File Name : test1.ring
Function Name : mytest
Method or Function : Function
==========================================
====== The Trace function is Active ======
Trace Function Name : mytrace()
Trace Event : New Line
Line Number : 12
File Name : test1.ring
Function Name : mytest
Method or Function : Function
==========================================
Message from mytest
====== The Trace function is Active ======
Trace Function Name : mytrace()
Trace Event : New Line
Line Number : 14
File Name : test1.ring
Function Name : mytest
Method or Function : Function
==========================================
====== The Trace function is Active ======
Trace Function Name : mytrace()
Trace Event : Return
Line Number : 8
File Name : test1.ring
Function Name :
Method or Function : Command
==========================================
====== The Trace function is Active ======
Trace Function Name : mytrace()
Trace Event : New Line
Line Number : 9
File Name : test1.ring
Function Name :
Method or Function : Command
==========================================
====== The Trace function is Active ======
Trace Function Name : mytrace()
Trace Event : New Line
Line Number : 43
File Name : test1.ring
Function Name :
Method or Function : Command
==========================================
====== The Trace function is Active ======

4.14. Ring VM - Tracing Functions 60


Ring Documentation, Release 1.5.2

Trace Function Name : mytrace()


Trace Event : Before C Function
Line Number : 9
File Name : test1.ring
Function Name : ismethod
Method or Function : Function
==========================================
====== The Trace function is Active ======
Trace Function Name : mytrace()
Trace Event : After C Function
Line Number : 9
File Name : test1.ring
Function Name : ismethod
Method or Function : Function
==========================================
====== The Trace function is Active ======
Trace Function Name : mytrace()
Trace Event : New Function
Line Number : 9
File Name : test1.ring
Function Name : mymethod
Method or Function : Method
==========================================
====== The Trace function is Active ======
Trace Function Name : mytrace()
Trace Event : New Line
Line Number : 44
File Name : test1.ring
Function Name : mymethod
Method or Function : Method
==========================================
Message from mymethod
====== The Trace function is Active ======
Trace Function Name : mytrace()
Trace Event : Return
Line Number : 9
File Name : test1.ring
Function Name :
Method or Function : Command
==========================================
====== The Trace function is Active ======
Trace Function Name : mytrace()
Trace Event : Before C Function
Line Number : 9
File Name : test1.ring
Function Name : ismethod
Method or Function : Function
==========================================
====== The Trace function is Active ======
Trace Function Name : mytrace()
Trace Event : After C Function
Line Number : 9
File Name : test1.ring
Function Name : ismethod
Method or Function : Function
==========================================
====== The Trace function is Active ======
Trace Function Name : mytrace()

4.14. Ring VM - Tracing Functions 61


Ring Documentation, Release 1.5.2

Trace Event : Before C Function


Line Number : 9
File Name : test1.ring
Function Name : ismethod
Method or Function : Function
==========================================
====== The Trace function is Active ======
Trace Function Name : mytrace()
Trace Event : After C Function
Line Number : 9
File Name : test1.ring
Function Name : ismethod
Method or Function : Function
==========================================
====== The Trace function is Active ======
Trace Function Name : mytrace()
Trace Event : New Line
Line Number : 11
File Name : test1.ring
Function Name :
Method or Function : Command
==========================================

4.15 Trace Library and Interactive Debugger

Ring 1.5 comes with the Trace Library and the Interactive Debugger
Using this library we can trace events, execute programs line by line, open the Interactive Debugger when an error
happens or at breakpoints.
Example:
The next example uses a Breakpoint to open the Interactive Debugger!
load "tracelib.ring"

test1()

func test1
x = 10
see :test1 + nl
t = 12
BreakPoint()
see "After breakpoint!" +nl
see "t = " + t + nl
see "End of program!" + nl

Screen Shots:
We have the Interactive Debugger at the Breakpoint!

4.15. Trace Library and Interactive Debugger 62


Ring Documentation, Release 1.5.2

We can print the variables values

We can change the variables values then continue execution

We can run the Interactive Debugger in the Output Window

4.15. Trace Library and Interactive Debugger 63


Ring Documentation, Release 1.5.2

4.16 More Syntax Flexibility

• Using braces { } in Packages/Classes/Functions


Example:
load "stdlib.ring"

import mypackage

new myclass {
myfunc()
}

package mypackage
{
class myclass
{
func myfunc
{
print("Hello, World!\n")
}
}
}

• Using ‘end’ keyword after Packages/Classes/Functions


Example:
import mypackage

new myclass {
myfunc()
}

4.16. More Syntax Flexibility 64

You might also like