Ultralight .NET bindings
NOTE: ultralight supports only x64 processors NOTE: At that time, ultralight doesn't support arm. (eg. Android phones or macs on M1)
- Windows
- Linux
- OSX
UltralightNet was a fork of UltralightSharp. But it was too complicated for me to update generated bindings. So i decided to rewrite it from scratch.
UltralightNet.Binaries
isUltralightSharp.Core.LinuxX64
,UltralightSharp.Core.OsxX64
andUltralightSharp.Core.WinX64
at same time.UltralightNet.Binaries
doesn't contain AppCore binaries, they're inUltralightNet.AppCore
UltralightNet.Resources
contains onlyresources
folder, asUltralightSharp.Core
UltralightSharp uses a lot of IL injection, UltralightNet doesn't.
name conflicts like System.String
and ImpromptuNinjas.UltralightSharp.String
: UltralightNet just adds UL
prefix.
Managed (string
) versions vs Unmanaged (ULString*
) versions: UltralightSharp has two different namespaces for that, UltralightNet just adds _
prefix. Example: ULFileSystem.OpenFile
and ULFileSystem._OpenFile
(also _ULFileSystem.OpenFile
for [UnmanagedCallersOnlyAttribute]
scenario)
Marshaling: UltralightNet heavily relies on DllImportGenerator for Native interop, it lets us easily marshal values without NET's CustomMarshaler
overhead.
- issues page on github
- Discord
SupinePandora43#3399
you need to install at least:
UltralightNet
UltralightNet.Binaries
UltralightNet.AppCore
because only AppCore provides font loader
to have fully functional Ultralight renderer
- Set Logger (optional)
- Set Font Loader (or crash)
- Set FileSystem (used by ultralight to load "resources" folder content)
- Create renderer (configurable, using ULConfig)
- Create View (html page)
- Load page: Page (raw html string) or URL (requires
UltralightNet.Resources
package, and ULConfig.ResourcePath set to./resources
) - Update renderer until page is loaded
- Render
- Get View's Surface
- Get Surface's Bitmap
- Swap Red and Blue channels
- Save bitmap to png file
using System;
using System.IO;
using System.Threading;
using UltralightNet;
using UltralightNet.AppCore;
namespace UltralightNet.GettingStarted
{
class Program
{
static void Main()
{
// Set Logger
ULPlatform.SetLogger(new ULLogger()
{
LogMessage = (level, message) =>
{
Console.WriteLine($"({level}): {message}");
}
});
// Set Font Loader
AppCoreMethods.ulEnablePlatformFontLoader();
// Set filesystem (Ultralight requires "resources/icudt67l.dat", and probably cacert.pem too)
AppCoreMethods.ulEnablePlatformFileSystem(Path.GetDirectoryName(typeof(Program).Assembly.Location));
// Create config, used for specifying resources folder (used for URL loading)
ULConfig config = new();
// Create Renderer
Renderer renderer = new(config);
// Create View
View view = new(renderer, 512, 512);
// Load URL
bool loaded = false;
view.SetFinishLoadingCallback((user_data, caller, frame_id, is_main_frame, url) =>
{
loaded = true;
});
view.URL = "https://github.com"; // Requires "UltralightNet.Resources"
// Update Renderer until page is loaded
while (!loaded)
{
renderer.Update();
// sleep | give ultralight time to process network etc.
Thread.Sleep(10);
}
// Render
renderer.Render();
// Get Surface
ULSurface surface = view.Surface;
// Get Bitmap
ULBitmap bitmap = surface.Bitmap;
// Swap Red and Blue channels
bitmap.SwapRedBlueChannels();
// save bitmap to png file
bitmap.WritePng("./github.png");
}
}
}