Javascript 为什么我的webGL上下文返回为null,但也显示它已被检索?

Javascript 为什么我的webGL上下文返回为null,但也显示它已被检索?,javascript,webgl,Javascript,Webgl,我刚开始学习webGL,我有点困惑。我在try/catch中获得了上下文,实际上我显示了尝试是成功的,但是,我也显示了我的上下文是空的。有人能解释一下为什么会这样吗?根据教程,我应该看到一个黑匣子,但我没有 HTML <body> <canvas id="webGL" width="500" height="500"></canvas> </body> 我来看看实际发生了什么。您正在调用depthFUNC,而您应该调用depthFUNC谢

我刚开始学习webGL,我有点困惑。我在try/catch中获得了上下文,实际上我显示了尝试是成功的,但是,我也显示了我的上下文是空的。有人能解释一下为什么会这样吗?根据教程,我应该看到一个黑匣子,但我没有

HTML

<body>
    <canvas id="webGL" width="500" height="500"></canvas>
</body>

我来看看实际发生了什么。

您正在调用
depthFUNC
,而您应该调用
depthFUNC

谢谢,但这并没有真正解决问题。我现在可以看到您所说的黑匣子了。好了,我必须清除我的缓存。非常感谢。
window.addEventListener("load", function(){
    start();
    var gl;//Holds the WebGL context
    function start(){
        var canvas = document.getElementById("webGL");
        gl = initWebGL(canvas);//Initializes the GL context
        if(gl){
            gl.clearColor(0.0, 0.0, 0.0, 1.0);//Sets the clear color to black
            gl.enable(gl.DEPTH_TEST);//Enables depth testing
            gl.depthFUNC(gl.LEQUAL);//Near things obsure far things
            gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);//Clears the color and depth buffer
        }
    }

    function initWebGL(canvas){
        gl = null;
        try{
            //Tries to grab the standard context.  If it fails, fallback to the experimental version
            gl = canvas.getContext("webgl") || canvas.getContext("experimental-webgl");
            console.log("Got it");
            console.log(gl);
        }
        catch(e){
            //If there is no GL context, give up
            if(!gl){
                gl = null;
                console.log("You suck");
                console.log(gl);
            }
        }
        return gl;
    }
})