WebGL context using node

Viewed 178

I'm building a Node app, and I have a Three.js animation running fine. Now I want to write a script that detects if there is a webGLcontext, but I can't figure out where or how to get my canvas's context.

Here is what I tried to do :

window.addEventListener("load", () => {

  let paragraph = document.getElementById("verifWebGL");
  let canvas = document.getElementById("renderCanvas");
  let glG = window.WebGLRenderingContext && ( canvas.getContext( 'webgl' ) || canvas.getContext( 'experimental-webgl' ));

  if (glG) {
    paragraph.textContent = "Ça se passe juste en dessous.";
    lancer = true;
  }
  else {
    paragraph.textContent = "Vous ne pourrez pas lancer de dé avec ce navigateur."
    +" Veuillez reesayer avec Google Chrome ou Mozilla Firefox.";
    lancer = false;
  }
}

But is doesn't work. I tried to use only canvas, but it also doesn't work. And I know I have a context because the animation is running. But in the chrome scope, 'glG' remains null. Any ideas ?

1 Answers

You can get the renderer's WebGL context like so:

const context = renderer.getContext();
Related