我正在尝试在opengl / processing3中渲染floortiles。
这是我的代码:
PImage floorImage;
void setup() {
size(1200, 600, P3D);
smooth(8);
floorImage = loadImage("floor3.png");
}
void draw() {
background(0);
ambientLight(255,255,255);
camera(0.0,100.0,-300.0,mouseX-width/2.0,-(mouseY-height/2.0),0.0,0.0,-1.0,0.0);
for(int x=-20;x<20;x++)
{
for(int z=-20;z<20;z++)
{
pushMatrix();
translate(x*32.0,0.0,z*32.0);
beginShape();
textureMode(NORMAL);
texture(floorImage);
vertex(-32.0,0.0,-32.0,0.0,0.0);
vertex(32.0,0.0,-32.0,1.0,0.0);
vertex(32.0,0.0,32.0,1.0,1.0);
vertex(-32.0,0.0,32.0,0.0,1.0);
endShape(CLOSE);
popMatrix();
}
}
}
然而,最终结果看起来很糟糕!
为什么?
答案 0 :(得分:2)
看起来你有四个尺寸= 64,但你在x和z方向上移动了32个。我想你在这里有交叉点。尝试替换为:
#include <string>