### OpenGL Application Setup and Rendering Source: https://ring-lang.github.io/doc1.27/usingopengl.html A comprehensive example demonstrating camera movement, window resizing, 3D object rendering, and frame rate calculation. ```Ring 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 xOrigin = -1 // Constant definitions for Menus C_RED = 1 C_GREEN = 2 C_BLUE = 3 C_ORANGE = 4 C_FILL = 5 C_LINE = 6 // Pop up menu identifiers fillMenu=NULL fontMenu=NULL mainMenu=NULL colorMenu=NULL // color for the nose red = 1.0 blue=0.5 green=0.5 // scale of snowman scale = 1.0 // menu status menuFlag = 0 // default font font = GLUT_BITMAP_TIMES_ROMAN_24 C_INT_GLUT_BITMAP_8_BY_13 = 7 C_INT_GLUT_BITMAP_9_BY_15 = 8 C_INT_GLUT_BITMAP_TIMES_ROMAN_10 = 9 C_INT_GLUT_BITMAP_TIMES_ROMAN_24 = 10 C_INT_GLUT_BITMAP_HELVETICA_10 = 11 C_INT_GLUT_BITMAP_HELVETICA_12 = 12 C_INT_GLUT_BITMAP_HELVETICA_18 = 13 // width and height of the window h = 0 w = 0 // variables to compute frames per second frame=0 time=0 timebase=0 s = "" 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 glScalef(scale, scale, scale) 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(red, green, blue) glRotatef(0.0,1.0, 0.0, 0.0) glutSolidCone(0.08,0.5,10,2) glColor3f(1.0, 1.0, 1.0) func renderBitmapString x,y,z,font,string glRasterPos3f(x, y,z) for c in string glutBitmapCharacter(font,ascii(c)) next func renderStrokeFontString x,y,z,font,string glPushMatrix() glTranslatef(x, y,z) glScalef(0.002, 0.002, 0.002) for c in string glutStrokeCharacter(font, Ascii(c)); next glPopMatrix() func restorePerspectiveProjection glMatrixMode(GL_PROJECTION) // restore previous projection matrix glPopMatrix() // get back to modelview mode glMatrixMode(GL_MODELVIEW) func setOrthographicProjection // switch to projection mode glMatrixMode(GL_PROJECTION) // save previous matrix which contains the //settings for the perspective projection glPushMatrix() // reset matrix glLoadIdentity() // set a 2D orthographic projection gluOrtho2D(0, w, h, 0) // switch back to modelview mode glMatrixMode(GL_MODELVIEW) func computePos deltaMove x += deltaMove * lx * 0.1 z += deltaMove * lz * 0.1 func renderScene if deltaMove computePos(deltaMove) 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 9 SnowMen for i = -3 to -1 for j = -3 to -1 glPushMatrix() glTranslatef(i*10.0, 0.0, j * 10.0) drawSnowMan() number = (i+3)*3+(j+3) renderBitmapString(0.0, 0.5, 0.0,font ,""+number) glPopMatrix() next next // Code to compute frames per second frame++ ``` -------------------------------- ### Initialize and Configure a Qt3D Scene Source: https://ring-lang.github.io/doc1.27/qt3d.html This example demonstrates the full lifecycle of a Qt3D scene, including window creation, camera setup, model loading, material application, and light source configuration. ```Ring load "guilib.ring" new qApp { oWidget = new QWidget() oView = new Qt3DWindow() oView.defaultFrameGraph().setClearColor(new QColor() {setRGB(0,0,0,255)}) oContainer = oWidget.createWindowContainer(oView,oWidget,0) oRootEntity = new QEntity(oContainer) oInput = new QInputAspect(oRootEntity) oView.registerAspect(oInput) oCameraEntity = oView.Camera() oCameraEntity.lens().setPerspectiveProjection(45.0, 16.0/9.0, 0.1, 1000) oCameraEntity.setPosition(new QVector3D(-13.34, -6.43, 16.47)) oCameraEntity.setUpVector(new QVector3D(0.02, 0, 1)) oCameraEntity.setViewCenter(new QVector3D(-13.34, 17.05, 15.42)) oCameraController = new QFirstPersonCameraController(oRootEntity) oCameraController.setCamera(oCameraEntity) oCameraController.setEnabled(False) oLongRoomEntity = new QEntity(oRootEntity) oLongRoomModel = new QMesh(oLongRoomEntity) oLongRoomModel.setSource( new qURL("file:///"+CurrentDir()+"/assets/model/Long_Room.obj") ) oLongRoomTransform = new QTransform(oLongRoomEntity) oLongRoomTransform.setScale(1) oLongRoomTransform.setTranslation(new QVector3D(5, 0, 15)) oLongRoomLoader = new QTextureLoader(oLongRoomModel) oLongRoomMaterial = new QTextureMaterial(oLongRoomModel) oLongRoomLoader.setSource( new QUrl("file:///"+currentdir()+"/assets/texture/croc.jpg") ) oLongRoomMaterial.setTexture(oLongRoomLoader) oLongRoomEntity.addComponent(oLongRoomModel) oLongRoomEntity.addComponent(oLongRoomMaterial) oLongRoomEntity.addComponent(oLongRoomTransform) oTableEntity = new QEntity(oRootEntity) oTableModel = new QMesh(oTableEntity) oTableModel.setSource( new qURL("file:///"+CurrentDir()+"/assets/model/Reception_Table.obj") ) oTableTransform = new QTransform(oTableEntity) oTableTransform.setScale(0.3) oTableTransform.setTranslation(new QVector3D(5, 0, 15)) oQ = new QQuaternion(0,0,0,0) oTableTransform.setRotation(oQ.fromAxisAndAngle(new QVector3D(0, 1, 1), -180)) oTableModelMaterial = new QPhongMaterial(oTableEntity) oTableModelMaterial.setDiffuse(new QColor() {setRGB(255,255,255,255)}) oTableEntity.addComponent(oTableModel) oTableEntity.addComponent(oTableModelmaterial) oTableEntity.addComponent(oTableTransform) oFirstLightEntity = new QEntity(oRootEntity) oFirstLight = new QPointLight(oFirstLightEntity) oFirstLight.setColor(new qColor() { setRGB(128,128,128,128) }) oFirstLight.setIntensity(1) oFirstLightTransform = new QTransform(oFirstLightEntity) oFirstLightTransform.setTranslation(new QVector3D(5, 0, 20)) oFirstLightEntity.addComponent(oFirstLight) oFirstLightEntity.addComponent(oFirstLightTransform) aCats = list(5) for n = 1 to 5 v = n * 0.1 aCats[n] = [] aCats[n][:oCatModelEntity] = new QEntity(oRootEntity) aCats[n][:oCatModel] = new QMesh(aCats[n][:oCatModelEntity]) aCats[n][:oCatModel].setSource( new qURL("file:///"+CurrentDir()+"/assets/model/Lucky_Cat.obj") ) aCats[n][:oCatModelMaterial] = new QPhongMaterial(aCats[n][:oCatModel]) aCats[n][:oCatModelMaterial].setDiffuse( new QColor() {setRGB(255,255,255,255)}) aCats[n][:oCatModelTransform] = new QTransform(aCats[n][:oCatModelEntity]) aCats[n][:oCatModelTransform].setScale(0.01) aCats[n][:oCatModelTransform].setTranslation( new QVector3D(-5*(v+v), 1, 15.2)) oQ = new QQuaternion(0,0,0,0) aCats[n][:oCatModelTransform].setRotation( oQ.fromAxisAndAngle( new QVector3D(0, 1, 1), 180)) aCats[n][:oCatModelEntity].addComponent(aCats[n][:oCatModel]) aCats[n][:oCatModelEntity].addComponent(aCats[n][:oCatModelmaterial]) aCats[n][:oCatModelEntity].addComponent(aCats[n][:oCatModelTransform]) next oSecondLightEntity = new QEntity(oRootEntity) oSecondLight = new QPointLight(oSecondLightEntity) oSecondLight.setColor(new qColor() { setRGB(255,255,255,255) }) oSecondLight.setIntensity(1) oSecondLightTransform = new QTransform(oSecondLightEntity) oSecondLightTransform.setTranslation(new QVector3D(-5, 1, 15.5)) oSecondLightEntity.addComponent(oSecondLight) oSecondLightEntity.addComponent(oSecondLightTransform) oRobotEntity = new QEntity(oRootEntity) ``` -------------------------------- ### LibUI Control Gallery Implementation Source: https://ring-lang.github.io/doc1.27/libui.html A complete example demonstrating the setup of a main window with tabs and various UI components like sliders, spinboxes, and file choosers. ```ring # Sample ported to Ring # Based on original sample from : https://github.com/andlabs/libui load "libui.ring" # Global Variables slider = NULL spinbox = NULL pBar = NULL entryOpen = NULL entrySave = NULL # Main Window mainwin = uiNewWindow("libui Control Gallery", 640, 480, 1) uiWindowOnClosing(mainwin, "onClosing()") tab = uiNewTab() uiWindowSetChild(mainwin, tab) uiWindowSetMargined(mainwin, 1) uiTabAppend(tab, "Basic Controls", makeBasicControlsPage()) uiTabSetMargined(tab, 0, 1) uiTabAppend(tab, "Numbers and Lists", makeNumbersPage()) uiTabSetMargined(tab, 1, 1) uiTabAppend(tab, "Data Choosers", makeDataChoosersPage()) uiTabSetMargined(tab, 2, 1) uiControlShow(mainwin) uiMain() func onClosing uiQuit() func makeDataChoosersPage hbox = uiNewHorizontalBox() uiBoxSetPadded(hbox, 1) vbox = uiNewVerticalBox() uiBoxSetPadded(vbox, 1) uiBoxAppend(hbox, vbox, 0) uiBoxAppend(vbox, uiNewDatePicker(), 0) uiBoxAppend(vbox, uiNewTimePicker(), 0) uiBoxAppend(vbox, uiNewDateTimePicker(), 0) uiBoxAppend(vbox, uiNewFontButton(), 0) uiBoxAppend(vbox, uiNewColorButton(), 0) uiBoxAppend(hbox, uiNewVerticalSeparator(), 0) vbox = uiNewVerticalBox() uiBoxSetPadded(vbox, 1) uiBoxAppend(hbox, vbox, 1) grid = uiNewGrid() uiGridSetPadded(grid, 1) uiBoxAppend(vbox, grid, 0) button = uiNewButton("Open File") entryOpen = uiNewEntry() uiEntrySetReadOnly(entryOpen, 1) uiButtonOnClicked(button, "onOpenFileClicked()") uiGridAppend(grid, button, 0, 0, 1, 1, 0, uiAlignFill, 0, uiAlignFill) uiGridAppend(grid, entryOpen, 1, 0, 1, 1, 1, uiAlignFill, 0, uiAlignFill) button = uiNewButton("Save File") entrySave = uiNewEntry() uiEntrySetReadOnly(entrySave, 1) uiButtonOnClicked(button, "onSaveFileClicked()") uiGridAppend(grid, button, 0, 1, 1, 1, 0, uiAlignFill, 0, uiAlignFill) uiGridAppend(grid, entrySave, 1, 1, 1, 1, 1, uiAlignFill, 0, uiAlignFill) msggrid = uiNewGrid() uiGridSetPadded(msggrid, 1) uiGridAppend(grid, msggrid, 0, 2, 2, 1, 0, uiAlignCenter, 0, uiAlignStart) button = uiNewButton("Message Box") uiButtonOnClicked(button, "onMsgBoxClicked()") uiGridAppend(msggrid, button, 0, 0, 1, 1, 0, uiAlignFill, 0, uiAlignFill) button = uiNewButton("Error Box") uiButtonOnClicked(button, "onMsgBoxErrorClicked()") uiGridAppend(msggrid, button, 1, 0, 1, 1, 0, uiAlignFill, 0, uiAlignFill) return hbox func makeNumbersPage hbox = uiNewHorizontalBox() uiBoxSetPadded(hbox, 1) group = uiNewGroup("Numbers") uiGroupSetMargined(group, 1) uiBoxAppend(hbox, group, 1) vbox = uiNewVerticalBox() uiBoxSetPadded(vbox, 1) uiGroupSetChild(group, vbox) spinbox = uiNewSpinbox(0, 100) slider = uiNewSlider(0, 100) pbar = uiNewProgressBar() uiSpinboxOnChanged(spinbox, "onSpinboxChanged()") uiSliderOnChanged(slider, "onSliderChanged()") uiBoxAppend(vbox, spinbox, 0) uiBoxAppend(vbox, slider, 0) uiBoxAppend(vbox, pbar, 0) ip = uiNewProgressBar() uiProgressBarSetValue(ip, -1) uiBoxAppend(vbox, ip, 0) group = uiNewGroup("Lists") uiGroupSetMargined(group, 1) uiBoxAppend(hbox, group, 1) vbox = uiNewVerticalBox() uiBoxSetPadded(vbox, 1) uiGroupSetChild(group, vbox) cbox = uiNewCombobox() uiComboboxAppend(cbox, "Combobox Item 1") uiComboboxAppend(cbox, "Combobox Item 2") uiComboboxAppend(cbox, "Combobox Item 3") uiBoxAppend(vbox, cbox, 0) ecbox = uiNewEditableCombobox() uiEditableComboboxAppend(ecbox, "Editable Item 1") uiEditableComboboxAppend(ecbox, "Editable Item 2") uiEditableComboboxAppend(ecbox, "Editable Item 3") uiBoxAppend(vbox, ecbox, 0) rb = uiNewRadioButtons() uiRadioButtonsAppend(rb, "Radio Button 1") uiRadioButtonsAppend(rb, "Radio Button 2") uiRadioButtonsAppend(rb, "Radio Button 3") uiBoxAppend(vbox, rb, 0) return hbox func makeBasicControlsPage vbox = uiNewVerticalBox() uiBoxSetPadded(vbox, 1) ``` -------------------------------- ### Install Dependencies Source: https://ring-lang.github.io/doc1.27/sourcecode.html Navigate to the build directory and execute the dependency installation script. ```bash cd ring/build ./installdepmac.sh ``` -------------------------------- ### Initialize OpenGL and GLUT Source: https://ring-lang.github.io/doc1.27/usingopengl.html Basic setup for OpenGL depth testing and starting the GLUT event processing loop. ```Ring // here are the two new functions glutMouseFunc(:mouseButton) glutMotionFunc(:mouseMove) // OpenGL init glEnable(GL_DEPTH_TEST) // enter GLUT event processing cycle glutMainLoop() ``` -------------------------------- ### Install RingQt3D Samples Source: https://ring-lang.github.io/doc1.27/qt3d.html Use the Ring Package Manager to install the sample projects for this chapter. ```bash ringpm install ringqt3dsamples ``` -------------------------------- ### Complete Build and Installation Source: https://ring-lang.github.io/doc1.27/sourcecode.html Commands to build the entire project and install the binary to the system path. ```bash cd ring/build ./buildclang.sh ``` ```bash cd ring/bin sudo ./install.sh ``` -------------------------------- ### Install and run Chess3D-Qt3D sample Source: https://ring-lang.github.io/doc1.27/whatisnew15.html Commands to install and execute the Chess3D-Qt3D application using the Ring Package Manager. ```bash ringpm install Chess3D-Qt3D ringpm run Chess3D-Qt3D ``` -------------------------------- ### Install Dependencies Source: https://ring-lang.github.io/doc1.27/sourcecode.html Runs the dependency installation script for Ubuntu. ```bash cd ring/build ./installdepubuntu.sh ``` -------------------------------- ### Install PPTXLib Source: https://ring-lang.github.io/doc1.27/whatisnew27.html Use the Ring package manager to install the PPTXLib library. ```bash ringpm install pptxlib ``` -------------------------------- ### Install Ring System-Wide Source: https://ring-lang.github.io/doc1.27/ring_cloud_cgi.html Execute the installation script to make the ring command available globally. ```bash cd /opt/ring/bin sudo bash install.sh ``` -------------------------------- ### Hello World using the Web Library Source: https://ring-lang.github.io/doc1.27/web.html Utilize the System.Web library to generate HTML pages. Example 1 uses the 'new' keyword, while Example 2 uses the WebPage() function. ```ring #!ring -cgi Load "weblib.ring" Import System.Web New Page { Text("Hello World!") } ``` ```ring #!ring -cgi Load "weblib.ring" Import System.Web WebPage() { Text("Hello World!") } ``` -------------------------------- ### Main menu program output example Source: https://ring-lang.github.io/doc1.27/demo.html Example output showing the interaction flow of the menu-driven program. ```Text Main Menu =========== [1] Say Hello [2] Sum two numbers [3] Stars [4] Fact [5] Exit 1 Enter your name ? Mahmoud Fayed Hello Mahmoud Fayed Main Menu =========== [1] Say Hello [2] Sum two numbers [3] Stars [4] Fact [5] Exit 2 number 1 : 3 number 2 : 4 Sum : 7 Main Menu =========== [1] Say Hello [2] Sum two numbers [3] Stars [4] Fact [5] Exit 3 * ** *** **** ***** ****** ******* ******** ********* ********** Main Menu =========== [1] Say Hello [2] Sum two numbers [3] Stars [4] Fact [5] Exit 4 Enter Number : 5 Output : 120 Main Menu =========== [1] Say Hello [2] Sum two numbers [3] Stars [4] Fact [5] Exit 5 ``` -------------------------------- ### Initialize a libui Window and Layout Source: https://ring-lang.github.io/doc1.27/libui.html Demonstrates the basic setup of a window, horizontal and vertical boxes, a font button, a form, and a combobox. ```Ring mainwin = uiNewWindow("libui Text-Drawing Example", 640, 480, 1) uiWindowSetMargined(mainwin, 1) uiWindowOnClosing(mainwin, "onClosing()") hbox = uiNewHorizontalBox() uiBoxSetPadded(hbox, 1) uiWindowSetChild(mainwin, hbox) vbox = uiNewVerticalBox() uiBoxSetPadded(vbox, 1) uiBoxAppend(hbox, vbox, 0) fontButton = uiNewFontButton() uiFontButtonOnChanged(fontButton, "onFontChanged()") uiBoxAppend(vbox, fontButton, 0) form = uiNewForm() uiFormSetPadded(form, 1) uiBoxAppend(vbox, form, 0) alignment = uiNewCombobox() uiComboboxAppend(alignment, "Left") uiComboboxAppend(alignment, "Center") uiComboboxAppend(alignment, "Right") uiComboboxSetSelected(alignment, 0) // start with left alignment uiComboboxOnSelected(alignment, "onComboboxSelected()") uiFormAppend(form, "Alignment", alignment, 0) oAreaHandler = uiNewAreaHandler("handlerDraw()","","","","") area = uiNewArea(oAreaHandler) uiBoxAppend(hbox, area, 1) uiControlShow(mainwin) uiMain() uiFreeAttributedString(attrstr) ``` -------------------------------- ### Install and Run TUI Framework Source: https://ring-lang.github.io/doc1.27/whatisnew26.html Commands to install and execute the TUI framework developed via prompt-driven development. ```bash ringpm install TUIFrameworkUsingClaudeCode ringpm run TUIFrameworkUsingClaudeCode ``` -------------------------------- ### Initialize Main Application Source: https://ring-lang.github.io/doc1.27/usingopengl.html Sets up the GLUT window, registers callbacks, and starts the event loop. ```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 10") // register callbacks glutDisplayFunc(:renderScene) glutReshapeFunc(:changeSize) glutIdleFunc(:renderScene) glutIgnoreKeyRepeat(1) glutKeyboardFunc(:processNormalKeys) glutSpecialFunc(:pressKey) glutSpecialUpFunc(:releaseKey) // here are the two new functions glutMouseFunc(:mouseButton) glutMotionFunc(:mouseMove) // OpenGL init glEnable(GL_DEPTH_TEST) glEnable(GL_CULL_FACE) // init Menus createPopupMenus() // enter GLUT event processing cycle glutMainLoop() ``` -------------------------------- ### Install RingPM packages Source: https://ring-lang.github.io/doc1.27/whatisnew24.html Install additional packages from the RingPM registry using the install command. ```bash ringpm install webview ``` -------------------------------- ### Create a Hello World console application Source: https://ring-lang.github.io/doc1.27/ringnotepad.html A basic example to print text to the standard output. ```Ring see "Hello, World!" ``` -------------------------------- ### Install Git Source: https://ring-lang.github.io/doc1.27/sourcecode.html Installs the Git version control system. ```bash sudo apt-get install git ``` -------------------------------- ### Run Installed Packages Source: https://ring-lang.github.io/doc1.27/ringpm.html Execute a package that has been previously installed. ```bash ringpm run firstpackage ``` -------------------------------- ### Multi-file project example Source: https://ring-lang.github.io/doc1.27/programstructure.html Demonstrates splitting an application into a main entry file and a secondary file containing function definitions. ```ring # File : Start.ring Load "sub.ring" sayhello("Mahmoud") ``` ```ring # File : sub.ring func sayhello cName see "Hello " + cName + nl ``` -------------------------------- ### Inheritance Example Output Source: https://ring-lang.github.io/doc1.27/oop.html The expected output from the inheritance example. ```Text Name : test Age : 20 Job : programmer Salary : 20000000 ``` -------------------------------- ### While Loop Example Source: https://ring-lang.github.io/doc1.27/controlstructures3.html Example of a while loop containing a switch statement. ```Ring While True { print(" Main Menu --------- (1) Say Hello (2) About (3) Exit ") nOption = GetString() switch nOption { case 1 print("Enter your name : ") name = getstring() print("Hello #{name}\n") case 2 print("Sample : using switch statement\n") case 3 Bye else print("bad option...\n") } } ``` -------------------------------- ### Install Ring-CFFI Source: https://ring-lang.github.io/doc1.27/whatisnew27.html Use the Ring package manager to install the library. ```bash ringpm install ring-cffi ``` -------------------------------- ### Install Archive Package Source: https://ring-lang.github.io/doc1.27/whatisnew26.html Command to install the Archive manipulation library. ```bash ringpm install archive ``` -------------------------------- ### Run Initialization Script Source: https://ring-lang.github.io/doc1.27/ring_cloud.html Execute the script to perform the SSL certificate setup. ```bash ./init-letsencrypt.sh ``` -------------------------------- ### Install RingSlint Package Source: https://ring-lang.github.io/doc1.27/whatisnew26.html Command to install the RingSlint UI package. ```bash ringpm install ring-slint ``` -------------------------------- ### Create a Notepad Application with RingQt Source: https://ring-lang.github.io/doc1.27/qt.html Initializes a main window with a toolbar containing various file and editing operation buttons. ```ring Load "guilib.ring" cActiveFileName = "" aTextColor = [0,0,0] aBackColor = [255,255,255] cFont = "MS Shell Dlg 2,14,-1,5,50,0,0,0,0,0" cWebsite = "http://www.google.com" oSearch = NULL oSearchValue = NULL oSearchCase = NULL oSearchFilter = NULL oReplaceValue = NULL lAskToSave = false MyApp = New qApp { win1 = new qMainWindow() { setwindowtitle("Ring Notepad") setGeometry(100,100,400,400) aBtns = [ new qpushbutton(win1) { setbtnimage(self,"image/new.png") setclickevent("pNew()") settooltip("New File") } , new qpushbutton(win1) { setbtnimage(self,"image/open.png") setclickevent("pOpen()") settooltip("Open File") } , new qpushbutton(win1) { setbtnimage(self,"image/save.png") setclickevent("pSave()") settooltip("Save") } , new qpushbutton(win1) { setbtnimage(self,"image/saveas.png") setclickevent("pSaveAs()") settooltip("Save As") } , new qpushbutton(win1) { setbtnimage(self,"image/cut.png") setclickevent("pCut()") settooltip("Cut") } , new qpushbutton(win1) { setbtnimage(self,"image/copy.png") setclickevent("pCopy()") settooltip("Copy") } , new qpushbutton(win1) { setbtnimage(self,"image/paste.png") setclickevent("pPaste()") settooltip("Paste") } , new qpushbutton(win1) { setbtnimage(self,"image/font.png") setclickevent("pFont()") settooltip("Font") } , new qpushbutton(win1) { setbtnimage(self,"image/colors.jpg") setclickevent("pColor()") settooltip("Text Color") } , new qpushbutton(win1) { setbtnimage(self,"image/search.png") setclickevent("pFind()") settooltip("Find and Replace") } , new qpushbutton(win1) { setbtnimage(self,"image/print.png") setclickevent("pPrint()") settooltip("Print") } , new qpushbutton(win1) { setbtnimage(self,"image/debug.png") setclickevent("pDebug()") settooltip("Debug (Run then wait!)") } , new qpushbutton(win1) { setbtnimage(self,"image/run.png") setclickevent("pRun()") settooltip("Run the program") } , new qpushbutton(win1) { setbtnimage(self,"image/close.png") setclickevent("pQuit()") settooltip("Quit") } ] tool1 = addtoolbar("files") { for x in aBtns addwidget(x) addseparator() next } menu1 = new qmenubar(win1) { sub1 = addmenu("File") ``` -------------------------------- ### Install CodeRooms3D Game Source: https://ring-lang.github.io/doc1.27/whatisnew26.html Command to install the CodeRooms3D game package. ```bash ringpm install coderooms3d ``` -------------------------------- ### Main Initialization Source: https://ring-lang.github.io/doc1.27/usingopengl.html Sets up the GLUT window and registers callback functions. ```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 11") // register callbacks glutDisplayFunc(:renderScene) glutReshapeFunc(:changeSize) glutIdleFunc(:renderScene) glutIgnoreKeyRepeat(1) glutKeyboardFunc(:processNormalKeys) glutSpecialFunc(:pressKey) glutSpecialUpFunc(:releaseKey) // here are the two new functions glutMouseFunc(:mouseButton) glutMotionFunc(:mouseMove) ``` -------------------------------- ### Creating Entry Point File Source: https://ring-lang.github.io/doc1.27/distribute.html Creating a ring.ring file to trigger the application execution. ```text Create a file c:\myapp\ring.ring ``` -------------------------------- ### Install LineDrawing3D Game Source: https://ring-lang.github.io/doc1.27/whatisnew26.html Command to install the LineDrawing3D game package. ```bash ringpm install linedrawing3d ``` -------------------------------- ### Install DaveTheFighter Game Source: https://ring-lang.github.io/doc1.27/whatisnew26.html Command to install the DaveTheFighter game package. ```bash ringpm install davethefighter ``` -------------------------------- ### Initialize Full Screen Window in Ring Raylib Source: https://ring-lang.github.io/doc1.27/ringraylib.html Demonstrates how to set up a window and toggle it to full-screen mode using the Raylib library. ```Ring load "raylib.ring" screenWidth = 1024 screenHeight = 768 InitWindow(screenWidth, screenHeight, "Full Screen") ToggleFullScreen() SetTargetFPS(60) while !WindowShouldClose() BeginDrawing() ClearBackground(DARKBLUE) DrawText("Count from 1 to 10", 190, 200, 20, Yellow) for t = 1 to 10 DrawText("Number: " + t, 190, 200+(30*t), 20, WHITE) next EndDrawing() end CloseWindow() ``` -------------------------------- ### Perform Complete Build Source: https://ring-lang.github.io/doc1.27/sourcecode.html Builds the compiler, VM, extensions, and tools, then runs the installation script. ```bash cd ring/build ./buildgcc.sh ``` -------------------------------- ### Install Tank3D Game Source: https://ring-lang.github.io/doc1.27/whatisnew26.html Command to install the Tank3D game package. ```bash ringpm install tank3d ``` -------------------------------- ### Closure Example Output Source: https://ring-lang.github.io/doc1.27/whatisnew26.html Expected output from the closure example code. ```text 1 11 12 1013 99 1014 98 ``` -------------------------------- ### Use the library wrapper Source: https://ring-lang.github.io/doc1.27/ringemb.html Example of loading and using the commercial library wrapper. ```ring load "commercialLib.ring" mylib.test() ``` -------------------------------- ### Create a Hello World GUI application Source: https://ring-lang.github.io/doc1.27/libui.html Initializes a window with buttons that trigger message boxes or close the application. ```ring load "libui.ring" oWindow = uiNewWindow( "Hello, World", 400, 400, True) uiWindowOnClosing(oWindow,"closeApp()") btn1 = uiNewButton("SayHello") uiButtonOnClicked(btn1,"sayHello()") btn2 = uiNewButton("Close") uiButtonOnClicked(btn2,"closeApp()") g = uiNewGrid() uiGridSetPadded(g, 1) uiWindowSetChild(oWindow, g) uiGridAppend(g, btn1, 0, 0, 2, 1, 1, uiAlignFill, 0, uiAlignFill) uiGridAppend(g, btn2, 0, 1, 1, 1, 1, uiAlignFill, 0, uiAlignFill) uiControlShow( oWindow ) uiMain() func sayHello uiMsgBox(oWindow,"Hi","Hello") func closeApp uiQuit() ``` -------------------------------- ### For in Loop Examples Source: https://ring-lang.github.io/doc1.27/controlstructures3.html Examples of iterating over lists and modifying items by reference. ```Ring aList = 1:10 # create list contains numbers from 1 to 10 for x in aList { print("#{x}\n") } # print numbers from 1 to 10 ``` ```Ring aList = 1:10 # create list contains numbers from 1 to 10 # print odd items inside the list for x in aList step 2 { print("#{x}\n") } ``` ```Ring aList = 1:5 # create list contains numbers from 1 to 5 # replace list numbers with strings for x in aList { switch x { case 1 x = "one" case 2 x = "two" case 3 x = "three" case 4 x = "four" case 5 x = "five" } } print(aList) # print the list items ``` -------------------------------- ### Initialize and Run a Libuv Loop Source: https://ring-lang.github.io/doc1.27/libuv.html Demonstrates the basic lifecycle of a libuv loop, including initialization, execution, and cleanup. ```ring load "libuv.ring" func main myloop = new_uv_loop_t() uv_loop_init(myloop) ? "Now quitting" uv_run(myloop, UV_RUN_DEFAULT) uv_loop_close(myloop) destroy_uv_loop_t(myloop) ``` -------------------------------- ### Install PDFLib Source: https://ring-lang.github.io/doc1.27/whatisnew27.html Use the Ring package manager to install the PDFLib library. ```bash ringpm install pdflib ``` -------------------------------- ### Install SVGLib Source: https://ring-lang.github.io/doc1.27/whatisnew27.html Use the Ring package manager to install the SVGLib library. ```bash ringpm install svglib ``` -------------------------------- ### Install Qt Runtime Source: https://ring-lang.github.io/doc1.27/sourcecode.html Command to copy Qt runtime files to the Ring bin folder. ```batch cd ring/extensions/ringqt/binupdate installqt515.bat ``` -------------------------------- ### Using System Class Methods Source: https://ring-lang.github.io/doc1.27/stdlibclasses.html Demonstrates how to execute system commands, retrieve environment variables, and check operating system properties. ```ring Load "stdlib.ring" oSystem = new System See "Test the System Class Methods" + nl oSystem.system("dir") see oSystem.sysget("path") + nl see oSystem.ismsdos() + nl see oSystem.iswindows() + nl see oSystem.iswindows64() + nl see oSystem.isunix() + nl see oSystem.ismacosx() + nl see oSystem.islinux() + nl see oSystem.isfreebsd() + nl see oSystem.isandroid() + nl see oSystem.windowsnl() + nl see oSystem.sysargv() + nl see oSystem.filename() + nl ``` -------------------------------- ### Initialize Main OpenGL Application Source: https://ring-lang.github.io/doc1.27/usingopengl.html Sets up the GLUT window, registers event callbacks, and starts the main event loop. ```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 - 9 SnowMan") // register callbacks glutDisplayFunc(:renderScene) glutReshapeFunc(:changeSize) glutIdleFunc(:renderScene) glutIgnoreKeyRepeat(1) glutKeyboardFunc(:processNormalKeys) glutSpecialFunc(:pressKey) glutSpecialUpFunc(:releaseKey) // here are the two new functions glutMouseFunc(:mouseButton) glutMotionFunc(:mouseMove) // OpenGL init glEnable(GL_DEPTH_TEST) glEnable(GL_CULL_FACE) // init Menus createPopupMenus() // enter GLUT event processing cycle glutMainLoop() ``` -------------------------------- ### Install Proc Package Source: https://ring-lang.github.io/doc1.27/whatisnew26.html Command to install the Proc package via ringpm. ```bash ringpm install proc ``` -------------------------------- ### Initialize and Render with LibSDL and Tilengine Source: https://ring-lang.github.io/doc1.27/tilengine.html Demonstrates the full lifecycle of integrating Tilengine with LibSDL, including initialization, setting the render target, and the main event loop. ```ring load "tilengine.ring" load "libsdl.ring" width = 640 height = 480 func main # Start Tilengine TLN_Init(width, height, 2, 80, 0) # Start LibSDL SDL_Init(SDL_INIT_EVERYTHING) win = SDL_CreateWindow("Using LibSDL and Tilengine", 100, 100, width, height, SDL_WINDOW_SHOWN|SDL_WINDOW_OPENGL) ren = SDL_CreateRenderer(win, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC ) # Create the Surface in LibSDL that will be used by Tilengine for Drawing surface = SDL_CreateRGBSurface(0, width, height, 32, 0,0,0,0) # Get the Surface Pixels pointer from the Surface Structure pixels = SDL_Get_SDL_Surface_Pixels(surface) # Pass the Pixels pointer to Tilengine TLN_SetRenderTarget(pixels, width * 4) # Using Tilengine TLN_SetLoadPath("assets\sonic") foreground = TLN_LoadTilemap ("Sonic_md_fg1.tmx", NULL) TLN_SetLayerTilemap(0, foreground) # Using LibSDL Events Loop oEvent = SDL_New_SDL_Event() while true # Using Tilengine to Update the Frame TLN_UpdateFrame(0) # Draw Tilengine results using LibSDL # ( Surface --> Texture --> Render) tex = SDL_CreateTextureFromSurface(ren, surface); SDL_RenderCopy2(ren,tex) SDL_DestroyTexture(tex) # Draw Rectangle using LibSDL rect = SDL_New_SDL_Rect() SDL_Set_SDL_Rect_x(rect,10) SDL_Set_SDL_Rect_y(rect,10) SDL_Set_SDL_Rect_w(rect,100) SDL_Set_SDL_Rect_h(rect,100) SDL_SetRenderDrawColor(ren,255,255,255,255) SDL_RenderDrawRect(ren,rect) SDL_Destroy_SDL_Rect(rect) # Display Results using LibSDL SDL_RenderPresent(ren) # Check Events SDL_PollEvent(oEvent) switch SDL_Get_SDL_Event_Type(oEvent) on SDL_Get_SDL_Quit() exit on SDL_Get_SDL_Keydown() Key = SDL_Get_SDL_Event_key_Keysym_Sym(oEvent) if key = 27 exit ok off end # End of Tilengine Usage TLN_Deinit() # End of LibSDL Usage SDL_DestroyWindow(win) SDL_Quit() ``` -------------------------------- ### Print ODBC Drivers Example Source: https://ring-lang.github.io/doc1.27/odbc.html Demonstrates initializing the ODBC interface, listing drivers, and closing the connection. ```ring See "ODBC test 1" + nl oODBC = odbc_init() See "Drivers " + nl see odbc_drivers(oODBC) odbc_close(oODBC) ``` -------------------------------- ### Ring-CFFI Example Output Source: https://ring-lang.github.io/doc1.27/whatisnew27.html Expected console output from the provided CFFI example. ```text sqrt(25) = 5 Hello, World! Number: 123 ``` -------------------------------- ### RandomList function example Source: https://ring-lang.github.io/doc1.27/whatisnew15.html Example usage of the RandomList function to randomize a list. ```ring load "stdlib.ring" aList = 1:5 ? RandomList(aList) ```