WebGL CORS error loading simple texture in Chrome
- by mathacka
Here's my code:
function loadTexture() {
textureImage = new Image();
textureImage.onload = function() {
setupTexture();
}
textureImage.src = "jumper2.png";
}
function setupTexture() {
texture = gl.createTexture();
gl.bindTexture(gl.TEXTURE_2D, texture);
gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, true);
// this next line has the error: Uncaught SecurityError: An attempt was made to break through the security policy of the user agent.
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, textureImage);
gl.texParameteri(gl.TEXTURE_2D, gl.OES_TEXTURE_FLOAT_LINEAR, gl.NEAREST);
if (!gl.isTexture(texture)) {
alert("Error: Texture is invalid");
}
glProgram.samplerUniform = gl.getUniformLocation(glProgram, "uSampler");
gl.uniform1i(glProgram.samplerUniform, 0);
}
I've researched it and it is a CORS error a "Cross-origin resource sharing" error, but it's a local file! I can't figure out what's wrong.
I did make the picture using gimp, and I'm not sure the coding was right on the export, but I eliminated a previous error using "gl.OES_TEXTURE_FLOAT_LINEAR".