WebGL CORS error loading simple texture in Chrome
Posted
by
mathacka
on Game Development
See other posts from Game Development
or by mathacka
Published on 2013-10-27T18:13:41Z
Indexed on
2013/10/27
22:02 UTC
Read the original article
Hit count: 437
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".
© Game Development or respective owner