纹理坐标不起作用?

时间:2011-08-05 20:42:47

标签: java opengl texture-mapping

说真的,我对这段代码感到生气,因为不行:

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子纹理):

enter image description here

1 个答案:

答案 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();