2016-07-28 4 views
-2

Hier finden Sie Code, den ich aus einem Tutorial bekam:WebGL funktioniert nicht

<meta http-equiv="Content-Type" content="text/html; charset=utf-8"> 

<script type="text/JavaScript"> 
    var canvas; 
    var gl; 
    function start() { 
    canvas = document.getElementById("glcanvas"); 
    initWebGL(canvas);  // Initialize the GL context 
    // Only continue if WebGL is available and working 
    if (gl) { 
     alert("works"); 
     gl.clearColor(0.0, 0.0, 0.0, 1.0); // Set clear color to black, fully opaque 
     gl.clearDepth(1.0);     // Clear everything 
     gl.enable(gl.DEPTH_TEST);   // Enable depth testing 
     gl.depthFunc(gl.LEQUAL);   // Near things obscure far things 
    } 
    } 
    function initWebGL() { 
    gl = null; 
    try { 
     gl = canvas.getContext("experimental-webgl"); 
    } 
    catch(e) { 
    } 
    // If we don't have a GL context, give up now 
    if (!gl) { 
     alert("Unable to initialize WebGL. Your browser may not support it."); 
    } 
    } 
</script> 


<body onload="start()"> 
<canvas id="glcanvas" width="640" height="480"> 
    Your browser doesn't appear to support the <code>&lt;canvas&gt;</code> element. 
</canvas> 

Eine Blackbox auftauchen sollte, aber ich bekomme nur einen einfachen weißen Bildschirm. Die Warnung wird angezeigt. Ich benutze Firefox und WebGl-Force: aktiviert ist in etwa: Config auf True gesetzt. Warum wird die Blackbox nicht angezeigt?

Antwort

3

Sie verpassen

// Clear the color as well as the depth buffer. 
gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT); 

am Ende Ihrer gl ruft

(source)