WebGL纹理贴图报错"RENDER WARNING: texture bound to texture unit 0 is not renderable..."

使用WebGL纹理贴图报错:

RENDER WARNING: texture bound to texture unit 0 is not renderable. It maybe non-power-of-2 and have incompatible texture filtering.

本以为是使用的图片宽高不是二次幂的原因,加上对纹理对象属性的处理,设置水平和垂直如何填充的时候,设置成水平和垂直拉伸

gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
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);

结果并没有生效,后发现是渲染纹理的时候纹理还未加载,解决方法是将渲染纹理的代码放在加载纹理代码的回调函数中。

猜你喜欢

转载自blog.csdn.net/qimingweikun/article/details/80155238