以下程序在使用底层 OpenGL 处理时正确渲染了带纹理的四边形。纹理在此处
PShape s;
void setup() {
size(800, 800, P3D);
PImage ringtexture = loadImage("saturnringcolor.jpg");
textureMode(NORMAL);
fill(150, 0, 0);
s = createShape();
s.beginShape();
s.texture(ringtexture);
final float INSET = 10;
final float x1 = INSET, x2 = width - INSET;
final float y1 = INSET, y2 = height - INSET;
s.vertex(x1+50, y1, 0, 0);
s.vertex(x2-50, y1, 1, 0);
s.vertex(x2, y2, 1, 1);
s.vertex(x1, y2, 0, 1);
s.endShape();
background(0);
shape(s);
}
当我创建一个包含多个四边形的环并尝试应用纹理时,它只是一种米色。
void setup() {
size(800,800,P3D);
PImage ringtexture = loadImage("saturnringcolor.jpg");
PShape s = createShape();
s.beginShape(QUADS);
s.noStroke();
float r2 = 250, r = 200;
float nexta;
s.texture(ringtexture);
for (float a = 0; a < PI*2; a = nexta) {
nexta = a + PI / 30;
// Define the 4 corners of the quad
s.vertex(r2 * cos(a), r2 * sin(a), 0, 0);
s.vertex(r2 * cos(nexta), r2 * sin(nexta), 1, 0);
s.vertex(r * cos(nexta), r * sin(nexta), 1, 1);
s.vertex(r * cos(a), r * sin(a), 0, 1);
}
s.endShape();
background(0);
translate(width/2, height/2);
shape(s);
}
除此之外,还有一张单独的透明图像,因为土星环有间隙。我想我必须将这两幅图像合并起来,并以支持它的格式获取 alpha 通道。那么将 jpeg 更改为 png 吗?