Drawing multiple images from a single image

I have an image that contains multiple images within. What is the best approach for “cutting” up this image and drawing different parts of it? Would I use glTexCoord2f() and just setup different coordinates, or would glTexSubImage2D() work better, or something else?

You mean you have a texture atlas ?
Probably glTexCoord2f is best, but I am not sure of what you want to do exactly.
glTexSubImage2D is only useful to update a part of a texture, so I don’t see how you could use that in this case ?

Ah that’s the name. I didn’t know what it was called, so searching didn’t help much :slight_smile:

I guess I misunderstood what glTexSubImage2D is for. I’ll try using glTexCoord2f. Is there any way I can use glTexCoord2f() with coordinates other than 0-1?

Is there any way I can use glTexCoord2f() with coordinates other than 0-1?

Opengl uses normalized texture coordinates because this way, texture mapping does not depend on texture image size. You can easily compute normalized texture coordinates from a coordinates in pixel knowing the texture image size.
Note that there is one case where opengl does not require normalized texture coordinates when you use the GL_TEXTURE_RECTANGLE target but this one has many limitations (no mipmapping support, …)

you can use 0, 0.1 , 0.33445433, … even 4.2 etc are valid.
However, outside the 0-1 range, the texture repeats.
You can also denormalise the coordinates and have integer texel coords xy like that:
glTexCoord2f(x * 1.0/texturewidth, y * 1.0/textureheight)

Ok thanks. I figured I’d just use basic math.