Dart Web-GL上下文为空

时间:2014-12-03 13:28:12

标签: dart webgl

我今天开始了Dart的旅程,但是我似乎无法获得WebGL上下文。这是我的所有代码。

CanvasElement canvas = querySelector("#area");

WebGL.RenderingContext gl = canvas.getContext("webgl");
if (gl == null) {
  gl = canvas.getContext("experimental-webgl");
}

if (gl == null) {
  querySelector("#console").text = "WebGL is not supported!";
} else {
  querySelector("#console").text = "WebGL is supported!";
}

对于html:

<html>
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Dart WebGL Test</title>
  </head>
  <body>
    <h1>Dart WebGL</h1>
    <p id="console">Trying to make a game work in Dart WebGL</p>

    <div id="container">
      <canvas id="area" height="400px"></canvas>
    </div>

    <script type="application/dart" src="main.dart"></script>
    <script src="packages/browser/dart.js"></script>
  </body>
</html>

Context始终等于null。任何想法为什么会这样? (我尝试在Chromium和Chrome上运行此功能)

1 个答案:

答案 0 :(得分:0)

啊......这样的错误。我发布的代码与我正在运行的代码不匹配,因为我认为这不重要。

CanvasElement canvas = querySelector("#area");
var context = canvas.context2D; // this line here

WebGL.RenderingContext gl = canvas.getContext("webgl");
if (gl == null) {
  gl = canvas.getContext("experimental-webgl");
}

if (gl == null) {
  querySelector("#console").text = "WebGL is not supported!";
} else {
  querySelector("#console").text = "WebGL is supported!";
}

没有意识到访问会员会做坏事:D抱歉。