【发布时间】:2017-05-18 06:25:21
【问题描述】:
我有一个 webgl 应用程序,我正在加载这样的纹理:
var Texture2D = function(gl, mediaFileUrl) {
mediaFileUrl = "../" + mediaFileUrl; //This is the line which not works
this.mediaFileUrl = mediaFileUrl;
this.glTexture = gl.createTexture();
this.image = new Image();
var theTexture = this;
this.image.onload = function() { theTexture.loaded(gl); } // Never gets called
this.image.src = mediaFileUrl;
};
如果我在文件系统的某处的父目录中有纹理,则它不起作用,但如果我的文件在其中一个子目录中(所以不使用 ../)它可以工作。
文件结构如下 [index.html - texture.png] - 同一文件夹 = 作品
[index.html - ../texture.png] - 父目录 = 无效
有什么办法解决这个问题吗?
更新:它现在可以在 chrome 上运行,但不能在 Firefox 上运行,这很奇怪。在 Firefox 中,如果我打开 "anonymous" 标志 (image.crossOrigin = "anonymous") ,它无法加载图像,如果我关闭,则会出现安全错误。 (错误:WebGL 警告:texImage2D:跨域元素需要 CORS)
【问题讨论】:
-
使用简单的服务器:试试Servez。有also others
标签: javascript webgl