nballiett
nballiett

Reputation: 7

Three.js: How to kill three.js if webgl is not detected?

I have seen other posted on how to fallback to canvasrenderer if webgl is not detected.

renderer = Detector.webgl? new THREE.WebGLRenderer(): new THREE.CanvasRenderer();

I am not sure where to start if I would want the whole thing to go away if webgl is not detected. I have an image behind my webgl that I would rather have displayed than the empty div I keep my three.js script in.

Here is the jsfiddle to the script in question: https://jsfiddle.net/nballiett/kkxo8kc5/3/

I apologize if this is a simply answered question, I am a bit new to this.

Upvotes: 0

Views: 192

Answers (1)

Falk Thiele
Falk Thiele

Reputation: 4494

You use the Detector to check if webGL is avaliable, and then call init() if it is or else some other JavaScript:

if ( Detector.webgl ) {
  init();
  animate();
} else {
  // no webGL
  // do something
}

Updated your jsfiddle: https://jsfiddle.net/kkxo8kc5/4/

Upvotes: 1

Related Questions