04、测试是否支持webgl

创建日期:2024-07-08
更新日期:2025-01-12
<!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>