webgl
webgl copied to clipboard
Wishlist: binding for: new Image
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)
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()
}
Thanks for the hint about js.Global.Get("Image").New() !