Answer the question
In order to leave comments, you need to log in
Javascript image.onload - how to find out the object that set the call?
How to find out who created or initiated an event call in JavaScript?
Now more about the task - loading a texture in WebGL. I implemented like this:
Texture.prototype.loadImage = function(url) {
image = new Image();
image.owner = this; // смело, но гложет червь сомнения
image.onload = function() {
gl.bindTexture(gl.TEXTURE_2D, this.owner.texture);
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, image);
}
image.src = url;
}
image.owner = this;
Answer the question
In order to leave comments, you need to log in
Texture.prototype.loadImage = function(url) {
var image = new Image();
var self = this;
image.onload = function() {
gl.bindTexture(gl.TEXTURE_2D, self.texture);
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, image);
}
image.src = url;
}
Texture.prototype.loadImage = function(url) {
var image = new Image();
image.onload = function() {
gl.bindTexture(gl.TEXTURE_2D, this.texture);
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, image);
}.bind(this);
image.src = url;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question