A nodejs adapter to use glfw library @glfw
@lux/glfw is a part of lux.js for transform C-language library glfw to nodejs
This project uses node and npm. Go check them out if you don't have them locally installed.
$ npm install --save @lux/glfw
@lux/glfw support most intefraces for glfw,except userdata* API( glfwGetJoystickUserPointer glfwGetMonitorUserPointer glfwGetWindowUserPointer glfwSetJoystickUserPointer glfwSetMonitorUserPointer glfwSetWindowUserPointer)
all glfw API was added CXX_ as prefix like CXX_glfwInit. for image @lux/glfw add CXX_createImage & CXX_deleteImage to create/delete a image object.
this is a simple demo to create a window and set a red rect to replace default cursor;
import glfw from "@lux/glfw";
glfw.CXX_glfwInit();
const window = glfw.CXX_glfwCreateWindow(1024, 768, "glfw-node");
const img = new Int32Array(32 * 32);
img.fill(0xff0000ff, 0, 32 * 32);
const image = glfw.CXX_createImage(32, 32, img);
const cursor = glfw.CXX_glfwCreateCursor(image, 0, 0);
glfw.CXX_deleteImage(image);
glfw.CXX_glfwSetCursor(window, cursor);
while (!glfw.CXX_glfwWindowShouldClose(window)) {
if (
glfw.CXX_glfwGetKey(window, glfw.KEY.ESCAPE) === glfw.ACTION.PRESS
) {
glfw.CXX_glfwSetWindowShouldClose(window, true);
}
glfw.CXX_glfwPollEvents();
}
glfw.CXX_glfwTerminate();
Feel free to dive in! Open an issue or submit PRs.
MIT © AserJoker