I’ve been trying my hands on some OpenGL programming lately and it’s been going quite nicely, there’s something i can’t seem to figure out though.
I want to load several textures in one swoop, I could put every single texture in it’s own *.tga file this does however not seem very clever since it would mean alot of files cluttering up my directories and loading would be very inefficient.
So i thought that I would put everything in one single file and load in 16x16 chunks this poses a problem though, how do I load this to textures? I tried using glfwReadImage and then loading the (first)texture with glTexImage2D(GL_TEXTURE_2D,0,GL_RGB16,16,16,0,GL_RGB,GL_UNSIGNED_BYTE, image.Data);
but this causes it to look distorted. Any ideas?
If you want to do this (I wouldn’t necessarily recommend it), you must tell OpenGL how big the image is because it will assume it is contiguous otherwise, use glPixelStore to do this. This will stride over the unused pixels to the next line edge. It is important to set this if you want to load a small non contiguous region of memory as a full image.
glPixelStore(GL_UNPACK_ROW_LENGTH, image_width); where image width is the full line width of the in memory loaded textures will do the trick.
When you load the images you can then simply increment the pointer you load with to the image origin in memory.
[This message has been edited by dorbie (edited 01-29-2004).]
Actually this was just the first thing that popped into my head, if you have any suggestions on how to do it in a better way i’d love to hear it.
Anyways is the image_width the width och the image in pixels?
Hmm, i’ll try it out, thanks for the help!
Yes, it counts pixles. I use it for separating the different faces of cube maps.
Before I included the TGA loader in GLFW, I used a custom loader that could read the TGA from any file position. This way I could concatenate several TGA:s into one file. Handy, but not a very elegant solution.
As I see it, if you are going to use many textures, it’s best to do one of the following:
- Put all the images in separate TGA:s in a separate directory, and use GLFW for loading them.
- Put all the images in separate PNG:s or JPG:s in a separate directory, and use DevIL for loading them.
- Put all the images in an archive (e.g. ZIP) and use some image loader that is capable of registring custom file I/O routines (I believe DevIL is one of them).
For just keeping a few images bunched together, use the “trick” described by Dorbie. You can use glfwReadImage() for loading it to client memory, and then glTexImage2D() for loading it to texture memory.
“Before I included the TGA loader in GLFW, I used a custom loader that could read the TGA from any file position. This way I could concatenate several TGA:s into one file. Handy, but not a very elegant solution.”
That’s kinda what I was trying to accomplish. Since I already have a file with 16x16 textures it seems to me like quite a waste to split them up and put them as single files in a directory.
That does however seem like the easiest way out at the moment so I’ll give it a shot. Thanks for your help!