spritesheet binding

Started by arminb, February 24, 2012, 16:07:51

Previous topic - Next topic

arminb

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).


i don't understand why it is not simply binding only the second sprite. thanks for your help.

kappa

your resizing the quad, what you need to do is set the correct texture values instead (i.e. amend glTexCoord2f values and not glVertex2f).

arminb

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.

Fool Running

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();
Programmers will, one day, rule the world... and the world won't notice until its too late.Just testing the marquee option ;D