|
Author |
Topic: texture on a sphere (Read 457 times) |
|
tobt
|
texture on a sphere
« on: Jul 20th, 2004, 5:21pm » |
|
i would like to map a texture to a sphere. in one thread i read about loading an image and place it with texture(theimage) in the beginShape, endShape term. in another thread i read about to draw a sphere by using the following method. (from toxi.) but how can i put these two elements together? (How works the texture() - there is no reference) thanks, tobt. CODE: void xsphere(float r) { if (g.sphere_detail == 0) { sphereDetail(30); } int sd=g.sphere_detail; float[] sx=g.sphereX; float[] sy=g.sphereY; float[] sz=g.sphereZ; int v1,v2; push(); // scale(r); // REMOVED!!! // 1st ring from south pole beginShape(TRIANGLE_STRIP); for (int i = 0; i <= sd; i++) { v2 = i % sd; vertex(0, -r, 0); vertex(sx[v2]*r, sy[v2]*r, sz[v2]*r); } endShape(); // middle rings int voff = 0; for(int i = 2; i < sd; i++) { voff += sd; beginShape(TRIANGLE_STRIP); for (int j = 0; j <= sd; j++) { v1 = voff - sd + j % sd; v2 = voff + j % sd; vertex(sx[v1]*r, sy[v1]*r, sz[v1]*r); vertex(sx[v2]*r, sy[v2]*r, sz[v2]*r); } endShape(); } // add the northern cap beginShape(TRIANGLE_STRIP); for (int i = 0; i <= sd; i++) { v2 = voff + i % sd; vertex(0, r, 0); vertex(sx[v2]*r, sy[v2]*r, sz[v2]*r); } endShape(); pop(); } }
|
« Last Edit: Jul 20th, 2004, 5:21pm by tobt » |
|
|
|
|
|