Skip to content

Latest commit

 

History

History
145 lines (128 loc) · 5.87 KB

Comparison.md

File metadata and controls

145 lines (128 loc) · 5.87 KB

Introduction

Emscripten comes with a built-in implementation of GLFW (3) written in 100% JavaScript. This implementation is an alternate and more complete implementation of the GLFW API (currently 3.4.0). This document explains the differences.

Brief History

From the git history and the current source code, it is possible to gather the facts that the built-in GLFW implementation was implemented back in 2013 in pure JavaScript. It currently states that it implements the 3.2.1 version of the API released in 2016 (as returned by glfwGetVersion). There have been 2 major releases since then (3.3.0 released in 2019 and 3.4.0 released in 2024). It does not comply with the error handling paradigm of GLFW (glfwSetErrorCallback stores the function pointer but never uses it and some APIs throw an exception when called (like glfwGetTimerFrequency)).

This library currently implements the latest GLFW API (3.4.0) in C++ (and JavaScript when necessary), using more modern browser technologies and addresses some issues from the JavaScript implementation. It tries to do its best to implement as much of the GLFW API that is possible to implement in the context of a web browser. When it can't, it handles the case gracefully and in compliance with error handling in GLFW.

Note

This implementation has taken great care to be backward compatible with the built-in implementation, for example, supporting Module['canvas'], so that it is a drop-in replacement.

How to use?

When compiling using the Emscripten compiler (emcc / em++), it is equally trivial to pick which flavor you want to use:

  • If you want to use the built-in implementation, you use the syntax -sUSE_GLFW=3
  • If you want to use this implementation, you use the syntax --use-port=contrib.glfw3

Tip

When using CMake, you need to define it as both a compile and link option:

target_compile_options(${target} PUBLIC "--use-port=contrib.glfw3")
target_link_options(${target} PUBLIC "--use-port=contrib.glfw3")

Main features comparison

This section describes the main features implemented by both libraries.

Feature emscripten-glfw
(this implementation)
library_glfw.js
(built-in implementation)
Single Window Yes Yes
Multiple Windows Yes No
Mouse Yes (includes sticky button behavior) Yes (NO sticky button behavior)
Keyboard Yes (includes sticky key behavior) Yes (NO sticky key behavior)
Keyboard / Meta Key Yes (implements workaround) Yes
Joystick Yes Yes
Gamepad Yes No 3.3.x feature
Fullscreen Yes Yes
Hi DPI Yes Yes
Clipboard (copy/paste) Yes No
Cursors (Standard + Custom) Yes No
Window Size constraints (size limits and aspect ratio) Yes No
Window Opacity Yes No
Window Status (Focused / Hovered / Position) Yes No
Timer Yes Yes (throws exception if called!)
Error Handing Yes Yes

Please refer to the exhaustive list of functions for further details.

Note

This table is built with data from Emscripten 3.1.65 (2024/08/22)

Warning

Emscripten embeds glfw3.h version 3.3.8 yet implements version 3.2.1.