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 > Everything you need to know about Sprites

#61916 - RedRobot - Fri Nov 25, 2005 3:57 am

I spent over an hour trying to figure out some answers to questions I had about Sprites today and I didn't get anywhere. I think that there is a gap in the available information for newbies in the Sprites area.

So here are some questions I had that hopefully some people can answer.


- The 2D graphics examples that come with libnds have .bin files in the data folder. I'm assuming that .jpgs or .bmp files are turned into .bin files somehow? How is this done. Which program?

- I have noticed gfx2gba mentioned in several tutorials. The readme file is quite bare to say the least. I quickly ran it without any options and it outputted a .raw file and a .pal file. How are these files used in a DS programming context? What options should people be using with gfx2gba? Can someone provide an example command for gfx2gba? Are there tutorials?

- Are there other methods that you use for getting Sprites on the DS other than .bin files or using gfx2gba?




As a newbie outsider trying to find out info about the DS I have found that there is a big hole where info about Sprites should be. Let's make a thread full of Sprite knowledge so the next newbie who goes looking for info can find it easier. Thanks!

#61918 - DekuTree64 - Fri Nov 25, 2005 4:41 am

Probably why you're having trouble finding info is that DS's sprite hardware is nearly identical to the GBA's (with a few added features), so nobody's gone to the trouble of writing a DS-specific sprite tutorial.

Here are some GBA sprite links:
GBATEK sprite info
TONC, especially BG/sprite overview and sprites
PERN project sprites
_________________
___________
The best optimization is to do nothing at all.
Therefore a fully optimized program doesn't exist.
-Deku

#61938 - RedRobot - Fri Nov 25, 2005 4:12 pm

Quickly reading over those pages, some of which I've already seen, I can tell that there is an amazing amount of great technical information about how graphics are done on the GBA/DS. However, none of these pages actually specifically answer any of the questions I posed.

Maybe I shouldn't be so subtle this time. I have no doubt that with the help of these great technical pages, I'll be able to use sprites on the DS effectively, but the main interest of mine and the thing I think would help new DS developers the most is the personal opinions of DS developers.

If you look at this page, http://www.gbadev.org/tools.php?section=gfx , there is a huge listing of graphics programs, but very little detail about their operations or whether they are any good or not.

So what do you use? Why do you use it? Where would you start? I mentioned earlier in my post about the NDS examples with libNDS using .bin files in the data folder. Which program do you find works best for converting images to .bin files? Do you not use .bin files? It's these sort of questions that aren't answered AT ALL in these tutorials. Authors of these tutorials usually pick one method arbitrarily and not explain how they do it, why they do it, or it's advantages over other methods.

If we take the short time to flesh out this thread with a wealth of knowledge instead of simply posting links to other sources (even though they are very useful!) it will be a much more relevant source of information to new DS developers.

I'll reiterate my earlier questions again:

- The 2D graphics examples that come with libnds have .bin files in the data folder. I'm assuming that .jpgs or .bmp files are turned into .bin files somehow? How is this done. Which program?

- I have noticed gfx2gba mentioned in several tutorials. The readme file is quite bare to say the least. I quickly ran it without any options and it outputted a .raw file and a .pal file. How are these files used in a DS programming context? What options should people be using with gfx2gba? Can someone provide an example command for gfx2gba? Are there tutorials?

- Are there other methods that you use for getting Sprites on the DS other than .bin files or using gfx2gba?

#61955 - crossraleigh - Fri Nov 25, 2005 8:26 pm

A .bin file could be in any raw binary format. (Even many of the early GBA demos were released with a .bin extension.) Data files in the libnds examples are given .bin extensions because the default devkitARM makefile will automatically convert and link .bin files. The programmer still needs to know what format they are in.

Note that there are 2 gfx2gba programs in the tools section of this site. When most people talk about gfx2gba, they mean the one with more options. Its readme.txt is comprehensive.

If you convert foo.bmp with gfx2gba and get the files foo.raw and foo.pal, you could rename them to foo.bin and foo_pal.bin so that the makefile will find them.

To make a 256-color 1D sprite, try this:

Code:
gfx2gba -St.bin -pfoo_pal.bin -t8 foo.bmp

_________________
My world is black and white, but if I blink fast enough, I see it in grayscale.

#62025 - Codax - Sat Nov 26, 2005 5:18 pm

I like to use Mirach and Usenti for all my graphics needs for the DS. ( http://user.chem.tue.nl/jakvijn/index.htm ) I export them as source code and #include them as necessary. It's important to remember that sprites are just collections of pixel data. And that pixel data is based off a palette. So...some psuedo code

Please note this is probably not the BEST way, but it is the EASIEST to understand

Code:

#include yourgraphics.h;
//This contains two arrays yourPALETTE[] and yourIMAGE[];

//Code to setup screens and memory areas, blah blah blah


for(i = 0; i < 256; i++)
{//Load 256 colors into the SPRITE_PALETTE

  SPRITE_PALETTE[i] = yourPALETTE[i];

}

//Load yourIMAGE into SPRITE Pixel data
for(i = 0; i < 64 * numof8x8tiles; i++)
{
  SPRITE_GFX[i] = yourIMAGE[i]
}

//Do all the fun stuff with OEM data remembering that GFXid is the number of the first 8x8 chunk of your sprite




While I couldn't be as far as I am with sprites without the above mentioned pages, it's important to also look at source code. There are a few demos that come with devkitArm that really made the difference. Don't be afraid to butcher them in such a way that you know what EACH LINE does. The more your read those docs the sense any of this will make. There is a lot of information there, so try to go into it with a goal. Also don't forget to check out memory.h and video.h in NDSlib
_________________
Codax
Dragon's Den Unlimited
http://www.DrgnDen.com