Problem while loading texture image via synchronous Ajax + Blob

717 views
Skip to first unread message

Danilo Guanabara

unread,
Nov 12, 2012, 7:25:57 PM11/12/12
to chromium...@chromium.org
Greetings,
I'm trying to load a image to bind on a WebGL texture using the following code:

AEngine.Image = function(url) {
var xhr = new XMLHttpRequest();
xhr.open("GET",directory,0);
xhr.overrideMimeType("text/plain; charset=x-user-defined");
xhr.send();
var response = xhr.responseText;
var buffer = new Uint8Array(response.length);
for (var i=0; i < buffer.length; i++)
buffer[i] = response.charCodeAt(i);
var blob = new Blob([buffer], {"type":"image/jpeg"});
var img = document.createElement("img");
img.src = window.URL.createObjectURL(blob);
return img;
}

The image is loading fine and I can see it by appending to my document's body.
But why can't I bind it to a WebGL texture? (It says: "WebGL: INVALID_VALUE: texImage2D: invalid image")
Why can't I draw it on a 2D context canvas?

Is there any way to load the textures synchronously? 

Thanks in advance,
Danilo Guanabara

Danilo Guanabara Fernandes

unread,
Nov 12, 2012, 7:38:43 PM11/12/12
to chromium...@chromium.org
I used the wrong term. I mean uploading the image to the current texture, not binding.

2012/11/12 Danilo Guanabara <dang...@gmail.com>

--
Chromium Discussion mailing list: chromium...@chromium.org
View archives, change email options, or unsubscribe:
http://groups.google.com/a/chromium.org/group/chromium-discuss

Yang, Jin A

unread,
Nov 13, 2012, 2:00:22 AM11/13/12
to dang...@gmail.com, chromium...@chromium.org

The image is not ready until image.onload has been called. So it reports invalid image. I think you should upload your image to texture in the image.onload callback. Hope it helps.

 

Regards,

Jin

Reply all
Reply to author
Forward
0 new messages