RGFW (Riley's General Framework for Windowing)

repository·main·Indexed 23 days ago

https://github.com/colleagueriley/rgfw

A minimalistic, dependency-free windowing framework for creating windows, managing graphics contexts (OpenGL, Vulkan, Metal, etc.), and handling input events. It features a C89 compatible API written in C99, with support for C++, Objective-C/C++, and Zig.

Tokens
1.3K
Snippets
3
Records
5
Agent score
34%

What's inside RGFW

  1. Getting started with RGFW

    main

    RGFW is a minimalistic windowing framework for creating windows, handling graphics contexts, and managing windowing inputs. It has a C89 compatible API and is primarily written with C99 in mind, but supports C++, Objective-C/C++, and Zig.

    To use RGFW, you must define RGFW_IMPLEMENTATION in exactly one source file before including RGFW.h.

    #define RGFW_IMPLEMENTATION
    #include "RGFW.h"
  2. Compile RGFW examples for different platforms

    main

    Use the following commands to compile a basic RGFW application on different operating systems:

    • Linux: gcc main.c -lX11 -lGL -lm -lXrandr
    • Windows: gcc main.c -lopengl32 -lgdi32
    • macOS: gcc main.c -framework Cocoa
    linux : gcc main.c -lX11 -lGL -lm -lXrandr
    windows : gcc main.c -lopengl32 -lgdi32
    macos : gcc main.c -framework Cocoa
  3. Configure Wayland support during compilation

    main

    When using the provided Makefile to compile examples, you can control Wayland support using these flags:

    • WAYLAND=1: Compiles for Wayland (adds #define RGFW_WAYLAND).
    • WAYLAND_X11=1: Enables Wayland with a fallback to X11 if a Wayland display is not found (adds both #define RGFW_WAYLAND and #define RGFW_X11).
  4. Enable graphics API helper functions

    main

    RGFW provides helper functions for various rendering APIs, but they are not included by default to keep the library small. You must explicitly request them by defining the corresponding macro before including the header:

    • RGFW_OPENGL
    • RGFW_VULKAN
    • RGFW_DIRECTX
    • RGFW_WEBGPU
  5. A simple RGFW window and event loop example

    main

    This example demonstrates initializing the framework, creating a window, using a callback for key presses, and using an event queue for mouse clicks and state checking.

    /*
       this example doesn't have any graphics, for a graphics example see the other examples
       examples/dx11/dx11 -> DirectX
       examples/metal/metal -> Metal
       examples/gl11/gl11 -> OpenGL 1.1
       examples/gl33/gl33 -> OpenGL 3.3
       examples/gles2/gles2 -> OpenGL ES 2
       examples/egl/egl -> egl
       examples/surface/surface -> software rendering
    */
    
    #define RGFW_IMPLEMENTATION
    #include "RGFW.h"
    
    #include <stdio.h>
    
    void keyfunc(const RGFW_event* event) {
        if (event->key.value == RGFW_keyEscape) {
            RGFW_window_setShouldClose(event->common.win, 1);
        }
    }
    
    int main() {
        RGFW_init("example", 0); /* load OpenGL, Vulkan or EGL functions here with RGFW_initOpenGL, RGFW_initEGL or RGFW_initVulkan */
    
        RGFW_window* win = RGFW_createWindow("a window", 0, 0, 800, 600, RGFW_windowCenter | RGFW_windowNoResize);
    
        RGFW_setEventCallback(RGFW_keyPressed, keyfunc); // you can use callbacks like this if you want
    
        i32 mouseX, mouseY;
    
        while (RGFW_window_shouldClose(win) == RGFW_FALSE) {
            RGFW_event event;
            while (RGFW_window_checkEvent(win, &event)) {  // or RGFW_pollEvents(); if you only want callbacks or state checking
                RGFW_window_getMouse(win, &mouseX, &mouseY);
    
                if (event.type == RGFW_mouseButtonPressed && event.button.value == RGFW_mouseLeft) {
                    printf("You clicked at x: %d, y: %d\n", mouseX, mouseY);
                }
            }
    
            /* state checking */
            if (RGFW_isMousePressed(RGFW_mouseRight)) {
                printf("The right mouse button was clicked at x: %d, y: %d\n", mouseX, mouseY);
            }
        }
    
        RGFW_window_close(win);
        RGFW_deinit();
        return 0;
    }