### Run Vercidium Engine Application Source: https://publish.obsidian.md/ve/index This C# code shows the `Main` function, the entry point of a Vercidium Engine application. It instantiates the custom client class and calls the `Run` method to start the application loop, which will display an empty window. This is a fundamental step for any Vercidium application. ```csharp internal class Program { static void Main() { var client = new ExampleClient(); // Run forever client.Run(); } } ``` -------------------------------- ### Define Custom Client Class for Vercidium Engine Source: https://publish.obsidian.md/ve/index This C# code defines a custom client class that inherits from the abstract `Client` class provided by the Vercidium Engine. It specifies the initial window dimensions for the application. No external dependencies are required beyond the Vercidium Engine framework. ```csharp public class ExampleClient : Client { protected override int InitialWindowWidth => 1280; protected override int InitialWindowHeight => 720; } ``` -------------------------------- ### Define Fragment Shader with FragmentOuter and FragmentInner Source: https://publish.obsidian.md/ve/Startup/Shaders This example shows how to define a custom fragment shader by overriding `FragmentOuter` and `FragmentInner` properties in a `ScreenShader` class. These properties define the output color of the shader. The `=>` syntax allows for real-time editing via Hot Reload. ```csharp public class ExampleShader : ScreenShader { protected override string FragmentOuter => @" out vec4 oColor; "; protected override string FragmentInner => @" // Green oColor = vec4(0.0, 1.0, 0.0, 1.0); "; } ``` -------------------------------- ### Use Shared Fence for Entire Frame Completion (C#) Source: https://publish.obsidian.md/ve/Classes/FenceObject This example shows how to obtain and use a shared fence provided by FenceManager to check if the entire frame has completed rendering. This is more efficient than creating individual fences for numerous commands. ```csharp // Perform any OpenGL command Gl.DrawArrays(...); // Get the shared fence var fence = FenceManager.GetCurrentFence(); // ... later // Later on, check if it's signaled if (fence.CheckSignal()) { // Entire frame has completed! } ``` -------------------------------- ### Construct and Render a Fragment Shader Program Source: https://publish.obsidian.md/ve/Startup/Shaders This code illustrates how to instantiate, activate, and render a shader program using the `ScreenShader`. It shows the process of creating a shader instance in `OnLoad` and using it in `OnRender` to draw the window buffer. It relies on `GLHelper.DrawWindowBuffer()` for rendering. ```csharp public class ExampleClient : Client { ExampleShader shader; protected override void OnLoad() { // Create a new shader shader = new(); } protected override void OnRender() { // Activate the shader shader.UseProgram(); // Render the screen-sized triangles GLHelper.DrawWindowBuffer(); } } ``` -------------------------------- ### C# VETask Completion Handling with TaskHelper Source: https://publish.obsidian.md/ve/Classes/TaskHelper Illustrates how to use VETask and TaskHelper methods like JustCompleted and Completed to manage task completion events. VETask includes a CompletionHandled field to prevent double-handling of task completions, ensuring callbacks are executed correctly. ```csharp VETask task; void Startup() { task = TaskHelper.Run(() => { // Do some work... }); } void OnFrame() { if (TaskHelper.JustCompleted(task)) { // This runs once when a task initially completes } if (TaskHelper.Completed(task)) { // This runs every frame, after the task has completed } } ``` -------------------------------- ### C# TaskHelper.Run vs Task.Run for Main Thread Management Source: https://publish.obsidian.md/ve/Classes/TaskHelper Demonstrates the correct usage of TaskHelper.Run to ensure tasks do not execute on the main thread, contrasting it with the default Task.Run behavior which may cause main thread slowdowns under high workload. TaskHelper.Run returns a VETask for better completion handling. ```csharp // This is good! VETask task = TaskHelper.Run(() => { Console.WriteLine("This code will never run on the main thread"); }); // This is not good! Task task = Task.Run(() => { Console.WriteLine("This code might run on the main thread"); }); ``` -------------------------------- ### Render Animated Elements with Lerp in C# Source: https://publish.obsidian.md/ve/Startup/Animation Illustrates how to use the interpolated values (ease1, ease2) obtained from EaseF to control visual properties like size and position using the Lerp function. Lerp interpolates between two values based on a third parameter, enabling smooth visual changes. ```csharp protected override void RenderToScreen(UIElement ctx) { var width = Lerp(100, 200, ease1); var height = Lerp(100, 200, ease2); var size = new Size(width, height); // Render the rectangle in the middle of the screen var position = screen.Center - size / 2; var rectangle = new Rectangle(position, size); ctx.FillRectangle(rectangle, Color.Cyan); } ``` -------------------------------- ### Asynchronous Texture Transfer with BackgroundOpenGLWindow Source: https://publish.obsidian.md/ve/Classes/BackgroundOpenGLWindow Demonstrates how to add texture transfer actions to the background OpenGL context for asynchronous operations. It shows how to use the separate GL context (GL2) and return a FenceObject to track completion. ```csharp FenceObject fence; BackgroundOpenGLWindow.TextureTransferActions.Add((GL GL2) => { // Perform a texture transfer GL2.TexSubImage2D(...); fence = new FenceObject(); fence.OnRender(GL2); return fence; }); ``` ```csharp if (fence.signaled) { // The transfer is complete - render the texure! } ``` -------------------------------- ### Manage Animation Timing with Skip and EaseF in C# Source: https://publish.obsidian.md/ve/Startup/Animation Demonstrates how to control animation timing within the Update function using Skip for delays and EaseF for smooth transitions. EaseF returns a value between 0.0 and 1.0 over a specified duration, useful for interpolating properties. ```csharp float ease1; float ease2; protected override void Update() { // Wait 400ms Skip(400); // Ease from 0.0 to 1.0 over 800ms ease1 = EaseF(800); Skip(400); ease2 = EaseF(800); } ``` -------------------------------- ### Implement Animation Checkpoints with Checkpoint in C# Source: https://publish.obsidian.md/ve/Startup/Animation Shows how to use the Checkpoint function within the Update method to create distinct stages in an animation. This prevents later animation values from overwriting earlier ones by pausing execution until a specified time has passed, ensuring sequential animation effects. ```csharp protected override void Update() { // Wait 400ms Skip(400); // Ease from 0.0 to 1.0 over 800ms ease1 = EaseF(800); Skip(400); ease2 = EaseF(800); // Wait until all the above have finished if (Checkpoint("Shrink", 400)) return; ease1 = 1.0f - EaseF(800); Skip(400); ease2 = 1.0f - EaseF(800); } ``` -------------------------------- ### Normal Generation with NormalManager in C# Source: https://publish.obsidian.md/ve/Classes/NormalManager Demonstrates how to enqueue a PalettedTextureArray for normal generation and then retrieve and bind the generated normal texture in the rendering loop. It shows the process of loading a texture, enqueuing it, checking for readiness, and binding it to a shader uniform. ```csharp PalettedTextureArray texArray; void Startup() { // Load a paletted RGBA texture array from disk texArray = new PalettedTextureArray(...); // Enqueue it for normal generation NormalManager.Enqueue(texArray); } void Render() { ModelShader.UseProgram(); // Check if normals have been generated if (NormalManager.readyPaletted.TryGetValue(texArray, out var normalArray)) { // Bind it to a ShaderUniformISampler2D shader uniform ShaderUniformISampler2D normalTex = ModelShader.uniforms.normalTex; normalTex.Set(normalArray); } // Render a model ... } ``` -------------------------------- ### Create Animation Sequence in C# Source: https://publish.obsidian.md/ve/Startup/Animation This snippet shows the basic structure for creating a custom animation sequence by inheriting from the Sequence class and overriding the Update and RenderToScreen methods. These methods are essential for managing animation logic and rendering the animation's visual elements, respectively. ```csharp public class SequenceAnimation : Sequence { protected override void Update() { } protected override void RenderToScreen(UIElement ctx) { } } ``` -------------------------------- ### C# TaskHelper Debugging: Running Tasks Singlethreaded Source: https://publish.obsidian.md/ve/Classes/TaskHelper Explains how to enable single-threaded task execution for debugging and profiling purposes using the TaskHelper.RunEverythingSinglethreaded static field. Setting this to true forces all tasks to run on the main thread, simplifying code execution flow tracking. ```csharp TaskHelper.RunEverythingSinglethreaded = true; ``` -------------------------------- ### Create and Check FenceObject for OpenGL Command Completion (C#) Source: https://publish.obsidian.md/ve/Classes/FenceObject This snippet demonstrates how to create a FenceObject after an OpenGL command and later check if that command has been executed on the GPU. This is useful for knowing when a specific operation is complete. ```csharp Gl.DrawArrays(...); var fence = new FenceObject(); // ... later if (fence.CheckSignal()) { // Command is done! } ``` -------------------------------- ### Wait for FenceObject Completion to Sync CPU and GPU (C#) Source: https://publish.obsidian.md/ve/Classes/FenceObject This code illustrates how to use the Wait() method of a FenceObject to halt the CPU until the associated OpenGL command on the GPU has finished execution. This ensures that both CPU and GPU are synchronized. ```csharp // Perform any OpenGL command Gl.DrawArrays(...); // Create a fence var fence = new FenceObject(); // Halt the CPU until the GPU has issued the above command fence.Wait(); // CPU and GPU are now in sync - the GPU now has nothing to do ``` -------------------------------- ### ScreenShader Implementation in C# Source: https://publish.obsidian.md/ve/Classes/ScreenShader This C# code defines the ScreenShader class, inheriting from SmartShader. It specifies the fragment and vertex shader code responsible for rendering triangles to fill the screen, using Vertex Attribute Strings for window vertex buffer information. The shader outputs texture coordinates to the color. ```csharp public class ScreenShader : SmartShader { protected override string FragmentOuter => "out vec4 oColor;"; protected override string FragmentInner => "oColor = vec4(vUV.x, vUV.y, 0.0, 1.0);"; // These three are sealed protected override sealed string Varyings => "in vec2 vUV;"; protected override sealed string VertexOuter => VertexAttribStrings.Get(); protected override sealed string VertexInner => @" vUV = aUV; gl_Position = vec4(aPosition, 0.0, 1.0); "; } ``` -------------------------------- ### Override OnRender for OpenGL Functions Source: https://publish.obsidian.md/ve/Startup/Shaders This snippet demonstrates how to override the `OnRender` function in a client class to execute OpenGL commands. It changes the background color to red. Ensure the `Gl` and `ClearBufferMask` types are available in your environment. ```csharp public class ExampleClient : Client { protected override void OnRender() { // Change the background colour to red Gl.ClearColor(1, 0, 0, 1); Gl.Clear(ClearBufferMask.ColorBufferBit); } } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.