纹理显示顺序错误
Texture is displayed in the wrong order
我正在尝试使用 libgdx 渲染三个带有纹理的立方体,但它们渲染不正确。先绘制远处的纹理,然后再绘制近处的纹理。你能帮我解决一下吗?
示例:
这里是Block
class:
public abstract class Block {
private int x, y, z;
private ModelInstance model;
public Block(int x, int y, int z){
this.x = x;
this.y = y;
this.z = z;
OnCreate();
}
public abstract void OnCreate();
public void onDraw(){
Main.modelBatch.render(model);
}
public void setTexture(Texture texture){
ModelBuilder modelBuilder = new ModelBuilder();
modelBuilder.begin();
Material material = new Material(TextureAttribute.createDiffuse(texture));
int attributes = VertexAttributes.Usage.Position | VertexAttributes.Usage.Normal | VertexAttributes.Usage.TextureCoordinates;
modelBuilder.part("left", GL20.GL_TRIANGLES, attributes, material).rect(
createVector(0, 1, -1),
createVector(0, 0, -1),
createVector(0, 0, 0),
createVector(0, 1, 0),
null
);
modelBuilder.part("right", GL20.GL_TRIANGLES, attributes, material).rect(
createVector(1, 1, 0),
createVector(1, 0, 0),
createVector(1, 0, -1),
createVector(1, 1, -1),
null
);
modelBuilder.part("top", GL20.GL_TRIANGLES, attributes, material).rect(
createVector(0, 1, -1),
createVector(0, 1, 0),
createVector(1, 1, 0),
createVector(1, 1, -1),
null
);
modelBuilder.part("bottom", GL20.GL_TRIANGLES, attributes, material).rect(
createVector(0, 0, 0),
createVector(0, 0, -1),
createVector(1, 0, -1),
createVector(1, 0, 0),
null
);
modelBuilder.part("front", GL20.GL_TRIANGLES, attributes, material).rect(
createVector(0, 1, 0),
createVector(0, 0, 0),
createVector(1, 0, 0),
createVector(1, 1, 0),
null
);
this.model = new ModelInstance(modelBuilder.end());
}
private Vector3 createVector(float n1, int n2, int n3){
return new Vector3(n1 + x, n2 + y, n3 + z);
}
}
值 camera.near
应该大于零(我什至不知道它是如何工作的)
我正在尝试使用 libgdx 渲染三个带有纹理的立方体,但它们渲染不正确。先绘制远处的纹理,然后再绘制近处的纹理。你能帮我解决一下吗?
示例:
这里是Block
class:
public abstract class Block {
private int x, y, z;
private ModelInstance model;
public Block(int x, int y, int z){
this.x = x;
this.y = y;
this.z = z;
OnCreate();
}
public abstract void OnCreate();
public void onDraw(){
Main.modelBatch.render(model);
}
public void setTexture(Texture texture){
ModelBuilder modelBuilder = new ModelBuilder();
modelBuilder.begin();
Material material = new Material(TextureAttribute.createDiffuse(texture));
int attributes = VertexAttributes.Usage.Position | VertexAttributes.Usage.Normal | VertexAttributes.Usage.TextureCoordinates;
modelBuilder.part("left", GL20.GL_TRIANGLES, attributes, material).rect(
createVector(0, 1, -1),
createVector(0, 0, -1),
createVector(0, 0, 0),
createVector(0, 1, 0),
null
);
modelBuilder.part("right", GL20.GL_TRIANGLES, attributes, material).rect(
createVector(1, 1, 0),
createVector(1, 0, 0),
createVector(1, 0, -1),
createVector(1, 1, -1),
null
);
modelBuilder.part("top", GL20.GL_TRIANGLES, attributes, material).rect(
createVector(0, 1, -1),
createVector(0, 1, 0),
createVector(1, 1, 0),
createVector(1, 1, -1),
null
);
modelBuilder.part("bottom", GL20.GL_TRIANGLES, attributes, material).rect(
createVector(0, 0, 0),
createVector(0, 0, -1),
createVector(1, 0, -1),
createVector(1, 0, 0),
null
);
modelBuilder.part("front", GL20.GL_TRIANGLES, attributes, material).rect(
createVector(0, 1, 0),
createVector(0, 0, 0),
createVector(1, 0, 0),
createVector(1, 1, 0),
null
);
this.model = new ModelInstance(modelBuilder.end());
}
private Vector3 createVector(float n1, int n2, int n3){
return new Vector3(n1 + x, n2 + y, n3 + z);
}
}
值 camera.near
应该大于零(我什至不知道它是如何工作的)