Haxe js webgl issue.

73 views
Skip to first unread message

Robert Śmietana

unread,
Feb 7, 2014, 2:56:57 AM2/7/14
to haxe...@googlegroups.com
I have very strange problem with setting texture from file. If I use Uint8Array instead (commented in code below) everything is ok and works. What important did I missed? Program always reaches "onload" so file is ok and it loads! Using more "untyped" constructions in various suitable places does not helps me.

public function addTexture(): Dynamic
    {
        var image: Image = untyped __js__("new Image()");
        image.src = "textures/tex0.png";
        image.onload = function(e: Event)
        {
            texture = gl.createTexture();
            gl.bindTexture(gl.TEXTURE_2D, texture);
            gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
            gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
            gl.texParameteri(gl.TEXTURE_2D, gl.GL_TEXTURE_WRAP_S, gl.CLAMP);
            gl.texParameteri(gl.TEXTURE_2D, gl.GL_TEXTURE_WRAP_T, gl.CLAMP);
            gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, 1024, 512, 0, gl.RGBA, gl.UNSIGNED_BYTE, image);
            /*
            gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, 2, 2, 0, gl.RGBA, gl.UNSIGNED_BYTE, new Uint8Array([
                255, 110, 0, 255, 255, 110, 250, 255, 255, 0, 0, 255, 55, 110, 0, 255]));
                */
        }

Robert Śmietana

unread,
Feb 8, 2014, 7:35:12 AM2/8/14
to haxe...@googlegroups.com
Solved:

public function addTexture(texture_url: String): Void
    {
        var img: Image = new Image();
        img.onload = function(e)
        {
            texture1 = gl.createTexture();
            gl.activeTexture(gl.TEXTURE1);
            gl.bindTexture(gl.TEXTURE_2D, texture1);
            gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
            gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
            gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, img);
        }
        img.src = texture_url;
    }

Reply all
Reply to author
Forward
0 new messages