项目作者: ajaysreedhar

项目描述 :
Node.js Addon example using SDL2 graphics library
高级语言: C++
项目地址: git://github.com/ajaysreedhar/nodejs-sdl-example.git
创建时间: 2019-08-30T18:17:09Z
项目社区:https://github.com/ajaysreedhar/nodejs-sdl-example

开源协议:MIT License

下载


Node.js C++ Addon - Example

Hardware accelarated image rendering with SDL2

Node.js follows a single threaded, event-driven approach. Hence it is not advised to write CPU intensive applications in
JavaScript and run them with Node.js as it may obstruct the event loop.
One of the ways to overcome this limitation is leveraging multi-threading capabilities with the help of Node.js Addons.

Node.js Addons are dynamically-linked shared libraries, written in C++, that can be loaded into Node.js runtime using
the require() function, and used just as if they were an ordinary JavaScript module.

This example demonstrates a Node.js Addon which performs hardware accelarated image rendering without interfering the event loop. Though events are captured on the main thread, image rendering is performed on a dedicated thread.

Prerequisites

The addon uses Simple DirectMedia Layer - a library that provides low level access to graphics hardware.

  1. # Debian/Ubuntu Linux
  2. $ sudo apt-get install libsdl2-dev libsdl2-image-dev libsdl2-doc
  3. # Mac OS
  4. $ brew install sdl2
  5. $ brew install sdl2_image

Additionally we need to install build tools and node-gyp, if not already installed.

  1. # Debian/Ubuntu Linux
  2. $ sudo apt-get install autoconf automake libtool
  3. # Mac OS
  4. $ brew install autoconf automake libtool
  5. # Install node-gyp
  6. $ sudo npm install -g node-gyp

Compiling and running

Clone the repository

  1. $ git clone https://github.com/ajaysreedhar/nodejs-sdl-example.git

Configure node-gyp and build the addon

  1. $ cd nodejs-sdl-example
  2. $ node-gyp configure
  3. $ npm install

Finally, execute main.js

  1. $ node main.js