2

I want to bind two different textures to a cube using the Texture class of Slick. The problem is that the first Texture I bind to the cube is shown correct, namely pixelwise but the other one I bind to the sides of the cube is blurred, as if I haven't entered

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

This is the code that renders the cube

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

}
Jack
  • 16,506
  • 19
  • 100
  • 167
skappler
  • 722
  • 1
  • 10
  • 26

1 Answers1

2

If you want both textures to be "blurry" as you call it, you need to bind each texture individually, and call the following functions.

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

If you them to be pixelated / "not blurry" you can call the following functions instead.

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

Remember that you need to call them individually, like this.

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);
vallentin
  • 23,478
  • 6
  • 59
  • 81
  • I think you have Nearest and Linear mixed up. Linear provides the "blurry" kind of effect, while nearest gives the pixelated effect. Image filtering: http://slick.ninjacave.com/wiki/index.php?title=Image#Image_Filtering – Samich Feb 13 '14 at 02:06
  • @Samich Thanks for pointing that out, it was simply a typo from my part. – vallentin Feb 13 '14 at 02:40