Giter VIP home page Giter VIP logo

node-addon-example's Introduction

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.

# Debian/Ubuntu Linux
$ sudo apt-get install libsdl2-dev libsdl2-image-dev libsdl2-doc

# Mac OS
$ brew install sdl2
$ brew install sdl2_image

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

# Debian/Ubuntu Linux
$ sudo apt-get install autoconf automake libtool

# Mac OS
$ brew install autoconf automake libtool

# Install node-gyp
$ sudo npm install -g node-gyp

Compiling and running

Clone the repository

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

Configure node-gyp and build the addon

$ cd nodejs-sdl-example
$ node-gyp configure
$ npm install

Finally, execute main.js

$ node main.js

node-addon-example's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

node-addon-example's Issues

Hala

What Maccha ,

Creating repo and all..

New startup ah ?

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.