### Example Gamepad Mapping (XInput) Source: https://github.com/ultralight-ux/appcore/blob/master/src/glfw/docs/input.dox An example of a gamepad mapping for an XInput gamepad on Windows. Real mappings must be on a single line. ```unparsed 78696e70757401000000000000000000,XInput Gamepad (GLFW),platform:Windows,a:b0, b:b1,x:b2,y:b3,leftshoulder:b4,rightshoulder:b5,back:b6,start:b7,leftstick:b8, rightstick:b9,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:a4, righttrigger:a5,dpup:h0.1,dpright:h0.2,dpdown:h0.4,dpleft:h0.8, ``` -------------------------------- ### Metal Headers Example Source: https://github.com/ultralight-ux/appcore/blob/master/shaders/build-shaders/README.md Demonstrates the inclusion of generated Metal shader headers, which contain metallib bytecode. It shows the master header and examples of individual shader data and size headers. ```cpp #include "shaders.h" // Master header - includes all Metal shaders // Individual headers: // vertex_path_vs_data, vertex_path_vs_size (metallib bytecode) // fill_ps_data, fill_ps_size (metallib bytecode) // etc. ``` -------------------------------- ### GLSL Headers Example Source: https://github.com/ultralight-ux/appcore/blob/master/shaders/build-shaders/README.md Shows how to include generated GLSL shader headers, which contain raw string literals for shader source code. Includes the master header and examples of individual shader source headers. ```cpp #include "glsl/shaders.h" // Master header - includes all GLSL shaders // Individual headers contain raw string literals: // vertex_path_vs_source (R"GLSL(...)GLSL") // fill_fs_source (R"GLSL(...)GLSL") (note: _fs not _ps) // etc. ``` -------------------------------- ### D3D11 Headers Example Source: https://github.com/ultralight-ux/appcore/blob/master/shaders/build-shaders/README.md Illustrates how to include generated D3D11 shader headers in C++ code. It shows the master header and examples of individual shader headers. ```cpp #include "d3d11/shaders.h" // Master header - includes all D3D11 shaders // Individual headers: // vertex_path_vs_data, vertex_path_vs_size // fill_ps_data, fill_ps_size // etc. ``` -------------------------------- ### Install CMake and Ninja on macOS Source: https://github.com/ultralight-ux/appcore/blob/master/README.md Use Homebrew to install CMake and Ninja on macOS. This command sets up the necessary build tools for the project. ```bash brew install cmake ninja ``` -------------------------------- ### Install CMake and Ninja on Windows Source: https://github.com/ultralight-ux/appcore/blob/master/README.md Use Chocolatey to install CMake and Ninja on Windows. Ensure you have administrative privileges to run this command. ```bash choco install cmake ninja ``` -------------------------------- ### Cursor Position Callback Function Example Source: https://github.com/ultralight-ux/appcore/blob/master/src/glfw/docs/input.dox Example of a cursor position callback function that receives cursor coordinates. ```c static void cursor_position_callback(GLFWwindow* window, double xpos, double ypos) { } ``` -------------------------------- ### Install Build Tools on Linux Source: https://github.com/ultralight-ux/appcore/blob/master/README.md Install essential build tools including CMake, Ninja, Clang, and development libraries on Debian-based Linux systems. This command ensures all dependencies are met for building. ```bash sudo apt install cmake ninja-build clang lld-4.0 libx11-dev xorg-dev libglu1-mesa-dev ``` -------------------------------- ### Load and Use OpenGL Extension Source: https://github.com/ultralight-ux/appcore/blob/master/src/glfw/docs/context.dox This example demonstrates how to load and use an OpenGL extension, including checking for support, fetching the function pointer, and calling the extension function. ```c #define GLFW_INCLUDE_GLEXT #include #define glGetDebugMessageLogARB pfnGetDebugMessageLog PFNGLGETDEBUGMESSAGELOGARBPROC pfnGetDebugMessageLog; // Flag indicating whether the extension is supported int has_ARB_debug_output = 0; void load_extensions(void) { if (glfwExtensionSupported("GL_ARB_debug_output")) { pfnGetDebugMessageLog = (PFNGLGETDEBUGMESSAGELOGARBPROC) glfwGetProcAddress("glGetDebugMessageLogARB"); has_ARB_debug_output = 1; } } void some_function(void) { if (has_ARB_debug_output) { // Now the extension function can be called as usual glGetDebugMessageLogARB(...); } } ``` -------------------------------- ### Use pkg-config with PKG_CONFIG_PATH Environment Variable Source: https://github.com/ultralight-ux/appcore/blob/master/src/glfw/docs/build.dox Specify the path to the glfw3.pc file using the PKG_CONFIG_PATH environment variable if the library is not installed system-wide. ```sh env PKG_CONFIG_PATH=path/to/glfw/src cc `pkg-config --cflags glfw3` -o myprog myprog.c `pkg-config --libs glfw3` ``` -------------------------------- ### Window Focus Callback Function Source: https://github.com/ultralight-ux/appcore/blob/master/src/glfw/docs/window.dox Example implementation of a window focus callback function. It checks the focused state and performs actions accordingly. ```c void window_focus_callback(GLFWwindow* window, int focused) { if (focused) { // The window gained input focus } else { // The window lost input focus } } ``` -------------------------------- ### Monitor connection callback function Source: https://github.com/ultralight-ux/appcore/blob/master/src/glfw/docs/monitor.dox Example implementation of a monitor callback function. Handles GLFW_CONNECTED and GLFW_DISCONNECTED events. ```c void monitor_callback(GLFWmonitor* monitor, int event) { if (event == GLFW_CONNECTED) { // The monitor was connected } else if (event == GLFW_DISCONNECTED) { // The monitor was disconnected } } ``` -------------------------------- ### File Drop Callback Implementation Source: https://github.com/ultralight-ux/appcore/blob/master/src/glfw/docs/input.dox Example implementation of a file drop callback. The provided path array is only valid until the callback returns, so deep copies are necessary if persistence is required. ```c void drop_callback(GLFWwindow* window, int count, const char** paths) { int i; for (i = 0; i < count; i++) handle_dropped_file(paths[i]); } ``` -------------------------------- ### Window Refresh Callback Function Source: https://github.com/ultralight-ux/appcore/blob/master/src/glfw/docs/window.dox Example implementation of a window refresh callback function. It redraws the window content and swaps buffers. ```c void window_refresh_callback(GLFWwindow* window) { draw_editor_ui(window); glfwSwapBuffers(window); } ``` -------------------------------- ### Basic AppCore Usage Source: https://github.com/ultralight-ux/appcore/blob/master/README.md Demonstrates the basic setup for creating an AppCore application, including initializing the app, creating a window, an overlay for rendering HTML, loading a URL, and running the application's main loop. ```cpp #include using namespace ultralight; int main() { // Create the App singleton auto app = App::Create(); // Create a window auto window = Window::Create(app->main_monitor(), 900, 600, false, kWindowFlags_Titled | kWindowFlags_Resizable); // Create an overlay to render HTML content auto overlay = Overlay::Create(window, window->width(), window->height(), 0, 0); // Load a URL overlay->view()->LoadURL("https://google.com"); // Run the app (blocks until all active windows are closed) app->Run(); return 0; } ``` -------------------------------- ### Get Window Visibility State Source: https://github.com/ultralight-ux/appcore/blob/master/src/glfw/docs/window.dox Get the current visibility state of a window. ```APIDOC ## glfwGetWindowAttrib (GLFW_VISIBLE) ### Description Retrieves the visibility state of the specified window. ### Function Signature ```c int glfwGetWindowAttrib(GLFWwindow* window, int attrib) ``` ### Parameters - **window**: The window to query. - **attrib**: Must be `GLFW_VISIBLE`. ### Returns One of `GLFW_TRUE` or `GLFW_FALSE`. ``` -------------------------------- ### Key callback function example Source: https://github.com/ultralight-ux/appcore/blob/master/src/glfw/docs/input.dox This callback function is triggered by key events. It checks for a specific key press (GLFW_KEY_E) and performs an action if detected. ```c void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods) { if (key == GLFW_KEY_E && action == GLFW_PRESS) activate_airship(); } ``` -------------------------------- ### Get Window Maximization State Source: https://github.com/ultralight-ux/appcore/blob/master/src/glfw/docs/window.dox Get the current maximization state of a window. ```APIDOC ## glfwGetWindowAttrib (GLFW_MAXIMIZED) ### Description Retrieves the maximization state of the specified window. ### Function Signature ```c int glfwGetWindowAttrib(GLFWwindow* window, int attrib) ``` ### Parameters - **window**: The window to query. - **attrib**: Must be `GLFW_MAXIMIZED`. ### Returns One of `GLFW_TRUE` or `GLFW_FALSE`. ``` -------------------------------- ### Get Window Iconification State Source: https://github.com/ultralight-ux/appcore/blob/master/src/glfw/docs/window.dox Get the current iconification state of a window. ```APIDOC ## glfwGetWindowAttrib (GLFW_ICONIFIED) ### Description Retrieves the iconification state of the specified window. ### Function Signature ```c int glfwGetWindowAttrib(GLFWwindow* window, int attrib) ``` ### Parameters - **window**: The window to query. - **attrib**: Must be `GLFW_ICONIFIED`. ### Returns One of `GLFW_TRUE` or `GLFW_FALSE`. ``` -------------------------------- ### Basic Full Screen Window Creation Source: https://github.com/ultralight-ux/appcore/blob/master/src/glfw/docs/moving.dox Compares the old and new methods for creating a basic full-screen window. The new method uses `glfwCreateWindow` and requires explicit monitor and context handling. ```c glfwOpenWindow(640, 480, 8, 8, 8, 0, 24, 0, GLFW_FULLSCREEN); ``` ```c window = glfwCreateWindow(640, 480, "My Window", glfwGetPrimaryMonitor(), NULL); ``` -------------------------------- ### Initialize AppCore Application Singleton Source: https://context7.com/ultralight-ux/appcore/llms.txt Bootstraps the AppCore runtime by initializing the Ultralight Platform, creating a Renderer, and preparing the run loop. Custom settings and configuration can be provided. ```cpp #include using namespace ultralight; class MyApp : public AppListener { public: MyApp() { Settings settings; settings.developer_name = "Acme"; settings.app_name = "MyDesktopApp"; settings.file_system_path = "./assets/"; // resolved relative to executable settings.force_cpu_renderer = false; // prefer GPU when available settings.idle_threshold = 0.5; // seconds before idle detection settings.sustained_idle_time = 2.0; // seconds idle before OnIdle fires settings.idle_utilization_threshold = 0.5; // CPU fraction threshold Config config; // config.cache_path is auto-set; config.face_winding may be overridden app_ = App::Create(settings, config); app_->set_listener(this); } void OnUpdate() override { // Called every frame before Renderer::Update/Render // Put game-loop-style app logic here } void OnIdle(double utilization) override { // Called after sustained idle (low CPU + no user input) // Good place to flush caches or run background work // utilization is 0.0–1.0 thread CPU over the last ~1 second } void Run() { app_->Run(); } // blocks until all windows are closed private: RefPtr app_; }; int main() { MyApp app; app.Run(); return 0; } ``` -------------------------------- ### Character Callback Function Example Source: https://github.com/ultralight-ux/appcore/blob/master/src/glfw/docs/input.dox Example of a character callback function that receives Unicode code points. ```c void character_callback(GLFWwindow* window, unsigned int codepoint) { } ``` -------------------------------- ### Initialize glad with GLFW context Source: https://github.com/ultralight-ux/appcore/blob/master/src/glfw/docs/context.dox Create a GLFW window, make its context current, and then initialize glad using glfwGetProcAddress. ```c window = glfwCreateWindow(640, 480, "My Window", NULL, NULL); if (!window) { ... } gglfwMakeContextCurrent(window); gladLoadGLLoader((GLADloadproc)glfwGetProcAddress); ``` -------------------------------- ### Create a Platform OS Window Source: https://context7.com/ultralight-ux/appcore/llms.txt Produces a native OS window with specified dimensions and flags. Includes methods for setting title, moving to center, and retrieving DPI-related information. Also demonstrates taking a screenshot and accessing the native window handle. ```cpp #include using namespace ultralight; class MyWindowListener : public WindowListener { public: void OnClose(Window* window) override { App::instance()->Quit(); // quit when the last window closes } void OnResize(Window* window, uint32_t width_px, uint32_t height_px) override { // Resize any overlays to match new pixel dimensions } bool OnKeyEvent(const KeyEvent& evt) override { // Return false to consume (prevent further propagation) return true; } bool OnMouseEvent(const MouseEvent& evt) override { return true; } bool OnScrollEvent(const ScrollEvent& evt) override { return true; } }; int main() { auto app = App::Create(); // 1024×768 in screen coords, windowed, titled + resizable auto window = Window::Create( app->main_monitor(), 1024, 768, /*fullscreen=*/false, kWindowFlags_Titled | kWindowFlags_Resizable | kWindowFlags_Maximizable ); static MyWindowListener listener; window->set_listener(&listener); window->SetTitle("My HTML App"); window->MoveToCenter(); // DPI helpers double scale = window->scale(); // e.g. 2.0 on Retina int px = window->ScreenToPixels(100); // 200 on 2× display uint32_t width = window->width(); // pixels uint32_t swidth = window->screen_width(); // screen coords // Screenshot auto bmp = window->TakeScreenshot(); // BGRA8_UNORM_SRGB bitmap // Native handle for platform integration void* hwnd = window->native_handle(); // HWND / NSWindow* / GLFWwindow* app->Run(); return 0; } ``` -------------------------------- ### Create Window and Context Source: https://github.com/ultralight-ux/appcore/blob/master/src/glfw/docs/quick.dox Create a window and its associated OpenGL context. Always check the return value for potential creation failures. ```c GLFWwindow* window = glfwCreateWindow(640, 480, "My Title", NULL, NULL); if (!window) { // Window or OpenGL context creation failed } ``` -------------------------------- ### Find Installed GLFW Package with CMake Source: https://github.com/ultralight-ux/appcore/blob/master/src/glfw/docs/build.dox When using an installed GLFW binary, use CMake's find_package command to locate and prepare to link against it. ```cmake find_package(glfw3 3.3 REQUIRED) ``` -------------------------------- ### C API — ulCreateApp / ulCreateWindow / ulCreateOverlay Source: https://context7.com/ultralight-ux/appcore/llms.txt Mirrors the C++ API with opaque handle types and free functions, suitable for FFI bindings. This example demonstrates setting up application settings, callbacks, window, and overlay creation, and loading a URL. ```c #include static void on_update(void* user_data) { /* called every frame */ } static void on_idle(void* user_data, double utilization) { /* app is idle; utilization is 0.0–1.0 */ } static void on_close(void* user_data, ULWindow window) { ULApp app = (ULApp)user_data; ulAppQuit(app); } static void on_resize(void* user_data, ULWindow window, unsigned int w, unsigned int h) { ULOverlay overlay = (ULOverlay)user_data; ulOverlayResize(overlay, w, h); } int main() { /* Settings */ ULSettings settings = ulCreateSettings(); ulSettingsSetDeveloperName(settings, ulCreateStringUTF8("Acme", 4)); ulSettingsSetAppName(settings, ulCreateStringUTF8("MyApp", 5)); ulSettingsSetForceCPURenderer(settings, false); ulSettingsSetIdleThreshold(settings, 0.5); ulSettingsSetSustainedIdleTime(settings, 2.0); ulSettingsSetIdleUtilizationThreshold(settings, 0.5); /* App */ ULApp app = ulCreateApp(settings, NULL); ulDestroySettings(settings); ulAppSetUpdateCallback(app, on_update, NULL); ulAppSetIdleCallback(app, on_idle, NULL); /* Window */ ULMonitor monitor = ulAppGetMainMonitor(app); ULWindow window = ulCreateWindow(monitor, 1024, 768, false, kWindowFlags_Titled | kWindowFlags_Resizable); ulWindowSetTitle(window, "My C App"); ulWindowMoveToCenter(window); ulWindowSetCloseCallback(window, on_close, app); /* Overlay */ ULOverlay overlay = ulCreateOverlay(window, ulWindowGetWidth(window), ulWindowGetHeight(window), 0, 0); ulWindowSetResizeCallback(window, on_resize, overlay); ULView view = ulOverlayGetView(overlay); ULString url = ulCreateStringUTF8("https://example.com", 19); ulViewLoadURL(view, url); ulDestroyString(url); ulAppRun(app); ulDestroyOverlay(overlay); ulDestroyWindow(window); ulDestroyApp(app); return 0; } ``` -------------------------------- ### App::Create — Initialize the application singleton Source: https://context7.com/ultralight-ux/appcore/llms.txt Initializes the AppCore runtime, including the Ultralight Platform, Renderer, and run loop. Only one App instance can exist per process. Custom settings and configuration can be provided. ```APIDOC ## App::Create — Initialize the application singleton ### Description `App::Create()` bootstraps the entire AppCore runtime: it initializes the Ultralight `Platform` singleton with OS-specific defaults (font loader, file system, GPU driver), creates a `Renderer`, and prepares the run loop. Only one `App` may exist per process lifetime. Custom `Settings` and `Config` are optional. ### Method Signature ```cpp static RefPtr App::Create(const Settings& settings = Settings(), const Config& config = Config()); ``` ### Parameters #### Settings - **developer_name** (string) - Optional - The name of the application developer. - **app_name** (string) - Optional - The name of the application. - **file_system_path** (string) - Optional - Path to the application's assets, resolved relative to the executable. - **force_cpu_renderer** (bool) - Optional - Forces the use of the CPU renderer, preferring GPU when available. - **idle_threshold** (double) - Optional - Seconds before idle detection begins. - **sustained_idle_time** (double) - Optional - Seconds of sustained idle before `OnIdle` fires. - **idle_utilization_threshold** (double) - Optional - CPU fraction threshold for idle detection. #### Config - **cache_path** (string) - Optional - Path for caching resources (auto-set by default). - **face_winding** (FaceWinding) - Optional - Overrides the default face winding order. ### Usage Example ```cpp #include using namespace ultralight; class MyApp : public AppListener { public: MyApp() { Settings settings; settings.developer_name = "Acme"; settings.app_name = "MyDesktopApp"; settings.file_system_path = "./assets/"; // resolved relative to executable settings.force_cpu_renderer = false; // prefer GPU when available settings.idle_threshold = 0.5; // seconds before idle detection settings.sustained_idle_time = 2.0; // seconds idle before OnIdle fires settings.idle_utilization_threshold = 0.5; // CPU fraction threshold Config config; // config.cache_path is auto-set; config.face_winding may be overridden app_ = App::Create(settings, config); app_->set_listener(this); } void OnUpdate() override { // Called every frame before Renderer::Update/Render // Put game-loop-style app logic here } void OnIdle(double utilization) override { // Called after sustained idle (low CPU + no user input) // Good place to flush caches or run background work // utilization is 0.0–1.0 thread CPU over the last ~1 second } void Run() { app_->Run(); } // blocks until all windows are closed private: RefPtr app_; }; int main() { MyApp app; app.Run(); return 0; } ``` ``` -------------------------------- ### Initialize GLFW Source: https://github.com/ultralight-ux/appcore/blob/master/src/glfw/docs/intro.dox Call `glfwInit` to initialize the library. It returns `GLFW_FALSE` if an error occurs. Initialization must be done before most other GLFW functions can be called. ```c if (!glfwInit()) { // Handle initialization failure } ``` -------------------------------- ### Get Window Visible Attribute Source: https://github.com/ultralight-ux/appcore/blob/master/src/glfw/docs/window.dox Retrieve the current visibility state of a window. ```c int visible = glfwGetWindowAttrib(window, GLFW_VISIBLE); ``` -------------------------------- ### Get Window Maximized Attribute Source: https://github.com/ultralight-ux/appcore/blob/master/src/glfw/docs/window.dox Retrieve the current maximization state of a window. ```c int maximized = glfwGetWindowAttrib(window, GLFW_MAXIMIZED); ``` -------------------------------- ### Initialize GLFW Source: https://github.com/ultralight-ux/appcore/blob/master/src/glfw/docs/quick.dox Initialize the GLFW library before using most of its functions. Check the return value for successful initialization. ```c if (!glfwInit()) { // Initialization failed } ``` -------------------------------- ### Get Window Iconified Attribute Source: https://github.com/ultralight-ux/appcore/blob/master/src/glfw/docs/window.dox Retrieve the current iconification state of a window. ```c int iconified = glfwGetWindowAttrib(window, GLFW_ICONIFIED); ``` -------------------------------- ### Create and Manage an Overlay in a Window Source: https://context7.com/ultralight-ux/appcore/llms.txt Embeds a web view within a native window using an Overlay. Handles basic setup, loading content, and managing visibility and focus. Resizing should typically be handled within WindowListener::OnResize. ```cpp #include using namespace ultralight; int main() { auto app = App::Create(); auto window = Window::Create(app->main_monitor(), 1280, 800, false, kWindowFlags_Titled | kWindowFlags_Resizable); // Full-window overlay at pixel offset (0, 0) auto overlay = Overlay::Create(window, window->width(), window->height(), 0, 0); // Load content overlay->view()->LoadURL("file:///index.html"); // from assets/ // overlay->view()->LoadHTML("

Hello

"); // inline HTML // Resize overlay when window resizes // (typically done inside WindowListener::OnResize) // overlay->Resize(new_width, new_height); // Visibility and focus overlay->Show(); overlay->Focus(); // grant keyboard focus // Wrap an existing View (e.g. created via Renderer::CreateView) // auto overlay2 = Overlay::Create(window, existing_view, x_offset, y_offset); app->Run(); return 0; } ``` -------------------------------- ### Get Joystick Name Source: https://github.com/ultralight-ux/appcore/blob/master/src/glfw/docs/input.dox Retrieving the human-readable, UTF-8 encoded name of a joystick. ```APIDOC ## Joystick Name The human-readable, UTF-8 encoded name of a joystick is returned by @ref glfwGetJoystickName. See the reference documentation for the lifetime of the returned string. @code const char* name = glfwGetJoystickName(GLFW_JOYSTICK_4); @endcode ``` -------------------------------- ### Create Window with Specific OpenGL Version Source: https://github.com/ultralight-ux/appcore/blob/master/src/glfw/docs/quick.dox Set window hints for the desired OpenGL major and minor version before creating the window. Failure to meet the requirements will result in creation failure. ```c glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 2); gglfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0); GLFWwindow* window = glfwCreateWindow(640, 480, "My Title", NULL, NULL); if (!window) { // Window or context creation failed } ``` -------------------------------- ### Compile and Link with pkg-config (Static GLFW and GLU) Source: https://github.com/ultralight-ux/appcore/blob/master/src/glfw/docs/build.dox Link statically against GLFW and link against GLU using pkg-config. Ensure you do not link statically against GLU itself if using the static version of GLFW. ```sh cc `pkg-config --cflags glfw3 glu` -o myprog myprog.c `pkg-config --static --libs glfw3` `pkg-config --libs glu` ``` -------------------------------- ### Get Monitor Name Source: https://github.com/ultralight-ux/appcore/blob/master/src/glfw/docs/monitor.dox Retrieves the human-readable, UTF-8 encoded name of a monitor. ```APIDOC ## Get Monitor Name ### Description Retrieves the human-readable, UTF-8 encoded name of a monitor. The lifetime of the returned string is managed by GLFW. ### Function Signature `const char* glfwGetMonitorName(GLFWmonitor* monitor);` ### Parameters - `monitor`: The monitor to query. ### Returns The UTF-8 encoded name of the monitor, or `NULL` if an error occurred. ### Example ```c const char* name = glfwGetMonitorName(monitor); ``` ### Notes Monitor names are not guaranteed to be unique. Only the monitor handle is guaranteed to be unique. ``` -------------------------------- ### Get Gamepad Name Source: https://github.com/ultralight-ux/appcore/blob/master/src/glfw/docs/input.dox Retrieving the human-readable name provided by the gamepad mapping for a joystick. ```APIDOC ## Gamepad Input You can query the human-readable name provided by the gamepad mapping with @ref glfwGetGamepadName. This may or may not be the same as the [joystick name](@ref joystick_name). @code const char* name = glfwGetGamepadName(GLFW_JOYSTICK_7); @endcode ``` -------------------------------- ### Get Key Name Source: https://github.com/ultralight-ux/appcore/blob/master/src/glfw/docs/input.dox Retrieves the keyboard layout dependent name of a printable key. ```APIDOC ## glfwGetKeyName ### Description Retrieves the keyboard layout dependent name of the specified printable key. This function can handle both [keys and scancodes](@ref input_key). If the specified key is `GLFW_KEY_UNKNOWN` then the scancode is used, otherwise it is ignored. ### Parameters - **key** (int) - The key to query, or `GLFW_KEY_UNKNOWN` if using a scancode. - **scancode** (int) - The scancode of the key to query. This is ignored if the key is not `GLFW_KEY_UNKNOWN`. ### Return Value On success, the name of the key is returned. If the key has no name, or the current keyboard layout cannot be determined, `NULL` is returned. ### Example ```c const char* key_name = glfwGetKeyName(GLFW_KEY_W, 0); show_tutorial_hint("Press %s to move forward", key_name); ``` ``` -------------------------------- ### Get Timer Frequency Source: https://github.com/ultralight-ux/appcore/blob/master/src/glfw/docs/input.dox Query the frequency of the system timer in Hz. This is useful for timing operations. ```c uint64_t freqency = glfwGetTimerFrequency(); ``` -------------------------------- ### Set Initialization Hint Source: https://github.com/ultralight-ux/appcore/blob/master/src/glfw/docs/intro.dox Use `glfwInitHint` to set initialization hints before calling `glfwInit`. These hints affect library behavior until termination. Hints are ignored if set after initialization. ```c glfwInitHint(GLFW_JOYSTICK_HAT_BUTTONS, GLFW_FALSE); ``` -------------------------------- ### Get Cursor Position Source: https://github.com/ultralight-ux/appcore/blob/master/src/glfw/docs/input.dox Retrieves the cursor position within the client area of the specified window. ```APIDOC ## glfwGetCursorPos ### Description Returns the cursor position, measured in screen coordinates but relative to the top-left corner of the window client area. On platforms that provide it, the full sub-pixel cursor position is passed on. ### Parameters - **window** (GLFWwindow*) - The window whose cursor position is to be queried. - **xpos** (double*) - Where to store the cursor's x-coordinate, relative to the left edge of the client area. - **ypos** (double*) - Where to store the cursor's y-coordinate, relative to the top edge of the client area. ### Example ```c double xpos, ypos; g glfwGetCursorPos(window, &xpos, &ypos); ``` ``` -------------------------------- ### Set and Get User Pointer Source: https://github.com/ultralight-ux/appcore/blob/master/src/glfw/docs/monitor.dox Allows associating a custom pointer with a monitor for user-defined purposes. ```APIDOC ## Set and Get User Pointer ### Description Each monitor has a user pointer that can be set and queried. This pointer can be used for any purpose and will not be modified by GLFW. The value persists until the monitor is disconnected or the library is terminated. ### Set User Pointer #### Function Signature `void glfwSetMonitorUserPointer(GLFWmonitor* monitor, void* pointer);` ### Parameters (Set) - `monitor`: The monitor to associate the pointer with. - `pointer`: The user pointer to set. ### Get User Pointer #### Function Signature `void* glfwGetMonitorUserPointer(GLFWmonitor* monitor);` ### Parameters (Get) - `monitor`: The monitor to query. ### Returns (Get) The user pointer associated with the monitor, or `NULL` if no pointer has been set. ### Example ```c // Set user pointer gglfwSetMonitorUserPointer(monitor, my_custom_data); // Get user pointer void* user_ptr = glfwGetMonitorUserPointer(monitor); ``` ### Notes The initial value of the user pointer is `NULL`. ``` -------------------------------- ### Making the OpenGL Context Current Source: https://github.com/ultralight-ux/appcore/blob/master/src/glfw/docs/quick.dox Before using the OpenGL API, you must make the window's OpenGL context current. This context will remain current until another context is made current or the window is destroyed. Initialize extension loader libraries like glad here. ```c glfwMakeContextCurrent(window); ``` ```c gladLoadGLLoader((GLADloadproc)glfwGetProcAddress); ``` -------------------------------- ### Get Monitor Position Source: https://github.com/ultralight-ux/appcore/blob/master/src/glfw/docs/monitor.dox Retrieves the virtual position of the monitor on the virtual desktop in screen coordinates. ```APIDOC ## Get Monitor Position ### Description Retrieves the virtual position of the monitor on the virtual desktop in screen coordinates. ### Function Signature `void glfwGetMonitorPos(GLFWmonitor* monitor, int* xpos, int* ypos);` ### Parameters - `monitor`: The monitor to query. - `xpos`: Pointer to a `int` to store the X position of the monitor's top-left corner. - `ypos`: Pointer to a `int` to store the Y position of the monitor's top-left corner. ### Example ```c int xpos, ypos; gglfwGetMonitorPos(monitor, &xpos, &ypos); ``` ``` -------------------------------- ### Get Monitor Position Source: https://github.com/ultralight-ux/appcore/blob/master/src/glfw/docs/monitor.dox Retrieves the virtual position of the monitor on the virtual desktop in screen coordinates. ```c int xpos, ypos; glfwGetMonitorPos(monitor, &xpos, &ypos); ``` -------------------------------- ### Create a Full Screen Window Source: https://github.com/ultralight-ux/appcore/blob/master/src/glfw/docs/window.dox Creates a full screen window on the primary monitor. This covers the entire display area without borders. ```c GLFWwindow* window = glfwCreateWindow(640, 480, "My Title", glfwGetPrimaryMonitor(), NULL); ``` -------------------------------- ### Window Monitor Association Source: https://github.com/ultralight-ux/appcore/blob/master/src/glfw/docs/window.dox Get the monitor associated with a window. Returns NULL for windowed mode windows. ```APIDOC ## glfwGetWindowMonitor ### Description Retrieves the monitor that the specified window is on. For full screen windows, this is the monitor the window is full screen on. For windowed mode windows, this function returns `NULL`. ### Function Signature ```c GLFWmonitor* glfwGetWindowMonitor(GLFWwindow* window) ``` ### Parameters - **window**: The window whose monitor to query. ``` -------------------------------- ### Set Window Monitor (Windowed) Source: https://github.com/ultralight-ux/appcore/blob/master/src/glfw/docs/window.dox Make a window windowed, specifying its position, size, and disabling refresh rate. ```c glfwSetWindowMonitor(window, NULL, xpos, ypos, width, height, 0); ``` -------------------------------- ### Getting Window Size Source: https://github.com/ultralight-ux/appcore/blob/master/src/glfw/docs/window.dox Retrieve the current size of a window's client area in screen coordinates. ```c int width, height; gglfwGetWindowSize(window, &width, &height); ``` -------------------------------- ### Get Gamepad State Source: https://github.com/ultralight-ux/appcore/blob/master/src/glfw/docs/input.dox Retrieving the current gamepad state of a joystick, including button and axis values. ```APIDOC ## Gamepad Input To retrieve the gamepad state of a joystick, call @ref glfwGetGamepadState. @code GLFWgamepadstate state; if (glfwGetGamepadState(GLFW_JOYSTICK_3, &state)) { if (state.buttons[GLFW_GAMEPAD_BUTTON_A]) { input_jump(); } input_speed(state.axes[GLFW_GAMEPAD_AXIS_RIGHT_TRIGGER]); } @endcode The @ref GLFWgamepadstate struct has two arrays; one for button states and one for axis states. The values for each button and axis are the same as for the @ref glfwGetJoystickButtons and @ref glfwGetJoystickAxes functions, i.e. `GLFW_PRESS` or `GLFW_RELEASE` for buttons and -1.0 to 1.0 inclusive for axes. The sizes of the arrays and the positions within each array are fixed. ``` -------------------------------- ### Create a Vulkan window surface Source: https://github.com/ultralight-ux/appcore/blob/master/src/glfw/docs/vulkan.dox Create a Vulkan surface for a GLFW window using glfwCreateWindowSurface. Remember to destroy the surface using vkDestroySurfaceKHR when it's no longer needed. ```c VkSurfaceKHR surface; VkResult err = glfwCreateWindowSurface(instance, window, NULL, &surface); if (err) { // Window surface creation failed } ``` -------------------------------- ### Get Key Scancode Source: https://github.com/ultralight-ux/appcore/blob/master/src/glfw/docs/input.dox Retrieves the platform-specific scancode for a named key. Scancodes are safe to save to disk. ```APIDOC ## glfwGetKeyScancode ### Description Retrieves the platform-specific scancode for the specified key. The scancode can be used to uniquely identify a physical key, regardless of the current keyboard layout. ### Parameters - **key** (int) - The key to query. See ""@ref keys"" ### Return Value On success, the platform-specific scancode of the key is returned. If the key is not recognized or does not have a scancode, `0` is returned. ### Example ```c const int scancode = glfwGetKeyScancode(GLFW_KEY_X); set_key_mapping(scancode, swap_weapons); ``` ``` -------------------------------- ### Set and Get Gamma Ramp Source: https://github.com/ultralight-ux/appcore/blob/master/src/glfw/docs/monitor.dox Manages the gamma ramp of a monitor, allowing for color correction adjustments. ```APIDOC ## Set and Get Gamma Ramp ### Description Manages the gamma ramp of a monitor. The gamma ramp allows for color correction adjustments. GLFW copies the gamma ramp data, so the original data does not need to be kept. ### Set Gamma Ramp #### Function Signature `void glfwSetGammaRamp(GLFWmonitor* monitor, const GLFWgammaramp* ramp);` ### Parameters (Set) - `monitor`: The monitor whose gamma ramp to set. - `ramp`: A pointer to the `GLFWgammaramp` structure to set. ### Get Gamma Ramp #### Function Signature `const GLFWgammaramp* glfwGetGammaRamp(GLFWmonitor* monitor);` ### Parameters (Get) - `monitor`: The monitor whose gamma ramp to retrieve. ### Returns (Get) A pointer to the current gamma ramp of the monitor. The lifetime of the returned structure is managed by GLFW. ### Example (Setting Gamma Ramp) ```c GLFWgammaramp ramp; unsigned short red[256], green[256], blue[256]; ramp.size = 256; ramp.red = red; ramp.green = green; ramp.blue = blue; for (int i = 0; i < ramp.size; i++) { // Fill out gamma ramp arrays as desired } gglfwSetGammaRamp(monitor, &ramp); ``` ### Example (Getting Gamma Ramp) ```c const GLFWgammaramp* ramp = glfwGetGammaRamp(monitor); ``` ### Related Functions - `glfwSetGamma(monitor, gamma)`: Sets a regular gamma ramp calculated from the desired exponent. ### Notes - It is recommended that the gamma ramp size matches the current gamma ramp size for the monitor. - The software-controlled gamma ramp is applied in addition to the hardware gamma correction. Setting a linear ramp or gamma 1.0 results in default (usually sRGB-like) behavior. ``` -------------------------------- ### Get Window Monitor Source: https://github.com/ultralight-ux/appcore/blob/master/src/glfw/docs/window.dox Retrieve the monitor associated with a full-screen window. Returns NULL for windowed mode windows. ```c GLFWmonitor* monitor = glfwGetWindowMonitor(window); ``` -------------------------------- ### Create a Window Source: https://github.com/ultralight-ux/appcore/blob/master/src/glfw/docs/window.dox Creates a windowed mode window with the specified dimensions and title. Always check the return value for success. ```c GLFWwindow* window = glfwCreateWindow(640, 480, "My Title", NULL, NULL); ``` -------------------------------- ### Get Joystick Name Source: https://github.com/ultralight-ux/appcore/blob/master/src/glfw/docs/input.dox Retrieve the human-readable, UTF-8 encoded name of a joystick. Note that names are not guaranteed to be unique. ```c const char* name = glfwGetJoystickName(GLFW_JOYSTICK_4); ``` -------------------------------- ### Set Window Visibility Hint Source: https://github.com/ultralight-ux/appcore/blob/master/src/glfw/docs/window.dox Set the GLFW_VISIBLE hint before creating a window to control its initial visibility. Hidden windows are not shown until explicitly made visible. ```c glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE); ``` -------------------------------- ### Get Key State Source: https://github.com/ultralight-ux/appcore/blob/master/src/glfw/docs/input.dox Retrieves the last reported state for a specified key. The state is either GLFW_PRESS or GLFW_RELEASE. ```APIDOC ## glfwGetKey ### Description Returns the last state of the specified key. The returned state is one of `GLFW_PRESS` or `GLFW_RELEASE`. This function only returns cached key event state. It does not poll the system for the current physical state of the key. ### Parameters - **window** (GLFWwindow*) - The window that the keys will be queried for. - **key** (int) - The desired key. See ""@ref keys"" ### Return Value One of `GLFW_PRESS` or `GLFW_RELEASE`. ### Example ```c int state = glfwGetKey(window, GLFW_KEY_E); if (state == GLFW_PRESS) { activate_airship(); } ``` ``` -------------------------------- ### Get Monitor Name Source: https://github.com/ultralight-ux/appcore/blob/master/src/glfw/docs/monitor.dox Retrieves the human-readable, UTF-8 encoded name of a monitor. Monitor names are not guaranteed to be unique. ```c const char* name = glfwGetMonitorName(monitor); ``` -------------------------------- ### C API - App Creation and Management Source: https://context7.com/ultralight-ux/appcore/llms.txt Functions for creating and managing the application, windows, and overlays using the C API. ```APIDOC ## C API — ulCreateApp / ulCreateWindow / ulCreateOverlay The C API (``) mirrors the C++ API with opaque handle types (`ULApp`, `ULWindow`, `ULOverlay`, `ULMonitor`) and free functions. It is suitable for FFI bindings from languages such as C, Rust, Python, or Go. ### Core Functions - **`ULApp ulCreateApp(ULSettings settings, void* user_data)`**: Creates a new Ultralight application instance. - **`ULWindow ulCreateWindow(ULMonitor monitor, unsigned int width, unsigned int height, bool fullscreen, unsigned int flags)`**: Creates a new window. - **`ULOverlay ulCreateOverlay(ULWindow window, unsigned int width, unsigned int height, int x, int y)`**: Creates an overlay on a window. - **`void ulAppQuit(ULApp app)`**: Quits the application. ### Callback Functions - **`void ulAppSetUpdateCallback(ULApp app, ULAppUpdateCallback callback, void* user_data)`**: Sets the update callback. - **`void ulAppSetIdleCallback(ULApp app, ULAppIdleCallback callback, void* user_data)`**: Sets the idle callback. - **`void ulWindowSetCloseCallback(ULWindow window, ULWindowCloseCallback callback, void* user_data)`**: Sets the window close callback. - **`void ulWindowSetResizeCallback(ULWindow window, ULWindowResizeCallback callback, void* user_data)`**: Sets the window resize callback. ### Example Usage ```c #include // ... (callback definitions: on_update, on_idle, on_close, on_resize) int main() { /* Settings */ ULSettings settings = ulCreateSettings(); ulSettingsSetDeveloperName(settings, ulCreateStringUTF8("Acme", 4)); ulSettingsSetAppName(settings, ulCreateStringUTF8("MyApp", 5)); // ... other settings /* App */ ULApp app = ulCreateApp(settings, NULL); ulDestroySettings(settings); ulAppSetUpdateCallback(app, on_update, NULL); ulAppSetIdleCallback(app, on_idle, NULL); /* Window */ ULMonitor monitor = ulAppGetMainMonitor(app); ULWindow window = ulCreateWindow(monitor, 1024, 768, false, kWindowFlags_Titled | kWindowFlags_Resizable); ulWindowSetTitle(window, "My C App"); ulWindowSetCloseCallback(window, on_close, app); /* Overlay */ ULOverlay overlay = ulCreateOverlay(window, ulWindowGetWidth(window), ulWindowGetHeight(window), 0, 0); ulWindowSetResizeCallback(window, on_resize, overlay); /* View */ ULView view = ulOverlayGetView(overlay); ULString url = ulCreateStringUTF8("https://example.com", 19); ulViewLoadURL(view, url); ulDestroyString(url); ulAppRun(app); // Cleanup ulDestroyOverlay(overlay); ulDestroyWindow(window); ulDestroyApp(app); return 0; } ``` ``` -------------------------------- ### Viewport Setup with Framebuffer Size Source: https://github.com/ultralight-ux/appcore/blob/master/src/glfw/docs/moving.dox Demonstrates how to correctly set the OpenGL viewport using framebuffer dimensions, which may differ from window dimensions on high-DPI monitors. `glfwGetFramebufferSize` is used in GLFW 3. ```c glfwGetWindowSize(&width, &height); glViewport(0, 0, width, height); ``` ```c glfwGetFramebufferSize(window, &width, &height); glViewport(0, 0, width, height); ``` -------------------------------- ### Get monitor physical size Source: https://github.com/ultralight-ux/appcore/blob/master/src/glfw/docs/monitor.dox Retrieve the physical dimensions of a monitor in millimeters. This is an estimation and has no relation to its current resolution. ```c int width_mm, height_mm; gàyglfwGetMonitorPhysicalSize(monitor, &width_mm, &height_mm); ``` -------------------------------- ### Get primary monitor Source: https://github.com/ultralight-ux/appcore/blob/master/src/glfw/docs/monitor.dox Retrieve the user's preferred monitor, typically the one with global UI elements. ```c GLFWmonitor* primary = glfwGetPrimaryMonitor(); ``` -------------------------------- ### Build Release Version on Windows Source: https://github.com/ultralight-ux/appcore/blob/master/README.md Build the release version of AppCore for 64-bit systems on Windows. This command initiates the compilation process for a production-ready build. ```makefile make release x64 ``` -------------------------------- ### Set Transparent Framebuffer Hint Source: https://github.com/ultralight-ux/appcore/blob/master/src/glfw/docs/window.dox Set the GLFW_TRANSPARENT_FRAMEBUFFER hint to enable per-pixel transparency for the window's content area. Requires desktop compositing. ```c glfwWindowHint(GLFW_TRANSPARENT_FRAMEBUFFER, GLFW_TRUE); ``` -------------------------------- ### Check OpenGL extension support Source: https://github.com/ultralight-ux/appcore/blob/master/src/glfw/docs/context.dox Use GLAD_GL_xxx booleans to determine if a specific OpenGL extension is supported by the current context. ```c if (GLAD_GL_ARB_debug_output) { // Use GL_ARB_debug_output } ``` -------------------------------- ### Get Window Focus Attribute Source: https://github.com/ultralight-ux/appcore/blob/master/src/glfw/docs/window.dox Retrieve the current input focus state of a window using glfwGetWindowAttrib with the GLFW_FOCUSED attribute. ```c int focused = glfwGetWindowAttrib(window, GLFW_FOCUSED); ``` -------------------------------- ### Get Window Position Source: https://github.com/ultralight-ux/appcore/blob/master/src/glfw/docs/window.dox Directly retrieves the current screen coordinates of the upper-left corner of a window's client area. ```c int xpos, ypos; gglfwGetWindowPos(window, &xpos, &ypos); ``` -------------------------------- ### Build on macOS and Linux Source: https://github.com/ultralight-ux/appcore/blob/master/README.md Build AppCore on macOS and Linux systems. This command initiates the build process for these platforms. ```bash ./make ``` -------------------------------- ### Get Raw Timer Value Source: https://github.com/ultralight-ux/appcore/blob/master/src/glfw/docs/input.dox Access the raw timer value, measured in units of 1/frequency seconds. The frequency is platform-dependent. ```c uint64_t value = glfwGetTimerValue(); ``` -------------------------------- ### Create a Windowed Full Screen Window Source: https://github.com/ultralight-ux/appcore/blob/master/src/glfw/docs/window.dox Creates a "windowed full screen" or "borderless full screen" window by requesting the current video mode. This avoids changing the monitor's video mode. ```c const GLFWvidmode* mode = glfwGetVideoMode(monitor); glfwWindowHint(GLFW_RED_BITS, mode->redBits); gglfwWindowHint(GLFW_GREEN_BITS, mode->greenBits); gglfwWindowHint(GLFW_BLUE_BITS, mode->blueBits); gglfwWindowHint(GLFW_REFRESH_RATE, mode->refreshRate); GLFWwindow* window = glfwCreateWindow(mode->width, mode->height, "My Title", monitor, NULL); ``` -------------------------------- ### Get Joystick Hat States Source: https://github.com/ultralight-ux/appcore/blob/master/src/glfw/docs/input.dox Retrieve the states of all hats for a given joystick. Hat states are represented by specific constants. ```c int count; const unsigned char* hats = glfwGetJoystickHats(GLFW_JOYSTICK_7, &count); ``` -------------------------------- ### Platform Services Source: https://context7.com/ultralight-ux/appcore/llms.txt Provides direct access to platform-native singletons for font loading, file system access, and logging. ```APIDOC ## Platform services — Font loader, file system, and logger `Platform.h` provides direct access to the platform-native singletons that AppCore installs automatically. You only need these explicitly when using the lower-level `Renderer` API without `App::Create()`. ### Methods - **`Platform& Platform::instance()`**: Get the singleton instance of the Platform. - **`void Platform::set_font_loader(std::unique_ptr loader)`**: Set the native font loader. - **`void Platform::set_file_system(std::unique_ptr file_system)`**: Set the native file system. - **`void Platform::set_logger(std::unique_ptr logger)`**: Set the native logger. ### Example Usage ```cpp #include #include using namespace ultralight; // Manually wire up platform services (skip if using App::Create()) Platform& platform = Platform::instance(); // Native font loader (DirectWrite / Core Text / Fontconfig) platform.set_font_loader(GetPlatformFontLoader()); // Native file system rooted at ./assets/ // On macOS pass "@resource_path" to use the app bundle's Resources/ platform.set_file_system(GetPlatformFileSystem("./assets/")); // Write log to disk platform.set_logger(GetDefaultLogger("./ultralight.log")); ``` ``` -------------------------------- ### Compile and Link with pkg-config (Static GLFW) Source: https://github.com/ultralight-ux/appcore/blob/master/src/glfw/docs/build.dox Use pkg-config to retrieve compile-time and link-time flags for the static version of the GLFW library. This command line is typical for Unix-like systems. ```sh cc `pkg-config --cflags glfw3` -o myprog myprog.c `pkg-config --static --libs glfw3` ``` -------------------------------- ### Get Joystick Button States Source: https://github.com/ultralight-ux/appcore/blob/master/src/glfw/docs/input.dox Retrieve the states of all buttons for a given joystick. Each button state is either GLFW_PRESS or GLFW_RELEASE. ```c int count; const unsigned char* buttons = glfwGetJoystickButtons(GLFW_JOYSTICK_3, &count); ``` -------------------------------- ### Get Key Scancode with GLFW Source: https://github.com/ultralight-ux/appcore/blob/master/src/glfw/docs/input.dox Query the scancode for any named key on the current platform. Scancodes are safe to save to disk. ```c const int scancode = glfwGetKeyScancode(GLFW_KEY_X); set_key_mapping(scancode, swap_weapons); ``` -------------------------------- ### Include Header File: Old vs. New Syntax Source: https://github.com/ultralight-ux/appcore/blob/master/src/glfw/docs/moving.dox Illustrates the change in the include directive for the GLFW header file from version 2 to version 3. ```c #include ``` ```c #include ``` -------------------------------- ### Get Monitor Gamma Ramp Source: https://github.com/ultralight-ux/appcore/blob/master/src/glfw/docs/monitor.dox Retrieves the current gamma ramp for a monitor. The lifetime of the returned structure is managed by GLFW. ```c const GLFWgammaramp* ramp = glfwGetGammaRamp(monitor); ```