hello people. i have a problem with binding sprites.
the sprite atlas size i want to load is 64x32 pixels and contains 2 sprites. i load it into a spritesheet with:
sprite = new SpriteSheet("res/image3.png", 32, 32);
in my rendering procedure i try to print the second sprite onto a quad by doing this:
sprite.getSprite(1, 0).bind();
GL11.glBegin(GL11.GL_QUADS);
GL11.glTexCoord2f(0,0);
GL11.glVertex2f(0,0);
GL11.glTexCoord2f(1f,0);
GL11.glVertex2f(32,0);
GL11.glTexCoord2f(1f,1);
GL11.glVertex2f(32,32);
GL11.glTexCoord2f(0,1);
GL11.glVertex2f(0,32);
GL11.glEnd();
instead of showing only the second sprite it shows me both (scaled to 32pixels).
(http://www.abload.de/thumb/clipboard01i0jvw.png) (http://www.abload.de/image.php?img=clipboard01i0jvw.png)
i don't understand why it is not simply binding only the second sprite. thanks for your help.
your resizing the quad, what you need to do is set the correct texture values instead (i.e. amend glTexCoord2f values and not glVertex2f).
i tried this too. with that i was just able to print the FIRST sprite by doing:
GL11.glBegin(GL11.GL_QUADS);
GL11.glTexCoord2f(0,0);
GL11.glVertex2f(0,0);
GL11.glTexCoord2f(0.5f,0); //changed 1f to 0.5f
GL11.glVertex2f(32,0);
GL11.glTexCoord2f(0.5f,1); //changed 1f to 0.5f
GL11.glVertex2f(32,32);
GL11.glTexCoord2f(0,1);
GL11.glVertex2f(0,32);
GL11.glEnd();
i don't know how to print the second sprite by changing glTexCoord2f.
I assume SpriteSheet is from Slick.
From looking at the documentation (http://slick.cokeandcode.com/javadoc/org/newdawn/slick/SpriteSheet.html), it looks like you need to do the following:
sprite.startUse();
sprite.renderInUse(x, y, 1, 0);
sprite.endUse();