What is the proper way to do a texture atlas for a 2D game?
I have read that you can just load in your atlas, calculate a ratio or map position based on the width / height of the atlas, and then in your render function use
glTexCoord2d(x, y)
Example
//Map caulation (upper left corner calculation)
// atlas width / atlus height : the size of the atlas in pixels
// imageColCountX / imageRowCountY : The number of sprites in the atlas based on row / columns
// spriteMaxWidthLocal / spriteMaxHeightLocal : the end pixel location of the sprite you wish to use
double spriteLoationX = (atlasWidth / imageColCountX) / spriteMaxWidthLocal;
double spriteLoationY = (atlasHeight / imageRowCountY) / spriteMaxHeightLocal;
//Upper left
glTexCoord2d(spriteLoationX, spriteLoationY);
glVertex2d(player.viewX, player.viewY);
/*
Other positions of the quad and etc ...
*/
Is there a better way?
edit: fixed inconstant variable names in example code