### Run MkDocs Serve Command Source: https://github.com/randygaul/cute_framework/blob/master/README.md This command is used to preview the Cute Framework documentation locally. It requires MkDocs and the Material theme to be installed and relies on Python 3.x. ```bash mkdocs serve ``` -------------------------------- ### Install MkDocs with Material Theme Source: https://github.com/randygaul/cute_framework/blob/master/README.md This command installs MkDocs and its Material theme using pip. This is a prerequisite for previewing the documentation locally and requires Python 3.x. ```bash pip install mkdocs mkdocs-material "mkdocs-material[imaging]" ``` -------------------------------- ### Install Target for Cute Framework (CMake) Source: https://github.com/randygaul/cute_framework/blob/master/CMakeLists.txt This install command defines how the 'cute' target should be installed. It specifies destinations for different types of artifacts: BUNDLE for macOS applications, RUNTIME for executables, LIBRARY for shared libraries, ARCHIVE for static libraries, and FRAMEWORK for macOS frameworks. ```cmake install(TARGETS cute BUNDLE DESTINATION . RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} FRAMEWORK DESTINATION ${CMAKE_INSTALL_LIBDIR} ) ``` -------------------------------- ### Install Git with Brew (macOS) Source: https://github.com/randygaul/cute_framework/blob/master/docs/topics/ios.md This command installs Git on a macOS system using the Homebrew package manager. Ensure Brew is installed first. ```bash brew install git ``` -------------------------------- ### C API Documentation Style Example Source: https://github.com/randygaul/cute_framework/blob/master/AGENTS.md Demonstrates the Doxygen-style documentation format used for public APIs in C header files. This includes function signatures, categories, brief descriptions, parameter details, return values, remarks, and related functions for cross-referencing. ```c /** * @function function_name * @category category_name * @brief Brief one-line description. * @param param_name Description of parameter. * @return Description of return value. * @remarks Additional details and usage notes. * @related Related functions for cross-reference. */ ``` -------------------------------- ### Full Dear ImGui Sample Program in C (Cute Framework) Source: https://github.com/randygaul/cute_framework/blob/master/docs/topics/dear_imgui.md A complete C program demonstrating the integration of Dear ImGui with the Cute Framework. It initializes the application and ImGui, then enters a main loop where ImGui windows are drawn and user interactions are handled. Includes an example of `ImGui_ShowDemoWindow` and basic input handling. ```c #include #include #include int main(int argc, char* argv[]) { CF_Result result = cf_make_app("Basic Input", 0, 0, 0, 640, 480, CF_APP_OPTIONS_WINDOW_POS_CENTERED, argv[0]); if (cf_is_error(result)) return -1; cf_app_init_imgui(); while (cf_app_is_running()) { cf_app_update(NULL); // Brief demo. static bool hello = true; static bool mutate = false; static bool big_demo = false; if (hello) { ImGui_Begin("Hello", &hello, 0); ImGui_Text("Formatting some text! Press X to %s\n", mutate ? "mutate." : "MUTATE!!!"); if (ImGui_Button("Press me!")) { printf("Clicked!\n"); } static char buffer[256] = "..."; ImGui_InputText("string", buffer, sizeof(buffer), 0); static float f; ImGui_SliderFloat("float", &f, 0, 10); if (ImGui_Button("Big Demo")) { big_demo = true; } ImGui_End(); if (big_demo) { ImGui_ShowDemoWindow(&big_demo); } } if (cf_key_just_pressed(CF_KEY_SPACE)) { hello = true; } if (cf_key_just_pressed(CF_KEY_X)) { mutate = !mutate; } cf_app_draw_onto_screen(); } cf_destroy_app(); return 0; } ``` -------------------------------- ### Emscripten Main Loop Setup Source: https://github.com/randygaul/cute_framework/blob/master/docs/topics/emscripten.md This C code demonstrates how to set up the main game loop for Emscripten builds using `emscripten_set_main_loop`. It conditionally compiles based on the `CF_EMSCRIPTEN` macro, providing a web-specific loop or a traditional loop for other platforms. ```c #ifdef CF_EMSCRIPTEN // Receives a function to call and some user data to provide it. emscripten_set_main_loop(update, 60, true); #else while (app_is_running()) { update(); } destroy_app(); #endif ``` -------------------------------- ### Configure Application Window Options (C++) Source: https://context7.com/randygaul/cute_framework/llms.txt This example demonstrates configuring application window properties like fullscreen, resizability, and the graphics API backend (Vulkan). It also sets a target framerate for power efficiency and includes logic to exit fullscreen mode using the Escape key. ```cpp #include int main(int argc, char* argv[]) { // Create fullscreen, resizable window with Vulkan backend int options = CF_APP_OPTIONS_FULLSCREEN_BIT | CF_APP_OPTIONS_RESIZABLE_BIT | CF_APP_OPTIONS_GFX_VULKAN_BIT; cf_make_app("Fullscreen Game", 0, 0, 0, 1920, 1080, options, argv[0]); // Target 60 FPS to reduce power consumption cf_set_target_framerate(60); while (cf_app_is_running()) { cf_app_update(NULL); // Check for escape to exit fullscreen if (cf_key_just_pressed(CF_KEY_ESCAPE)) { break; } cf_app_draw_onto_screen(true); } cf_destroy_app(); return 0; } ``` -------------------------------- ### Install Build Dependencies for Linux Source: https://github.com/randygaul/cute_framework/blob/master/README.md This command sequence installs essential development tools and libraries required for building projects on Linux systems, particularly those using CMake and graphics APIs like Vulkan. It ensures that the necessary compilers, build utilities, and graphics-related development files are present. ```bash sudo apt-get update -qq sudo apt-get install build-essential gcc-multilib cmake sudo apt-get install libasound2-dev libpulse-dev sudo apt-get install -y --no-install-recommends libvulkan-dev libx11-dev libxcursor-dev libxrandr-dev libxinerama-dev libxi-dev libxext-dev libxfixes-dev ``` -------------------------------- ### Install CMake with Brew (macOS) Source: https://github.com/randygaul/cute_framework/blob/master/docs/topics/ios.md This command installs CMake on a macOS system using the Homebrew package manager. Ensure Brew is installed first. ```bash brew install cmake ``` -------------------------------- ### Emscripten Shell Library Setup Source: https://github.com/randygaul/cute_framework/blob/master/samples/CMakeLists.txt Configures a custom target and an interface library for Emscripten builds. It copies Emscripten-specific shell files and links them with a shell file for the Emscripten build environment. This is essential for running samples in a web browser. ```cmake if (EMSCRIPTEN) add_custom_target(copy-emscripten-shell COMMAND ${CMAKE_COMMAND} -E copy_directory_if_different ${CMAKE_CURRENT_SOURCE_DIR}/emscripten ${CMAKE_BINARY_DIR}/emscripten ) add_library(cute-emscripten-shell INTERFACE) add_dependencies(cute-emscripten-shell copy-emscripten-shell) target_link_options(cute-emscripten-shell INTERFACE --shell-file "${CMAKE_CURRENT_SOURCE_DIR}/emscripten/shell.html") endif () ``` -------------------------------- ### Load and Play Sound Effects with Cute Framework Source: https://github.com/randygaul/cute_framework/blob/master/docs/topics/audio.md Illustrates loading WAV audio files for sound effects and playing them using Cute Framework. This example shows how to load multiple sound effects and play them based on an enum, with an option to enable looping. It utilizes `cf_sound_params_defaults` to set parameters before calling `cf_play_sound`. ```cpp CF_Audio jump; CF_Audio bonk; void LoadSounds() { jump = cf_audio_load_wav("/sounds/jump.wav"); bonk = cf_audio_load_wav("/sounds/bonk.wav"); } // Play a sound based on an enum in your game called `SoundFX`, with an optional // setting for looping (on by default). void PlaySound(SoundFX fx, bool loop = false) { CF_SoundParams params = cf_sound_params_defaults(); params.loop = loop; switch (fx) { case JUMP_FX: cf_play_sound(jump, params); break; case BONK_FX: cf_play_sound(bonk, params); break; default: CF_ASSERT(false); break; // Unknown sound type. } } ``` -------------------------------- ### glslang and Shader Compilation Setup Source: https://github.com/randygaul/cute_framework/blob/master/CMakeLists.txt This snippet sets up glslang for shader compilation, conditional on `CF_RUNTIME_SHADER_COMPILATION` or `CF_CUTE_SHADERC`. It configures glslang build options to disable tests, build as a static library, enable optimizations, and skip SPIRV-Tools executables. It then fetches glslang, links it with `cute-shader` (a wrapper library), and optionally links `cute-shader` for runtime compilation or builds `cute-shaderc` for offline compilation. Dependencies include `Python3`, `glslang`, `SPIRV`, and `spirv-cross-c`. ```cmake if (CF_RUNTIME_SHADER_COMPILATION OR CF_CUTE_SHADERC) set(GLSLANG_TESTS_DEFAULT OFF CACHE BOOL "Do not build glslang tests.") set(BUILD_SHARED_LIBS OFF CACHE BOOL "Do not build glslang as a shared lib.") set(ENABLE_OPT ON CACHE BOOL "Enable optimization.") set(SKIP_SPIRV_TOOLS_INSTALL OFF CACHE BOOL "Don't install the SPIR-V Tools as they are built.") set(SPIRV_SKIP_EXECUTABLES ON CACHE BOOL "Don't build any SPIR-V Tools executables/tests.") set(SPIRV_WERROR OFF CACHE BOOL "Turn off SPIR-V warnings as error.") set(ENABLE_GLSLANG_BINARIES OFF CACHE BOOL "Turn off some standalone binary tools for glslang.") set(GLSLANG_ENABLE_INSTALL OFF CACHE BOOL "Disable installation option for glslang.") find_package(Python3 REQUIRED) FetchContent_Declare( glslang URL https://github.com/KhronosGroup/glslang/archive/refs/tags/15.4.0.zip DOWNLOAD_EXTRACT_TIMESTAMP ON PATCH_COMMAND ${Python3_EXECUTABLE} update_glslang_sources.py ) FetchContent_MakeAvailable(glslang) set(CUTE_SHADER_SRCS src/cute_shader/cute_shader.cpp) add_library(cute-shader STATIC ${CUTE_SHADER_SRCS}) target_link_libraries(cute-shader PRIVATE glslang glslang-default-resource-limits SPIRV spirv-cross-c) install(TARGETS cute-shader BUNDLE DESTINATION . RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) if (NOT MSVC AND NOT CF_FRAMEWORK_STATIC) set_target_properties(cute-shader PROPERTIES POSITION_INDEPENDENT_CODE TRUE) endif() target_include_directories(cute-shader PUBLIC include) if (CF_RUNTIME_SHADER_COMPILATION) target_compile_definitions(cute PUBLIC CF_RUNTIME_SHADER_COMPILATION) set(CF_LINK_LIBS ${CF_LINK_LIBS} cute-shader) endif() if (CF_CUTE_SHADERC) set(CUTE_SHADERC_SRCS src/cute_shader/cute_shaderc.cpp) add_executable(cute-shaderc ${CUTE_SHADERC_SRCS}) target_link_libraries(cute-shaderc cute-shader) install(TARGETS cute-shaderc BUNDLE DESTINATION . RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) endif() endif() ``` -------------------------------- ### Wavelet Demo Shader Example - GLSL Source: https://github.com/randygaul/cute_framework/blob/master/docs/topics/drawing.md A comprehensive GLSL shader example from the cute_framework's shallow water demo. This shader utilizes multiple textures and uniforms to create a wavelet effect, demonstrating advanced techniques like normal calculation from heightmaps and conditional rendering based on uniforms. ```glsl layout (set = 2, binding = 1) uniform sampler2D wavelets_tex; layout (set = 2, binding = 2) uniform sampler2D noise_tex; layout (set = 2, binding = 3) uniform sampler2D scene_tex; layout (set = 3, binding = 1) uniform shd_uniforms { float show_normals; float show_noise; }; vec2 normal_from_heightmap(sampler2D tex, vec2 uv) { float ha = textureOffset(tex, uv, ivec2(-1, 1)).r; float hb = textureOffset(tex, uv, ivec2( 1, 1)).r; float hc = textureOffset(tex, uv, ivec2( 0,-1)).r; vec2 n = vec2(ha-hc, hb-hc); return n; } vec4 normal_to_color(vec2 n) { return vec4(n * 0.5 + 0.5, 1.0, 1.0); } vec4 shader(vec4 color, vec2 pos, vec2 screen_uv, vec4 params) { vec2 uv = screen_uv; vec2 dim = vec2(1.0/160.0,1.0/120.0); vec2 n = normal_from_heightmap(noise_tex, uv); vec2 w = normal_from_heightmap(wavelets_tex, uv+n*dim*10.0); vec4 c = mix(normal_to_color(n), normal_to_color(w), 0.25); c = texture(scene_tex, uv+(n+w)*dim*10.0); c = mix(c, vec4(1), length(n+w) > 0.2 ? 0.1 : 0.0); c = show_normals > 0.0 ? mix(normal_to_color(n), normal_to_color(w), 0.25) : c; c = show_noise > 0.0 ? texture(noise_tex, uv) : c; return c; } ``` -------------------------------- ### Create and Manage a Game Window in C++ Source: https://github.com/randygaul/cute_framework/blob/master/README.md This C++ code snippet demonstrates the basic structure for creating a game window using the Cute Framework. It initializes the application with a specified title and resolution, enters a main loop to process updates and drawing, and finally destroys the application. This serves as a foundational example for any game built with CF. ```cpp #include using namespace Cute; int main(int argc, char* argv[]) { // Create a window with a resolution of 640 x 480. CF_Result result = make_app("Fancy Window Title", 0, 0, 0, 640, 480, CF_APP_OPTIONS_WINDOW_POS_CENTERED_BIT, argv[0]); if (is_error(result)) return -1; while (app_is_running()) { app_update(); // All your game logic and updates go here... app_draw_onto_screen(); } destroy_app(); return 0; } ``` -------------------------------- ### Mount Content Directory (C++ API) Source: https://github.com/randygaul/cute_framework/blob/master/docs/topics/file_io.md Mounts a specified directory to a virtual path using the C++ API. It gets the base directory, normalizes it, pops the build-related subdirectories, appends '/content', and then mounts it to the provided virtual directory alias. This offers a more streamlined way to set up VFS. ```cpp void mount_content_directory_as(const char* dir) { Path path = fs_get_base_directory(); path.normalize(); path.pop(2); // Pop out of build/debug/ path += "/content"; fs_mount(path.c_str(), dir); } ``` -------------------------------- ### Vertex Shader Example in GLSL Source: https://github.com/randygaul/cute_framework/blob/master/docs/topics/low_level_graphics.md A simplified vertex shader for the Cute Framework, demonstrating input attributes for position, UV coordinates, and color, and outputting UV and color to be used by the fragment shader. It transforms the input position into clip space. ```glsl layout (location = 0) in vec2 in_pos; layout (location = 1) in vec2 in_uv; layout (location = 2) in vec4 in_col; layout (location = 0) out vec2 v_uv; layout (location = 1) out vec4 v_col; void main() { vec4 posH = vec4(in_pos, 0, 1); v_uv = in_uv; v_col = in_col; gl_Position = posH; } ``` -------------------------------- ### Query Display Information (C++) Source: https://context7.com/randygaul/cute_framework/llms.txt This code snippet shows how to retrieve and display information about available monitors connected to the system. It utilizes Cute Framework functions to get the count, names, positions, sizes, refresh rates, and bounds of each display. ```cpp #include int main(int argc, char* argv[]) { cf_make_app("Display Info", 0, 0, 0, 800, 600, CF_APP_OPTIONS_WINDOW_POS_CENTERED_BIT, argv[0]); // Get all available displays CF_DisplayID* displays = cf_get_display_list(); int display_count = cf_display_count(); for (int i = 0; i < display_count; i++) { printf("Display %d: %s\n", i, cf_display_name(displays[i])); printf(" Position: (%d, %d)\n", cf_display_x(displays[i]), cf_display_y(displays[i])); printf(" Size: %dx%d\n", cf_display_width(displays[i]), cf_display_height(displays[i])); printf(" Refresh Rate: %.2f Hz\n", cf_display_refresh_rate(displays[i])); CF_Rect bounds = cf_display_bounds(displays[i]); printf(" Bounds: (%.0f, %.0f, %.0f, %.0f)\n", bounds.x, bounds.y, bounds.w, bounds.h); } cf_free_display_list(displays); cf_destroy_app(); return 0; } ``` -------------------------------- ### SDL3 Integration Source: https://github.com/randygaul/cute_framework/blob/master/CMakeLists.txt This snippet integrates the SDL3 library for platform support, excluding Emscripten builds. It configures SDL to build as a static library by default, disables tests and examples, and fetches SDL3 from a specified release URL. The CMake arguments ensure correct static/shared library builds based on the `CF_FRAMEWORK_STATIC` variable. Dependencies include the `EMSCIPTEN` CMake variable and `CF_FRAMEWORK_STATIC`. ```cmake if(NOT EMSCRIPTEN) set(SDL_REQUIRED_VERSION 3.2.16) set(SDL_SHARED_ENABLED_BY_DEFAULT OFF) set(SDL_STATIC ${CF_FRAMEWORK_STATIC} CACHE BOOL "Build SDL as a static library") set(SDL_SHARED $ CACHE BOOL "Do not build SDL as a shared library") set(SDL_TEST_LIBRARY OFF CACHE BOOL "Do not build SDL tests") set(SDL_EXAMPLES OFF CACHE BOOL "Do not build SDL examples") FetchContent_Declare( SDL3 URL https://github.com/libsdl-org/SDL/releases/download/release-${SDL_REQUIRED_VERSION}/SDL3-${SDL_REQUIRED_VERSION}.zip DOWNLOAD_EXTRACT_TIMESTAMP ON CMAKE_ARGS -DSDL_SHARED=$ -DSDL_STATIC=${CF_FRAMEWORK_STATIC} -DSDL_TEST_LIBRARY=OFF -DSDL_TESTS=OFF -DSDL_EXAMPLES=OFF ) FetchContent_MakeAvailable(SDL3) if(CF_FRAMEWORK_STATIC) set(CF_LINK_LIBS ${CF_LINK_LIBS} SDL3::SDL3-static) else () set(CF_LINK_LIBS ${CF_LINK_LIBS} SDL3::SDL3) endif() target_include_directories(cute PUBLIC ${SDL3_INCLUDE_DIRS}) endif() ``` -------------------------------- ### Shader Inclusion with Offline Compilation (Command Line) Source: https://github.com/randygaul/cute_framework/blob/master/docs/topics/shader_compilation.md This example shows how to compile a shader with includes using `cute-shaderc` on the command line. It specifies the include directory with `-I` and the output header file with `-oheader`, demonstrating offline compilation of shaders that utilize the `#include` directive. ```bash cute-shaderc -Ishaders -o src/my_shader_shd.h my_shader.shd ``` -------------------------------- ### C Example Use-Case for Incoming Packet Replay Protection Source: https://github.com/randygaul/cute_framework/blob/master/docs/topics/protocol.md Demonstrates how to integrate replay protection logic into packet processing for incoming packets. It shows the steps of reading the sequence number, calling the `replay_buffer_cull_duplicate` function, and updating the buffer using `replay_buffer_update` after successful decryption. ```c int read_packet( uint8_t* packet, int size, replay_buffer_t* replay_buffer, /* ... other params ... */ ) { // ... // Perform replay protection uint8_t packet_type = read_uint8(&packet); uint8_t sequence = read_uint64(&packet); if (replay_buffer_cull_duplicate(replay_buffer, sequence)) { return -1; } // Continue on with decryption steps ... replay_buffer_update(replay_buffer, sequence); // Continue with any other optional processing ... } ``` -------------------------------- ### Draw Text with Cute Framework Source: https://github.com/randygaul/cute_framework/blob/master/docs/topics/drawing.md Illustrates how to load a font file and draw text onto the screen using the Cute framework. This example highlights basic text rendering and mentions advanced features like text wrapping, font sizing, and blurring, which can be controlled via push/pop functions. The text position is the top-left corner. ```cpp // Assuming 'font' is a loaded font object (e.g., from cf_make_font) // Assuming 'text' is the string to draw // Assuming 'position' is a V2 representing the top-left corner // Example of drawing text (actual function calls depend on context) // cf_push_font_size(font, 16); // cf_draw_text(text, position, color_white); // cf_pop_font_size(); ``` -------------------------------- ### Fetch and Configure SPIRV-Cross for Shader Compilation (CMake) Source: https://github.com/randygaul/cute_framework/blob/master/CMakeLists.txt This snippet fetches the SPIRV-Cross library from GitHub using FetchContent if not building for Emscripten. It configures SPIRV-Cross to be built statically, with C API enabled, exceptions converted to assertions, and reflection, shared libraries, GLSLANG installation, tests, and utilities disabled. Platform-specific options are set to disable MSL support on Windows and HLSL support on Apple. Finally, it makes SPIRV-Cross available and links the 'spirv-cross-c' library. ```cmake if(NOT EMSCRIPTEN) set(SPIRV_CROSS_CLI OFF CACHE BOOL "Turn off building SPIRV-Cross CLI.") FetchContent_Declare( SPIRV_CROSS GIT_REPOSITORY https://github.com/KhronosGroup/SPIRV-Cross.git GIT_TAG 0a88b2d5c08708d45692b7096a0a84e7bfae366c CMAKE_ARGS -DSPIRV_CROSS_EXCEPTIONS_TO_ASSERTIONS=ON -DSPIRV_CROSS_CLI=OFF -DSPIRV_CROSS_SHARED=OFF -DSPIRV_CROSS_STATIC=ON UPDATE_DISCONNECTED TRUE GIT_PROGRESS TRUE ) set(SPIRV_CROSS_ENABLE_TESTS OFF CACHE BOOL "Disable SPIRV-Cross tests") set(SPIRV_CROSS_ENABLE_GLSLANG_INSTALL OFF CACHE BOOL "Disable GLSLANG install") set(SPIRV_CROSS_SHARED OFF CACHE BOOL "Build SPIRV-Cross as shared library") set(SPIRV_CROSS_STATIC ON CACHE BOOL "Do not build SPIRV-Cross as static library") set(SPIRV_CROSS_C_API ON CACHE BOOL "Enable the C API") set(SPIRV_CROSS_EXCEPTIONS_TO_ASSERTIONS ON CACHE BOOL "Turn off exceptions in SPIRV-Cross.") set(SPIRV_CROSS_ENABLE_REFLECT OFF CACHE BOOL "Turn off reflection in SPIRV-Cross.") set(SPIRV_CROSS_SKIP_INSTALL OFF CACHE BOOL "Turn off install targets in SPIRV-Cross.") set(SPIRV_CROSS_ENABLE_UTIL OFF CACHE BOOL "Turn off utils in SPIRV-Cross.") set(SPIRV_CROSS_ENABLE_CPP OFF CACHE BOOL "Turn off CPP target support in SPIRV-Cross.") set(SPIRV_CROSS_FORCE_PIC $ CACHE BOOL "Force position-independent code for all targets.") if (WINDOWS) set(SPIRV_CROSS_ENABLE_MSL OFF CACHE BOOL "Turn off MSL support when on windows.") endif() if (APPLE) set(SPIRV_CROSS_ENABLE_HLSL OFF CACHE BOOL "Turn off HLSL support when on windows.") endif() FetchContent_MakeAvailable(SPIRV_CROSS) set(CF_LINK_LIBS ${CF_LINK_LIBS} spirv-cross-c) endif() ``` -------------------------------- ### Enumerate Directory Contents (C++) Source: https://github.com/randygaul/cute_framework/blob/master/docs/topics/virtual_file_system.md This C++ example demonstrates how to enumerate files within a directory using the `Directory` wrapper class. It provides a more object-oriented approach to iterating through directory contents compared to the C version. The `Directory::open` function initializes the enumeration, and the `dir.next()` method retrieves each file name. ```cpp Directory dir = Directory::open("/data"); for (const char* file = dir.next(); file; file = dir.next()) { printf("Found %s\n", file); } ``` -------------------------------- ### Send HTTPS GET Request and Save Response - C Source: https://github.com/randygaul/cute_framework/blob/master/docs/topics/web.md Demonstrates how to send an HTTPS GET request to a specified hostname, process the request until completion, and save the response content to a file named 'response.txt'. This example utilizes functions like cf_https_get, cf_https_process, cf_https_response, cf_https_response_content, and cf_https_destroy. It handles potential errors during the process and ensures the request object is properly destroyed. ```c #include #include int main(int argc, char* argv[]) { const char* hostname = "www.google.com"; CF_HttpsRequest request = cf_https_get(hostname, 443, "/", true); while (1) { CF_HttpsResult state = cf_https_process(request); if (state < 0) { printf("%s\n", cf_https_result_to_string(state)); cf_https_destroy(request); return -1; } if (state == CF_HTTPS_RESULT_OK) { printf("Connected!\n"); break; } } CF_HttpsResponse response = cf_https_response(request); FILE* fp = fopen("response.txt", "wb"); if (!fp) { printf("Unable to open response.txt.\n"); return -1; } fwrite(cf_https_response_content(response), cf_https_response_content_length(response), 1, fp); fclose(fp); cf_https_destroy(request); printf("Saved response in response.txt\n"); return 0; } ``` -------------------------------- ### Build and Run Project Samples Source: https://github.com/randygaul/cute_framework/blob/master/AGENTS.md This snippet shows how to build and run sample programs within the cute_framework project. Samples are automatically built with the main project. Specific sample executables can be run directly from the build directory. ```bash # Samples are automatically built with the main project # Run a specific sample ./build/debug/[sample_name] # Key sample programs (40+ available): # Basic: hello_triangle, basic_sprite, basic_input, basic_networking # Graphics: instancing, indexed_rendering, stencil, render_to_texture # Effects: metaballs, waves, fluid_sim, water, particles # Games: spaceshooter, platformer, tetris # ImGui: imgui, imgui_custom_font, imgui_backend # Tools: docs_parser (generates API documentation) ``` -------------------------------- ### Create and Manage Game Window in C++ Source: https://github.com/randygaul/cute_framework/blob/master/docs/getting_started.md Demonstrates how to initialize a game window with a specified resolution using the Cute Framework. It includes the main application loop for updates and drawing, and handles window destruction. Dependencies include the 'cute.h' header and the CF library. ```cpp #include using namespace Cute; int main(int argc, char* argv[]) { // Create a window with a resolution of 640 x 480. CF_Result result = make_app("Fancy Window Title", 0, 0, 0, 640, 480, CF_APP_OPTIONS_WINDOW_POS_CENTERED_BIT, argv[0]); if (is_error(result)) { printf("Error: %s\n", result.details); return -1; } while (app_is_running()) { app_update(); // All your game logic and updates go here... app_draw_onto_screen(); } destroy_app(); return 0; } ``` -------------------------------- ### Generate and Serve Project Documentation Source: https://github.com/randygaul/cute_framework/blob/master/AGENTS.md Commands for generating and serving the documentation for the cute_framework project. The `docs_parser` generates API references, and `mkdocs` is used for serving and building the documentation site. ```bash # Generate API reference ./build/debug/docs_parser # Serve documentation locally mkdocs serve # Build documentation site mkdocs build ``` -------------------------------- ### Coordinate System Transformation Order in C++ Source: https://github.com/randygaul/cute_framework/blob/master/docs/topics/camera.md Illustrates the impact of the order of transformation functions (rotate and translate) on the final rendering of a box. The first example shows a rotation about the origin followed by a translation, while the second example shows a translation followed by a local rotation. ```cpp cf_draw_rotate(CF_PI/4); cf_draw_translate(50,0); cf_draw_box(cf_make_aabb(cf_v2(-5,-5),cf_v2(5,5)),1,0.5); ``` ```cpp cf_draw_translate(50,0); cf_draw_rotate(CF_PI/4); cf_draw_box(cf_make_aabb(cf_v2(-5,-5),cf_v2(5,5)),1,0.5); ``` -------------------------------- ### Project Configuration and Options Source: https://github.com/randygaul/cute_framework/blob/master/CMakeLists.txt Sets up the minimum CMake version, project details, C++ standard, and build options for the cute_framework. This includes enabling/disabling features like static library builds, shader compilation, and platform-specific framework types. ```cmake cmake_minimum_required(VERSION 3.14) project( cute_framework description "The cutest framework out there for creating 2D games in C++!" homepage_url "https://github.com/RandyGaul/cute_framework" LANGUAGES C CXX VERSION 1.1.0 ) # Must have at least C++20. set(CMAKE_CXX_STANDARD 20) include(GNUInstallDirs) # These are needed for how we use FetchContent. include(FetchContent) Set(FETCHCONTENT_QUIET FALSE) set_property(GLOBAL PROPERTY USE_FOLDERS ON) # Todo - Fix how turning some of these off breaks the build. option(CF_FRAMEWORK_STATIC "Build static library for Cute Framework." ON) option(CF_RUNTIME_SHADER_COMPILATION "Build CF with online shader compilation support (requires python 3.x installation)." ON) option(CF_CUTE_SHADERC "Build cute-shaderc, an offline shader compiler (requires python 3.x installation)." ON) option(CF_FRAMEWORK_APPLE_FRAMEWORK "Build CF libraries as Apple Framework" OFF) # Make sure all libraries are placed into the same output folder. set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) # Disable annoying MSVC warnings. if(MSVC) add_definitions(-D_CRT_SECURE_NO_WARNINGS) add_definitions(-D_CRT_SECURE_NO_DEPRECATE) add_compile_options("$<$:/utf-8>") add_compile_options("$<$:/utf-8>") endif() if(CF_FRAMEWORK_WITH_HTTPS MATCHES OFF) add_definitions(-DCF_NO_HTTPS) endif() configure_file( "${CMAKE_CURRENT_SOURCE_DIR}/include/cute_version.h.in" "${CMAKE_CURRENT_SOURCE_DIR}/include/cute_version.h" @ONLY ) configure_file( "${CMAKE_CURRENT_SOURCE_DIR}/src/cute_version.cpp.in" "${CMAKE_CURRENT_SOURCE_DIR}/src/cute_version.cpp" @ONLY ) # Common directories for compiler/linker path. include_directories(src libraries test) ``` -------------------------------- ### Load and Draw a Demo Sprite with Cute Framework Source: https://github.com/randygaul/cute_framework/blob/master/docs/topics/drawing.md Demonstrates loading a pre-defined demo sprite (a pixel art girl) and drawing it on screen. It includes setting animations, scale, and updating the sprite's state within the application loop. Assumes the 'cute' framework header is included and the application is initialized. ```cpp #include using namespace Cute; int main(int argc, char* argv[]) { Result result = make_app("Basic Sprite", 0, 0, 0, 640, 480, APP_OPTIONS_WINDOW_POS_CENTERED_BIT, argv[0]); if (is_error(result)) return -1; Sprite girl_sprite = cf_make_demo_sprite(); girl_sprite.play("idle"); girl_sprite.scale = V2(4,4); while (app_is_running()) { app_update(); girl_sprite.update(); girl_sprite.draw(); app_draw_onto_screen(); } destroy_app(); return 0; } ``` -------------------------------- ### C++ String Class Manipulation Source: https://github.com/randygaul/cute_framework/blob/master/docs/topics/strings.md Provides an example of using the C++ `String` class in the Cute Framework, demonstrating trimming whitespace and replacing substrings. The class manages memory automatically. ```cpp String s = " Well hello there! Today is day, meaning everything is the color . "; s.trim().replace("", "red"); printf("%s", s.c_str()); ``` -------------------------------- ### Get App's Default Canvas in C++ Source: https://github.com/randygaul/cute_framework/blob/master/docs/topics/low_level_graphics.md Shows how to retrieve the application's default canvas using `cf_app_get_canvas` in C++. This canvas is typically used for rendering to the screen. ```cpp CF_Canvas* canvas = cf_app_get_canvas(); ``` -------------------------------- ### C++ Map Wrapper for Hash Table Source: https://github.com/randygaul/cute_framework/blob/master/docs/topics/data_structures.md Shows usage of the C++ `Map` class, a wrapper around the C `htbl` API. It provides methods for adding, getting, and checking for the existence of elements, returning values by reference or pointer. ```cpp Map vecs; vecs.add(0, V2(0,0)); vecs.add(1, V2(10,0)); v2 a = vecs.get(0); v2 b = vecs.get(1); v2* a_ptr = vecs.try_get(0); v2* b_ptr = vecs.try_get(1); ``` -------------------------------- ### Load and Play Music with Cute Framework Source: https://github.com/randygaul/cute_framework/blob/master/docs/topics/audio.md Demonstrates loading an OGG audio file and playing it as music using Cute Framework's audio functions. This snippet shows how to load audio data into a CF_Audio structure and then initiate playback with an optional fade-in time. It assumes the audio file path is valid. ```cpp CF_Audio my_song; void LoadMusic() { my_song = cf_audio_load_ogg("/music/song.ogg"); } void PlayMusic(float fade_in_time = 0) { cf_music_play(my_song, fade_in_time); } ``` -------------------------------- ### Running Cute Framework Tests (Bash) Source: https://github.com/randygaul/cute_framework/blob/master/AGENTS.md Illustrates the bash command to build and execute all tests for the Cute Framework. It also notes that tests are managed by the pico_unit framework and located in the 'test/' directory. ```bash # Build and run all tests cmake --build build/debug ./build/debug/tests # The test executable uses pico_unit framework # Test files are in test/ directory with pattern test_*.cpp ``` -------------------------------- ### Fragment Shader Example in GLSL Source: https://github.com/randygaul/cute_framework/blob/master/docs/topics/low_level_graphics.md A simplified fragment shader for the Cute Framework that reads from a texture using smoothed UV coordinates and a texture size uniform. It discards fragments with zero alpha and outputs the final color. ```glsl layout (location = 0) in vec2 v_uv; layout (location = 1) in vec4 v_col; layout(location = 0) out vec4 result; layout (set = 2, binding = 0) uniform sampler2D u_image; layout (set = 3, binding = 0) uniform uniform_block { vec2 u_texture_size; }; #include "smooth_uv.shd" void main() { vec4 c = de_gamma(texture(u_image, smooth_uv(v_uv, u_texture_size))); if (c.a == 0) discard; result = c; } ``` -------------------------------- ### Hash Table Operations in C Source: https://github.com/randygaul/cute_framework/blob/master/docs/topics/data_structures.md Provides an example of using the C hash table (htbl) for key-value storage. It covers setting values with 64-bit keys, retrieving values, iterating over key-value pairs, and freeing the table's memory. ```cpp htbl CF_V2* pts = NULL; hset(pts, 0, cf_v2(3, 5)); hset(pts, 10, cf_v2(-1, -1); hset(pts, -2, cf_v2(0, 0)); // Use `hget` to fetch values. CF_V2 a = hget(pts, 0); CF_V2 b = hget(pts, 10); CF_V2 c = hget(pts, -2); // Loop over {key, item} pairs like so: const uint64_t* keys = hkeys(pts); for (int i = 0; i < hcount(pts); ++i) { uint64_t key = keys[i]; CF_V2 v = pts[i]; // ... } hfree(pts); ``` -------------------------------- ### Add Sample Executable Function Source: https://github.com/randygaul/cute_framework/blob/master/samples/CMakeLists.txt Defines a CMake function `add_sample` to streamline the creation of executable samples. This function handles adding the executable, linking the 'cute' library, and applying platform-specific properties for macOS bundles and Windows DXC, as well as Emscripten output. ```cmake function(add_sample TARGET_NAME SOURCE_FILE) add_executable(${TARGET_NAME} ${SOURCE_FILE}) target_link_libraries(${TARGET_NAME} PRIVATE cute) if (APPLE) set_target_properties(${TARGET_NAME} PROPERTIES MACOSX_BUNDLE_GUI_IDENTIFIER "com.cuteframework.${TARGET_NAME}" MACOSX_BUNDLE_BUNDLE_VERSION "${PROJECT_VERSION}" MACOSX_BUNDLE_SHORT_VERSION_STRING "${PROJECT_VERSION}" ) endif() set_target_properties(${TARGET_NAME} PROPERTIES FOLDER "samples" RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR} ) if (WINDOWS) target_dxc_copy(${TARGET_NAME}) endif() if (EMSCRIPTEN) set_target_properties(${TARGET_NAME} PROPERTIES OUTPUT_NAME "${TARGET_NAME}" SUFFIX ".html") target_compile_options(${TARGET_NAME} PRIVATE -O1 -fno-rtti -fno-exceptions -gsplit-dwarf) target_link_options(${TARGET_NAME} PRIVATE -o ${TARGET_NAME}.html -sASYNCIFY=1 -O1 -gseparate-dwarf) target_link_libraries(${TARGET_NAME} PRIVATE cute-emscripten-shell) endif() endfunction() ``` -------------------------------- ### Create a Centered Window with Game Loop (C++) Source: https://github.com/randygaul/cute_framework/blob/master/docs/topics/application_window.md Demonstrates how to create a window with specific dimensions (640x480) centered on the screen and initiates a typical game loop. It includes error handling for window creation and basic application lifecycle management. ```cpp #include int main(int argc, char* argv[]) { // Create a window with a resolution of 640 x 480. CF_Result result = cf_make_app("Fancy Window Title", 0, 0, 0, 640, 480, CF_APP_OPTIONS_WINDOW_POS_CENTERED_BIT, argv[0]); if (is_error(result)) { printf("Error: %s\n", result.details); return -1; } while (cf_app_is_running()) { cf_app_update(NULL); // All your game logic and updates go here... cf_app_draw_onto_screen(); } cf_destroy_app(); return 0; } ``` -------------------------------- ### Static Check for Path Type (Directory/File) in C++ Source: https://github.com/randygaul/cute_framework/blob/master/docs/topics/strings.md Provides examples of using static member functions `Path::is_directory()` and `Path::is_file()` to check the type of a given path string without needing to instantiate a `Path` object. This is useful for quick checks. ```cpp // Check if path is a directory. if (Path::is_directory("/content/areas")) { // ... } // Check if path is a file. if (Path::is_file("/content/areas/area1.txt")) { // ... } ``` -------------------------------- ### Play Sound Effects with Volume and Pitch Control Source: https://context7.com/randygaul/cute_framework/llms.txt Illustrates loading WAV and OGG audio files and playing them as sound effects. It demonstrates setting global audio volume, controlling individual sound volume and pitch (including random pitch variation), and handling looping sounds with a timed stop. Requires the Cute framework's audio module and sound files. ```cpp #include int main(int argc, char* argv[]) { cf_make_app("Audio Demo", 0, 0, 0, 640, 480, CF_APP_OPTIONS_WINDOW_POS_CENTERED_BIT, argv[0]); // Load audio files CF_Audio jump_sound = cf_audio_load_wav("/sounds/jump.wav"); CF_Audio coin_sound = cf_audio_load_ogg("/sounds/coin.ogg"); // Set global audio settings cf_audio_set_global_volume(0.8f); cf_audio_set_pan(0.5f); // Centered stereo while (cf_app_is_running()) { cf_app_update(NULL); // Play sound on key press if (cf_key_just_pressed(CF_KEY_SPACE)) { CF_SoundParams params = cf_sound_params_defaults(); params.volume = 1.0f; params.pitch = 1.0f + (rand() % 20 - 10) / 100.0f; // Random pitch params.looped = false; params.paused = false; CF_Sound sound = cf_play_sound(jump_sound, params); printf("Playing sound, ID: %llu\n", sound.id); } // Play looping sound if (cf_key_just_pressed(CF_KEY_M)) { CF_SoundParams params = cf_sound_params_defaults(); params.looped = true; params.volume = 0.5f; CF_Sound looping_sound = cf_play_sound(coin_sound, params); // Stop after 3 seconds if (cf_on_interval(3.0f)) { cf_sound_stop(looping_sound); } } cf_app_draw_onto_screen(true); } cf_audio_destroy(jump_sound); cf_audio_destroy(coin_sound); cf_destroy_app(); return 0; } ``` -------------------------------- ### Virtual File System Operations Source: https://context7.com/randygaul/cute_framework/llms.txt Demonstrates mounting physical directories and zip archives to virtual paths, and performing file operations like reading, writing, enumerating, and stat-ing. It requires the 'cute.h' header. ```cpp #include int main(int argc, char* argv[]) { cf_make_app("VFS Demo", 0, 0, 0, 640, 480, APP_OPTIONS_WINDOW_POS_CENTERED_BIT, argv[0]); // Mount physical directory to virtual path cf_fs_mount("/", "data", true); cf_fs_mount("/assets", "../assets", true); cf_fs_mount("/mods", "mods", false); // Read-only // Mount archive files cf_fs_mount_zip("/archive", "data.zip"); // Read file from virtual path size_t size; void* data = cf_fs_read_entire_file("/assets/config.json", &size); if (data) { printf("Loaded config: %d bytes\n", (int)size); cf_free(data); } // Write file to virtual path const char* save_data = "{\"level\":5,\"score\":1000}"; CF_Result result = cf_fs_write_entire_file("/save.json", save_data, strlen(save_data)); if (cf_is_error(result)) { printf("Failed to save: %s\n", result.details); } // Enumerate files CF_Directory dir = cf_fs_enumerate_directory("/assets"); while (dir.has_next) { CF_File file = cf_fs_next(&dir); printf("File: %s (size: %lld bytes)\n", file.name, file.size); } // Get file info CF_Stat stat = cf_fs_stat("/save.json"); if (stat.exists) { printf("Save modified: %lld\n", stat.modification_time); printf("Is directory: %d\n", stat.is_directory); } // Unmount when done cf_fs_unmount("/assets"); cf_app_draw_onto_screen(true); cf_destroy_app(); return 0; } ``` -------------------------------- ### Run Project Tests Source: https://github.com/randygaul/cute_framework/blob/master/AGENTS.md Instructions for running all tests within the cute_framework project. Tests are automatically built with the main project and their results are printed to the console. ```bash # Run all tests ./build/debug/tests # Tests are automatically built with the project # Test results are printed to console with pass/fail status ``` -------------------------------- ### Emscripten Sample Data Preloading Source: https://github.com/randygaul/cute_framework/blob/master/samples/CMakeLists.txt Ensures that data files for specific samples (waves and spaceshooter) are included in the web build when targeting Emscripten. This is achieved by using `target_link_options` with the `--preload-file` flag, making the data accessible in the browser environment. ```cmake # Ensure that sample data is included in web build if (EMSCRIPTEN) target_link_options(waves PRIVATE --preload-file "${CMAKE_CURRENT_SOURCE_DIR}/waves_data@/waves_data") target_link_options(spaceshooter PRIVATE --preload-file "${CMAKE_CURRENT_SOURCE_DIR}/spaceshooter_data@/spaceshooter_data") endif () ``` -------------------------------- ### Initialize Random Number Generator with System Time Seed Source: https://github.com/randygaul/cute_framework/blob/master/docs/topics/random_numbers.md Initializes a random number generator using the current system time as the seed. This produces a different sequence of random numbers each time the application starts, creating seemingly random behavior. It requires including the `` header. ```cpp #include // CF_Rnd rnd = cf_rnd_seed((int)(time(NULL))); ```