Results 1 to 4 of 4

Thread: problem about "gl.texImage2D" function

  1. #1
    Junior Member
    Join Date
    Feb 2012
    Posts
    3

    problem about "gl.texImage2D" function

    about my program:

    var imgSrc = "XXX.gif";
    var texture = gl.createTexture();
    texture.image = new Image();
    texture.onload = function(){
    gl.bindTexture(gl.TEXTURE_2D,texture);
    gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL,true);
    gl.texImage2D(gl.TEXTURE_2D,0,gl.RGBA,gl.RGBA,gl.U NSIGNED_BYTE,texture.image);
    gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
    gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
    gl.bindTexture(gl.TEXTURE_2D, null);
    };
    texture.image.src = imgSrc;

    problem:
    the error firefox tell me is happen on the line

    "gl.texImage2D(gl.TEXTURE_2D,0,gl.RGBA,gl.RGBA,gl. UNSIGNED_BYTE,texture.image);

    but the URL of the image is correct,so I think the error is on "put image to graphic card's texture space"

    but I have no idea how to solve this error

  2. #2
    Junior Member
    Join Date
    Feb 2012
    Posts
    3

    Re: problem about "gl.texImage2D" function

    the message firefox says

    error: uncaught exception: [Exception... "Failure arg 5 [nsIDOMWebGLRenderingContext.texImage2D]" nsresult: "0x80004005 (NS_ERROR_FAILURE)" location: "JS frame :: file:///E:/%E5%B0%88%E9%A1%8C(%E6%9C%89bug)/code/Painter.js :: <TOP_LEVEL> :: line 11" data: no]

    line 11 is the place gl.texImage2D function

  3. #3
    Junior Member
    Join Date
    Feb 2012
    Posts
    3

    Re: problem about "gl.texImage2D" function

    How amazing

    var imgSrc = "XXX.gif";
    var texture = gl.createTexture();
    texture.image = new Image();
    texture.image.src = imgSrc;//<----- 1
    texture.onload = function(){
    gl.bindTexture(gl.TEXTURE_2D,texture);
    gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL,true);
    gl.texImage2D(gl.TEXTURE_2D,0,gl.RGBA,gl.RGBA,gl.U NSIGNED_BYTE,texture.image);
    gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
    gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
    //gl.bindTexture(gl.TEXTURE_2D, null);//<------ 2
    };

    I put 1 to the front and comment 2 and the program run~~

    Is there any one can tell me why?

  4. #4
    Junior Member
    Join Date
    Mar 2012
    Posts
    3

    Re: problem about "gl.texImage2D" function

    because you are doing it wrong

    you need to set the onload event for image in the texture, not the texture. because image is loaded asynchronously and you want to wait untill it is loaded and the n perform the actions.

    so instead of texture.onload = ... use texture.image.onload = ...

Similar Threads

  1. Replies: 1
    Last Post: 02-29-2012, 06:34 PM
  2. include files using "I -dir" function
    By yakovm in forum OpenCL
    Replies: 3
    Last Post: 07-26-2011, 05:21 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •