Search in sources :

Example 6 with WebGLTexture

use of com.google.gwt.webgl.client.WebGLTexture in project playn by threerings.

the class WebGLDemo method createTexture.

private WebGLTexture createTexture(String url) {
    // Create the texture object.
    final WebGLTexture tex = gl.createTexture();
    // Load the image.
    final ImageElement img = createImage();
    img.setSrc(url);
    hookOnLoad(img, new EventHandler() {

        @Override
        public void onEvent(NativeEvent e) {
            // Load image data into the texture object once it's loaded.
            gl.bindTexture(TEXTURE_2D, tex);
            gl.texImage2D(TEXTURE_2D, 0, RGBA, RGBA, UNSIGNED_BYTE, img);
            gl.texParameteri(TEXTURE_2D, TEXTURE_MAG_FILTER, LINEAR);
            gl.texParameteri(TEXTURE_2D, TEXTURE_MIN_FILTER, LINEAR);
            gl.texParameteri(TEXTURE_2D, TEXTURE_WRAP_S, CLAMP_TO_EDGE);
            gl.texParameteri(TEXTURE_2D, TEXTURE_WRAP_T, CLAMP_TO_EDGE);
            gl.bindTexture(TEXTURE_2D, null);
        }
    });
    return tex;
}
Also used : WebGLTexture(com.google.gwt.webgl.client.WebGLTexture) ImageElement(com.google.gwt.dom.client.ImageElement) NativeEvent(com.google.gwt.dom.client.NativeEvent)

Aggregations

WebGLTexture (com.google.gwt.webgl.client.WebGLTexture)6 ImageElement (com.google.gwt.dom.client.ImageElement)1 NativeEvent (com.google.gwt.dom.client.NativeEvent)1 WebGLRenderbuffer (com.google.gwt.webgl.client.WebGLRenderbuffer)1