【问题标题】:WebGL texture bound to texture unit 0 is not renderable绑定到纹理单元 0 的 WebGL 纹理不可渲染
【发布时间】:2017-08-05 01:23:19
【问题描述】:

我正在尝试为反射设置立方体纹理,但出现此错误:

  WebGL: drawElements: texture bound to texture unit 0 is not renderable. 
It maybe non-power-of-2 and have incompatible texture filtering or is not 'texture complete'.
 Or the texture is Float or Half Float type with linear filtering while OES_float_linear or OES_half_float_linear extension is not enabled.
index.js:404 WebGL: too many errors, no more errors will be reported to the console for this context.

我确信图像 (PNG) 已正确加载,因为 console.log 打印了两个高度和宽度的正确幂...

当我尝试绘制任何东西时出现此错误,即使在另一个着色器程序中也是如此。

这是纹理加载的代码:

gl.useProgram(shaderProgram);
cubeMap = gl.createTexture();
gl.bindTexture(gl.TEXTURE_CUBE_MAP, cubeMap);

gl.texImage2D(gl.TEXTURE_CUBE_MAP_POSITIVE_X, 0, gl.RGBA,
gl.RGBA, gl.UNSIGNED_BYTE, image_pos_x);
//5 more times for different faces of the cube

gl.activeTexture( gl.TEXTURE0 );
gl.uniform1i(gl.getUniformLocation(shaderProgram, "texture"),0);

【问题讨论】:

  • 请显示纹理加载代码。
  • 我刚开始的时候也遇到过这类问题,我只能说,从最简单的例子开始,比如这里的“hello triangle”:khronos.org/assets/uploads/books/… 然后“二等分”你的代码和示例,直到您找到问题为止。
  • 还要特别注意纹理过滤和“ST_clamp”等模式。在尝试更改之前,请确保您阅读了所有文档并将其配置为类似于工作示例

标签: opengl-es webgl


【解决方案1】:

尝试添加这些

    gl.texParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
    gl.texParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
    gl.texParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
    gl.texParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);

【讨论】:

    【解决方案2】:

    我说:

    gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);  
    gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
    

    在我的 activeTexture 和 bindTexture 调用之间,它对我有用。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-04-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多