小编Fel*_*lix的帖子

texImage2D : XMLHttpRequest 后的图像无效

我正在使用静态文件服务器加载本地.jpg图像。

let xhr = new XMLHttpRequest();
this.isLoaded = false;
this.image = new Image();
xhr.open("GET", "http://localhost:8080/testing/ressources/" + url, true);
xhr.responseType = 'blob';

this.textureBuffer = gl.createTexture();
gl.bindTexture(gl.TEXTURE_2D, this.textureBuffer);
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, 1, 1, 0, gl.RGBA, gl.UNSIGNED_BYTE, new Uint8Array([255, 0, 0, 255]));
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
xhr.onload = (e) => {

  if (xhr.readyState === XMLHttpRequest.DONE && xhr.status === 200) {
    let blob = new Blob([xhr.response], {
      type: 'image/jpg'
    });
    let urlCreator = window.URL || window.webkitURL;
    this.image.src = urlCreator.createObjectURL(blob);

    gl.bindTexture(gl.TEXTURE_2D, …
Run Code Online (Sandbox Code Playgroud)

xmlhttprequest webgl

1
推荐指数
1
解决办法
2021
查看次数

标签 统计

webgl ×1

xmlhttprequest ×1