### AppDir Example Source: https://github.com/leadwerks/documentation/blob/master/CS/AppDir.md Demonstrates how to use the AppDir() function to get the application's starting folder. ```csharp using System; namespace MyApp { class Program { static void Main(string[] args) { Console.WriteLine(AppDir()); } } } ``` -------------------------------- ### Example Source: https://github.com/leadwerks/documentation/blob/master/CPP/Window_GetSize.md This example demonstrates how to get and display the window size and client size. ```cpp #include "UltraEngine.h" using namespace UltraEngine; int main(int argc, const char* argv[]) { //Get the displays auto displays = GetDisplays(); //Create window auto window = CreateWindow("Ultra Engine", 0, 0, 800, 600, displays[0], WINDOW_TITLEBAR | WINDOW_RESIZABLE); //Create user interface auto ui = CreateInterface(window); //Display window size auto sz = ui->root->ClientSize(); auto label = CreateLabel("", 0, 0, sz.x, sz.y, ui->root, LABEL_CENTER | LABEL_MIDDLE); label->SetLayout(1, 1, 1, 1); sz = window->GetSize(); auto csz = window->ClientSize(); label->SetText("Window size: " + String(sz.x) + " x " + String(sz.y) + "\n\nClient size: " + String(csz.x) + " x " + String(csz.y)); while (true) { const Event ev = WaitEvent(); switch (ev.id) { case EVENT_WINDOWSIZE: sz = window->GetSize(); csz = window->ClientSize(); label->SetText("Window size: " + String(sz.x) + " x " + String(sz.y) + "\n\nClient size: " + String(csz.x) + " x " + String(csz.y)); break; case EVENT_WINDOWCLOSE: return 0; break; } } return 0; } ``` -------------------------------- ### Example Source: https://github.com/leadwerks/documentation/blob/master/CPP/Window_ClientSize.md This example demonstrates how to get and display the window client size. ```C++ #include "UltraEngine.h" using namespace UltraEngine; int main(int argc, const char* argv[]) { //Get the displays auto displays = GetDisplays(); //Create window auto window = CreateWindow("Ultra Engine", 0, 0, 800, 600, displays[0], WINDOW_TITLEBAR | WINDOW_RESIZABLE); //Create user interface auto ui = CreateInterface(window); //Display window size auto sz = ui->root->ClientSize(); auto label = CreateLabel("", 0, 0, sz.x, sz.y, ui->root, LABEL_CENTER | LABEL_MIDDLE); label->SetLayout(1, 1, 1, 1); sz = window->GetSize(); auto csz = window->ClientSize(); label->SetText("Window size: " + String(sz.x) + " x " + String(sz.y) + "\n\nClient size: " + String(csz.x) + " x " + String(csz.y)); while (true) { const Event ev = WaitEvent(); switch (ev.id) { case EVENT_WINDOWSIZE: sz = window->GetSize(); csz = window->ClientSize(); label->SetText("Window size: " + String(sz.x) + " x " + String(sz.y) + "\n\nClient size: " + String(csz.x) + " x " + String(csz.y)); break; case EVENT_WINDOWCLOSE: return 0; break; } } return 0; } ``` -------------------------------- ### Example Source: https://github.com/leadwerks/documentation/blob/master/Lua/Thread_Start.md Creates a thread object and starts the thread. ```lua -- Create a thread object local thread = Thread() -- Start the thread thread:Start() ``` -------------------------------- ### Example Source: https://github.com/leadwerks/documentation/blob/master/CS/Window_GetSize.md This example demonstrates how to get the window size and client size and display them in a label. ```csharp using System; using System.Collections.Generic; using UltraEngine; class Program { static void Main(string[] args) { //Get the displays var displays = Display.GetDisplays(); //Create window var window = new Window("Ultra Engine", 0, 0, 800, 600, displays[0], Window.Style.WindowTitlebar | Window.Style.WindowResizable); //Create user interface var ui = window.CreateInterface(); //Display window size var sz = ui.root.ClientSize(); var label = new Label("", 0, 0, sz.x, sz.y, ui.root, Label.Style.LabelCenter | Label.Style.LabelMiddle); label.SetLayout(1, 1, 1, 1); sz = window.GetSize(); var csz = window.ClientSize(); label.SetText("Window size: " + sz.x.ToString() + " x " + sz.y.ToString() + "\n\nClient size: " + csz.x.ToString() + " x " + csz.y.ToString()); while (true) { var ev = window.WaitForEvent(); switch (ev.id) { case Event.Type.WindowSize: sz = window.GetSize(); csz = window.ClientSize(); label.SetText("Window size: " + sz.x.ToString() + " x " + sz.y.ToString() + "\n\nClient size: " + csz.x.ToString() + " x " + csz.y.ToString()); break; case Event.Type.WindowClose: return; } } } } ``` -------------------------------- ### Input Example Source: https://github.com/leadwerks/documentation/blob/master/CPP/Input.md Example demonstrating how to use the Input function to get user input and print it. ```cpp #include "pch.h" using namespace UltraEngine; int main(int argc, const char* argv[]) { WString s = Input("Enter your name:"); Print("You entered \"" + s + "."); return 0; } ``` -------------------------------- ### Input Example Source: https://github.com/leadwerks/documentation/blob/master/Lua/Input.md Example demonstrating how to use the Input function to get user input and print it. ```lua local s = Input("Enter your name:") Print("You entered \" .. s .. \".") ``` -------------------------------- ### Example Usage Source: https://github.com/leadwerks/documentation/blob/master/CPP/LoadPlugin.md This example demonstrates how to load a plugin, load a model, set up the environment, create a camera and light, and run the main loop. ```cpp #include "UltraEngine.h" #include "ComponentSystem.h" using namespace UltraEngine; int main(int argc, const char* argv[]) { //Get the displays auto displays = GetDisplays(); //Create a window auto window = CreateWindow("Ultra Engine", 0, 0, 1280, 720, displays[0], WINDOW_CENTER | WINDOW_TITLEBAR); //Create a world auto world = CreateWorld(); world->SetAmbientLight(0); //Create a framebuffer auto framebuffer = CreateFramebuffer(window); //Load FreeImage plugin auto plg = LoadPlugin("Plugins/FITextureLoader"); //Load model //Cyber Samurai by Khoa Minh: https://sketchfab.com/3d-models/cyber-samurai-26ccafaddb2745ceb56ae5cfc65bfed5 auto model = LoadModel(world, "https://github.com/UltraEngine/Documentation/raw/master/Assets/Models/Characters/cyber_samurai.glb"); model->Turn(0, 180, 0, true); //Environment maps auto specmap = LoadTexture("https://github.com/UltraEngine/Assets/raw/main/Materials/Environment/footprint_court/specular.dds"); auto diffmap = LoadTexture("https://github.com/UltraEngine/Assets/raw/main/Materials/Environment/footprint_court/diffuse.dds"); world->SetEnvironmentMap(diffmap, ENVIRONMENTMAP_BACKGROUND); world->SetEnvironmentMap(specmap, ENVIRONMENTMAP_SPECULAR); world->SetEnvironmentMap(diffmap, ENVIRONMENTMAP_DIFFUSE); //Create a camera auto camera = CreateCamera(world); camera->SetClearColor(0.125); camera->SetPosition(0, 1.4, -1); camera->SetFov(70); camera->AddPostEffect(LoadPostEffect("Shaders/PostEffects/FXAA.json")); //Camera controls auto actor = CreateActor(camera); actor->AddComponent(); //Create light auto light = CreateBoxLight(world); light->SetRange(-10, 10); light->SetArea(15, 15); light->SetRotation(45, 35, 0); light->SetColor(1.2); //Main loop while (window->Closed() == false and window->KeyDown(KEY_ESCAPE) == false) { world->Update(); world->Render(framebuffer); } return 0; } ``` -------------------------------- ### GetHmd Example Source: https://github.com/leadwerks/documentation/blob/master/CPP/GetHmd.md This example demonstrates how to get the VR headset using the GetHmd function and then uses it in a VR rendering setup. ```C++ #include "UltraEngine.h" using namespace UltraEngine; int main(int argc, const char* argv[]) { //Get the displays auto displays = GetDisplays(); //Create a window auto window = CreateWindow("Ultra Engine", 0, 0, 1280, 720, displays[0], WINDOW_CLIENTCOORDS | WINDOW_CENTER | WINDOW_TITLEBAR); //Create a framebuffer auto framebuffer = CreateFramebuffer(window); //Create a world auto world = CreateWorld(); //Get the VR headset auto hmd = GetHmd(world); //Environment maps auto specmap = LoadTexture("https://github.com/UltraEngine/Assets/raw/main/Materials/Environment/footprint_court/specular.dds"); auto diffmap = LoadTexture("https://github.com/UltraEngine/Assets/raw/main/Materials/Environment/footprint_court/diffuse.dds"); world->SetEnvironmentMap(specmap, ENVIRONMENTMAP_BACKGROUND); world->SetEnvironmentMap(specmap, ENVIRONMENTMAP_SPECULAR); world->SetEnvironmentMap(diffmap, ENVIRONMENTMAP_DIFFUSE); //Create a light auto light = CreateBoxLight(world); light->SetRotation(55, 35, 0); light->SetRange(-10, 10); light->SetColor(2); //Add a floor auto floor = CreateBox(world, 5, 1, 5); floor->SetPosition(0, -0.5, 0); auto mtl = CreateMaterial(); mtl->SetTexture(LoadTexture("https://github.com/UltraEngine/Documentation/raw/master/Assets/Materials/Developer/griid_gray.dds")); floor->SetMaterial(mtl); //Main loop while (window->Closed() == false and window->KeyDown(KEY_ESCAPE) == false) { world->Update(); world->Render(framebuffer); } return 0; } ``` -------------------------------- ### Example Usage Source: https://github.com/leadwerks/documentation/blob/master/Lua/Window_Activate.md Demonstrates how to create two windows and then activate the first one, bringing it to the foreground. ```Lua -- Get the displays local displays = GetDisplays() -- Create window local window1 = CreateWindow("Window 1", 0, 0, 640, 480, displays[1], WINDOW_TITLEBAR) local window2 = CreateWindow("Window 2", 200, 200, 640, 480, displays[1], WINDOW_TITLEBAR) window1:Activate() while true do local ev = WaitEvent() if ev.id == EVENT_WINDOWCLOSE then return end end ``` -------------------------------- ### C# Thread Start Source: https://github.com/leadwerks/documentation/blob/master/CS/Thread_Start.md Example of starting a thread using C# in Leadwerks. ```csharp using System; using System.Threading; public class Program { public static void MyFunction() { Console.WriteLine("This is a thread!"); } public static void Main(string[] args) { Thread myThread = new Thread(MyFunction); myThread.Start(); myThread.Join(); } } ``` -------------------------------- ### Server Example Source: https://github.com/leadwerks/documentation/blob/master/CS/Server.md Demonstrates how to create and use the Server class. ```csharp Server server = Server.CreateServer(); server.Broadcast("Hello, everyone!"); server.Send(123, "Welcome to the server!"); server.Update(); server.Disconnect(456); ``` -------------------------------- ### C++ Thread Start Source: https://github.com/leadwerks/documentation/blob/master/CS/Thread_Start.md Example of starting a thread using C++ in Leadwerks. ```cpp #include #include using namespace std; void myFunction() { cout << "This is a thread!" << endl; } int main() { thread myThread(myFunction); myThread.Start(); myThread.join(); return 0; } ``` -------------------------------- ### Example Source: https://github.com/leadwerks/documentation/blob/master/Lua/Window_GetSize.md Demonstrates how to get and display the window size and client size, updating it when the window is resized. ```lua --Get the displays local displays = GetDisplays() --Create window local window = CreateWindow("Ultra Engine", 0, 0, 800, 600, displays[1], WINDOW_TITLEBAR | WINDOW_RESIZABLE) --Create user interface local ui = CreateInterface(window) --Display window size local sz = ui.background:ClientSize() local label = CreateLabel("", 0, 0, sz.x, sz.y, ui.background, LABEL_CENTER | LABEL_MIDDLE) label:SetLayout(1, 1, 1, 1) sz = window:GetSize() local csz = window:ClientSize() label:SetText("Window size: " .. tostring(sz.x) .. " x " .. tostring(sz.y) .. "\n\nClient size: " .. tostring(csz.x) .. " x " .. tostring(csz.y)) while true do local ev = WaitEvent() if ev.id == EVENT_WINDOWSIZE then sz = window:GetSize() csz = window:ClientSize() label:SetText("Window size: " .. tostring(sz.x) .. " x " .. tostring(sz.y) .. "\n\nClient size: " .. tostring(csz.x) .. " x " .. tostring(csz.y)) elseif ev.id == EVENT_WINDOWCLOSE then return 0 end end ``` -------------------------------- ### Get Leaderboard Entries Example Source: https://github.com/leadwerks/documentation/blob/master/Lua/Steamworks_GetLeaderboardEntries.md This example demonstrates how to initialize Steamworks, get a leaderboard, retrieve its entries, and print the user names and scores. ```lua -- Initialize Steam if not Steamworks.Initialize() then RuntimeError("Steamworks failed to initialize.") return end -- Get the leaderboard local leaderboard = Steamworks.GetLeaderboard("Feet Traveled") Print("Leaderboard: " .. tostring(leaderboard)) -- Get leaderboard entries and print them local entries = Steamworks.GetLeaderboardEntries(leaderboard) for n = 1, #entries do local name = Steamworks.GetUserName(entries[n].userid) Print(name .. ": " .. tostring(entries[n].score)) end -- Shutdown Steam Steamworks.Shutdown() ``` -------------------------------- ### Example Source: https://github.com/leadwerks/documentation/blob/master/CS/Window_Activate.md This example demonstrates how to create two windows and then activate the first window. ```csharp using System; using UltraEngine; class Program { static void Main(string[] args) { //Get the displays var displays = Engine.GetDisplays(); //Create window var window1 = Engine.CreateWindow("Window 1", 0, 0, 640, 480, displays[0]); var window2 = Engine.CreateWindow("Window 2", 200, 200, 640, 480, displays[0]); window1.Activate(); while (true) { Event ev = Engine.WaitEvent(); switch (ev.id) { case Engine.EVENT_WINDOWCLOSE: return; } } } } ``` -------------------------------- ### Example Source: https://github.com/leadwerks/documentation/blob/master/CS/Window_GetPosition.md Example of how to get and display the window position. ```csharp using System; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Input; public class Game1 : Game { GraphicsDeviceManager graphics; SpriteBatch spriteBatch; Vector2 windowPosition; public Game1() { graphics = new GraphicsDeviceManager(this); Content.RootDirectory = "Content"; } protected override void Initialize() { //Create window Window.Position = Point.Zero; //Create user interface //TODO: Create UI base.Initialize(); } protected override void LoadContent() { spriteBatch = new SpriteBatch(GraphicsDevice); //Display window position var label = new Label(); //TODO: Set label properties label.Text = "Window position: " + windowPosition.X + " x " + windowPosition.Y; //TODO: Add label to UI base.LoadContent(); } protected override void Update(GameTime gameTime) { //Get window position windowPosition = Window.Position.ToVector2(); base.Update(gameTime); } protected override void Draw(GameTime gameTime) { GraphicsDevice.Clear(Color.CornflowerBlue); spriteBatch.Begin(); //TODO: Draw UI spriteBatch.End(); base.Draw(gameTime); } static void Main(string[] args) { using (var game = new Game1()) { game.Run(); } } } ``` -------------------------------- ### GetRotation Example Source: https://github.com/leadwerks/documentation/blob/master/CS/VrDevice_GetRotation.md Example of how to get the device rotation. ```csharp Vector3 rotation = VrDevice.GetRotation(); ``` -------------------------------- ### Example Source: https://github.com/leadwerks/documentation/blob/master/Lua/Window_ClientSize.md Demonstrates how to get and display the window's client size, updating it when the window is resized. ```lua -- Get the displays local displays = GetDisplays() -- Create window local window = CreateWindow("Ultra Engine", 0, 0, 800, 600, displays[1], WINDOW_TITLEBAR | WINDOW_RESIZABLE) -- Create user interface local ui = CreateInterface(window) -- Display window size local sz = ui.background:ClientSize() local label = CreateLabel("", 0, 0, sz.x, sz.y, ui.background, LABEL_CENTER | LABEL_MIDDLE) label:SetLayout(1, 1, 1, 1) sz = window:GetSize() local csz = window:ClientSize() label:SetText("Window size: " .. tostring(sz.x) .. " x " .. tostring(sz.y) .. "\n\nClient size: " .. tostring(csz.x) .. " x " .. tostring(csz.y)) while true do local ev = WaitEvent() if ev.id == EVENT_WINDOWSIZE then sz = window:GetSize() csz = window:ClientSize() label:SetText("Window size: " .. tostring(sz.x) .. " x " .. tostring(sz.y) .. "\n\nClient size: " .. tostring(csz.x) .. " x " .. tostring(csz.y)) elseif ev.id == EVENT_WINDOWCLOSE then return 0 end end ``` -------------------------------- ### Example Source: https://github.com/leadwerks/documentation/blob/master/CS/VrController_GetAxis.md Example of how to get the touchpad axis position. ```csharp Vec2 axisPosition = VrController.GetAxis(VrAxis.VRAXIS_TOUCHPAD); ``` -------------------------------- ### Basic Example Source: https://github.com/leadwerks/documentation/blob/master/CPP/Leadwerks.md This program demonstrates creating a window with Ultra App Kit, then using its handle to create a Leadwerks custom window and a 3D rendering context. ```c++ #include "App.h" using namespace Leadwerks; int main(int argc,const char *argv[]) { //Ultra App Kit window auto displays = UltraEngine::GetDisplays(); auto mainwindow = UltraEngine::CreateWindow("Leadwerks", 0, 0, 1024, 768, displays[0]); //Leadwerks custom window Window* window = Window::Create(mainwindow->GetHandle()); Context* context = Context::Create(window); World* world = World::Create(); Camera* camera = Camera::Create(); camera->Move(0, 0, -3); Light* light = DirectionalLight::Create(); light->SetRotation(35, 45, 0); //Create a model auto model = Model::Box(); model->SetColor(0.0, 0.0, 1.0); while (true) { if (mainwindow->Closed() or mainwindow->KeyDown(UltraEngine::KEY_ESCAPE)) break; model->Turn(0, Time::GetSpeed() * 0.5, 0); Time::Update(); world->Update(); world->Render(); context->Sync(); } return 0; } ``` -------------------------------- ### GetLobbyOwner Example Source: https://github.com/leadwerks/documentation/blob/master/Lua/Steamworks_GetLobbyOwner.md Example of how to create a lobby and get its owner. ```lua -- Initialize Steam if not Steamworks.Initialize() then RuntimeError("Steamworks failed to initialize.") return end -- Create a lobby local lobby = Steamworks.CreateLobby() -- Get the owner of the lobby local owner = Steamworks.GetLobbyOwner(lobby) -- Print lobby and owner information Print("Lobby: " .. tostring(lobby)) Print("Owner: " .. Steamworks.GetUserName(owner)) -- Shutdown Steam Steamworks.Shutdown() ``` -------------------------------- ### Example Source: https://github.com/leadwerks/documentation/blob/master/CS/Asset_GetPackage.md An example demonstrating how to use the Asset.GetPackage method. ```csharp Asset asset = new Asset(); Asset package = asset.GetPackage(); if (package != null) { Console.WriteLine("Asset was loaded from package: " + package.ToString()); } else { Console.WriteLine("Asset was not loaded from any package."); } ``` -------------------------------- ### Example Source: https://github.com/leadwerks/documentation/blob/master/CPP/WriteFile.md Demonstrates how to write a new file, write a string to it, and then read it back. ```C++ #include "pch.h" using namespace UltraEngine; int main(int argc, const char* argv[]) { WString path = GetPath(PATH_DOCUMENTS) + "/temp.txt"; //Write a new file auto stream = WriteFile(path); if (stream == NULL) { Print("Failed to write file."); return 0; } stream->WriteString("Hello, world!"); stream->Close(); stream = ReadFile(path); Print(stream->ReadString()); return 0; } ``` -------------------------------- ### Speaker.GetPitch Example Source: https://github.com/leadwerks/documentation/blob/master/CS/Speaker_GetPitch.md Example of how to get the speaker pitch setting. ```csharp float pitch = Speaker.GetPitch(); ``` -------------------------------- ### GetLobbyOwner Example Source: https://github.com/leadwerks/documentation/blob/master/CPP/Steamworks_GetLobbyOwner.md Example of how to get the lobby owner. ```cpp #include "UltraEngine.h" #include "Steamworks/Steamworks.h" using namespace UltraEngine; int main(int argc, const char* argv[]) { // Initialize Steam if (not Steamworks::Initialize()) { RuntimeError("Steamworks failed to initialize."); return 1; } auto lobby = Steamworks::CreateLobby(); auto owner = Steamworks::GetLobbyOwner(lobby); Print("Lobby: " + String(lobby)); Print("Owner: " + Steamworks::GetUserName(owner)); Steamworks::Shutdown(); return 0; } ``` -------------------------------- ### DownloadFile Example Source: https://github.com/leadwerks/documentation/blob/master/Lua/DownloadFile.md Demonstrates how to download a file from a URL and save it to a local path, then run the downloaded file. ```lua src = "https://raw.githubusercontent.com/Leadwerks/Documentation/master/Images/ultraengine_logo.png" dst = GetPath(PATH_DOCUMENTS) .. "/temp.png" print("Downloading...") if DownloadFile(src,dst) then print("Download complete.") RunFile(dst) else print("Failed to download file.") end ``` -------------------------------- ### GetDepthAttachment Example Source: https://github.com/leadwerks/documentation/blob/master/CS/TextureBuffer_GetDepthAttachment.md Example of how to get the depth attachment from a texture buffer. ```csharp Texture depthAttachment = textureBuffer.GetDepthAttachment(); ``` -------------------------------- ### Example Source: https://github.com/leadwerks/documentation/blob/master/CS/Light_GetShadowMapSize.md Example of how to get the light's shadow map resolution. ```csharp int shadowMapSize = Light.GetShadowMapSize(); ``` -------------------------------- ### DownloadFile Example Source: https://github.com/leadwerks/documentation/blob/master/CPP/DownloadFile.md This example demonstrates how to use the DownloadFile function to download an image and then open it. ```C++ #include "pch.h" using namespace UltraEngine; int main(int argc, const char* argv[]) { WString src = "https://raw.githubusercontent.com/Leadwerks/Documentation/master/Images/ultraengine_logo.png"; WString dst = GetPath(PATH_DOCUMENTS) + "/temp.png"; Print("Downloading..."); if (DownloadFile(src,dst)) { Print("Download complete."); RunFile(dst); } else { Print("Failed to download file."); } return 0; } ``` -------------------------------- ### GetTextureMappingPlane Example Source: https://github.com/leadwerks/documentation/blob/master/CS/Face_GetTextureMappingTranslation.md Example of how to get the texture mapping translation for a face. ```csharp Vector2 GetTextureMappingPlane() { // Code to get the texture mapping translation } ``` -------------------------------- ### Window Creation and Event Handling Source: https://github.com/leadwerks/documentation/blob/master/CS/Window.md This example demonstrates how to create a window, show it, and handle basic keyboard and mouse input within a main loop. ```csharp // Example: using System; class Program { static void Main(string[] args) { // Create a window Window window = CreateWindow("MyWindow", 800, 600); // Show the window window.Show(); // Main loop while (!window.Closed()) { // Process events // Handle keyboard input if (window.KeyHit(Keys.Space)) { // Space key pressed } // Handle mouse input if (window.MouseHit(0)) { // Left mouse button clicked } } } } ``` -------------------------------- ### Example Source: https://github.com/leadwerks/documentation/blob/master/CS/Map_Save.md This example saves the starting scene and reloads it when the space key is pressed. ```csharp using System; using UltraEngine; public class Program { public static void Main(string[] args) { //Get the displays var displays = Display.GetDisplays(); //Create a window var window = Window.Create("Ultra Engine", 0, 0, 1280, 720, displays[0], WindowFlags.WINDOW_CENTER | WindowFlags.WINDOW_TITLEBAR); //Create a world var world = World.Create(); //Create a framebuffer var framebuffer = Framebuffer.Create(window); //Create a camera var camera = Camera.Create(world); camera.SetClearColor(0.125); camera.SetPosition(0, 1, -4); //Create light var light = BoxLight.Create(world); light.SetRange(-10, 10); light.SetArea(15, 15); light.SetRotation(45, 35, 0); light.SetColor(2); //Create the ground var ground = Box.Create(world, 10, 1, 10); ground.SetPosition(0, -0.5, 0); ground.SetColor(0, 1, 0); //Create a scene var scene = Map.Create(); scene.entities.Add(ground); scene.entities.Add(light); ground = null; light = null; //Add some boxes for (int n = 0; n < 10; ++n) { var box = Box.Create(world); box.SetColor(0, 0, 1); box.SetPosition(Rand.Float(-5, 5), Rand.Float(5, 10), Rand.Float(-5, 5)); box.SetMass(1); scene.entities.Add(box); } //Save the starting scene to a file scene.Save("game.sav"); //Main loop while (!window.Closed() && !window.KeyDown(Keys.KEY_ESCAPE)) { //Reload the starting scene when space key is pressed if (window.KeyHit(Keys.KEY_SPACE)) { scene.Reload("game.sav"); } world.Update(); world.Render(framebuffer); } } } ``` -------------------------------- ### Example Usage Source: https://github.com/leadwerks/documentation/blob/master/CPP/Window_GetPosition.md This example demonstrates how to get and display the position of a window. ```cpp #include "UltraEngine.h" using namespace UltraEngine; int main(int argc, const char* argv[]) { //Get the displays auto displays = GetDisplays(); //Create window auto window = CreateWindow("Ultra Engine", 0, 0, 800, 600, displays[0]); //Create user interface auto ui = CreateInterface(window); //Display window position auto sz = ui->root->ClientSize(); auto label = CreateLabel("", 0, 0, sz.x, sz.y, ui->root, LABEL_CENTER | LABEL_MIDDLE); label->SetLayout(1, 1, 1, 1); auto pos = window->GetPosition(); label->SetText("Window position: " + String(pos.x) + " x " + String(pos.y)); while (true) { const Event ev = WaitEvent(); switch (ev.id) { case EVENT_WINDOWMOVE: pos = window->GetPosition(); label->SetText("Window position: " + String(pos.x) + " x " + String(pos.y)); break; case EVENT_WINDOWCLOSE: return 0; break; } } return 0; } ``` -------------------------------- ### Example Source: https://github.com/leadwerks/documentation/blob/master/CPP/World_Render.md This example demonstrates how to use the World::Render method, including setting up a window, world, framebuffer, and camera, and handling the EVENT_STARTRENDERER event. ```cpp import UltraEngine; using namespace UltraEngine; int main(int argc, const char* argv[]) { //Get the displays auto displays = GetDisplays(); //Create window auto window = CreateWindow("Ultra Engine", 0, 0, 800, 600, displays[0], WINDOW_CENTER | WINDOW_TITLEBAR); //Create world auto world = CreateWorld(); //Create framebuffer auto framebuffer = CreateFramebuffer(window); //Create a camera auto camera = CreateCamera(world, PROJECTION_ORTHOGRAPHIC); camera->SetClearColor(0.125); while (window->Closed() == false and window->KeyDown(KEY_ESCAPE) == false) { while (PeekEvent()) { const auto e = WaitEvent(); switch (e.id) { case EVENT_STARTRENDERER: if (e.data == 1) { //Display the graphics device name window->SetText(window->text + " - " + e.text); } else { //Show error message Notify("Renderer failed to initialize.\n\n" + e.text, "Error", true); return 0; } break; case EVENT_QUIT: return 0; } } world->Update(); world->Render(framebuffer); } return 0; } ``` -------------------------------- ### Example Source: https://github.com/leadwerks/documentation/blob/master/Lua/Scene_Save.md This example saves the starting scene and reloads it when the space key is pressed. ```lua -- Get the displays local displays = GetDisplays() -- Create a window local window = CreateWindow("Ultra Engine", 0, 0, 1280, 720, displays[1], WINDOW_CENTER + WINDOW_TITLEBAR) -- Create a world local world = CreateWorld() -- Create a framebuffer local framebuffer = CreateFramebuffer(window) -- Create a camera local camera = CreateCamera(world) camera:SetClearColor(0.125) camera:SetPosition(0, 1, -4) -- Create light local light = CreateBoxLight(world) light:SetRange(-10, 10) light:SetArea(15, 15) light:SetRotation(45, 35, 0) light:SetColor(2) -- Create the ground local ground = CreateBox(world, 10, 1, 10) ground:SetPosition(0, -0.5, 0) ground:SetColor(0, 1, 0) -- Create a scene local scene = CreateScene() -- Add some boxes for n = 1, 10 do local box = CreateBox(world) box:SetColor(0, 0, 1) box:SetPosition(Random(-5, 5), Random(5, 10), Random(-5, 5)) box:SetMass(1) scene.entities[#scene.entities + 1] = box end -- Save the starting scene to a file scene:Save("game.sav") -- Main loop while not window:Closed() and not window:KeyDown(KEY_ESCAPE) do -- Reload the starting scene when space key is pressed if window:KeyHit(KEY_SPACE) then scene:Reload("game.sav") end world:Update() world:Render(framebuffer) end ``` -------------------------------- ### CreateFile Example Source: https://github.com/leadwerks/documentation/blob/master/Lua/CreateFile.md Example demonstrating how to create a new file using CreateFile, including error handling and opening the directory. ```lua path = GetPath(PATH_DOCUMENTS) .. "/temp.txt" -- Create a new file if not CreateFile(path) then print("Failed to write file.") return 0 end OpenDir(path) ``` -------------------------------- ### Window Activation Example Source: https://github.com/leadwerks/documentation/blob/master/CPP/Window_Activate.md This example demonstrates how to create two windows and then activate the first window, bringing it to the foreground. ```C++ #include "UltraEngine.h" using namespace UltraEngine; int main(int argc, const char* argv[]) { //Get the displays auto displays = GetDisplays(); //Create window auto window1 = CreateWindow("Window 1", 0, 0, 640, 480, displays[0]); auto window2 = CreateWindow("Window 2", 200, 200, 640, 480, displays[0]); window1->Activate(); while (true) { const Event ev = WaitEvent(); switch (ev.id) { case EVENT_WINDOWCLOSE: return 0; break; } } return 0; } ``` -------------------------------- ### Example Source: https://github.com/leadwerks/documentation/blob/master/CPP/Scene_Save.md This example saves the starting scene and reloads it when the space key is pressed. ```cpp #include "UltraEngine.h" using namespace UltraEngine; int main(int argc, const char* argv[]) { //Get the displays auto displays = GetDisplays(); //Create a window auto window = CreateWindow("Ultra Engine", 0, 0, 1280, 720, displays[0], WINDOW_CENTER | WINDOW_TITLEBAR); //Create a world auto world = CreateWorld(); //Create a framebuffer auto framebuffer = CreateFramebuffer(window); //Create a camera auto camera = CreateCamera(world); camera->SetClearColor(0.125); camera->SetPosition(0, 1, -4); //Create light auto light = CreateBoxLight(world); light->SetRange(-10, 10); light->SetArea(15, 15); light->SetRotation(45, 35, 0); light->SetColor(2); //Create the ground auto ground = CreateBox(world, 10, 1, 10); ground->SetPosition(0, -0.5, 0); ground->SetColor(0, 1, 0); //Create a scene auto scene = CreateScene(); scene->entities.push_back(ground); scene->entities.push_back(light); ground = NULL; light = NULL; //Add some boxes for (int n = 0; n < 10; ++n) { auto box = CreateBox(world); box->SetColor(0, 0, 1); box->SetPosition(Random(-5, 5), Random(5, 10), Random(-5, 5)); box->SetMass(1); scene->entities.push_back(box); } //Save the starting scene to a file scene->Save("game.sav"); //Main loop while (window->Closed() == false and window->KeyDown(KEY_ESCAPE) == false) { //Reload the starting scene when space key is pressed if (window->KeyHit(KEY_SPACE)) { scene->Reload("game.sav"); } world->Update(); world->Render(framebuffer); } return 0; } ``` -------------------------------- ### Get Leaderboard Example Source: https://github.com/leadwerks/documentation/blob/master/Lua/Steamworks_GetLeaderboard.md Demonstrates how to get a leaderboard by name, retrieve its entries, and print them. ```Lua -- Initialize Steam if not Steamworks.Initialize() then RuntimeError("Steamworks failed to initialize.") return end -- Get the leaderboard local leaderboard = Steamworks.GetLeaderboard("Feet Traveled") Print("Leaderboard: " .. tostring(leaderboard)) -- Get leaderboard entries and print them local entries = Steamworks.GetLeaderboardEntries(leaderboard, Steamworks.LEADERBOARD_AROUNDUSER) for n = 1, #entries do local name = Steamworks.GetUserName(entries[n].userid) Print(name .. ": " .. tostring(entries[n].score)) end -- Shutdown Steam Steamworks.Shutdown() ``` -------------------------------- ### Maximize Window Example Source: https://github.com/leadwerks/documentation/blob/master/CPP/Window_Maximize.md Demonstrates how to create a window and then maximize it. ```c++ #include "UltraEngine.h" using namespace UltraEngine; int main(int argc, const char* argv[]) { //Get the displays auto displays = GetDisplays(); //Create windows auto window = CreateWindow("Ultra Engine", 0, 0, 800, 600, displays[0], WINDOW_TITLEBAR | WINDOW_RESIZABLE); //Create user interface auto ui = CreateInterface(window); //Maximize window window->Maximize(); while (true) { const Event ev = WaitEvent(); switch (ev.id) { case EVENT_WINDOWCLOSE: return 0; break; } } return 0; } ``` -------------------------------- ### Example Usage Source: https://github.com/leadwerks/documentation/blob/master/CS/Window_GetMousePosition.md This example demonstrates how to get and display the mouse position relative to the window. ```csharp using System; using UltraEngine; class Program { static void Main(string[] args) { // Get the displays var displays = Engine.GetDisplays(); // Create window var window = Engine.CreateWindow("Ultra Engine", 0, 0, 800, 600, displays[0]); // Create user interface var ui = Engine.CreateInterface(window); // Display window position var sz = ui.Root.ClientSize(); var label = Engine.CreateLabel("", 0, 0, sz.x, sz.y, ui.Root, LabelStyle.CENTER | LabelStyle.MIDDLE); label.SetLayout(1, 1, 1, 1); var pos = window.GetMousePosition(); label.SetText("Mouse position: " + pos.x + " x " + pos.y); while (true) { var ev = Engine.WaitEvent(); switch (ev.id) { case EventId.MOUSEMOVE: pos = window.GetMousePosition(); label.SetText("Mouse position: " + pos.x + " x " + pos.y); break; case EventId.WINDOWCLOSE: return; } } } } ``` -------------------------------- ### Example Source: https://github.com/leadwerks/documentation/blob/master/CPP/ReadFile.md This example demonstrates how to write to and read from a file using the ReadFile and WriteFile functions. ```C++ #include "pch.h" using namespace UltraEngine; int main(int argc, const char* argv[]) { WString path = GetPath(PATH_DOCUMENTS) + "/temp.txt"; //Write a new file auto stream = WriteFile(path); if (stream == NULL) { Print("Failed to write file."); return 0; } stream->WriteLine("Hello, world!"); stream->Close(); stream = ReadFile(path); Print(stream->ReadLine()); return 0; } ``` -------------------------------- ### CountColorAttachments Example Source: https://github.com/leadwerks/documentation/blob/master/CS/TextureBuffer_CountColorAttachments.md This example demonstrates how to get the number of color attachments for a texture buffer. ```csharp int colorAttachments = TextureBuffer.CountColorAttachments(); ``` -------------------------------- ### Example Source: https://github.com/leadwerks/documentation/blob/master/Lua/Print.md Prints the string "Hello, world!" to the program output. ```lua Print("Hello, world!") ``` -------------------------------- ### CreateProcess Example Source: https://github.com/leadwerks/documentation/blob/master/CS/CreateProcess.md Launches Notepad.exe and waits for it to exit. ```csharp using System; using System.Diagnostics; class Program { static void Main(string[] args) { Console.WriteLine("Launching process"); Process proc = Process.Start(@"C:\Windows\notepad.exe"); Console.WriteLine("Process running"); int exitcode = proc.WaitForExit(); Console.WriteLine("Process ended (" + exitcode + ")"); } } ``` -------------------------------- ### Example Usage Source: https://github.com/leadwerks/documentation/blob/master/CS/Package_FileSize.md Example of how to use the FileSize method to get the size of a file. ```csharp string filePath = "path/to/file"; ulong fileSize = Package.FileSize(filePath); Console.WriteLine("File Size: " + fileSize); ``` -------------------------------- ### GetHmd Example Source: https://github.com/leadwerks/documentation/blob/master/CS/GetHmd.md This example demonstrates how to get the VR headset using the GetHmd function. ```csharp using UltraEngine; class Program { static void Main(string[] args) { //Get the displays var displays = GetDisplays(); //Create a window var window = CreateWindow("Ultra Engine", 0, 0, 1280, 720, displays[0], WindowFlags.WINDOW_CLIENTCOORDS | WindowFlags.WINDOW_CENTER | WindowFlags.WINDOW_TITLEBAR); //Create a framebuffer var framebuffer = CreateFramebuffer(window); //Create a world var world = CreateWorld(); //Get the VR headset var hmd = GetHmd(world); //Environment maps var specmap = LoadTexture("https://github.com/UltraEngine/Assets/raw/main/Materials/Environment/footprint_court/specular.dds"); var diffmap = LoadTexture("https://github.com/UltraEngine/Assets/raw/main/Materials/Environment/footprint_court/diffuse.dds"); world.SetEnvironmentMap(specmap, EnvironmentMapType.ENVIRONMENTMAP_BACKGROUND); world.SetEnvironmentMap(specmap, EnvironmentMapType.ENVIRONMENTMAP_SPECULAR); world.SetEnvironmentMap(diffmap, EnvironmentMapType.ENVIRONMENTMAP_DIFFUSE); //Create a light var light = CreateBoxLight(world); light.SetRotation(55, 35, 0); light.SetRange(-10, 10); light.SetColor(2); //Add a floor var floor = CreateBox(world, 5, 1, 5); floor.SetPosition(0, -0.5, 0); var mtl = CreateMaterial(); mtl.SetTexture(LoadTexture("https://github.com/UltraEngine/Documentation/raw/master/Assets/Materials/Developer/griid_gray.dds")); floor.SetMaterial(mtl); //Main loop while (!window.Closed() && !window.KeyDown(KeyCode.KEY_ESCAPE)) { world.Update(); world.Render(framebuffer); } } } ``` -------------------------------- ### Example Usage Source: https://github.com/leadwerks/documentation/blob/master/Lua/CreateSpotLight.md Creates a spot light and demonstrates its basic setup within a scene. ```Lua --Get the displays local displays = GetDisplays() --Create a window local window = CreateWindow("Ultra Engine", 0, 0, 1280, 720, displays[1], WINDOW_CENTER | WINDOW_TITLEBAR) --Create a framebuffer local framebuffer = CreateFramebuffer(window) --Create a world local world = CreateWorld() --Create a camera local camera = CreateCamera(world) camera:SetClearColor(0.125) camera:SetFOV(70) camera:Move(0, 2, -2) --Create light local light = CreateSpotLight(world) light:SetPosition(0,1,0) light:SetColor(2) --Create ground local ground = CreateBox(world, 20, 1, 20) ground:SetPosition(0, -0.5, 0) ground:SetColor(0, 1, 0) --Main loop while window:Closed() == false and window:KeyHit(KEY_ESCAPE) == false do world:Update() world:Render(framebuffer) end ``` -------------------------------- ### CreateFile Example Source: https://github.com/leadwerks/documentation/blob/master/CPP/CreateFile.md Example demonstrating how to create a new file using the CreateFile function. ```c++ #include "pch.h" using namespace UltraEngine; int main(int argc, const char* argv[]) { WString path = GetPath(PATH_DOCUMENTS) + "/temp.txt"; //Create a new file if (!CreateFile(path)) { Print("Failed to write file."); return 0; } OpenDir(path); return 0; } ```