精简的跨平台 GUI 库-Fenster


Fenster /ˈfɛnstɐ/—— 在德语中 “window” 的意思。这个库提供了最简洁、最实用的跨平台 2D 画布显示方式。只需几行代码,你就能实现跨平台的键盘 / 鼠标输入和音频播放。主要采用C/C++、Go编写开发并在MIT协议下授权。
This library provides the most minimal and highly opinionated way to display a cross-platform 2D canvas. If you remember Borland BGI or drawing things in QBASIC or INT 10h- you know what I mean. As a nice bonus you also get cross-platform keyboard/mouse input and audio playback in only a few lines of code.
特点:
具有指定大小和标题的单一应用程序窗口。
应用程序生命周期和系统事件均自动处理。
最小 24 位 RGB 帧缓冲区。
跨平台键盘事件(键码)。
跨平台鼠标事件(X/Y + 鼠标点击)。
跨平台计时器具有稳定的 FPS 速率。
跨平台音频播放(WinMM、CoreAudio、ALSA)。
简单的轮询 API,无需回调或多线程(如 Arduino/Processing)。
一个约 300LOC 的 C99 头文件,易于理解和扩展。
Go 绑定(import "github.com/zserge/fenster",参见 godoc)
Zig 绑定(参见 examples/minimal-zig)
Lua 绑定(参见 https://github.com/jonasgeiler/lua-fenster)
可以运行 Doom!
示例
// main.c
#include "fenster.h"
#define W 320
#define H 240
int main() {
uint32_t buf[W * H];
struct fenster f = { .title = "hello", .width = W, .height = H, .buf = buf };
fenster_open(&f);
while (fenster_loop(&f) == 0) {
for (int i = 0; i < W; i++) {
for (int j = 0; j < H; j++) {
fenster_pixel(&f, i, j) = rand();
}
}
}
fenster_close(&f);
return 0;
}
编译并运行:
# Linux
cc main.c -lX11 -lasound -o main && ./main
# macOS
cc main.c -framework Cocoa -framework AudioToolbox -o main && ./main
# windows
cc main.c -lgdi32 -lwinmm -o main.exe && main.exe
最新版本:
项目主页:https://github.com/zserge/fenster
This library provides the most minimal and highly opinionated way to display a cross-platform 2D canvas. If you remember Borland BGI or drawing things in QBASIC or INT 10h- you know what I mean. As a nice bonus you also get cross-platform keyboard/mouse input and audio playback in only a few lines of code.
特点:
具有指定大小和标题的单一应用程序窗口。
应用程序生命周期和系统事件均自动处理。
最小 24 位 RGB 帧缓冲区。
跨平台键盘事件(键码)。
跨平台鼠标事件(X/Y + 鼠标点击)。
跨平台计时器具有稳定的 FPS 速率。
跨平台音频播放(WinMM、CoreAudio、ALSA)。
简单的轮询 API,无需回调或多线程(如 Arduino/Processing)。
一个约 300LOC 的 C99 头文件,易于理解和扩展。
Go 绑定(import "github.com/zserge/fenster",参见 godoc)
Zig 绑定(参见 examples/minimal-zig)
Lua 绑定(参见 https://github.com/jonasgeiler/lua-fenster)
可以运行 Doom!
示例
// main.c
#include "fenster.h"
#define W 320
#define H 240
int main() {
uint32_t buf[W * H];
struct fenster f = { .title = "hello", .width = W, .height = H, .buf = buf };
fenster_open(&f);
while (fenster_loop(&f) == 0) {
for (int i = 0; i < W; i++) {
for (int j = 0; j < H; j++) {
fenster_pixel(&f, i, j) = rand();
}
}
}
fenster_close(&f);
return 0;
}
编译并运行:
# Linux
cc main.c -lX11 -lasound -o main && ./main
# macOS
cc main.c -framework Cocoa -framework AudioToolbox -o main && ./main
# windows
cc main.c -lgdi32 -lwinmm -o main.exe && main.exe
最新版本:
项目主页:https://github.com/zserge/fenster