0
我必须组成一个立方体的6个四边形,我想绑定不同的纹理到每个四边形。我到底该怎么做?这是我到目前为止有:openGL绑定多个纹理四边形
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();
我每次运行应用程序前刚刚出现的黑色,其余都是相同的纹理。 感谢您的帮助!
您不能在固定函数GL中使用数组纹理。 –
@NicolBolas:嗯,我建议除了放弃固定功能之外,还要使用纹理阵列。 – datenwolf
我更新了我的代码以现在使用Vertex数组,但是非常感谢 – APerson