Y
Y
Yana Egorova2021-05-27 13:32:00
JavaScript
Yana Egorova, 2021-05-27 13:32:00

How to check webGL and OpenGL support on the user side using JavaScript?

There is a site on which there is a 3D model working using the potree.js library. But on some devices (on some phones) it does not work, I suspect that due to the lack of webGL support. I found the modernizr library, which seems to check webGL support, but on a phone where the 3D model does not work, it shows that webGL is supported. Or am I checking something wrong?

How I checked support:

if (Modernizr.webgl) {
  // WebGL supported
} else {
  // WebGL not supported
}

I have never worked with 3d models and webGL , maybe I misunderstood something?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Somewhere Intech, 2021-05-27
@yanadev

function initWebGL(canvas){
  var ctx = null;
  for (name of ["webgl", "experimental-webgl"]){
    try {
      ctx = canvas.getContext(name);
    } catch(error) {
      console.log(name + ' not supported');
    }
    if (ctx) break;
  }
  return ctx;
}

let canvas = document.createElement('canvas');
const webGL = initWebGL(canvas);
if (webGL) // supported
else // not supported

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question