我正在使用opengl c ++开发一个项目。我试图创建一个天空盒,我已经能够用正确的图像坐标创建具有正确纹理的所有4个面。但我在上面有一个问题。我无法正确设置图像坐标。这是代码:
glBegin(GL_QUADS); // back
glTexCoord2f(0.0f, 1.0f); glVertex3f(-size , height , -size);
glTexCoord2f(1.0f, 1.0f); glVertex3f( size , height , -size);
glTexCoord2f(1.0f, 0.0f); glVertex3f( size , -17.00f , -size);
glTexCoord2f(0.0f, 0.0f); glVertex3f(-size , -17.00f , -size);
glEnd();
//left
glBindTexture(GL_TEXTURE_2D, skytexture[1]);
glBegin(GL_QUADS);
glTexCoord2f(1.0f, 1.0f); glVertex3f(-size , height , -size);
glTexCoord2f(0.0f, 1.0f); glVertex3f(-size , height , size);
glTexCoord2f(0.0f, 0.0f); glVertex3f(-size , -17.00f , size);
glTexCoord2f(1.0f, 0.0f); glVertex3f(-size , -17.00f ,-size);
glEnd();
//front
glBindTexture(GL_TEXTURE_2D , skytexture[3]);
glBegin(GL_QUADS);
glTexCoord2f(0.0f , 1.0f);glVertex3f( size , height , size);
glTexCoord2f(1.0f , 1.0f);glVertex3f( -size , height , size);
glTexCoord2f(1.0f , 0.0f);glVertex3f( -size , -17.0f , size);
glTexCoord2f(0.0f , 0.0f);glVertex3f(size , -17.0f , size);
glEnd();
//right
glBindTexture(GL_TEXTURE_2D, skytexture[2]);
glBegin(GL_QUADS);
glTexCoord2f(0.0f , 1.0f); glVertex3f(size , height , -size);
glTexCoord2f(1.0f , 1.0f); glVertex3f(size , height , size);
glTexCoord2f(1.0f , 0.0f); glVertex3f(size , -17.00f , size);
glTexCoord2f(0.0f , 0.0f); glVertex3f(size , -17.00f ,-size);
glEnd();
// ------这是设置坐标的问题 // ------结果已被删除
//up
glBindTexture(GL_TEXTURE_2D , skytexture[4]);
glBegin(GL_QUADS);
glTexCoord2f(0.0f , 0.0f);glVertex3f(-size , height , -size);
glTexCoord2f(1.0f , 0.0f);glVertex3f( size , height , -size);
glTexCoord2f(1.0f , 1.0f);glVertex3f( size , height , size);
glTexCoord2f(0.0f , 1.0f);glVertex3f(-size , height , size);
glEnd();