PDA

View Full Version : Texture Inaccuracy - Sprite's?



steadi
04-05-2013, 10:41 AM
Hello There,

I have been using OpenGL for a while now. Most of my games use a single texture with loads of sprites on it (spritesheet) and these get loaded using the following code:



//Draw
glBindTexture(GL_TEXTURE_2D, tex); ///Binds the Spritesheet Texture
glBegin(GL_POLYGON);
glTexCoord2f(tx, ty); glVertex2f(x,y);
glTexCoord2f(tx+32, ty); glVertex2f(x+32,y); ///The +32 is the W and H.
glTexCoord2f(tx+32, ty+32); glVertex2f(x+32,y+32);
glTexCoord2f(tx, ty+32); glVertex2f(x,y+32);
glEnd();

//Flip
glMatrixMode(GL_TEXTURE);
glLoadIdentity();
glScalef(1/uno, -1/dos, 1.0); ///Scales the Texture to make pixels accurate.


My problem is - when I use this, my Sprite's have strange bleeding gaps (Bear in mind, I cannot use spaces due to toolkit limitations) - Here is a picture of the spritesheet and the game when run:

Spritesheet:
https://pbs.twimg.com/media/BHGucHgCEAAJRkE.jpg

Game:
https://pbs.twimg.com/media/BHGuktCCcAAVEWL.jpg

How do I fix this?

Thanks In Advance,
Matt

P.S - You guys have been a big help with my previous questions.

carsten neumann
04-05-2013, 12:10 PM
Are you using linear filtering? Since there is no minification/magnification happening in your application you can use nearest filtering. Or adjust s texture coordinates by +/-0.5/textureWidth (i.e. 1/2 pixel) and t texture coordinates by +/-0.5/textureHeight, so that you don't accidentally sample texels that are part of the next sprite.