知识库
Three.js开发教程(threejs-cookbook):04、测试是否支持webgl
2025-01-12 22:09:26 李腾 2 次阅读 0 次点赞
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>04_测试是否支持webgl</title>
<link href="../css/index.css" rel="stylesheet" />
<script src="../libs/three.js"></script>
</head>
<body>
<script>
var detectWebGL = function () {
var canvas = document.createElement('canvas');
var webgl = null;
try {
webgl = canvas.getContext('webgl');
} catch (e) {
webgl = null;
}
if (webgl) {
return true;
}
return false;
}
window.onload = function () {
if (detectWebGL()) {
alert('支持WebGL!');
} else {
alert('不支持WebGL!');
}
}
</script>
</body>
</html>
本文由人工编写,AI优化,请仔细甄别,转载请注明转自www.hylab.cn,原文地址:Three.js开发教程(threejs-cookbook):04、测试是否支持webgl