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