Native OpenGL Utility Toolkit (GLUT) bindings for Node.js (with TypeScript typings), powered by FreeGLUT.
This package exposes GLUT (OpenGL Utility Toolkit) functions directly to Node.js via N-API, with full IntelliSense using src/types/index.d.ts. It provides window management, input handling, and utility functions for creating OpenGL applications with cross-platform support.
Note: this package creates and manages OpenGL contexts and windows. It can be used standalone or in combination with other OpenGL libraries like @devzolo/node-native-gl and @devzolo/node-native-glu.
Prerequisites:
- Node.js 16+ (LTS recommended)
- pnpm, npm, or yarn
If you use GitHub Packages, add to your .npmrc:
@devzolo:registry=https://npm.pkg.github.com
//npm.pkg.github.com/:_authToken=${GITHUB_TOKEN}Install:
# pnpm
pnpm add @devzolo/node-native-glut
# npm
npm install @devzolo/node-native-glut
# yarn
yarn add @devzolo/node-native-glutThe package attempts to download prebuilt binaries. If a binary is not available for your platform, it will build from source (requires a C++ toolchain).
TypeScript / ESM:
import GLUT from '@devzolo/node-native-glut';
// Initialize GLUT
GLUT.init();
// Create a window
GLUT.createWindow('My GLUT Window');
// Set up display callback
GLUT.displayFunc(() => {
// Your OpenGL rendering code here
GLUT.swapBuffers();
});
// Set up reshape callback
GLUT.reshapeFunc((width, height) => {
// Handle window resize
console.log(`Window resized to ${width}x${height}`);
});
// Set up keyboard callback
GLUT.keyboardFunc((key, x, y) => {
if (key === 27) { // ESC key
process.exit(0);
}
});
// Start the main loop
GLUT.mainLoop();JavaScript (CommonJS):
const GLUT = require('@devzolo/node-native-glut').default;
GLUT.init();
GLUT.createWindow('My GLUT Window');
GLUT.displayFunc(() => {
// Your OpenGL rendering code here
GLUT.swapBuffers();
});
GLUT.mainLoop();- Constants and functions mirror the GLUT API, exposed under the
GLUTnamespace with TypeScript types. - Type reference: see
src/types/index.d.tsin this repository. - Examples of available symbols:
- Window functions:
GLUT.createWindow(),GLUT.setWindowTitle(),GLUT.setWindowSize(),GLUT.setWindowPosition(). - Callback functions:
GLUT.displayFunc(),GLUT.reshapeFunc(),GLUT.keyboardFunc(),GLUT.mouseFunc(). - Utility functions:
GLUT.mainLoop(),GLUT.swapBuffers(),GLUT.postRedisplay().
- Window functions:
Typing: the default export is a GLUT object containing all typed members (TypeScript).
- Supported platforms: Windows (x64/x86), Linux (x64), macOS (x64/ARM64)
- GLUT implementation: FreeGLUT 3.2.1 (bundled)
- Prebuilt binaries are downloaded automatically when available.
- Fallback: local build with
node-pre-gyp/node-gyp(requires a C++ toolchain). See next section.
- OpenGL libraries:
opengl32.lib,freeglut.lib(bundled) - Build tools: Visual Studio Build Tools 2019/2022 with C++ (MSVC)
- Python: 3.x in PATH
- OpenGL libraries:
libGL.so,libGLU.so,libglut.so(system packages) - Installation (Ubuntu/Debian):
sudo apt update sudo apt install -y libgl1-mesa-dev libglu1-mesa-dev freeglut3-dev
- Installation (CentOS/RHEL/Fedora):
sudo yum install -y mesa-libGL-devel mesa-libGLU-devel freeglut-devel # or for newer versions: sudo dnf install -y mesa-libGL-devel mesa-libGLU-devel freeglut-devel - Build tools:
gcc,g++,make,python3
- OpenGL libraries:
OpenGL.framework,GLUT.framework(system/bundled) - Build tools: Xcode Command Line Tools
- Installation:
xcode-select --install
- Visual Studio Build Tools 2019/2022 with C++ (MSVC)
- Python 3.x in PATH
- Compatible
node-gyp(pulled by the ecosystem as needed)
- GCC/G++ compiler
- Make
- Python 3.x
- OpenGL development libraries (see installation commands above)
- Xcode Command Line Tools
- Python 3.x
# Install dependencies
pnpm install
# or
npm install
# Build the native module
pnpm build
# or
npm run buildOther useful scripts:
pnpm test # run tests
pnpm dist # compile TypeScript to ./dist
pnpm package # build addon + tests + package- Missing context: GLUT call failures usually indicate initialization issues. Ensure
GLUT.init()is called before other functions. - Missing build tools: if binary download fails, a local build requires platform-specific tools. Install the required tools and retry.
- Unsupported Node: for N-API errors, upgrade to Node 16+ or a recent LTS.
- Missing build tools: Install Visual Studio Build Tools 2019/2022 with C++ (MSVC)
- Python 3.12: 'distutils' missing: If you hit
ModuleNotFoundError: No module named 'distutils'with Python 3.12, run:py -3 -m ensurepip --upgrade py -3 -m pip install --upgrade pip py -3 -m pip install "setuptools<70" packaging wheel pnpm build
- Missing OpenGL libraries: Install the required development packages:
# Ubuntu/Debian sudo apt update sudo apt install -y libgl1-mesa-dev libglu1-mesa-dev freeglut3-dev # CentOS/RHEL/Fedora sudo yum install -y mesa-libGL-devel mesa-libGLU-devel freeglut-devel # or for newer versions: sudo dnf install -y mesa-libGL-devel mesa-libGLU-devel freeglut-devel
- Missing build tools: Install GCC, Make, and Python:
# Ubuntu/Debian sudo apt install -y build-essential python3-dev # CentOS/RHEL/Fedora sudo yum groupinstall -y "Development Tools" sudo yum install -y python3-devel
- Missing Xcode tools: Install Xcode Command Line Tools:
xcode-select --install
- Python issues: Ensure Python 3.x is available and in PATH
This package is designed to work across Windows, Linux, and macOS with the following considerations:
- Uses
opengl32.liband bundledfreeglut.lib(static linking) - Requires Windows 10+ for optimal OpenGL support
- Supports both x64 and x86 architectures
- Uses Windows-specific headers conditionally (
windows.h,tchar.h)
- Uses system OpenGL libraries and bundled FreeGLUT
- Compatible with Mesa drivers (software and hardware acceleration)
- Supports major distributions (Ubuntu, Debian, CentOS, RHEL, Fedora)
- Uses Linux-specific headers (
unistd.h,dlfcn.h)
- Uses
OpenGL.frameworkand system GLUT - Compatible with both Intel and Apple Silicon (ARM64)
- Requires macOS 10.14+ for optimal OpenGL support
- Uses macOS-specific OpenGL headers
The package uses node-gyp with platform-specific configurations:
- Windows: MSVC compiler with Windows SDK
- Linux: GCC/G++ with system OpenGL libraries
- macOS: Clang with Xcode Command Line Tools
- Cross-platform: FreeGLUT 3.2.1 is bundled for consistent behavior
- Static linking: Used on Windows for easier distribution
- Dynamic linking: Used on Linux and macOS for better compatibility
Contributions are welcome! Please open issues and pull requests. Keep the project style and ensure tests pass.
MIT © devzolo. See LICENSE.
- FreeGLUT 3.2.1 for providing a modern, cross-platform GLUT implementation.