Your first view
From a free key to the code that creates, draws and feeds a view. Account, license, download, and the three ways to a first page on screen.
This page takes you from an account to the code that makes the engine draw an HTML page. The first steps happen in the portal. The rest is code in your host, the program that owns your window, GPU device and input.
1. Get a key and a download
- Sign up at /sign-up and create your company, or choose it if you already have one. Aperture UI keys, projects and downloads belong to the company.
- Open the portal. An owner or admin accepts the Free Agreement on the company's behalf, and the company's free key is issued and emailed. The free key covers titles under US$100,000 in gross revenue.
- Register your title as a project: its name and the file names of its executables (one to ten). The project page shows the Project ID and the key to configure.
- Under Downloads, pick a package. Packages are listed by SDK version, platform and flavor. The
genericflavor is for your own engine, and theunrealando3deflavors are for those engines. Each download is stamped for your company. Downloads unlock once the company has an active key.
Licensing in practice explains what each kind of build needs from the license
system. Development SDKs verify your project key and signed aperture.license locally. Shipping
SDKs use the signed certificate without a development key. Download the certificate from the
project page; no runtime activation or machine registration is needed.
2. What you have
The generic package is a RuntimeBuild: engine DLLs, import libraries, public headers, shaders,
data files, a CMake config, LICENSE.md and THIRD_PARTY_NOTICES.md.
Project structure lists every folder.
The package is a library, not an app
With only the generic download you have the engine and its headers, but no host and no
renderer backend. There are three ways to a first page on screen: the
Unreal plugin, the O3DE gem (early: no scripts or
text yet, see its known gaps), or your own
host with a backend of your own, a class derived from SimpleAPHIRenderContext for your graphics
API (see Rendering backends). That last way is a
substantial job. APPlayer and its D3D11 and Vulkan contexts are part of the engine source, which
the Source add-on gives you read access to. They are not in the download.
3. APPlayer, the reference host (with the source)
APPlayer is the host that lives in the engine's own source tree: an SDL2 window with a Direct3D 11
render context, or Vulkan with --vulkan. Its code is in Code/Applications/APPlayer and it
builds as the apertureplayer target. The download has no built copy, so this section applies if
you have the engine source (the Source add-on). With a build in hand, run it on any HTML file:
apertureplayer.exe path\to\index.html| Argument | Meaning |
|---|---|
a path or URL, --html <path>, --url <url> | The document to load: a file, or an http:// or https:// address |
--watch | Reload when a file under the document's folder changes |
--vulkan, --d3d11 | Pick the render backend. Direct3D 11 is the default; Vulkan needs a build made with the Vulkan SDK. |
--content-root=<dir> | Let the page read assets under another folder, such as ../shared |
--devtools-token <token> | Require this token from DevTools clients |
--single-frame | Render one frame and exit |
The engine's file sandbox lets a page read only the UI resources root, its own folder and folders
the host trusts. APPlayer trusts the folder above the document as well, unless that folder is a
drive root or your user profile folder or one of its parents. For a deeper tree, add
--content-root.
APPlayer also starts a Chrome DevTools server on 127.0.0.1:9222 and logs the address. Open it in
Chrome to inspect the page. The server has no token unless you pass --devtools-token.
Save this as index.html and open it:
<!doctype html>
<html>
<head>
<style>
body { margin: 0; background: #12151f; color: white; font-family: sans-serif; }
h1 { padding: 40px; font-size: 48px; }
</style>
</head>
<body>
<h1>Hello from Aperture UI</h1>
</body>
</html>4. Your own host
A host does five things: install the platform interfaces, start the SDK, create a view, tick and draw it every frame, and forward input. Compile and link it with the settings in Requirements. Without them it does not build. Your own C++ host is the reference for each step.
Start the SDK
Install the platform interfaces before you call Initialize. The license check runs inside it and
uses them, and the reason for a failure goes to the logging system.
#include <APHTML/APEngine.h>
#include <APHTML/API/APUIView.h>
#include <APHTML/Interfaces/APCFileSystem.h>
#include <APHTML/Interfaces/APCLoggingSystem.h>
#include <APHTML/Interfaces/APCMemoryAllocator.h>
#include <APHTML/Interfaces/APCPlatform.h>
#include <APHarrlow/RenderPath/Interfaces/APHIRenderPath.h>
#include <memory>
#include <string>
namespace
{
std::string g_root; // IAPCFileSystem keeps this pointer, not a copy
std::unique_ptr<aperture::core::IAPCFileSystem> g_fileSystem;
std::unique_ptr<aperture::core::DefaultLoggingSystem> g_logging;
std::unique_ptr<aperture::core::IAPCMemoryAllocator> g_memory;
std::unique_ptr<aperture::UIView> g_view;
} // namespace
// executableDirectory is the folder that holds your .exe, ending in a path separator.
bool StartAperture(const std::string& executableDirectory)
{
aperture::ApertureSDK::SetScriptThreadCount(2);
g_root = executableDirectory;
g_fileSystem = std::make_unique<aperture::core::IAPCFileSystem>(g_root.c_str());
g_logging = std::make_unique<aperture::core::DefaultLoggingSystem>();
g_memory = std::make_unique<aperture::core::IAPCMemoryAllocator>();
auto platform = aperture::core::IAPCPlatform::GetEnginePlatform();
platform->SetFileSystem(g_fileSystem.get());
platform->SetLoggingSystem(g_logging.get());
platform->SetMemoryAllocator(g_memory.get());
aperture::LicenseConfig license;
license.key = "APUI-XXXX-XXXX-XXXX-XXXX"; // the key from your project page
license.projectId = "your-project-id"; // the Project ID from your project page
aperture::ApertureSDK::Initialize(license);
if (!aperture::ApertureSDK::IsSDKActive())
return false; // the reason is in the log
if (!platform->InitializePlatform())
return false;
platform->StartPlatform();
// Nothing starts V8 for you. Without this call, pages with a script tag run no script.
return platform->InitializeJavaScriptEngine().IsSuccess();
}Three details in that listing matter:
- The file system's root decides where the engine looks for V8's data. It drops the last name from
the root path and appends
resources/(snapshot_blob.binand the ICU data), so the root must end in a path separator, asexecutableDirectorydoes. To keep those files elsewhere, seticuDataPathandsnapshotBlobPathon anaperture::JSEngineConfigand pass it toApertureSDK::ConfigureJavaScriptEnginebeforeInitialize. - Relative paths you pass to
loadHtmlFromFileresolve against the same root. The bundled fallback fonts are found atBase/Fontsunder the root, or atData/Base/Fontsbeside the executable, which is where the package'sdata/folder puts them (see Requirements). If you skipSetFileSystem, no fonts load and every string lays out empty. - A shipping build ignores
license.keyand readsaperture.licensenext to the executable, or fromlicense.certificatePath. IfIsSDKActive()isfalse, do not create a view.
Create a view and draw it
bool CreateMainMenu(aperture::harrlow::renderpath::APHIRenderContext* renderContext,
unsigned width, unsigned height)
{
g_view = std::make_unique<aperture::UIView>();
g_view->setViewportSize(width, height);
// Needed for opacity groups, filters, masks and blend modes to composite correctly.
g_view->setRenderPathContext(renderContext);
return g_view->loadHtmlFromFile("ui/index.html"); // relative to the root above
}
void Frame(float deltaSeconds, aperture::harrlow::renderpath::APHIRenderContext* renderContext)
{
g_view->tick(deltaSeconds);
const auto& commands = g_view->buildCommandList();
renderContext->SubmitHarrlowCommands(commands);
// Your backend presents the frame.
}renderContext is the render context that your backend provides, and writing it is the largest
part of a custom host: the graphics device, the swap chain, the shaders and the translation of the
command list into draws. Derive it from SimpleAPHIRenderContext. APPlayer's
APPlayerD3D11Context and APPlayerVulkanContext are the models, and they are in the engine
source. How a frame begins and ends depends on your graphics API, which is why that part is yours.
Each UIView has its own DOM, window, scripts, input state and command list.
Forward input
aperture::UIView::ModifierKeys mods;
mods.shift = shiftIsDown;
mods.ctrl = ctrlIsDown;
g_view->onMouseMove(x, y, mods);
g_view->onMouseDown(x, y, aperture::UIView::MouseButton::Left, mods);
g_view->onMouseUp(x, y, aperture::UIView::MouseButton::Left, mods);
g_view->onClick(x, y, aperture::UIView::MouseButton::Left, mods); // after every onMouseUp
g_view->onKeyDown("Enter", "Enter", mods, false);Coordinates are in the view's viewport space, in pixels. Convert from window coordinates first.
The engine does not make a click out of a press and a release, so send onClick after every
onMouseUp. For gamepad navigation, UIView::moveFocusSpatial moves focus in a direction. See
Input.
Shut down
Destroy views before the platform interfaces they borrowed, and your render context after the views:
void StopAperture()
{
g_view.reset();
if (auto platform = aperture::core::IAPCPlatform::GetEnginePlatform())
platform->KillPlatform();
g_memory.reset();
g_logging.reset();
g_fileSystem.reset();
aperture::ApertureSDK::Shutdown();
}When the first run fails
| Symptom | Likely cause |
|---|---|
| Error C1083, "Cannot open include file: 'Features_Platform.h'" | include/Foundation/Platform/Win is not on the include path. See Requirements. |
LNK2001 on nsFoundation::s_pDefaultAllocator or nsFoundation::s_bIsInitialized | BUILDSYSTEM_COMPILE_ENGINE_AS_DLL is not defined for your project. |
IsSDKActive() is false after Initialize | The license check failed. The log names the rule and the portal page that fixes it. You see nothing if no logging system was installed first. |
| "ICU data file not found" or "Snapshot file not found" | resources/ is not in the folder that holds the file system's root, or JSEngineConfig points somewhere else. |
| "JavaScript engine is not initialized" in the log, and scripts never run | InitializeJavaScriptEngine() was not called. |
| The page loads but nothing draws | tick() or buildCommandList() is not called every frame, or nothing submits the command list. |
| Boxes draw but there is no text | No file system installed, or data/Base/Fonts is missing: the log warns that text may not render. |
| A stylesheet, font or image is missing and the log says "Blocked sandbox escape" | The file is outside the UI resources root and the document's folder. Add its folder with IAPCFileSystem::AddTrustedRoot. |
| Mouse hits land in the wrong place | Coordinates were not converted to the view's viewport pixels. |
Next
- Project structure: how to lay out the package and your content.
- Integration: the host in detail, the Unreal plugin and the O3DE gem, rendering, input, scripting and files.
- Licensing in practice: the certificate, the attribution text and the shipping checklist.