Loading a .tga file in java to use as....

Started by
3 comments, last by OrangyTang 16 years, 10 months ago
Hey everyone. Ok, i don't know if this subject has been addressed again or anything, or if i should post it in the java-related part of the forums but still any help would be great. To the point.... I am currently working on java with JOGL API for my project and i am focused on terrain generation. I have found sources (books, net) talking about generating a terrain using a heightmap. Usually proposing to load data from a .tga image (though i suppose any grayscale image file or bitmap would do?) and use them to produce the heights for your terrain. Still I am completely clueless on how to load a .tga file correctly in java and how to proceed. Some sources i found on the net are doing the procedure in C++ but i guess my knowledge is not enough to either fully understand the procedure and use it in java. I know its a big subject but any help (sources to study from or any example or guideline) would be very appreciated. Thanks in advance for any help.
Advertisement
If you're struggling to find resources, this article may help.

I wouldn't just copy this solution though, (it's only meant to be an example) but it should get you started.
My advice would be to find an image-loading library that lets you load a file into a buffer of memory that you can read back from.

These are common in C/C++, and I'd bet they are not that rare in Java.

Basically, avoid writing your own image loading code -- somebody else has already done it, and probably did it better than you would. :)
Thanks for the reply guys.
I'll get to the bottom of this....
ImageIO is the usual way to load images, but IIRC it doesn't support .tga files. If you don't specifically need tga I'd switch to png (which is also non-lossy compressed, and can be loaded via ImageIO).

If you were using LWJGL then you could use DevIL, which supports pretty much every graphics format known to man (including tga).

This topic is closed to new replies.

Advertisement