views:

46

answers:

3

Hello.

I need to load PNGs and JPGs to textures. I also need to save textures to PNGs. When an image exceeds GL_MAX_TEXTURE_SIZE I need to split the image into separate textures.

I want to do this with C++.

What could I do?

Thank you.

+1  A: 

I need to load PNGs and JPGs to textures

  1. SDL_Image
  2. Qt 4
  3. or use libpng and libjpeg directly (you don't really want to do that, though).

When an image exceeds GL_MAX_TEXTURE_SIZE I need to split the image into separate textures.

You'll have to code it yourself. It isn't difficult.

SigTerm
The last I checked, SDL_Image loads an image but doesn't do anything about creating a texture for you. You have to handle that yourself. (Which can be a bit fiddly.)
Kylotan
Thank you for the reply.Those libraries are very large and unnecessary for my needs. It seems a completely ridiculous way to do something so simple. SDL Image uses SDL which is a large library (Qt is large also). Tapping into SDL to then split the images, could work but feels very bloated. I might as well continue loading the images with pygame on the python side which I don't like at all for obvious reasons.I'm having temptations to use libpng and libjpg which will use a lot of my time but might be the only method to achieve the quality I'm looking for.But thank you for your answer.
Matthew Mitchell
Kylotan, I think there are functions in SDL that allow you to get pixel data for these "surfaces" much like pygame (pygame is based on SDL) which I'm temporarily using.I think it's a nasty solution. I really want something dedicated for OpenGL. I've seen libraries which can load textures but the image splitting is the problem.
Matthew Mitchell
@Kylotan: *sigh*. glTexImage2D takes width, height and pointer to array of pixels as argument. And SDL_Image loads image and allows to access its width, height and array of pixels. The rest is simple. And I don't think it is "fiddly".
SigTerm
@Matthew Mitchell: "Those libraries are very large and unnecessary for my needs." Boost is larger and people still use it everywhere. If you don't like SDL/Qt (which is *easiest* solution), go for #3 or download NVidia OpenGL SDK and see what they are using. AFAIK, their code license is permissive and you should be able to use parts of sdk in their code.
SigTerm
@Matthew Mitchell: "but the image splitting is the problem" *BEcause* you need splitting, I recommended you SDL. To split images you need to access them as surfaces and have a basic "blit" or "copy rect" support. This is where Qt and SDL comes into play. You could use ready-to-use libraries (which are both crossplatform and will save you from a lot of trouble), or you can reinvent the wheel, waste a lot of time, and write and debug your own "surface" class that would load multiple image formats, and split them. I'd go with simplest(least time required) solution. Which is SDL.
SigTerm
@Matthew Mitchell: Besides, whether you like it or not, you'll have to link with external libraries (libjpeg, zlib and libpng are minimal requirements). Without them you'll be limited with BMP, TGA and maybe XPM/XBM formats for images. SDL/Qt 4 offer simpler interface. Or (if you don't care about cross-platform capabilities) you could use whatever graphic routines your platform/operating system offers. At least blitting should be supported.
SigTerm
Maybe you are right. If I did make my own code, I wouldn't need to make any surface class. I'd just read the image in squares when copying to textures but the time required to program it all would be long.I wish there was a nicer solution.
Matthew Mitchell
I didn't know SDL_Image is already on OSX. That's handy for the Mac version. I'm going to try it.Thank you again.Oh but it wont save PNGs...I'm going to have to come back to this problem. For now I'll use pygame despite my desire to crush pygame into tiny pieces.
Matthew Mitchell
@SigTerm - it's not that simple, as I've seen from many posts on Gamedev.net where people ask why their texture is upside down or with the colours corrupted.
Kylotan
@Kylotan: Texture loader is not the only possible cause of "upside down" problem, and flipping second texture coordinate isn't that difficult. Personally I prefer DirectX-like texture coordinates where "v"("t" coordinates in OpenGL) points down (OpenGL doesn't care anyway). There is much more complicated stuff in game development than loading textures, so if people get stuck with basics, I don't think they'll learn much...
SigTerm
+1  A: 

DevIL can load and save many image formats including PNG and JPEG. It comes with helper functions that upload these images to OpenGL textures (ilutGLBindTexImage, ilutGLLoadImage) and functions to copy only parts of an image to a new image (ilCopyPixels, can be used to split large textures).

Malte Clasen
Thank you but I see no OSX binaries anywhere. Are they provided some where else?
Matthew Mitchell
I'm not sure, but it should be no problem to compile the library from source (we do that on Windows and OS X).
Malte Clasen
Okay, thank you. I will have to take another look and try to compile it.
Matthew Mitchell
A: 

For the loading part SOIL looks rather self-contained.

genpfault
I've looked at that but it doesn't save PNGs and I don't know how I would split textures but thank you for your contribution.
Matthew Mitchell
Ah, missed the part about saving PNGs.
genpfault