2013-07-30 4 views
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(); 

내가 앱을 실행할 때마다 상단이 검게 나타나고 나머지는 같은 텍스처입니다. 도움 주셔서 감사합니다!

답변

0

glBegin/glEnd 블록 내에서 텍스처 바인딩을 변경할 수 없습니다. 이것은 프리미티브가 그려지지 않은 상태에서 변경되어야하는 상태입니다. 즉 : 직접 모드라고도하는 glBegin/glEnd는 사용하지 마십시오. 현대의 OpenGL에서 사용되지 않으며 제거되었습니다. 대신 Vertex Buffer Object (VBO)와 함께 Vertex Arrays를 사용하십시오.

또한 텍스처를 전환하는 대신 텍스처 배열을 사용해야합니다.

+0

고정 함수 GL에서 배열 텍스처를 사용할 수 없습니다. –

+0

@NicolBolas : 글쎄, 고정 배열 기능을 버리는 것 외에도 텍스처 배열을 사용할 것을 제안했습니다. – datenwolf

+0

버텍스 배열을 사용하도록 코드를 업데이트했으나 어쨌든 고마워요. – APerson