Here’s a screenshot of a reduced code version illustrating how stroke(255,0,0) produces blue instead of red.
Here is the reduced code:
PGraphics texture;
PImage texmap;
float[] cx, cz, sphereX, sphereY, sphereZ;
float sinLUT[];
float cosLUT[];
float SINCOS_PRECISION = 0.5f;
float globeRadius = 597; //597;
float pushBack = -100;
int sDetail = 64; //128; // Sphere detail setting
int SINCOS_LENGTH = PApplet.parseInt(360.0f / SINCOS_PRECISION);
public void setup() {
hint(DISABLE_DEPTH_TEST);
size(1275, 750, P3D);
blendMode(SCREEN);
texmap = loadImage("alphatest.png");
texture = createGraphics(texmap.width, texmap.height);
initStars();
addDiagonalLine();
}
public void initStars() {
texture.beginDraw();
texture.image(texmap,0,0);
texture.endDraw();
}
public void addDiagonalLine() {
texture.beginDraw();
texture.stroke(255,0,0);
texture.strokeWeight(2);
texture.line(0,0,0, texture.height);
texture.line(texture.width/12, 0,texture.width/12,texture.height);
texture.line(texture.width/12*2, 0,texture.width/12*2,texture.height);
texture.line(texture.width/12*3, 0,texture.width/12*3,texture.height);
texture.line(texture.width/12*4, 0,texture.width/12*4,texture.height);
texture.line(texture.width/12*5, 0,texture.width/12*5,texture.height);
texture.line(texture.width/12*6, 0,texture.width/12*6,texture.height);
texture.line(texture.width/12*7, 0,texture.width/12*7,texture.height);
texture.line(texture.width/12*8, 0,texture.width/12*8,texture.height);
texture.line(texture.width/12*9, 0,texture.width/12*9,texture.height);
texture.line(texture.width/12*10, 0,texture.width/12*10,texture.height);
texture.line(texture.width/12*11, 0,texture.width/12*11,texture.height);
///// texture.line(texture.width/12 * 11 -texture.width/12/3, 0,texture.width/12 * 11 -texture.width/12/3,texture.height);
texture.line(texture.width/12 -texture.width/12/2, 0,texture.width/12 -texture.width/12/2,texture.height);
texture.line(texture.width/12+texture.width/12/2, 0,texture.width/12+texture.width/12/2,texture.height);
texture.line(texture.width/12/2+texture.width/12/2, 0,texture.width/12/2+texture.width/12/2,texture.height);
texture.line(texture.width/12 * 2+texture.width/12/2, 0,texture.width/12 * 2+texture.width/12/2,texture.height);
texture.line((texture.width/12 * 3)+texture.width/12/2, 0,(texture.width/12 * 3)+texture.width/12/2,texture.height);
texture.line((texture.width/12 * 4)+texture.width/12/2, 0,(texture.width/12 * 4)+texture.width/12/2,texture.height);
texture.line((texture.width/12 * 5)+texture.width/12/2, 0,(texture.width/12 * 5)+texture.width/12/2,texture.height);
texture.line((texture.width/12 * 6)+texture.width/12/2, 0,(texture.width/12 * 6)+texture.width/12/2,texture.height);
texture.line((texture.width/12 * 7)+texture.width/12/2, 0,(texture.width/12 * 7)+texture.width/12/2,texture.height);
texture.line((texture.width/12 * 8)+texture.width/12/2, 0,(texture.width/12 * 8)+texture.width/12/2,texture.height);//////////////
texture.line((texture.width/12 * 9)+texture.width/12/2, 0,(texture.width/12 * 9)+texture.width/12/2,texture.height);
texture.line((texture.width/12 * 10)+texture.width/12/2, 0,(texture.width/12 * 10)+texture.width/12/2,texture.height);
texture.line((texture.width/12 * 11)+texture.width/12/2, 0,(texture.width/12 * 11)+texture.width/12/2,texture.height);
//latitude lines
//texture
texture.stroke(255,255,255);
texture.line(0, texture.height/2,texture.width,texture.height/2); // +15 degrees
texture.stroke(255,0,0);
texture.line(0, texture.height/2/3,texture.width,texture.height/2/3); // +60 degrees
texture.line(0, texture.height/2/3 * 2,texture.width,texture.height/2/3 * 2); // +30 degrees
texture.line(0, texture.height/2/6,texture.width,texture.height/2/6 ); // +75 degrees
texture.line(0, texture.height/2/3 + texture.height/2/6,texture.width,texture.height/2/3 + texture.height/2/6); // +45 degrees
// texture.stroke(255,255,255);
texture.line(0, texture.height/2/3 * 2 + texture.height/2/6 ,texture.width,texture.height/2/3 * 2 + texture.height/2/6); // equator 0 degrees
// texture.stroke(255,255,255);
texture.line(0, texture.height/2 + texture.height/2/3/2 ,texture.width,texture.height/2 + texture.height/2/3/2); // -15 degrees
// texture.stroke(255,255,255);
// texture.line(0, texture.height/2 -texture.height/2/3 ,texture.width,texture.height/2 -texture.height/2/3); //redundant
// texture.stroke(255,255,255);
texture.line(0, texture.height - texture.height/2/3 * 2,texture.width,texture.height -texture.height/2/3 * 2); // -30 degrees
texture.line(0, texture.height -texture.height/2/3,texture.width,texture.height -texture.height/2/3); // -60 degrees
texture.line(0, texture.height - texture.height/2/3 * 2 + texture.height/2/6,texture.width,texture.height -texture.height/2/3 * 2 + texture.height/2/6); // -45 degrees
texture.line(0, texture.height -texture.height/2/3 + texture.height/2/6,texture.width,texture.height -texture.height/2/3 + texture.height/2/6); // -75 degrees
texture.endDraw();
}
public void renderGlobe() {
pushMatrix();
translate(width/2, height/2, pushBack);
pushMatrix();
noFill();
stroke(255,200);
strokeWeight(2);
smooth();
popMatrix();
lights();
pushMatrix();
rotateX(radians(90));
fill(200);
noStroke();
textureMode(IMAGE);
// texturedSphere(globeRadius, texture);
texturedSphere(globeRadius, texture);
popMatrix();
popMatrix();
}
public void initializeSphere(int res)
{
sinLUT = new float[SINCOS_LENGTH];
cosLUT = new float[SINCOS_LENGTH];
for (int i = 0; i < SINCOS_LENGTH; i++) {
sinLUT[i] = (float) Math.sin(i * DEG_TO_RAD * SINCOS_PRECISION);
cosLUT[i] = (float) Math.cos(i * DEG_TO_RAD * SINCOS_PRECISION);
}
float delta = (float)SINCOS_LENGTH/res;
float[] cx = new float[res];
float[] cz = new float[res];
// Calc unit circle in XZ plane
for (int i = 0; i < res; i++) {
cx[i] = -cosLUT[(int) (i*delta) % SINCOS_LENGTH];
cz[i] = sinLUT[(int) (i*delta) % SINCOS_LENGTH];
}
// Computing vertexlist vertexlist starts at south pole
int vertCount = res * (res-1) + 2;
int currVert = 0;
// Re-init arrays to store vertices
sphereX = new float[vertCount];
sphereY = new float[vertCount];
sphereZ = new float[vertCount];
float angle_step = (SINCOS_LENGTH*0.5f)/res;
float angle = angle_step;
// Step along Y axis
for (int i = 1; i < res; i++) {
float curradius = sinLUT[(int) angle % SINCOS_LENGTH];
float currY = -cosLUT[(int) angle % SINCOS_LENGTH];
for (int j = 0; j < res; j++) {
sphereX[currVert] = cx[j] * curradius;
sphereY[currVert] = currY;
sphereZ[currVert++] = cz[j] * curradius;
}
angle += angle_step;
}
sDetail = res;
}
// Generic routine to draw textured sphere
public void texturedSphere(float r, PGraphics t) {
int v1,v11,v2;
r = (r + 240 ) * 0.33f;
beginShape(TRIANGLE_STRIP);
texture(t);
float iu=(float)(t.width-1)/(sDetail);
float iv=(float)(t.height-1)/(sDetail);
float u=0,v=iv;
for (int i = 0; i < sDetail; i++) {
vertex(0, -r, 0,u,0);
vertex(sphereX[i]*r, sphereY[i]*r, sphereZ[i]*r, u, v);
u+=iu;
}
vertex(0, -r, 0,u,0);
vertex(sphereX[0]*r, sphereY[0]*r, sphereZ[0]*r, u, v);
endShape();
// Middle rings
int voff = 0;
for(int i = 2; i < sDetail; i++) {
v1=v11=voff;
voff += sDetail;
v2=voff;
u=0;
beginShape(TRIANGLE_STRIP);
texture(t);
for (int j = 0; j < sDetail; j++) {
vertex(sphereX[v1]*r, sphereY[v1]*r, sphereZ[v1++]*r, u, v);
vertex(sphereX[v2]*r, sphereY[v2]*r, sphereZ[v2++]*r, u, v+iv);
u+=iu;
}
// Close each ring
v1=v11;
v2=voff;
vertex(sphereX[v1]*r, sphereY[v1]*r, sphereZ[v1]*r, u, v);
vertex(sphereX[v2]*r, sphereY[v2]*r, sphereZ[v2]*r, u, v+iv);
endShape();
v+=iv;
}
u=0;
// Add the northern cap
beginShape(TRIANGLE_STRIP);
texture(t);
for (int i = 0; i < sDetail; i++) {
v2 = voff + i;
vertex(sphereX[v2]*r, sphereY[v2]*r, sphereZ[v2]*r, u, v);
vertex(0, r, 0,u,v+iv);
u+=iu;
}
vertex(sphereX[voff]*r, sphereY[voff]*r, sphereZ[voff]*r, u, v);
endShape();
}
public void draw() {
background(0);
initStars();
addDiagonalLine();
initializeSphere(sDetail);
renderGlobe();
}
Here is the blank image “alphatest.png” that should go in a directory called data.