尝试设置TextureCoord参数时,WebGL返回错误

塔兰加

我有一个简单的webGL程序,几乎可以从Mozilla开发人员网络复制粘贴内容由于某种原因,我设法创建了一种具有单色的立方体侧面,并在顶部和底部创建了纹理,并且可以看到纹理,但是我不确定是否正确设置了闪电。我正在尝试修复以下错误,而我尝试使用aTextureCoord参数初始化着色器时发现该错误发生。以下是我的着色器和我要使用的javascript代码。有人能弄清楚为什么会发生这种情况吗?属性highp vec3 aVertexNormal; 属性highp vec3 aVertexPosition; 属性highp vec2 aTextureCoord;

uniform highp mat4 uNormalMatrix;
uniform highp mat4 uMVMatrix;
uniform highp mat4 uPMatrix;

varying highp vec3 vLighting;
varying highp vec2 vTextureCoord;

void main(void) {
  gl_Position = uPMatrix * uMVMatrix * vec4(aVertexPosition, 1.0);
  vTextureCoord = aTextureCoord;

  highp vec3 ambientLight = vec3(0.6, 0.6, 0.6);
  highp vec3 directionalLightColor = vec3(0.5, 0.5, 0.75);
  highp vec3 directionalVector = vec3(0.85, 0.8, 0.75);

  highp vec4 transformedNormal = uNormalMatrix * vec4(aVertexNormal, 1.0);

  highp float directional = max(dot(transformedNormal.xyz, directionalVector), 0.0);
  vLighting = ambientLight + (directionalLightColor * directional);
 }
</script>

以下是javascript代码。

      shaderProgram.vertexPositionAttribute = gl.getAttribLocation(shaderProgram, "aVertexPosition");
  gl.enableVertexAttribArray(shaderProgram.vertexPositionAttribute);      
  shaderProgram.vertexColorAttribute = gl.getAttribLocation(shaderProgram, "aVertexColor");
  gl.enableVertexAttribArray(shaderProgram.vertexColorAttribute);     
  shaderProgram.pMatrixUniform = gl.getUniformLocation(shaderProgram, "uPMatrix");
  shaderProgram.mvMatrixUniform = gl.getUniformLocation(shaderProgram, "uMVMatrix");

  shaderProgram4Tex.vertexPositionAttribute = gl.getAttribLocation(shaderProgram4Tex, "aVertexPosition");
  gl.enableVertexAttribArray(shaderProgram4Tex.vertexPositionAttribute);      
  shaderProgram4Tex.vertexTextureAttribute = gl.getAttribLocation(shaderProgram4Tex, "aTextureCoord");
  gl.enableVertexAttribArray(shaderProgram4Tex.vertexTextureAttribute);   
  shaderProgram4Tex.pMatrixUniform = gl.getUniformLocation(shaderProgram4Tex, "uPMatrix");
  shaderProgram4Tex.mvMatrixUniform = gl.getUniformLocation(shaderProgram4Tex, "uMVMatrix");
  shaderProgram4Tex.vertexNormalAttribute = gl.getAttribLocation(shaderProgram4Tex, "aVertexNormal");
  gl.enableVertexAttribArray(shaderProgram4Tex.vertexNormalAttribute);
  shaderProgram4Tex.samplerUniform = gl.getUniformLocation(shaderProgram4Tex, "uSampler");
  shaderProgram4Tex.normalMatrix = gl.getUniformLocation(shaderProgram4Tex, "uNormalMatrix");

运行程序时出现以下错误。

 WebGL: INVALID_OPERATION: drawElements: attribs not setup correctly

希望有人能回答这个问题,因为我已经花了10个小时来解决这个问题,却不知道为什么会这样。

man

“未正确设置文件”是指

  1. 您尚未设置任何程序。换句话说,您没有gl.useProgram使用有效的程序进行调用

  2. 您使用打开了一个属性,gl.enableVertexAttribArray但是没有通过调用来为其分配缓冲区,而gl.bindBuffer(gl.ARRAY_BUFFER, someBuffer)在某个时候通过调用gl.vertexAttribPointer将当前绑定分配ARRAY_BUFFER给指定的属性来对其进行分配

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

设置排除参数时,xcopy返回错误“参数数量无效”

来自分类Dev

尝试为Access中的查询设置QueryDefs参数时出现VBA错误

来自分类Dev

尝试为Access中的查询设置QueryDefs参数时出现VBA错误

来自分类Dev

尝试在R中设置哈希图的值时,环境子分配的参数错误

来自分类Dev

尝试删除参数时出现lambda错误

来自分类Dev

尝试参数更新时的JDBC错误

来自分类Dev

尝试更新设置时出现错误

来自分类Dev

尝试编译fftw时返回错误

来自分类Dev

CoreData:尝试获取时错误返回 nil

来自分类Dev

尝试返回类类型,但模板参数错误

来自分类Dev

尝试设置ProcessStrictHandleCheckPolicy返回87-错误的函数

来自分类Dev

尝试使用绑定参数时出现ROracle错误

来自分类Dev

尝试使用绑定参数时出现ROracle错误

来自分类Dev

尝试循环 if 条件时收到错误:“参数长度为零”

来自分类Dev

尝试设置熊猫列名称时出现“总线错误:10”

来自分类Dev

尝试设置墙纸时出现以下错误

来自分类Dev

错误:尝试设置路由时出现[$ injector:unpr]

来自分类Dev

尝试打开Windows显示设置时如何解决错误?

来自分类Dev

尝试设置墙纸时出现以下错误

来自分类Dev

jQuery Mobile尝试触发pagecreate时返回错误

来自分类Dev

尝试在换行符上分割时,Groovy返回错误

来自分类Dev

尝试使用C#执行查询时SqlCommand返回错误

来自分类Dev

尝试使用任何方法时,Wikipedia API返回错误

来自分类Dev

尝试返回标签计数时,lapply出现“,”错误

来自分类Dev

尝试返回多个查询时出现Open DataReader错误

来自分类Dev

尝试返回值时的对象对象错误

来自分类Dev

尝试返回值时遇到两个错误

来自分类Dev

在Linux上运行VirtualBox时出现“错误参数设置”

来自分类Dev

函数有多个参数时读取表将返回错误

Related 相关文章

  1. 1

    设置排除参数时,xcopy返回错误“参数数量无效”

  2. 2

    尝试为Access中的查询设置QueryDefs参数时出现VBA错误

  3. 3

    尝试为Access中的查询设置QueryDefs参数时出现VBA错误

  4. 4

    尝试在R中设置哈希图的值时,环境子分配的参数错误

  5. 5

    尝试删除参数时出现lambda错误

  6. 6

    尝试参数更新时的JDBC错误

  7. 7

    尝试更新设置时出现错误

  8. 8

    尝试编译fftw时返回错误

  9. 9

    CoreData:尝试获取时错误返回 nil

  10. 10

    尝试返回类类型,但模板参数错误

  11. 11

    尝试设置ProcessStrictHandleCheckPolicy返回87-错误的函数

  12. 12

    尝试使用绑定参数时出现ROracle错误

  13. 13

    尝试使用绑定参数时出现ROracle错误

  14. 14

    尝试循环 if 条件时收到错误:“参数长度为零”

  15. 15

    尝试设置熊猫列名称时出现“总线错误:10”

  16. 16

    尝试设置墙纸时出现以下错误

  17. 17

    错误:尝试设置路由时出现[$ injector:unpr]

  18. 18

    尝试打开Windows显示设置时如何解决错误?

  19. 19

    尝试设置墙纸时出现以下错误

  20. 20

    jQuery Mobile尝试触发pagecreate时返回错误

  21. 21

    尝试在换行符上分割时,Groovy返回错误

  22. 22

    尝试使用C#执行查询时SqlCommand返回错误

  23. 23

    尝试使用任何方法时,Wikipedia API返回错误

  24. 24

    尝试返回标签计数时,lapply出现“,”错误

  25. 25

    尝试返回多个查询时出现Open DataReader错误

  26. 26

    尝试返回值时的对象对象错误

  27. 27

    尝试返回值时遇到两个错误

  28. 28

    在Linux上运行VirtualBox时出现“错误参数设置”

  29. 29

    函数有多个参数时读取表将返回错误

热门标签

归档