bmp loader

anyone got around to trying to get a bmp file loader working? just abit stuck without one… now worry mind…

No. However why stick with MS’ BMPs?

With the free Xnview (1) you could batch-convert all your Bmp files to some more handy format, like the nice Png format (2) or Tga.
Png (and Jpeg) is being supported directly by Java (javax.imageio.*). So with two or three lines of code you load Png files (3) and give them as textures to your OpenGL/Jogl project.

(1) http://www.xnview.com - Xnview handles about 99% of the functions of Acdsee, however supports many more formats and is free.

(2) http://www.w3.org/Graphics/PNG/

(3) This is one of the many reasons why I love Java so much: its large and usable standard library lets you really concentrate on your job. :slight_smile:

But what is the deal with alpha transparency and pngs!? If I understand correctly pngs don’t define a specific alpha channel, but encode their transparency by other means.

Confusion was greatly added when Adobe attempted to jump the gun on pngs and implemented png transparencies in Photoshop 5 with an alpha channel, causing lots of confusing info to ripple out all over the net.

When ImageIO loads a png that has transparency, the resulting BufferedImage is not in RGBA format. However drawing it with a Graphics object results in correct transparency.

I finally gave up and went with targas. I like the tangible and easy to work with alpha channel anyway.

because MD2 models use BMP files… if they didnt i would be happy :slight_smile: but they do so… oh well…

[quote]But what is the deal with alpha transparency and pngs!? If I understand correctly pngs don’t define a specific alpha channel, but encode their transparency by other means.
[/quote]
Unfortunately I don’t know.

[quote]When ImageIO loads a png that has transparency, the resulting BufferedImage is not in RGBA format. However drawing it with a Graphics object results in correct transparency.

I finally gave up and went with targas. I like the tangible and easy to work with alpha channel anyway.
[/quote]
Yes, Targas are a nice format, our artists love it. Still, when they do transparency textures with Lightwave, they insist in having the alpha layer in an own picture file (no matter if it’s PNG or TGA).

[quote]because MD2 models use BMP files… if they didnt i would be happy :slight_smile: but they do so… oh well…
[/quote]
Oh, I see.
And which graphic format does MD3 support?

bmp also :slight_smile: i have a md3 loader also. but the textures are still bmp… thats way i asked… i guess i could pre convert all the images to somthing else… just would be a downer… nice md2 and md3 exporters for modelers out there.

[quote]bmp also :slight_smile: i have a md3 loader also. but the textures are still bmp… thats way i asked… i guess i could pre convert all the images to somthing else… just would be a downer… nice md2 and md3 exporters for modelers out there.
[/quote]
Interestingly the MD3 models of the nice game Jedi Outcat use TGA files as texture file format. The textures are stored as JPG files in the Pk-Zip-Archiv but when you convert them to TGA you can watch the models with a MD3 viewer.

Some info about various graphics formats are available here: http://www.wotsit.org/

PS: Does anybody know of a better site than the above for various formats?

[quote]anyone got around to trying to get a bmp file loader working? just abit stuck without one… now worry mind…
[/quote]
download
http://www.scottshaver2000.com/files/lwjgl_sg/lwjgl_sg_src.zip

and look and the ImageFile and WindowsBitmapFile classes.

TGA images are nice but lets also remember that many java games for the forseeable future will be dowloaded not purchased on a cd. If you were to create any type of large scaled 3d game these textures alone would probably require over 100mbs. Not acceptable for a downloaded game when you also have to add into that the code, sounds, data files, map/lvl files, model files etc…

With this in mind its important to be able to load jpegs and for textures with an alpha component to be able to use gif.

But since jpegs and gifs are already compressed, you can’t squeeze much out of them.

I just threw one of my tga textures into a jar and got 77% compression. Some jpeg I have laying around thrown in only gave me 6% compression. I’d be willing to bet that in the end the difference won’t be that large.

Compression depends a lot on image content. JPEG compression will be VERY good for photo like images. Since it is lossy there is a lot of tuning you can do and the compression would be much better for that style of image than zipping a TGA. If you need crisp lines with high frequency detail then zipping a TGA might be better than wrecking the images with a lossy compressor. PNGs also are compressed pretty good and not lossy… zipping won’t do much more to them.

If you want to go non-lossy I would choose PNG simply because the loader is built-in and it supports any feature you would likely need (Alpha, Gamma, various palette sizes + true colour).

My personal advice is to use whatever texture is necessary to make the game work, just be responsible. I use PNGs for most things at this point becase they work well for what I’m trying to do. Between the various image formats I have found little to no difference once the formats have all been compressed between their relative sizes. I’ve taken the same image - a 512x512 and tried it as JPEG, PNG, and TGA and once it was compressed, there really wasn’t much difference in size. Since you can read images right from the .zip format, not really a big deal about compressing textures for production content.

most of the time i use TIM2 image files. i find when u use a TGA u still need up uncompress it before using it. so its just to big. its cool for Output mind… just using BMP because i have millions of BMP textures. NP i am recompressing them…

fun fun fun :)…

If I need to put my jpeg compression down to about 8 or my gif color table down to 64 or 128 colors, sacrificing quality I get a lot smaller file sizes then zipping TGA or png files. About 1/4 of the file size for jpegs without sacrificing much in quality.

There are instances where it would be useful to load in textures in the format that I origionally saved them in because that already yielded the best quality/size ratio I could get.

Looking forward to your loader with any image type.

[quote]But what is the deal with alpha transparency and pngs!? If I understand correctly pngs don’t define a specific alpha channel, but encode their transparency by other means.
[/quote]
I now learned that PNG does allow to have a 8 bpp Alphamask and it works great. :slight_smile:

With the help of Gregor’s nice Jogl texture mapping tutorial I’ve now successfully loaded 32-bpp PNGs which contain 24 bpp RGB plus 8 bpp Alphamask.
Java does do this with just a few lines of code and it works very well.
Of course it also works with 24-bpp PNGs with no Alphamask.

Basically you just do this:


BufferedImage img = ImageIO.read(new File("filename.png"));
// flip it or not. :)
int rgbFormat = (img.getAlphaRaster() == null) ? GL.GL_RGB : GL.GL_RGBA;
byte[] bytearray = ( (DataBufferByte) img.getRaster().getDataBuffer() ).getData();

final int internalOglFormat = rgbFormat;
gl.gluBuild2DMipmaps(o.GL_TEXTURE_2D,
                       internalOglFormat,
                       img.getWidth(), img.getHeight(),
                       rgbFormat,
                       o.GL_UNSIGNED_BYTE,
                       bytearray);

Thanks to the others for the tutorial steps. Now that’s the easyness of Java I love.