WebGL不呈现可能与警告有关

时间:2015-04-25 17:38:50

标签: webgl

我对OpenGL很陌生并尝试学习一点WebGl。我偶然发现a tutorial,虽然很棒,但似乎有点过时了。我实现了自己的example in a Plunkr版本。我故意遗漏广场,然而,一旦我把所有东西都连接起来,我都看不到三角形。我在控制台发现了警告......

WARNING: Attribute 0 is disabled. This has signficant performance penalty

还有另外一个SO question看起来很相似,但通过差异我无法让它发挥作用,我无法得到他所说的点击。这是我的绘图代码供参考......

drawScene() {
    this.gl.viewport(0, 0, this.gl.viewportWidth, this.gl.viewportHeight);
    this.gl.clear(this.gl.COLOR_BUFFER_BIT | this.gl.DEPTH_BUFFER_BIT);
    mat4.perspective(45, this.gl.viewportWidth / this.gl.viewportHeight, 0.1, 100.0, this.pMatrix);
    mat4.identity(this.mvMatrix);
    mat4.translate(this.mvMatrix, this.mvMatrix, [-1.5, 0.0, -7.0]);
    this.gl.bindBuffer(this.gl.ARRAY_BUFFER, this.triangleVertexPositionBuffer);
    this.gl.vertexAttribPointer(this.shaderProgram.vertexPositionAttribute, this.triangleVertexPositionBuffer.itemSize, this.gl.FLOAT, false, 0, 0);
    this.setMatrixUniforms();
    this.gl.drawArrays(this.gl.TRIANGLES, 0, this.triangleVertexPositionBuffer.numItems);
  }

有没有人在这里有经验可以帮助引导新手?

1 个答案:

答案 0 :(得分:0)

所以回顾this link帮助了很多。要考虑的一件事是它没有谈论他们导入的glUtils js文件,所以是的,这是必要的。似乎警告消息所指的是在较新版本中需要明确有关着色器的参数。这是一个example plnkr你会注意到这是不同的......

// NEEDED to prevent warning
    this.vertexPositionAttribute = this.gl.getAttribLocation(this.shaderProgram, "aVertexPosition");
    this.gl.enableVertexAttribArray(this.vertexPositionAttribute);

当我以这种方式设置着色器属性时,我会避免警告!