0
\$\begingroup\$

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".

\$\endgroup\$
2
  • \$\begingroup\$ Can you be more specific about the exact problem you're having? \$\endgroup\$
    – House
    Oct 27, 2013 at 18:24
  • \$\begingroup\$ it's producing a black box without a texture, and it's producing the webgl error in chrome: Uncaught SecurityError: An attempt was made to break through the security policy of the user agent." \$\endgroup\$ Oct 27, 2013 at 18:28

1 Answer 1

0
\$\begingroup\$

I found the problem, it needs to be run from a web server to bypass the security policy, then it can access the local files as they are set up in the server.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .