Git Product home page Git Product logo

glfwjs's Introduction

glfwJS

The N-API bindings for GLFW multi-platform library for OpenGL, OpenGL ES and Vulkan development on the desktop. It provides a simple API for creating windows, contexts and surfaces, receiving input and events.

Example

if (!glfwInit()) {
    process.exit(1);
}

const window = glfwCreateWindow(kWidth, kHeight, "Simple example", null, null);
if (!window) {
    glfwTerminate();
    process.exit(1);
}
glfwMakeContextCurrent(window);

glfwSwapInterval(1);
glfwSetKeyCallback(window, key_callback);

function drawLoop() {
    if (!glfwWindowShouldClose(window)) {
        setTimeout(drawLoop, 0);
    } else {
        glfwDestroyWindow(window);
        glfwTerminate();
        process.exit(0);
    }

    glfwSwapBuffers(window);
    glfwPollEvents();
}
drawLoop();

glfwjs's People

Contributors

reon90 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

glfwjs's Issues

Provide TypeScript definitions file for ease of use

I came across this project through the official glfw website and was hoping to use it, but as no typescript definitions exist, this is a little bit more difficult. I'm wondering if there's gonna be some way to generate this quickly. I happened to notice the /include/ast/glfw3.xml file and was wondering if this could be used. Similarly the .h file could be used for this, but I'm not sure how this would be done. Otherwise, the library works great and is very on-par with the C++ docs. Thank you for this.

Local builds are placed in wrong directory

On Linux, the npm package contains a Linux build in...

build/linux/Release/glfwJS.node

... however, when building the package locally on post-install, the build ends up in...

build/Release/glfwJS.node

... and the other contents of the build folder seem to get wiped out. This produces the following error when attempting to use glfwJS:

[nix-shell:~/projects/ui-experiment]$ node example.js 
node:internal/modules/cjs/loader:936
  throw err;
  ^

Error: Cannot find module '../build/linux/Release/glfwJS.node'
Require stack:
- /home/sven/projects/ui-experiment/node_modules/glfw-n-api/generated/interface.js
- /home/sven/projects/ui-experiment/node_modules/glfw-n-api/index.js
- /home/sven/projects/ui-experiment/example.js
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
    at Function.Module._load (node:internal/modules/cjs/loader:778:27)
    at Module.require (node:internal/modules/cjs/loader:1005:19)
    at require (node:internal/modules/cjs/helpers:102:18)
    at Object.<anonymous> (/home/sven/projects/ui-experiment/node_modules/glfw-n-api/generated/interface.js:2:14)
    at Module._compile (node:internal/modules/cjs/loader:1105:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1159:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Module.require (node:internal/modules/cjs/loader:1005:19) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '/home/sven/projects/ui-experiment/node_modules/glfw-n-api/generated/interface.js',
    '/home/sven/projects/ui-experiment/node_modules/glfw-n-api/index.js',
    '/home/sven/projects/ui-experiment/example.js'
  ]
}

(Note that I cannot use the build included in the npm package for using-a-weird-distro reasons, but presumably this affects any case where the build gets carried out locally for any reason)

Cannot build on Windows

I'm not familiar with gyp, but it turns out it misses the include path in windows.

It will says

C:\Users\<user>\Workspace\<project>\node_modules\glfw-n-api\generated\calls.c(1,10): fatal error C1083: Cannot open include file: “include/c/glfw3.h”: No such file or directory [C:\Users\<user>\Workspace\<project>\node_modules\glfw-n-api\build\glfwJS.vcxproj]

In the glfwJS.vsxproj, all the compile paths are missing path splitting \ like:

C:UsersXXXWorkspacenglnode_modulesglfw-n-api

Update:

In binding.gyp, we have

"include_dirs": [
  "<@(module_root_dir)",
],

If I remove the @, it can compile correctly:

"include_dirs": [
  "<(module_root_dir)",
],

Additionally:

Once the compile is passed, I found the javascript is requiring the ../build/${platform}/Release/glfwJS.node whereas the glfwJS.node is built to ../build/Release/glfwJS.node on Windows.

Update:
I switch to use the git repo zip. It seems the git repo is up-to-date, but the npm package (0.0.4) is outdate. Maybe you can update the npm package. Thanks.

Add tests

Generate JS tests by C interface.

Cannot find libglfw.so.3

Hi it's me again :P

I've been playing around with the library for a little bit and it's worked, except now I can't start the application because of

(node:52496) UnhandledPromiseRejectionWarning: Error: libglfw.so.3: cannot open shared object file: No such file or directory
    at Object.Module._extensions..node (internal/modules/cjs/loader.js:1251:18)
    at Module.load (internal/modules/cjs/loader.js:1050:32)
    at Function.Module._load (internal/modules/cjs/loader.js:938:14)
    at Module.require (internal/modules/cjs/loader.js:1090:19)
    at require (internal/modules/cjs/helpers.js:75:18)
    at Object.<anonymous> (/usr/lib/lotus/native/glfwJS/generated/interface.js:2:14)
    at Module._compile (internal/modules/cjs/loader.js:1201:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1221:10)
    at Module.load (internal/modules/cjs/loader.js:1050:32)
    at Function.Module._load (internal/modules/cjs/loader.js:938:14)

I'd like to point out also that I had to modify the /generated/interface.js file at like 2 as node-gyp does not create a /build/linux directory, and it has worked so far. Otherwise, I haven't touched anything and I suddenly cannot use the library any more.

would you know what to do about it? I've been playing around with some build scripts for a little bit and can't seem to locate the issue :/

Thanks

Cannot use on M1 Macs

Minor issue, but since the library is hardcoded to use the prebuilt libraries, I feel that I should raise this issue. If a user on an M1 Mac downloads this package because there is no arm64 binary included, node-gyp nukes the build directory and starts from scratch. As a result of this, when the package tries to pull the prebuilt binary it fails because the prebuilt binary doesn't exist because node-gyp never creates the darwin folder (for whatever reason). This is the resulting directory structure on an M1 Mac.

Screen Shot 2021-03-07 at 9 47 23 PM

I'm not entirely sure how this could be handled...unless I were to send you my arm64 compiled node file and you could create say a darwin-arm64 folder...I'm not very good with native addons.

It should be noted, this was the result whether I installed the library directly from NPM, or from the master branch.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.