### Conditionally Add Example Subdirectory and Set Startup Project Source: https://github.com/inanevin/linavg/blob/master/CMakeLists.txt This snippet conditionally adds an 'Example' subdirectory to the build if the LINAVG_BUILD_EXAMPLES variable is set. It also configures the IDE to start the 'Example' project by default. ```cmake if(LINAVG_BUILD_EXAMPLES) add_subdirectory(Example) set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT Example) endif() ``` -------------------------------- ### Enable Example Project Build with CMake Source: https://github.com/inanevin/linavg/blob/master/README.md Use the LINAVG_BUILD_EXAMPLES option to enable the example project when configuring with CMake. ```shell cmake DLINAVG_BUILD_EXAMPLES=ON ``` -------------------------------- ### Set MSVC Entry Point for GUI Examples Source: https://github.com/inanevin/linavg/blob/master/Example/Dependencies/glfw/examples/CMakeLists.txt Configures the linker to use 'mainCRTStartup' as the entry point for GUI-only executables when using MSVC or a compatible compiler. This ensures the application starts from 'main'. ```cmake if (MSVC) # Tell MSVC to use main instead of WinMain set_target_properties(${GUI_ONLY_BINARIES} PROPERTIES LINK_FLAGS "/ENTRY:mainCRTStartup") elseif (CMAKE_C_SIMULATE_ID STREQUAL "MSVC") # Tell Clang using MS CRT to use main instead of WinMain set_target_properties(${GUI_ONLY_BINARIES} PROPERTIES LINK_FLAGS "-Wl,/entry:mainCRTStartup") endif() ``` -------------------------------- ### Group Example Binaries into Folders Source: https://github.com/inanevin/linavg/blob/master/Example/Dependencies/glfw/examples/CMakeLists.txt Organizes GUI and console example executables into separate folders within the build system. This improves project structure. ```cmake set(GUI_ONLY_BINARIES boing gears heightmap particles sharing simple splitview wave) set(CONSOLE_BINARIES offscreen) set_target_properties(${GUI_ONLY_BINARIES} ${CONSOLE_BINARIES} PROPERTIES FOLDER "GLFW3/Examples") ``` -------------------------------- ### Simple Example: Initialize GLFW, Create Window, and Render Triangle Source: https://github.com/inanevin/linavg/blob/master/Example/Dependencies/glfw/docs/html/quick_guide.html This example demonstrates the complete process of initializing GLFW, setting window hints for OpenGL version, creating a window, and setting up basic shaders and vertex data for rendering a colored triangle. It includes error and key callbacks. ```c #include #define GLFW_INCLUDE_NONE #include #include "linmath.h" #include #include static const struct { float x, y; float r, g, b; } vertices[3] = { { -0.6f, -0.4f, 1.f, 0.f, 0.f }, { 0.6f, -0.4f, 0.f, 1.f, 0.f }, { 0.f, 0.6f, 0.f, 0.f, 1.f } }; static const char* vertex_shader_text = "#version 110\n" "uniform mat4 MVP;\n" "attribute vec3 vCol;\n" "attribute vec2 vPos;\n" "varying vec3 color;\n" "void main()\n" "{\n" " gl_Position = MVP * vec4(vPos, 0.0, 1.0);\n" " color = vCol;\n" "}\n"; static const char* fragment_shader_text = "#version 110\n" "varying vec3 color;\n" "void main()\n" "{\n" " gl_FragColor = vec4(color, 1.0);\n" "}\n"; static void error_callback(int error, const char* description) { fprintf(stderr, "Error: %s\n", description); } static void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods) { if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS) glfwSetWindowShouldClose(window, GLFW_TRUE); } int main(void) { GLFWwindow* window; GLuint vertex_buffer, vertex_shader, fragment_shader, program; GLint mvp_location, vpos_location, vcol_location; glfwSetErrorCallback(error_callback); if (!glfwInit()) exit(EXIT_FAILURE); glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 2); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0); window = glfwCreateWindow(640, 480, "Simple example", NULL, NULL); if (!window) { glfwTerminate(); exit(EXIT_FAILURE); } ``` -------------------------------- ### Install X11 Dependencies on FreeBSD Source: https://github.com/inanevin/linavg/blob/master/Example/Dependencies/glfw/docs/compile.dox Ensures X11 headers are available on FreeBSD by installing the xorgproto package if necessary. ```shell pkg install xorgproto ``` -------------------------------- ### Get Module Property Example Source: https://github.com/inanevin/linavg/blob/master/Dependencies/FreeType-2.12.1/docs/reference/ft2-module_management.html Example of how to retrieve a 'range' property named 'baz' from the module 'foo'. The 'value' parameter will be populated with the property's data. ```c typedef range_ { FT_Int32 min; FT_Int32 max; } range; range baz; FT_Property_Get( library, "foo", "baz", &baz ); ``` -------------------------------- ### Clone and Build LinaVG with Examples Source: https://github.com/inanevin/linavg/wiki/01-Installation Clone the LinaVG repository, create a build directory, and configure the build with CMake, enabling example projects. Finally, build the project using CMake. ```shell # Clone LinaVG git clone https://github.com/inanevin/LinaVG # Create a directory for solution directory mkdir build_x64 # Navigate to directory cd build_x64 # Build LinaVG & examples cmake ../ -DLINAVG_BUILD_EXAMPLES=ON -G "Visual Studio 17 2022" -A "x64" # After the project files are built, you can build the project via cmake --build . --target ALL_BUILD ``` -------------------------------- ### Window Size Callback Function Example Source: https://github.com/inanevin/linavg/blob/master/Example/Dependencies/glfw/docs/window.dox An example of a window size callback function. This function is called when the window is resized and receives the new width and height in screen coordinates. ```c void window_size_callback(GLFWwindow* window, int width, int height) { } ``` -------------------------------- ### Example Gamepad Mapping Source: https://github.com/inanevin/linavg/blob/master/Example/Dependencies/glfw/docs/html/input_guide.html This is an example of a gamepad mapping for an Xbox controller using the XInput API on Windows. Real gamepad mappings must be a single line. ```text 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, ``` -------------------------------- ### Example FREETYPE_PROPERTIES environment variable Source: https://github.com/inanevin/linavg/blob/master/Dependencies/FreeType-2.12.1/docs/reference/ft2-module_management.html This example shows the syntax for the FREETYPE_PROPERTIES environment variable, used to control driver properties. It demonstrates setting properties for 'truetype' and 'cff' modules. ```shell FREETYPE_PROPERTIES=truetype:interpreter-version=35 \ cff:no-stem-darkening=0 ``` -------------------------------- ### Install Wayland Dependencies on FreeBSD Source: https://github.com/inanevin/linavg/blob/master/Example/Dependencies/glfw/docs/compile.dox Installs the necessary Wayland, libxkbcommon, and CMake modules for GLFW compilation on FreeBSD. ```shell pkg install wayland libxkbcommon wayland-protocols kf5-extra-cmake-modules ``` -------------------------------- ### GLFW Version String Example Source: https://github.com/inanevin/linavg/blob/master/Example/Dependencies/glfw/docs/intro.dox An example of the format for the GLFW version string, which includes the GLFW version, window system API, context creation API, and platform-specific options. This string is intended for debugging and bug reports. ```text 3.0.0 Win32 WGL MinGW ``` -------------------------------- ### Key Callback Function Example Source: https://github.com/inanevin/linavg/blob/master/Example/Dependencies/glfw/docs/html/input_guide.html Example of a key callback function that activates an airship when the 'E' key is pressed. ```c void key_callback(GLFWwindow * window, int key, int scancode, int action, int mods) { if (key == GLFW_KEY_E && action == GLFW_PRESS) activate_airship(); } ``` -------------------------------- ### OpenGL Buffer and Shader Setup Source: https://github.com/inanevin/linavg/blob/master/Example/Dependencies/glfw/docs/html/quick_guide.html Initializes OpenGL buffers and compiles vertex and fragment shaders. This is a prerequisite for rendering. ```c // NOTE: OpenGL error checks have been omitted for brevity glGenBuffers(1, &vertex_buffer); glBindBuffer(GL_ARRAY_BUFFER, vertex_buffer); glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW); vertex_shader = glCreateShader(GL_VERTEX_SHADER); glShaderSource(vertex_shader, 1, &vertex_shader_text, NULL); glCompileShader(vertex_shader); fragment_shader = glCreateShader(GL_FRAGMENT_SHADER); glShaderSource(fragment_shader, 1, &fragment_shader_text, NULL); glCompileShader(fragment_shader); program = glCreateProgram(); glAttachShader(program, vertex_shader); glAttachShader(program, fragment_shader); glLinkProgram(program); ``` -------------------------------- ### Install GLFW Targets Source: https://github.com/inanevin/linavg/blob/master/Example/Dependencies/glfw/src/CMakeLists.txt Installs the GLFW targets, including runtime, archive, and library destinations, when the GLFW_INSTALL option is enabled. This makes the built library available for use in other projects. ```cmake if (GLFW_INSTALL) install(TARGETS glfw EXPORT glfwTargets RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}") endif() ``` -------------------------------- ### Key Callback Function Example Source: https://github.com/inanevin/linavg/blob/master/Example/Dependencies/glfw/docs/input.dox An example key callback function that is triggered by key events. It checks for a specific key press and performs an action. ```c void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods) { if (key == GLFW_KEY_E && action == GLFW_PRESS) activate_airship(); } ``` -------------------------------- ### Add Executable Targets for Examples Source: https://github.com/inanevin/linavg/blob/master/Example/Dependencies/glfw/examples/CMakeLists.txt Defines executable targets for various GLFW examples. Includes platform-specific flags and common source files like icons and GLAD headers. ```cmake add_executable(boing WIN32 MACOSX_BUNDLE boing.c ${ICON} ${GLAD_GL}) add_executable(gears WIN32 MACOSX_BUNDLE gears.c ${ICON} ${GLAD_GL}) add_executable(heightmap WIN32 MACOSX_BUNDLE heightmap.c ${ICON} ${GLAD_GL}) add_executable(offscreen offscreen.c ${ICON} ${GLAD_GL}) add_executable(particles WIN32 MACOSX_BUNDLE particles.c ${ICON} ${TINYCTHREAD} ${GETOPT} ${GLAD_GL}) add_executable(sharing WIN32 MACOSX_BUNDLE sharing.c ${ICON} ${GLAD_GL}) add_executable(simple WIN32 MACOSX_BUNDLE simple.c ${ICON} ${GLAD_GL}) add_executable(splitview WIN32 MACOSX_BUNDLE splitview.c ${ICON} ${GLAD_GL}) add_executable(wave WIN32 MACOSX_BUNDLE wave.c ${ICON} ${GLAD_GL}) ``` -------------------------------- ### Set Module Property Example Source: https://github.com/inanevin/linavg/blob/master/Dependencies/FreeType-2.12.1/docs/reference/ft2-module_management.html Example of how to set an integer property 'bar' to value 1 within the module 'foo'. Ensure to reset the cache if necessary after changing properties. ```c FT_UInt bar; bar = 1; FT_Property_Set( library, "foo", "bar", &bar ); ``` -------------------------------- ### Basic LinaVG Drawing Example Source: https://github.com/inanevin/linavg/blob/master/README.md A minimal implementation for drawing with LinaVG, assuming a graphics backend and window context are already set up. This example draws a rectangle with a gradient color. ```cpp #include "LinaVG.hpp" LinaVG::Drawer lvgDrawer; lvgDrawer.GetCallbacks().drawDefault = std::bind(&MyRenderingBackend::DrawDefault, &myRenderer, std::placeholders::_1); // Your application loop while (m_applicationRunning) { // Setup style, give a gradient color from red to blue. StyleOptions style; style.isFilled = true; style.color.start = Vec4(1, 0, 0, 1); style.color.end = Vec4(0, 0, 1, 1); // Draw a 200x200 rectangle starting from 300, 300. const Vec2 min = Vec2(300, 300); const Vec2 max = Vec2(500, 500); lvgDrawer.DrawRect(min, max, style); lvgDrawer.FlushBuffers(); lvgDrawer.ResetFrame(); } ``` -------------------------------- ### GLFW_GAMEPAD_BUTTON_GUIDE Source: https://github.com/inanevin/linavg/blob/master/Example/Dependencies/glfw/docs/html/group__gamepad__buttons.html Represents the GUIDE button on a gamepad. ```APIDOC ## GLFW_GAMEPAD_BUTTON_GUIDE ### Description Represents the GUIDE button on a gamepad. ### Value `8` ``` -------------------------------- ### GLFW_GAMEPAD_BUTTON_START Source: https://github.com/inanevin/linavg/blob/master/Example/Dependencies/glfw/docs/html/group__gamepad__buttons.html Represents the START button on a gamepad. ```APIDOC ## GLFW_GAMEPAD_BUTTON_START ### Description Represents the START button on a gamepad. ### Value `7` ``` -------------------------------- ### Window Focus Callback Function Source: https://github.com/inanevin/linavg/blob/master/Example/Dependencies/glfw/docs/window.dox Example implementation of a window focus callback function that receives focus state changes. ```c void window_focus_callback(GLFWwindow* window, int focused) { if (focused) { // The window gained input focus } else { // The window lost input focus } } ``` -------------------------------- ### Getting Joystick GUID Source: https://github.com/inanevin/linavg/blob/master/Example/Dependencies/glfw/docs/html/group__input.html Retrieves the SDL compatible GUID of a specified joystick as a UTF-8 encoded hexadecimal string. Returns NULL if the joystick is not present. ```c const char *glfwGetJoystickGUID(int jid); ``` -------------------------------- ### Initialize GLFW and Create Window Source: https://github.com/inanevin/linavg/blob/master/Example/Dependencies/glfw/docs/html/quick_guide.html Sets up the GLFW environment, creates a window, and makes its OpenGL context current. Requires a key callback function. ```c glfwSetKeyCallback(window, key_callback); glmkefwMakeContextCurrent(window); gladLoadGL(glfwGetProcAddress); glmkefwSwapInterval(1); ``` -------------------------------- ### Get Monitor Position Source: https://github.com/inanevin/linavg/blob/master/Example/Dependencies/glfw/docs/html/monitor_guide.html Retrieves the position of a monitor on the virtual desktop in screen coordinates. This is useful for window placement and multi-monitor setups. ```c int xpos, ypos;glfwGetMonitorPos(monitor, &xpos, &ypos); ``` -------------------------------- ### Setting up FT_Incremental_InterfaceRec for FT_Open_Face Source: https://github.com/inanevin/linavg/blob/master/Dependencies/FreeType-2.12.1/docs/reference/ft2-incremental.html This example demonstrates how to configure an FT_Incremental_InterfaceRec structure and use it as an optional parameter with FT_Open_Args to open a font face with incremental loading support. ```c FT_Incremental_InterfaceRec inc_int; FT_Parameter parameter; FT_Open_Args open_args; // set up incremental descriptor inc_int.funcs = my_funcs; inc_int.object = my_object; // set up optional parameter parameter.tag = FT_PARAM_TAG_INCREMENTAL; parameter.data = &inc_int; // set up FT_Open_Args structure open_args.flags = FT_OPEN_PATHNAME | FT_OPEN_PARAMS; open_args.pathname = my_font_pathname; open_args.num_params = 1; open_args.params = ¶meter; // we use one optional argument // open the font error = FT_Open_Face( library, &open_args, index, &face ); ... ``` -------------------------------- ### Drawing a Semi-Circle Arc Source: https://github.com/inanevin/linavg/wiki/07-Drawing Example of drawing a semi-circle arc using DrawCircle. The start and end angles define the portion of the circle to be drawn. ```cpp lvgDrawer.DrawCircle(Vec2(startPos.x + 75, startPos.y + 75), 75, defaultStyle, 36, rotateAngle, 0.0f, 245.0f, 1); ``` -------------------------------- ### Drawing a Small Arc Segment Source: https://github.com/inanevin/linavg/wiki/07-Drawing Example of drawing a small arc segment using DrawCircle. This demonstrates drawing a specific portion of a circle defined by start and end angles. ```cpp lvgDrawer.DrawCircle(Vec2(startPos.x + 75, startPos.y + 75), 75, defaultStyle, 36, rotateAngle, 300.0f, 330.0f, 2); ``` -------------------------------- ### Initialize glad with GLFW context Source: https://github.com/inanevin/linavg/blob/master/Example/Dependencies/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); ``` -------------------------------- ### Integrated Extension Loading and Usage Source: https://github.com/inanevin/linavg/blob/master/Example/Dependencies/glfw/docs/context.dox This example demonstrates how to load OpenGL extensions by checking support with `glfwExtensionSupported`, fetching function pointers with `glfwGetProcAddress`, and then conditionally calling the extension function. It includes defining the function pointer type and a flag to track extension availability. ```c #define GLFW_INCLUDE_GLEXT #include #define glSpecializeShaderARB pfnSpecializeShaderARB PFNGLSPECIALIZESHADERARBPROC pfnSpecializeShaderARB; // Flag indicating whether the extension is supported int has_ARB_gl_spirv = 0; void load_extensions(void) { if (glfwExtensionSupported("GL_ARB_gl_spirv")) { pfnSpecializeShaderARB = (PFNGLSPECIALIZESHADERARBPROC) glfwGetProcAddress("glSpecializeShaderARB"); has_ARB_gl_spirv = 1; } } void some_function(void) { if (has_ARB_gl_spirv) { // Now the extension function can be called as usual glSpecializeShaderARB(...); } } ``` -------------------------------- ### glfwGetJoystickGUID Source: https://github.com/inanevin/linavg/blob/master/Example/Dependencies/glfw/docs/html/glfw3_8h_source.html Returns the GUID of the specified joystick. The GUID is a UTF-8 encoded string that uniquely identifies the joystick. ```APIDOC ## glfwGetJoystickGUID ### Description Returns the GUID of the specified joystick. The GUID is a UTF-8 encoded string that uniquely identifies the joystick. ### Method GLFWAPI ### Endpoint `glfwGetJoystickGUID(int jid)` ### Parameters #### Path Parameters - **jid** (int) - Description: The index of the joystick to query. ### Response #### Success Response Returns the UTF-8 encoded GUID of the joystick, or `NULL` if the joystick is not present. #### Response Example (No explicit response example provided in source) ``` -------------------------------- ### Load and Use Extension Function Source: https://github.com/inanevin/linavg/blob/master/Example/Dependencies/glfw/docs/html/context_guide.html This example demonstrates how to check for extension support, load the function pointer, and then conditionally call the extension function. This pattern ensures that extension functions are only called when they are available. ```c #define GLFW_INCLUDE_GLEXT #include #define glSpecializeShaderARB pfnSpecializeShaderARB PFNGLSPECIALIZESHADERARBPROC pfnSpecializeShaderARB; // Flag indicating whether the extension is supported int has_ARB_gl_spirv = 0; void load_extensions(void) { if (glfwExtensionSupported("GL_ARB_gl_spirv")) { pfnSpecializeShaderARB = (PFNGLSPECIALIZESHADERARBPROC) glfwGetProcAddress("glSpecializeShaderARB"); has_ARB_gl_spirv = 1; } } void some_function(void) { if (has_ARB_gl_spirv) { // Now the extension function can be called as usual glSpecializeShaderARB(...); } } ``` -------------------------------- ### Old Viewport Setup Using Window Size Source: https://github.com/inanevin/linavg/blob/master/Example/Dependencies/glfw/docs/moving.dox Shows how viewport was set using the window's general size in GLFW 2. ```c glfwGetWindowSize(&width, &height); glViewport(0, 0, width, height); ``` -------------------------------- ### Install X11 Dependencies on Debian/Ubuntu Source: https://github.com/inanevin/linavg/blob/master/Example/Dependencies/glfw/docs/compile.dox Installs the necessary X11 development packages for compiling GLFW on Debian-based systems. ```shell sudo apt install xorg-dev ``` -------------------------------- ### Create a Window and OpenGL Context Source: https://github.com/inanevin/linavg/blob/master/Example/Dependencies/glfw/docs/quick.dox Create a window and its associated OpenGL context. Always check the return value for NULL, which indicates failure. ```c GLFWwindow* window = glfwCreateWindow(640, 480, "My Title", NULL, NULL); if (!window) { // Window or OpenGL context creation failed } ``` -------------------------------- ### Install Wayland Dependencies on Debian/Ubuntu Source: https://github.com/inanevin/linavg/blob/master/Example/Dependencies/glfw/docs/compile.dox Installs the necessary Wayland and xkbcommon development packages for compiling GLFW on Debian-based systems. ```shell sudo apt install libwayland-dev libxkbcommon-dev wayland-protocols extra-cmake-modules ``` -------------------------------- ### Install X11 Dependencies on Fedora/Red Hat Source: https://github.com/inanevin/linavg/blob/master/Example/Dependencies/glfw/docs/compile.dox Installs the required X11 extension packages for GLFW on Fedora and Red Hat-based systems. ```shell sudo dnf install libXcursor-devel libXi-devel libXinerama-devel libXrandr-devel ``` -------------------------------- ### Example of Using FT_LOAD_TARGET_LIGHT with LCD Rendering Source: https://github.com/inanevin/linavg/blob/master/Dependencies/FreeType-2.12.1/docs/reference/ft2-base_interface.html Demonstrates using the 'light' hinting algorithm with horizontal LCD pixel mode rendering. Note that FT_LOAD_TARGET_XXX flags cannot be ORed. ```c FT_Load_Glyph( face, glyph_index, load_flags | FT_LOAD_TARGET_LIGHT ); FT_Render_Glyph( face->glyph, FT_RENDER_MODE_LCD ); ``` -------------------------------- ### Create Window with Specific OpenGL Version Source: https://github.com/inanevin/linavg/blob/master/Example/Dependencies/glfw/docs/quick.dox Set window hints for the desired OpenGL version before creating the window and context. If the minimum version is not supported, creation will fail. ```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 } ``` -------------------------------- ### Install Wayland Dependencies on Fedora/Red Hat Source: https://github.com/inanevin/linavg/blob/master/Example/Dependencies/glfw/docs/compile.dox Installs the required Wayland, libxkbcommon, and related development packages on Fedora and Red Hat-based systems. ```shell sudo dnf install wayland-devel libxkbcommon-devel wayland-protocols-devel extra-cmake-modules ``` -------------------------------- ### Initialize Menu and Search Source: https://github.com/inanevin/linavg/blob/master/Example/Dependencies/glfw/docs/html/main_8dox.html Initializes the documentation menu and the search functionality when the document is ready. ```javascript $(function() { initMenu('',true,false,'search.php','Search'); $(document).ready(function() { init_search(); }); }); ``` -------------------------------- ### Set OpenGL Context Version Hints Source: https://github.com/inanevin/linavg/blob/master/Example/Dependencies/glfw/docs/html/quick_guide.html Sets hints for the desired OpenGL major and minor version before creating a window. If the version is not supported, window creation will fail. ```c glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 2); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0); ``` -------------------------------- ### Find Installed GLFW Package with CMake Source: https://github.com/inanevin/linavg/blob/master/Example/Dependencies/glfw/docs/build.dox Locate an installed GLFW package in your CMake project using 'find_package'. Specify the package name and version required for your application. ```cmake find_package(glfw3 3.3 REQUIRED) ``` -------------------------------- ### Project and Version Definition Source: https://github.com/inanevin/linavg/blob/master/Dependencies/FreeType-2.12.1/CMakeLists.txt Defines the project name and version components. Sets up version variables for the build. ```cmake project(freetype C) set(VERSION_MAJOR "2") set(VERSION_MINOR "12") set(VERSION_PATCH "1") ``` -------------------------------- ### Get FSSpec from Mac ATS Font Name Source: https://github.com/inanevin/linavg/blob/master/Dependencies/FreeType-2.12.1/docs/reference/ft2-mac_specific.html Use FT_GetFile_From_Mac_ATS_Name to get an FSSpec for a font file from its Mac OS ATS framework name. This function is deprecated. ```c FT_EXPORT( FT_Error ) FT_GetFile_From_Mac_ATS_Name( const char* fontName, FSSpec* pathSpec, FT_Long* face_index ) FT_DEPRECATED_ATTRIBUTE; ``` -------------------------------- ### Configure X11 Backend Source: https://github.com/inanevin/linavg/blob/master/Example/Dependencies/glfw/CMakeLists.txt This section configures the X11 backend by finding the X11 package, setting up include and library paths, and checking for essential X11 extensions like RandR, Xinerama, Xkb, Xcursor, and Xi. ```cmake if (_GLFW_X11) find_package(X11 REQUIRED) list(APPEND glfw_PKG_DEPS "x11") # Set up library and include paths list(APPEND glfw_INCLUDE_DIRS "${X11_X11_INCLUDE_PATH}") list(APPEND glfw_LIBRARIES "${X11_X11_LIB}" "${CMAKE_THREAD_LIBS_INIT}") # Check for XRandR (modern resolution switching and gamma control) if (NOT X11_Xrandr_INCLUDE_PATH) message(FATAL_ERROR "RandR headers not found; install libxrandr development package") endif() # Check for Xinerama (legacy multi-monitor support) if (NOT X11_Xinerama_INCLUDE_PATH) message(FATAL_ERROR "Xinerama headers not found; install libxinerama development package") endif() # Check for Xkb (X keyboard extension) if (NOT X11_Xkb_INCLUDE_PATH) message(FATAL_ERROR "XKB headers not found; install X11 development package") endif() # Check for Xcursor (cursor creation from RGBA images) if (NOT X11_Xcursor_INCLUDE_PATH) message(FATAL_ERROR "Xcursor headers not found; install libxcursor development package") endif() # Check for XInput (modern HID input) if (NOT X11_Xi_INCLUDE_PATH) message(FATAL_ERROR "XInput headers not found; install libxi development package") endif() list(APPEND glfw_INCLUDE_DIRS "${X11_Xrandr_INCLUDE_PATH}" "${X11_Xinerama_INCLUDE_PATH}" "${X11_Xkb_INCLUDE_PATH}" "${X11_Xcursor_INCLUDE_PATH}" "${X11_Xi_INCLUDE_PATH}") endif() ``` -------------------------------- ### Create Full Screen Window Source: https://github.com/inanevin/linavg/blob/master/Example/Dependencies/glfw/docs/html/window_guide.html Creates a full-screen window using the primary monitor. Ensure you have retrieved monitor information if needed. ```c [GLFWwindow](group__window.html#ga3c96d80d363e67d13a41b5d1821f3242)* window = [glfwCreateWindow](group__window.html#ga3555a418df92ad53f917597fe2f64aeb)(640, 480, "My Title", [glfwGetPrimaryMonitor](group__monitor.html#gac3adb24947eb709e1874028272e5dfc5)(), NULL); ``` -------------------------------- ### Old Basic Full Screen Window Creation Source: https://github.com/inanevin/linavg/blob/master/Example/Dependencies/glfw/docs/moving.dox Demonstrates the older method of opening a basic fullscreen window in GLFW 2. ```c glfwOpenWindow(640, 480, 8, 8, 8, 0, 24, 0, GLFW_FULLSCREEN); ``` -------------------------------- ### glfwCreateWindow Source: https://github.com/inanevin/linavg/blob/master/Example/Dependencies/glfw/docs/html/glfw3_8h_source.html Creates a window and its associated OpenGL or Vulkan context. ```APIDOC ## glfwCreateWindow ### Description Creates a window and its associated OpenGL or Vulkan context. ### Method GLFWAPI GLFWwindow* ### Parameters - **width** (*int**) - The desired width, in screen coordinates, of the window. - **height** (*int**) - The desired height, in screen coordinates, of the window. - **title** (*const char***) - The UTF-8 encoded window title. - **monitor** (*GLFWmonitor**) - The monitor to use for fullscreen mode, or NULL to use windowed mode. - **share** (*GLFWwindow**) - The window whose context to share resources with, or NULL to not share resources. ``` -------------------------------- ### Get Font Driver Name Macro Source: https://github.com/inanevin/linavg/blob/master/Dependencies/FreeType-2.12.1/docs/reference/ft2-module_management.html A macro to retrieve the name of the font driver associated with a FreeType face object. This name can be used with property setting and getting functions. ```c #define FT_FACE_DRIVER_NAME( face ) \ ( ( *FT_REINTERPRET_CAST( FT_Module_Class**, \ ( face )->driver ) )->module_name ) ``` -------------------------------- ### Old Viewport Setup using Window Size Source: https://github.com/inanevin/linavg/blob/master/Example/Dependencies/glfw/docs/html/moving_guide.html This snippet shows the previous method of setting the OpenGL viewport using the window's content area size. ```c int width, height; [glfwGetWindowSize](group__window.html#gaeea7cbc03373a41fb51cfbf9f2a5d4c6)(&width, &height); glViewport(0, 0, width, height); ``` -------------------------------- ### Get Outline Bounding Box Source: https://github.com/inanevin/linavg/blob/master/Dependencies/FreeType-2.12.1/docs/reference/ft2-outline_processing.html Computes the exact bounding box of an outline. This is slower than getting the control box but provides a more precise boundary. It can be very fast if the control and bounding boxes coincide. ```c FT_EXPORT( FT_Error ) FT_Outline_Get_BBox( FT_Outline* outline, FT_BBox *abbox ); ``` -------------------------------- ### Set CFF Hinting Engine to Adobe Source: https://github.com/inanevin/linavg/blob/master/Dependencies/FreeType-2.12.1/docs/reference/ft2-properties.html Demonstrates how to select Adobe's hinting engine for the 'cff' module using FT_Property_Set. Error handling is omitted for brevity. ```c FT_Library library; FT_UInt hinting_engine = FT_HINTING_ADOBE; FT_Init_FreeType( &library ); FT_Property_Set( library, "cff", "hinting-engine", &hinting_engine ); ``` -------------------------------- ### Attribute and Uniform Location Setup Source: https://github.com/inanevin/linavg/blob/master/Example/Dependencies/glfw/docs/html/quick_guide.html Retrieves locations for shader attributes and uniforms, and enables vertex attribute arrays. This prepares the program for drawing. ```c mvp_location = glGetUniformLocation(program, "MVP"); vpos_location = glGetAttribLocation(program, "vPos"); vcol_location = glGetAttribLocation(program, "vCol"); glEnableVertexAttribArray(vpos_location); glVertexAttribPointer(vpos_location, 2, GL_FLOAT, GL_FALSE, sizeof(vertices[0]), (void*) 0); glEnableVertexAttribArray(vcol_location); glVertexAttribPointer(vcol_location, 3, GL_FLOAT, GL_FALSE, sizeof(vertices[0]), (void*) (sizeof(float) * 2)); ``` -------------------------------- ### FT_Property_Get Source: https://github.com/inanevin/linavg/blob/master/Dependencies/FreeType-2.12.1/docs/reference/ft2-index.html Gets a property. ```APIDOC ## FT_Property_Get ### Description Gets a property. ### Method Not applicable (SDK function) ### Endpoint Not applicable (SDK function) ### Parameters (Details not provided in source) ### Request Example (Not provided in source) ### Response (Not provided in source) ``` -------------------------------- ### Make Existing Window Full Screen Source: https://github.com/inanevin/linavg/blob/master/Example/Dependencies/glfw/docs/html/window_guide.html Converts an existing window into a full screen window by setting its monitor and video mode to match the current desktop resolution. This is useful when transitioning from a windowed mode to full screen. ```c const GLFWvidmode *mode = glfwGetVideoMode(monitor); glyphSetWindowMonitor(window, monitor, 0, 0, mode->width, mode->height, mode->refreshRate); ``` -------------------------------- ### Get Last GLFW Error Source: https://github.com/inanevin/linavg/blob/master/Example/Dependencies/glfw/docs/html/intro_guide.html Retrieves and clears the last error code for the calling thread. Returns GLFW_NO_ERROR if no error has occurred. The description pointer can be used to get a human-readable error message. ```c int code = glfwGetError(NULL); ``` ```c const char* description; int code = glfwGetError(&description); ``` ```c void error_callback(int code, const char* description) { display_error_message(code, description); } ``` -------------------------------- ### Create a 'Windowed Full Screen' Window Source: https://github.com/inanevin/linavg/blob/master/Example/Dependencies/glfw/docs/window.dox Creates a borderless full-screen window that matches the monitor's current video mode. This is useful for smoother application switching and is achieved by setting window hints to match the current video mode. ```c const GLFWvidmode* mode = glfwGetVideoMode(monitor); glfwWindowHint(GLFW_RED_BITS, mode->redBits); glfwWindowHint(GLFW_GREEN_BITS, mode->greenBits); glfwWindowHint(GLFW_BLUE_BITS, mode->blueBits); glfwWindowHint(GLFW_REFRESH_RATE, mode->refreshRate); GLFWwindow* window = glfwCreateWindow(mode->width, mode->height, "My Title", monitor, NULL); ``` -------------------------------- ### FT_Outline_Get_Orientation Source: https://github.com/inanevin/linavg/blob/master/Dependencies/FreeType-2.12.1/docs/reference/ft2-index.html Gets the orientation of an outline. ```APIDOC ## FT_Outline_Get_Orientation ### Description Gets the orientation of an outline. ### Method (Not specified in source) ### Endpoint (Not specified in source) ### Parameters (Not specified in source) ### Request Example (Not specified in source) ### Response #### Success Response (200) (Not specified in source) #### Response Example (Not specified in source) ``` -------------------------------- ### Basic LinaVG Drawing Implementation Source: https://github.com/inanevin/linavg/wiki/02-Quick-Start This C++ snippet shows the minimal setup for drawing a rectangle using LinaVG. It includes binding a draw callback, setting up style options with a gradient color, drawing the rectangle, and flushing the buffers. Ensure your graphics backend and window context are already set up. ```cpp // Include LinaVG #include "LinaVG.hpp" LinaVG::Drawer lvgDrawer; // Bind draw callback. lvgDrawer.GetCallbacks().draw = std::bind(&GLBackend::DrawDefault, m_renderingBackend, std::placeholders::_1); // Your application loop while (m_applicationRunning) { // Setup style, give a gradient color from red to blue. StyleOptions style; style.isFilled = true; style.color.start = Vec4(1, 0, 0, 1); style.color.end = Vec4(0, 0, 1, 1); // Draw a 200x200 rectangle starting from 300, 300. const Vec2 min = Vec2(300, 300); const Vec2 max = Vec2(500, 500); lvgDrawer.DrawRect(min, max, style); // Flush buffers, this will call your callback functions. lvgDrawer.FlushBuffers(); // Shrink buffers. lvgDrawer.ResetFrame(); } ``` -------------------------------- ### Generate ftoption.h Source: https://github.com/inanevin/linavg/blob/master/Dependencies/FreeType-2.12.1/CMakeLists.txt Reads the ftoption.h template and enables specific configuration options (like ZLIB, BZIP2, PNG, HARFBUZZ, BROTLI) if the corresponding libraries are found. Writes the generated options to the build directory. ```cmake file(READ "${PROJECT_SOURCE_DIR}/include/freetype/config/ftoption.h" FTOPTION_H) if (ZLIB_FOUND) string(REGEX REPLACE "/\* +(#define +FT_CONFIG_OPTION_SYSTEM_ZLIB) +\*/" "\1" FTOPTION_H "${FTOPTION_H}") endif () if (BZIP2_FOUND) string(REGEX REPLACE "/\* +(#define +FT_CONFIG_OPTION_USE_BZIP2) +\*/" "\1" FTOPTION_H "${FTOPTION_H}") endif () if (PNG_FOUND) string(REGEX REPLACE "/\* +(#define +FT_CONFIG_OPTION_USE_PNG) +\*/" "\1" FTOPTION_H "${FTOPTION_H}") endif () if (HARFBUZZ_FOUND) string(REGEX REPLACE "/\* +(#define +FT_CONFIG_OPTION_USE_HARFBUZZ) +\*/" "\1" FTOPTION_H "${FTOPTION_H}") endif () if (BROTLIDEC_FOUND) string(REGEX REPLACE "/\* +(#define +FT_CONFIG_OPTION_USE_BROTLI) +\*/" "\1" FTOPTION_H "${FTOPTION_H}") endif () set(FTOPTION_H_NAME "${PROJECT_BINARY_DIR}/include/freetype/config/ftoption.h") if (EXISTS "${FTOPTION_H_NAME}") file(READ "${FTOPTION_H_NAME}" ORIGINAL_FTOPTION_H) else () set(ORIGINAL_FTOPTION_H "") endif () if (NOT (ORIGINAL_FTOPTION_H STREQUAL FTOPTION_H)) file(WRITE "${FTOPTION_H_NAME}" "${FTOPTION_H}") endif () ``` -------------------------------- ### Accessing Faces and Named Instances Source: https://github.com/inanevin/linavg/blob/master/Dependencies/FreeType-2.12.1/docs/reference/ft2-base_interface.html This example shows how to access all faces and their named instances within a font file. It uses a do-while loop and bit manipulation to construct the `face_index` for FT_Open_Face, allowing access to both faces and specific named instances. ```c FT_Face face; FT_Long num_faces = 0; FT_Long num_instances = 0; FT_Long face_idx = 0; FT_Long instance_idx = 0; do { FT_Long id = ( instance_idx << 16 ) + face_idx; error = FT_Open_Face( library, args, id, &face ); if ( error ) { ... } num_faces = face->num_faces; num_instances = face->style_flags >> 16; ... FT_Done_Face( face ); if ( instance_idx < num_instances ) instance_idx++; else { face_idx++; instance_idx = 0; } } while ( face_idx < num_faces ) ``` -------------------------------- ### Include Header File: Old vs. New Syntax Source: https://github.com/inanevin/linavg/blob/master/Example/Dependencies/glfw/docs/moving.dox Illustrates the change in the header file include path from GLFW 2 to GLFW 3. ```c #include ``` ```c #include ``` -------------------------------- ### Window Close Callback Function Example Source: https://github.com/inanevin/linavg/blob/master/Example/Dependencies/glfw/docs/window.dox An example of a window close callback function. This function is called when the close flag is set and can be used to override the close action, for instance, by clearing the close flag if certain conditions are not met. ```c void window_close_callback(GLFWwindow* window) { if (!time_to_close) glfwSetWindowShouldClose(window, GLFW_FALSE); } ``` -------------------------------- ### glfwGetJoystickGUID Source: https://github.com/inanevin/linavg/blob/master/Example/Dependencies/glfw/docs/html/glfw3_8h.html Retrieves the SDL compatible GUID of a specified joystick. ```APIDOC ## glfwGetJoystickGUID ### Description Returns the SDL compatible GUID of the specified joystick. ### Function Signature ```c const char *glfwGetJoystickGUID(int jid) ``` ### Parameters * **jid** (int) - The joystick to query. ``` -------------------------------- ### glfwInit Source: https://github.com/inanevin/linavg/blob/master/Example/Dependencies/glfw/docs/html/glfw3_8h_source.html Initializes the GLFW library. This function must be called before most other GLFW functions. It returns `GLFW_TRUE` if initialization was successful, and `GLFW_FALSE` otherwise. ```APIDOC ## glfwInit ### Description Initializes the GLFW library. This function must be called before most other GLFW functions. It returns `GLFW_TRUE` if initialization was successful, and `GLFW_FALSE` otherwise. ### Method `int glfwInit(void)` ### Parameters None ### Response - `int`: `GLFW_TRUE` on success, `GLFW_FALSE` on failure. ``` -------------------------------- ### Get Joystick User Pointer Source: https://github.com/inanevin/linavg/blob/master/Example/Dependencies/glfw/docs/input.dox Retrieves the user-defined pointer for a joystick. ```APIDOC ## glfwGetJoystickUserPointer ### Description Retrieves the user-defined pointer for the specified joystick. ### Parameters #### Path Parameters - **`joy`** (int) - Required - The desired joystick. This must be one of `GLFW_JOYSTICK_1` through `GLFW_JOYSTICK_16`. #### Query Parameters None #### Request Body None ### Request Example ```c void* my_data = glfwGetJoystickUserPointer(GLFW_JOYSTICK_1); ``` ### Response #### Success Response (200) - **`pointer`** (void*) - The user-defined pointer associated with the joystick. This will be `NULL` if no pointer has been set. #### Response Example ```json { "pointer": "0x12345678" } ``` ``` -------------------------------- ### Create a Shared Context Window Source: https://github.com/inanevin/linavg/blob/master/Example/Dependencies/glfw/docs/context.dox Create a new window and share its OpenGL or OpenGL ES context objects with an existing window. ```c GLFWwindow* second_window = glfwCreateWindow(640, 480, "Second Window", NULL, first_window); ``` -------------------------------- ### Initialization Functions Source: https://github.com/inanevin/linavg/blob/master/Example/Dependencies/glfw/docs/html/glfw3_8h.html Functions for initializing, terminating, and configuring the GLFW library. ```APIDOC ## glfwInit ### Description Initializes the GLFW library. This function must be called before most other GLFW functions. ### Function Signature `int glfwInit(void)` ### Returns `GLFW_TRUE` if initialization was successful, or `GLFW_FALSE` if an error occurred. ## glfwTerminate ### Description Terminates the GLFW library. This function must be called before the application exits. ### Function Signature `void glfwTerminate(void)` ## glfwInitHint ### Description Sets the specified initialization hint to the desired value. Hints affect the behavior of `glfwInit`. ### Function Signature `void glfwInitHint(int hint, int value)` ### Parameters * `hint` (int) - The initialization hint to set. See [Initialization Hints](group__init.html#ga3d30804063210081603402801803264a) for a list of available hints. * `value` (int) - The desired value for the hint. ## glfwGetVersion ### Description Retrieves the version of the GLFW library. ### Function Signature `void glfwGetVersion(int *major, int *minor, int *rev)` ### Parameters * `major` (int *) - Pointer to store the major version number. * `minor` (int *) - Pointer to store the minor version number. * `rev` (int *) - Pointer to store the revision number. ## glfwGetVersionString ### Description Returns a string describing the compile-time configuration of the GLFW library. ### Function Signature `const char *glfwGetVersionString(void)` ### Returns A string describing the GLFW library's compile-time configuration. ``` -------------------------------- ### Get Window Maximized State Source: https://github.com/inanevin/linavg/blob/master/Example/Dependencies/glfw/docs/window.dox Retrieves the current maximization state of the window. ```c int maximized = glfwGetWindowAttrib(window, GLFW_MAXIMIZED); ``` -------------------------------- ### Setting Up Character Input Callback Source: https://github.com/inanevin/linavg/blob/master/Example/Dependencies/glfw/docs/html/input_guide.html Sets a callback function to receive Unicode character input. This callback handles text input, respecting keyboard layouts and dead keys, and provides Unicode code points. ```c glfwSetCharCallback(window, character_callback); ``` ```c void character_callback(GLFWwindow * window, unsigned int codepoint) { } ``` -------------------------------- ### Get Window Iconified State Source: https://github.com/inanevin/linavg/blob/master/Example/Dependencies/glfw/docs/window.dox Retrieves the current iconification state of the window. ```c int iconified = glfwGetWindowAttrib(window, GLFW_ICONIFIED); ``` -------------------------------- ### Get Joystick Name Source: https://github.com/inanevin/linavg/blob/master/Example/Dependencies/glfw/docs/input.dox Retrieves the human-readable, UTF-8 encoded name of a joystick. ```APIDOC ## glfwGetJoystickName ### Description Retrieves the human-readable, UTF-8 encoded name of the specified joystick. ### Parameters #### Path Parameters - **`joy`** (int) - Required - The desired joystick. This must be one of `GLFW_JOYSTICK_1` through `GLFW_JOYSTICK_16`. #### Query Parameters None #### Request Body None ### Request Example ```c const char* name = glfwGetJoystickName(GLFW_JOYSTICK_4); ``` ### Response #### Success Response (200) - **`name`** (const char*) - A pointer to a null-terminated UTF-8 encoded string containing the name of the joystick. This string may be `NULL` if the joystick is not connected or if it has no name. #### Response Example ```json { "name": "Logitech F710 Gamepad" } ``` ```