Texture Sampling Coordinates to Render a Sprite
Let's say we have a texture (in this case 8x8 pixels) we want to use as a sprite sheet. One of the sub-images (sprite) is a subregion of 4x3 inside the texture, like in this image: (Normalized texture coordinates of the four corners are shown) Now, there are basically two ways to assign texture coordinates to a 4px x 3px-sized quad so that it effectively becomes the sprite we are looking for; The first and most straightforward is to sample the texture at the corners of the subregion: // Texture coordinates GLfloat sMin = (xIndex0 ) / imageWidth; GLfloat sMax = (xIndex0 + subregionWidth ) /