如何使跨来源资源共享与WebGL纹理正常工作?我想我已经采取了我需要的所有步骤。
-
图像位于
http://localhost:15555/imgbuttons/nexthand.png
。 -
JavaScript代码为:
var res = new Image(); res.crossorigin = "anonymous"; res.onload = function () { if (ondone) { var tex = new cc.Texture2D(); tex.initWithElement(res); tex.handleLoadedTexture(); ondone(tex); } res = null; }; res.src = "http://localhost:15555/imgbuttons/nexthand.png";
如果
.handleLoadedTexture()
在以下线路上发生故障:gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, this._htmlElementObj);
其中,
this._htmlElementObj
是上述Image
。 -
服务器发送带有以下响应标头的图像:
Access-Control-Allow-Credentials:true Access-Control-Allow-Methods:GET Access-Control-Allow-Origin:*
这不应该是所有必需的原料吗?我错过了什么?
我注意到Origin: null
在请求头中是而不是。也许这就是问题所在,但我不确定为什么不是——res.crossorigin = "anonymous";
不应该解决这个问题吗?
Doh!原因是该属性区分大小写,实际上称为crossOrigin
:
res.crossOrigin = "anonymous";