【问题标题】:What's wrong with my texture rendering?我的纹理渲染有什么问题?
【发布时间】:2016-08-05 13:48:35
【问题描述】:

我正在尝试在 opengl/processing3 中渲染地砖。

这是我的代码:

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();
    }
  }
}

这是纹理:

然而,最终的结果看起来很糟糕!

为什么?

【问题讨论】:

    标签: opengl textures processing


    【解决方案1】:

    看起来你的四边形大小 = 64,但你在 x 和 z 方向上移动了 32。我认为你在这里有交叉点。尝试替换为:

    translate(x*64.0,0.0,z*64.0);
    

    【讨论】:

      猜你喜欢
      • 2013-11-09
      • 1970-01-01
      • 1970-01-01
      • 2018-03-18
      • 2014-10-26
      • 1970-01-01
      • 1970-01-01
      • 2010-11-20
      • 1970-01-01
      相关资源
      最近更新 更多