Good, fast, stable support for JPEG files in LOADSPRITE etc.

Previous topic - Next topic


To quote the online manual:

QuoteLOADSPRITE bmp$, num%

Loads the graphic file (bmp or png) into memory for using it with DRAWSPRITE commands later on. Every loaded sprite needs a unique ID number (num%) which allows you to access the sprite. If an ID is reused, the image in memory for that ID will be replaced by the new image.

Now I've read apparent comments that JPEG support had been added, but that it tended to cuase problems - I really want to be able to use JPEGs. Please?

Ian Price

I came. I saw. I played.


There are some advantages to JPG. For example, in casual Hidden Object games that have lots of full screen backgrounds, huge "sprites" etc. it's sensible to use JPG. In fact almost all casual frameworks support it.
Sometimes is acceptable to have slightly lossy images but with the benefit of much smaller game download. JPG at 95% quality is still way smaller than PNG, without apparent degradation in quality.

Also, textures for 3d models mostly don't have to be losless, due to the way they're displayed on screen.


Also, in my instance many 3D models in .OBJ format have .jpg textures. If I supply a program to someone I doubt they will want to convert all their textures to .png and fix the references to go to the .pngs before using whatever I could write to use them :(

I'm surpriseed no-one has written a user function to read JPEGS - is the file format not available, or really convoluted?


Can "we", as a user group, find the jpeg spec and write a reader (as I'm currently attempting with .OBJ files)? I don't know how into "group helping and sharing" we are here, yet. I'll learn!

Kitty Hello

You can try to load jpeg on Win32. On most platforms it works - iPhone does for sure _not_.
I am aware of that bug, but so far I can't get it fixed as it's a different library I have to use.


Cool - I'll try it on Win32 a bit later. Personally I don't need iPhone support yet but was nervous about jpeg as it doesn't seem to be documented and the forum posts I found seemed to suggest it was, ah, flakey?

Ian Price

JPEG doesn't work properly EVEN on Windows, I'm afraid.

It might load one or more images once, but try to use them more than once and/or other images and it all fecks up.

I brought this up ages ago, as I was working on a Top Trumps game and wanted the card images to use JPEG. It seems fine at first, but goes awry very quickly when JPEGs are loaded and displayed.
I came. I saw. I played.


:( thanks Ian, I had a horrible feeling that's what I'd found - so jpeg support is back on my list of things to consider trying to write. Ah well! :|


As it causes immense problems, I dont see it being in for quite a while.

At the moment you can only use it with one file - any further use (especially to the same id number) will crash your program...


I must admit, I had hoped that someone would ahve taken a similar approach to my initial thoughts on the .obj file format - and started tackling the .jpeg file format in GLBasic from first principles. Possibly even converting from C source code freely avaiable at site slike:

(links very quickly obtained via google).

I have slightly fond memories of using a version of FORTH which had been written and compiled in an earlier version of FORTH, and have wondered whether producing our own 2libraries" might be something the community was "up for" on a collective basis - there certainly seem to be some code snippets along those lines. Maybe those who post their code thend not to be those interested in 3D or different graphic formats?


The ability to load raw image data to a sprite has only been available for a few days, hold your horses :-)


Apparently Gernot is using the jpeg code from - but its being a problem...


I can wait a bit. Even without days like today when my head's splitting too much to code, I've got a fair few bits and pieces to put together and test out. Plenty of refining before I NEED good .jpeg support - though I fear I have lost sight of the prudence I intended to have when approaching GLB to eval :(


QuoteJPG at 95% quality is still way smaller than PNG, without apparent degradation in quality.

I must be the only one who prefers PNGs because they almost always seem to be smaller than JPGs with better quality. That's why I typically only use PNGs for web design.  After a certain size a JPG might be smaller, but for mostly what I've done PNG has been smaller.