webgl icon indicating copy to clipboard operation
webgl copied to clipboard

Wishlist: binding for: new Image

Open udhos opened this issue 10 years ago • 2 comments

Want constructor for javascript Image.

I am currently using this work-around:

func newImage() *js.Object {
    return js.Global.Call("eval", "(new Image())")
}

image := newImage()
image.Set("onload", func() {
    //go onLoad(gl, t, textureURL) // call onload handling goroutine
})
image.Set("src", textureURL)

udhos avatar Jun 08 '15 17:06 udhos

This is also a valid feature request. This is WebGL-specific (and therefore less portable), unlike #11, but it is faster because image decoding happens in fast browser (C++) code rather than in compiled JavaScript (see relevant discussion here).

Note that you don't need to use eval in your current workaround, instead do this:

func newImage() *js.Object {
    return js.Global.Get("Image").New()
}

dmitshur avatar Jun 09 '15 08:06 dmitshur

Thanks for the hint about js.Global.Get("Image").New() !

udhos avatar Jun 09 '15 16:06 udhos