View Full Version : Drawing multiple images from a single image
02-09-2009, 12:38 PM
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?
02-09-2009, 01:10 PM
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 ?
02-09-2009, 02:45 PM
Ah that's the name. I didn't know what it was called, so searching didn't help much :)
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?
02-09-2009, 03:03 PM
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, ...)
02-09-2009, 03:26 PM
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)
02-09-2009, 03:48 PM
Ok thanks. I figured I'd just use basic math.
Powered by vBulletin® Version 4.2.2 Copyright © 2014 vBulletin Solutions, Inc. All rights reserved.