title: WebGL textures not working on some textures
body: <p>I am trying to follow a tutorial on WebGL and I am getting weird behavior with textures. I use this code to create the texture: </p>
  
  <pre><code>var tex = gl.createTexture();
  gl.bindTexture(gl.TEXTURE_2D, tex);
  
  gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
  gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
  
  gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
  gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
  
  gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, document.getElementById("img"));
  gl.bindTexture(gl.TEXTURE_2D, null);
  </code></pre>
  
  <p>I have an image in the html file that looks like this:</p>
  
  <pre><code>&lt;img id="img" src="texture.png" width="0" height="0"&gt;&lt;/img&gt;
  </code></pre>
  
  <p>Here everything is working. I have seen a way to load images in JS only that looks like this:</p>
  
  <pre><code>function loadFileAsIMG(filename) {
    var result = new Image();
    result.src = filename;
    return result;
  }
  </code></pre>
  
  <p>Adding the loaded image to HTML is working as it should. But somehow using this loaded image in the <code>gl.texImage2D</code> function doesn't work at all and produces this error message: </p>
  
  <pre><code>[Error] WebGL: INVALID_VALUE: texImage2D: invalid image
      texImage2D
      run (glmain.js:149)
      init (glmain.js:26)
      onload (index.html:11)
  </code></pre>