Giter Site home page Giter Site logo

node-3d / glfw-raub Goto Github PK

View Code? Open in Web Editor NEW
54.0 2.0 10.0 21.07 MB

GLFW for Node.js

Home Page: https://github.com/node-3d/node-3d

License: MIT License

JavaScript 30.54% C++ 69.46%
addon glfw opengl gl graphics window bindings native node-3d cpp

glfw-raub's Introduction

Node3D

NPM ESLint Test

npm i -s 3d-core-raub

Node3D

Desktop 3D applications with Node.js and OpenGL.

  • WebGL-like interface. Real OpenGL though.
  • Three.js compatible environment.
  • Use node modules and compiled addons: CUDA, OpenCL, etc.
  • Window control. Multiwindow applications.
  • Read/write files.
  • Crossplatform: Linux x64, Linux ARM, MacOS x64, Windows x64.

Example

Compatibility with three.js allows porting the existing JS code. The real OpenGL backend is used (not ANGLE). So it is possible to use the GL resource IDs to setup interoperation with CUDA or OpenCL. This is the most important feature of this project and why it was created in the first place.

It is quite possible to create a fully-features apps and games using this framework. For example, see Space Simulation Toolkit.

Quick start

  1. Setup the project directory:

    mkdir my-project
    cd my-project
    npm init -y
    npm i -s 3d-core-raub three
    touch index.js
  2. Paste the code and see if it works:

    const three = require('three');
    const { init, addThreeHelpers } = require('3d-core-raub');
    
    const { doc, gl, requestAnimationFrame } = init({ isGles3: true });
    addThreeHelpers(three, gl);
    
    const renderer = new three.WebGLRenderer();
    renderer.setPixelRatio( doc.devicePixelRatio );
    renderer.setSize( doc.innerWidth, doc.innerHeight );
    
    const camera = new three.PerspectiveCamera(70, doc.innerWidth / doc.innerHeight, 1, 1000);
    camera.position.z = 2;
    const scene = new three.Scene();
    
    const geometry = new three.BoxGeometry();
    const material = new three.MeshBasicMaterial({ color: 0xFACE8D });
    const mesh = new three.Mesh( geometry, material );
    scene.add(mesh);
    
    doc.addEventListener('resize', () => {
    	camera.aspect = doc.innerWidth / doc.innerHeight;
    	camera.updateProjectionMatrix();
    	renderer.setSize(doc.innerWidth, doc.innerHeight);
    });
    
    const animate = () => {
    	requestAnimationFrame(animate);
    	const time = Date.now();
    	mesh.rotation.x = time * 0.0005;
    	mesh.rotation.y = time * 0.001;
    	
    	renderer.render(scene, camera);
    };
    
    animate();
  3. See docs and examples: 3d-core-raub.

  4. Take a look at Three.js examples.

Node3D Modules

  1. Dependency - carries one or more precompiled binary and/or C++ headers.

  2. Addon - provides native bindings.

  3. Plugin - a high-level Node3D module for extending the 3d-core features. For example:

    import { init, addThreeHelpers } from '3d-core-raub';
    import { init as initQml } from '3d-qml-raub';
    const __dirname = dirname(fileURLToPath(import.meta.url));
    const {
    	doc, Image: Img, gl, glfw,
    } = init({
    	isGles3: true, isWebGL2: true, mode: 'borderless',
    });
    addThreeHelpers(three, gl);
    const {
    	QmlOverlay, Property, Method, View, loop, release, textureFromId,
    } = initQml({ doc, gl, cwd: __dirname, three });
  4. Other:

Contributing to Node3D

Bugs and enhancements are tracked as GitHub issues. You can also create an issue on a specific repository of Node3D.

Issues

  • Use a clear and descriptive title.
  • Describe the desired enhancement / problem.
  • Provide examples to demonstrate the issue.
  • If the problem involves a crash, provide its trace log.

Pull Requests

  • Do not include issue numbers in the PR title.
  • Commits use the present tense ("Add feature" not "Added feature").
  • Commits use the imperative mood ("Move cursor to..." not "Moves cursor to...").
  • File System
    • Only lowercase in file/directory names.
    • Words are separated with dashes.
    • If there is an empty directory to be kept, place an empty .keep file inside.
    • Use SemVer versioning pattern.

License

Node3D can be used commercially. You don't have to pay for Node3D or any of its third-party libraries.

Node3D modules have their own code licensed under MIT, meaning "I've just put it here, do what you want, have fun". Some modules have separately licensed third-party software in them. For instance, deps-freeimage-raub carries the FreeImage binaries and headers, and those are the property of their respective owners, and are licensed under FIPL terms (but free to use anyway).

All such cases are explained in README.md per project in question.

glfw-raub's People

Contributors

avaer avatar crashuxx avatar dithi avatar igor-levkov avatar lipx1508 avatar maratyszcza avatar mikeseven avatar otkpobehue avatar peoro avatar raub avatar samzanemesis avatar tmpvar avatar trusktr avatar yetzt 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  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

glfw-raub's Issues

upgrade glfw to version 3.4+

The Node3D project is awesome!

I need to use new features in 3.4 like MOUSE_PASSTHROUGH hint, currently there's no binding for it because the pre-built library version is 3.3, so I'm getting this error:

glfw.windowHint(glfw.MOUSE_PASSTHROUGH, 1);
     ^

Error: Argument 0 must be of type `Uint32`

Error: Can't create GLFW window (in macOS GitHub Actions, works fine in Linux)

I've got this test that you can see passes in Ubuntu, but fails in macOS:

https://github.com/lume/lume/runs/2551739245?check_suite_focus=true

The error is

Error: Can't create GLFW window
    at Document._create (/Users/runner/work/lume/lume/packages/glas/node_modules/glfw-raub/js/window.js:510:24)
    at Document.set mode [as mode] (/Users/runner/work/lume/lume/packages/glas/node_modules/glfw-raub/js/window.js:214:9)
    at new Window (/Users/runner/work/lume/lume/packages/glas/node_modules/glfw-raub/js/window.js:65:13)
    at new Document (/Users/runner/work/lume/lume/packages/glas/node_modules/glfw-raub/js/document.js:24:3)

Any ideas on how to make it pass in macOS?

ESM support

When importing glfw-raub using import in a Node ESM file, it has an error:

/home/trusktr/src/lume+lume/packages/glas/node_modules/glfw-raub/js/window.js:76
                        const dirpath = path.dirname(process.mainModule.filename);
                                                                        ^

TypeError: Cannot read property 'filename' of undefined
    at new Window (/home/trusktr/src/lume+lume/packages/glas/node_modules/glfw-raub/js/window.js:76:52)
    at new Document (/home/trusktr/src/lume+lume/packages/glas/node_modules/glfw-raub/js/document.js:24:3)
    at file:///home/trusktr/src/lume+lume/packages/glas/src/as/test-cube-html.mjs:24:13
    at ModuleJob.run (internal/modules/esm/module_job.js:146:23)
    at async Loader.import (internal/modules/esm/loader.js:165:24)
    at async Object.loadESM (internal/process/esm_loader.js:68:5)

This is because there is no process.mainModule in ESM mode.

Mac 10.14 Mojave error

dyld: lazy symbol binding failed: Symbol not found: _objc_opt_respondsToSelector
  Referenced from: ./node_modules/glfw-raub/bin-osx/../../deps-opengl-raub/bin-osx/glfw.dylib (which was built for Mac OS X 10.15)
  Expected in: /usr/lib/libobjc.A.dylib

dyld: Symbol not found: _objc_opt_respondsToSelector
  Referenced from: ./node_modules/glfw-raub/bin-osx/../../deps-opengl-raub/bin-osx/glfw.dylib (which was built for Mac OS X 10.15)
  Expected in: /usr/lib/libobjc.A.dylib

found a similar error here: koekeishiya/yabai#371, seem like maybe you could add argument -mmacosx-version-min=10.13 to support older macs maybe. Updating my Mac to see if my error goes away :)

Segfault random time after window creation

I really love this library, but the problem is after creating a window, after some time it throws a segfault. I can theoretically ignore the segfault as it doesn't happen again and doesn't affect the application as far as i can, but it's kind of weird to ignore a segfault.

Segfault:

PID 9732 received SIGSEGV for address: 0x7fffe9d03b29
00007FFFE4751D29 (segfault): (#unknown_file): (#unknown_function)
00007FFFEC8985B6 (ntdll): (#unknown_file): RtlIsGenericTableEmpty
00007FFFEC88A056 (ntdll): (#unknown_file): RtlRaiseException
00007FFFEC889FC3 (ntdll): (#unknown_file): RtlRaiseException
00007FFFE9D03B29 (KERNELBASE): (#unknown_file): RaiseException
00007FFF86C1AE17 (OWExplorer): (#unknown_file): base::CriticalSection::TryLock
00007FFF86C19D8B (OWExplorer): (#unknown_file): base::CriticalSection::TryLock
00007FFFEB2E7BD4 (KERNEL32): (#unknown_file): BaseThreadInitThunk
00007FFFEC88CE51 (ntdll): (#unknown_file): RtlUserThreadStart

Code:

import glfw from 'glfw-raub';

if (glfw.init()) {
  const callback = (error, description) => console.log(error, description);
  const window = glfw.createWindow(640, 480, callback, '123', null);

  if (window) {
    glfw.makeContextCurrent(window);
    glfw.swapInterval(1);

    while (!glfw.windowShouldClose(window)) {
      const size = glfw.getFramebufferSize(window);
      glfw.testScene(size.width, size.height);

      glfw.swapBuffers(window);
      glfw.pollEvents();
    }
  }

  glfw.destroyWindow(window);
}

glfw.terminate();

Running on Windows x64 - Node 12.16.1 x64 - ES6

Vulkan API support?

I would like support for things from the Vulkan API. I'm just developing my bindings for that. And I need support for Vulkan API Surface from GLFW.

Cannot install

it seems the install is using the process.env.npm_package_config_install, and it's missing:

https://github.com/node-3d/glfw-raub/releases/download/undefined/windows.zip

There are multiple packages raub have this problem.

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.