gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

DS development > Using jpg/png files loaded from filesystem in 3d scene?

#173847 - SatNav - Tue May 04, 2010 1:49 pm

Hi,

As the title suggests, I'm trying to find the best way to display a jpeg or png image from disk in a 3d scene. I want to be able to select an image to use as a background in my Rubik's Cube game. I've had a search around, and didn't find anything of much use, but I may have missed something, so apologies if I have.

I've found pnglib, and libjpeg - I'm guessing I have to use those. would I need to compile them for DS first? once I can actually load in the images, how would I use them in the scene? Would it involve somehow texture-mapping them to the rear poly (or another poly that I draw in manually)? Or is there some easier way that I could just plop them onto the background?

TIA,
Mark
_________________
Cube-DS: A Kick-Ass Rubik's Cube Game for DS
http://cube-ds.googlecode.com

#173848 - sverx - Tue May 04, 2010 2:35 pm

You can load a jpg using the JPEG Decompression Library for DS kindly provided by HeadSpin, here, DS Tools section. Then you could copy the image data into a VRAM bank and use that data as a texture.

#173850 - vuurrobin - Tue May 04, 2010 3:42 pm

if the images will always be the same, you can use grit to convert them during compile time.

if the images are from users, than you can use one of the portlibs to decompress them during runtime.

http://wiki.devkitpro.org/index.php/portlibs
_________________
my blog:
http://vuurrobin.100webcustomers.com/

#173860 - Miked0801 - Tue May 04, 2010 9:26 pm

FYI JPEG decompression tends to be very slow in my experience.

#173869 - SatNav - Wed May 05, 2010 4:23 pm

Awesome responses, thanks very much :)

vuurrobin: Yes, the image will be supplied by the user - I thought it would be a nice touch for players to be able to select their own background image to use in the game. And cheers for pointing me to those portlibs, I had no idea they were there - so much for my googling skills!

Miked: Hmm... how slow is slow? could you maybe give me a guess for, say, a 1024x768? Speed isn't a huge issue, since usually only one jpeg will need to be decompressed per play session, but if it's gonna take more than 3 or 4 seconds I might have to rethink..

Not looking forward to tackling texture mapping - I've barely even looked at it, past browsing through the devkitpro examples :/
_________________
Cube-DS: A Kick-Ass Rubik's Cube Game for DS
http://cube-ds.googlecode.com

#173870 - Ruben - Wed May 05, 2010 4:37 pm

Erm.... Why would you want to decompress a 1024x768 image if the screens are only 256x192? o_O

#173872 - SatNav - Wed May 05, 2010 6:19 pm

I don't especially, but it doesn't seem unlikely that a lazy user might find a large jpg somewhere on the interwebs and want to use it without bothering to resize :P
_________________
Cube-DS: A Kick-Ass Rubik's Cube Game for DS
http://cube-ds.googlecode.com

#173905 - Miked0801 - Fri May 07, 2010 6:50 pm

I can't say exactly as it varies a ton per library - though the DS has a DSP that can hardware accelerate this, though I'm not sure how much support there is for this in hobbiest land.

I wouldn't be surprised to see a 256x192 image take 1 second to decompress. A 1024x768 - well, you'd probably run out of RAM and patience before it was done. :)

#173968 - sverx - Mon May 10, 2010 10:12 am

Miked0801 wrote:
I wouldn't be surprised to see a 256x192 image take 1 second to decompress.


No, it's faster. Check Cydrak 18 bpp display demo.

#173983 - Miked0801 - Mon May 10, 2010 7:36 pm

Excellent then - again I haven't had to decompress a JPG outside of APIs for quite a while so I had no frame of refernce since GBA days.

#174066 - dheart88 - Sun May 16, 2010 10:48 pm

Well, grit provided with Devkitpro chain tool... Actually i use gfx2gba to create an image into these files:

bgPal.bin
bgTiles.bin
bgMap.bin

after that just load all of them in their pointer, pal in background palette, Tiles in background tiles and Map in background map..
--------------------------------------------------------
It's not hard to combine 2 BG (1 3D and 1 2D), if you put the 3D in bg0 and 2D in yourBGhere:

bgPriority(bg0,1);
bgPriority(yourBGhere,0);

you also can stay in only 1 bg 3D, by inserting a quad that will fit your screen and then change your view with glulookat() to change the view before rendering your model