我必须有 6 个四边形组成一个立方体,我想将不同的纹理绑定到每个四边形。我怎么能这样做?这是我到目前为止所拥有的:
glPushMatrix(); {
glTranslatef(x, y, z);
glBegin(GL_QUADS);
{
//FrontFace
if(id != Blocks.Air){
setTexCords = true;
glColor3f(1, 1, 1);
id.getFrontTexture().bind();
}else{
setTexCords = false;
if(textureType == "IMAGE"){
}else{
glColor3d(toFloatColor(tid.getRed()), toFloatColor(tid.getGreen()), toFloatColor(tid.getBlue()));
}
}
if(setTexCords) glTexCoord2f(0, 0);
glVertex3f(-Blocks.BLOCK_SIZE,-Blocks.BLOCK_SIZE,Blocks.BLOCK_SIZE);
if(setTexCords) glTexCoord2f(0, 1);
glVertex3f(Blocks.BLOCK_SIZE,-Blocks.BLOCK_SIZE,Blocks.BLOCK_SIZE);
if(setTexCords) glTexCoord2f(1, 1);
glVertex3f(Blocks.BLOCK_SIZE,Blocks.BLOCK_SIZE,Blocks.BLOCK_SIZE);
if(setTexCords) glTexCoord2f(1, 0);
glVertex3f(-Blocks.BLOCK_SIZE,Blocks.BLOCK_SIZE,Blocks.BLOCK_SIZE);
{
glEnd();
glBegin(GL_QUADS);
{
//BackFace
if(id != Blocks.Air){
setTexCords = true;
id.getBackTexture().bind();
}else{
setTexCords = false;
if(textureType == "IMAGE"){
}else{
glColor3d(toFloatColor(tid.getRed()), toFloatColor(tid.getGreen()), toFloatColor(tid.getBlue()));
}
}
if(setTexCords) glTexCoord2f(0, 0);
glVertex3f(-Blocks.BLOCK_SIZE,-Blocks.BLOCK_SIZE,-Blocks.BLOCK_SIZE);
if(setTexCords) glTexCoord2f(0, 1);
glVertex3f(-Blocks.BLOCK_SIZE,Blocks.BLOCK_SIZE,-Blocks.BLOCK_SIZE);
if(setTexCords) glTexCoord2f(1, 1);
glVertex3f(Blocks.BLOCK_SIZE,Blocks.BLOCK_SIZE,-Blocks.BLOCK_SIZE);
if(setTexCords) glTexCoord2f(1, 0);
glVertex3f(Blocks.BLOCK_SIZE,-Blocks.BLOCK_SIZE,-Blocks.BLOCK_SIZE);
}
glEnd();
glBegin(GL_QUADS);
{
//BottomFace
if(id != Blocks.Air){
setTexCords = true;
id.getBottomTexture().bind();
}else{
setTexCords = false;
if(textureType == "IMAGE"){
}else{
glColor3d(toFloatColor(tid.getRed()), toFloatColor(tid.getGreen()), toFloatColor(tid.getBlue()));
}
}
if(setTexCords) glTexCoord2f(0, 0);
glVertex3f(-Blocks.BLOCK_SIZE,-Blocks.BLOCK_SIZE,-Blocks.BLOCK_SIZE);
if(setTexCords) glTexCoord2f(0, 1);
glVertex3f(-Blocks.BLOCK_SIZE,-Blocks.BLOCK_SIZE,Blocks.BLOCK_SIZE);
if(setTexCords) glTexCoord2f(1, 1);
glVertex3f(-Blocks.BLOCK_SIZE,Blocks.BLOCK_SIZE,Blocks.BLOCK_SIZE);
if(setTexCords) glTexCoord2f(1, 0);
glVertex3f(-Blocks.BLOCK_SIZE,Blocks.BLOCK_SIZE,-Blocks.BLOCK_SIZE);
}
glEnd();
glBegin(GL_QUADS);
{
//TopFace
if(id != Blocks.Air){
glColor3f(1, 1, 1);
setTexCords = true;
id.getTopTexture().bind();
}else{
setTexCords = false;
if(textureType == "IMAGE"){
}else{
glColor3d(toFloatColor(tid.getRed()), toFloatColor(tid.getGreen()), toFloatColor(tid.getBlue()));
}
}
if(setTexCords) glTexCoord2f(0, 0);
glVertex3f(Blocks.BLOCK_SIZE,-Blocks.BLOCK_SIZE,-Blocks.BLOCK_SIZE);
if(setTexCords) glTexCoord2f(0, 1);
glVertex3f(Blocks.BLOCK_SIZE,-Blocks.BLOCK_SIZE,Blocks.BLOCK_SIZE);
if(setTexCords) glTexCoord2f(1, 1);
glVertex3f(Blocks.BLOCK_SIZE,Blocks.BLOCK_SIZE,Blocks.BLOCK_SIZE);
if(setTexCords) glTexCoord2f(1, 0);
glVertex3f(Blocks.BLOCK_SIZE,Blocks.BLOCK_SIZE,-Blocks.BLOCK_SIZE);
}
glEnd();
glBegin(GL_QUADS);
{
//LeftFace
if(id != Blocks.Air){
setTexCords = true;
id.getLeftTexture().bind();
}else{
setTexCords = false;
if(textureType == "IMAGE"){
}else{
glColor3d(toFloatColor(tid.getRed()), toFloatColor(tid.getGreen()), toFloatColor(tid.getBlue()));
}
}
if(setTexCords) glTexCoord2f(0, 0);
glVertex3f(-Blocks.BLOCK_SIZE,-Blocks.BLOCK_SIZE,-Blocks.BLOCK_SIZE);
if(setTexCords) glTexCoord2f(0, 1);
glVertex3f(Blocks.BLOCK_SIZE,-Blocks.BLOCK_SIZE,-Blocks.BLOCK_SIZE);
if(setTexCords) glTexCoord2f(1, 1);
glVertex3f(Blocks.BLOCK_SIZE,-Blocks.BLOCK_SIZE,Blocks.BLOCK_SIZE);
if(setTexCords) glTexCoord2f(1, 0);
glVertex3f(-Blocks.BLOCK_SIZE,-Blocks.BLOCK_SIZE,Blocks.BLOCK_SIZE);
}
glEnd();
glBegin(GL_QUADS);
{
//Right Face
if(id != Blocks.Air){
setTexCords = true;
id.getRightTexture().bind();
}else{
setTexCords = false;
if(textureType == "IMAGE"){
}else{
glColor3d(toFloatColor(tid.getRed()), toFloatColor(tid.getGreen()), toFloatColor(tid.getBlue()));
}
}
if(textureType == "IMAGE"){
}else{
glColor3d(toFloatColor(tid.getRed()), toFloatColor(tid.getGreen()), toFloatColor(tid.getBlue()));
}
if(setTexCords) glTexCoord2f(0, 0);
glVertex3f(-Blocks.BLOCK_SIZE,Blocks.BLOCK_SIZE,-Blocks.BLOCK_SIZE);
if(setTexCords) glTexCoord2f(0, 1);
glVertex3f(Blocks.BLOCK_SIZE,Blocks.BLOCK_SIZE,-Blocks.BLOCK_SIZE);
if(setTexCords) glTexCoord2f(1, 1);
glVertex3f(Blocks.BLOCK_SIZE,Blocks.BLOCK_SIZE,Blocks.BLOCK_SIZE);
if(setTexCords) glTexCoord2f(1, 0);
glVertex3f(-Blocks.BLOCK_SIZE,Blocks.BLOCK_SIZE,Blocks.BLOCK_SIZE);
}
glEnd();
}
glPopMatrix();
每次我运行应用程序时,顶部都会变黑,其余的都是相同的纹理。谢谢你的帮助!