说真的,我对这段代码感到生气,因为不行:
switch(particle) {
case 0:
glBegin(GL_TRIANGLE_STRIP); // STONE
glNormal3f(0.0f, 0.0f, 1.0f);
glTexCoord2d(1, 1); glVertex3f(x+size, y+size, 0.0f); // Top Right
glTexCoord2d(0.5, 1); glVertex3f(x-size, y+size, 0.0f); // Top Left
glTexCoord2d(1, 0.5); glVertex3f(x+size, y-size, 0.0f); // Bottom Right
glTexCoord2d(0.5, 0.5); glVertex3f(x-size, y-size, 0.0f); // Bottom Left
glEnd();
break;
case 1:
glBegin(GL_TRIANGLE_STRIP); // EARTH
glNormal3f(0.0f, 0.0f, 1.0f);
glTexCoord2d(0.5, 0.5); glVertex3f(x+size, y+size, 0.0f); // Top Right
glTexCoord2d(0, 0.5); glVertex3f(x-size, y+size, 0.0f); // Top Left
glTexCoord2d(0.5, 0); glVertex3f(x+size, y-size, 0.0f); // Bottom Right
glTexCoord2d(0, 0); glVertex3f(x-size, y-size, 0.0f); // Bottom Left
glEnd();
break;
}
案例0工作正常,但案例1没有,我不知道为什么... 这是图像(32x32,带有两个16x16子纹理):
答案 0 :(得分:4)
给那个案例0显然工作正常,案例1的纹理坐标是错误的。他们应该是:
glBegin(GL_TRIANGLE_STRIP); // EARTH
glNormal3f(0.0f, 0.0f, 1.0f);
glTexCoord2d(0.5, 1.0); glVertex3f(x+size, y+size, 0.0f); // Top Right
glTexCoord2d(0, 1.0); glVertex3f(x-size, y+size, 0.0f); // Top Left
glTexCoord2d(0.5, 0.5); glVertex3f(x+size, y-size, 0.0f); // Bottom Right
glTexCoord2d(0, 0.5); glVertex3f(x-size, y-size, 0.0f); // Bottom Left
glEnd();