LWJGL Forum

Programming => OpenGL => Topic started by: arminb on February 24, 2012, 16:07:51

Title: spritesheet binding
Post by: arminb on February 24, 2012, 16:07:51
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.
Title: Re: spritesheet binding
Post by: kappa on February 24, 2012, 17:57:56
your resizing the quad, what you need to do is set the correct texture values instead (i.e. amend glTexCoord2f values and not glVertex2f).
Title: Re: spritesheet binding
Post by: arminb on February 24, 2012, 18:08:34
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.
Title: Re: spritesheet binding
Post by: Fool Running on February 27, 2012, 14:00:25
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();