Problem to create and texturing a sphere in opengl

I have a problem with a code to create and texturing a sphere. Can you help me please? Obs.: My texture has 259 width by 194 height

var theta = 2 * Math.PI;
var phi = Math.PI;
var u = 0;
var v = 0;
var deltaUV = 1 / 20;

gl.beginShape(gl.TRIANGLE_STRIP);

for (var i = 0.0; i < phi; i += phi / 20) {
    for (var j = 0.0; j < theta; j += theta / 20) {
        x = radius * Math.cos(j) * Math.sin(i);
        y = radius * Math.sin(j) * Math.sin(i);
        z = radius * Math.cos(i);

        u = Math.atan2(x, z) / (2.0 * Math.PI) + 0.5;
        v = Math.asin(y) / Math.PI + 0.5;

        gl.vertex(x, y, z, u * 259, v * 194);

        x = radius * Math.cos(j) * Math.sin(i + Math.PI / 20);
        y = radius * Math.sin(j) * Math.sin(i + Math.PI / 20);
        z = radius * Math.cos(i + Math.PI / 20);

        gl.vertex(x, y, z, u * 259, v * 194);
    }
}

gl.endShape();

Imagem1

Answers

This discussion has been closed.