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;
}