Original Post
I'm making a 2D game. For animating tiles/sprites, I have made my own format for saving graphics. All frames are put onto one image and when drawing that sprite/tile the correct frame gets selected by glTexCoord2f. Is there a way to specify direct position in pixels, instead of [0;1] range? If my images have odd frame number (like 9), the image is unstable when animating, because of incorrect precision when dividing numbers. This is the code that I have written: It currently is very unclean. I'll clean it after I solve this problem. [Edited by - Giedrius on July 4, 2006 3:18:49 PM]
void DrawSpr(sprite *spr)
{
static int _frame = 0;
int frame = _frame/100;
double w = (double)spr->w / (spr->w*spr->num_frames);
glBindTexture(GL_TEXTURE_2D,spr->id);
glBegin(GL_QUADS);
glTexCoord2d(w*frame,0);
glVertex2i(0,0);
glTexCoord2d(w*frame+w,0);
glVertex2i(spr->w,0);
glTexCoord2d(w*frame+w,1);
glVertex2i(spr->w,spr->h);
glTexCoord2d(w*frame,1);
glVertex2i(0,spr->h);
glEnd();
_frame++;
if (_frame>spr->num_frames*100) _frame = 0;
}