一个光滑的纹理是模糊的,一个不是

时间:2012-11-20 16:24:19

标签: java opengl lwjgl slick2d

我想使用Slick的Texture类将两个不同的纹理绑定到一个立方体。 问题是我绑定到立方体的第一个纹理是正确的,即按像素,但另一个我绑定到立方体的边是模糊的,好像我还没有进入

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);

这是呈现多维数据集的代码

    public void render(){
    float x = coordinate.x;
    float y = coordinate.y;
    float z = coordinate.z;

    top.bind();
    glBegin(GL_QUADS);

        //TOP
        glNormal3f(0f, 1f, 0f);
        glTexCoord2f(0f, 0f);
        glVertex3f(x,y,z);
        glTexCoord2f(0f, 1f);
        glVertex3f(x, y, z+1);
        glTexCoord2f(1f, 1f);
        glVertex3f(x+1, y, z+1);
        glTexCoord2f(1f, 0f);
        glVertex3f(x+1, y, z);
    glEnd();

    bottom.bind();
    glBegin(GL_QUADS);
        //BOTTOM
        glNormal3f(0f, -1f, 0f);
        glTexCoord2f(0f, 0f);
        glVertex3f(x,y-1,z);
        glTexCoord2f(0f, 1f);
        glVertex3f(x, y-1, z+1);
        glTexCoord2f(1f, 1f);
        glVertex3f(x+1, y-1, z+1);
        glTexCoord2f(1f, 0f);
        glVertex3f(x+1, y-1, z);
    glEnd();

    sides.bind();
    glBegin(GL_QUADS);
        //BACK
        glNormal3f(0,0,-1);
        glTexCoord2f(0f, 0f);
        glVertex3f(x,y,z);
        glTexCoord2f(1f, 0f);
        glVertex3f(x+1, y, z);
        glTexCoord2f(1f, 1f);
        glVertex3f(x+1, y-1, z);
        glTexCoord2f(0f, 1f);
        glVertex3f(x, y-1, z);

        //FRONT
        glNormal3f(0,0,1);
        glTexCoord2f(0f, 0f);
        glVertex3f(x,y,z+1);
        glTexCoord2f(1f, 0f);
        glVertex3f(x+1, y, z+1);
        glTexCoord2f(1f, 1f);
        glVertex3f(x+1, y-1, z+1);
        glTexCoord2f(0f, 1f);
        glVertex3f(x, y-1, z+1);

        //LEFT
        glNormal3f(-1,0,0);
        glTexCoord2f(0f, 0f);
        glVertex3f(x,y,z);
        glTexCoord2f(0f, 1f);
        glVertex3f(x, y-1, z);
        glTexCoord2f(1f, 1f);
        glVertex3f(x, y-1, z+1);
        glTexCoord2f(1f, 0f);
        glVertex3f(x, y, z+1);

        //RIGHT
        glNormal3f(1,0,0);
        glTexCoord2f(0f, 0f);
        glVertex3f(x+1,y,z);
        glTexCoord2f(0f, 1f);
        glVertex3f(x+1, y-1, z);
        glTexCoord2f(1f, 1f);
        glVertex3f(x+1, y-1, z+1);
        glTexCoord2f(1f, 0f);
        glVertex3f(x+1, y, z+1);
    glEnd();

}

1 个答案:

答案 0 :(得分:2)

如果您希望两个纹理在调用时都“模糊”,则需要单独绑定每个纹理,并调用以下函数。

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

如果你要像素化/“不模糊”,你可以改为调用以下功能。

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);

请记住,您需要单独调用它们,就像这样。

texture1.bind();
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

texture2.bind();
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);