160x144 image loading
Written by Mike Parks (BigRedPimp@juno.com)
Basic 160x144 image loading.
First, convert your image using PCX2GB (prefered) to GBDK output format using this on the command line
pcx2gb n d filename.pcx filename.c
(I'll be using PCX2GB for this description, there are other utils you can use for this). Next, in the output file, change the name of the unsigned char to whatever you'd like. Then, in your project's main source file, put
Now, you'll put this whereever you want your image to appear:
draw_image(unsigned char's name);
You should get a nice, full screen image.
I used this in my South Park X-Treme demo and it worked fine. There were some drawbacks to doing it this way, though (cart size was 128k, had to use bank switching to hold the images).
Advanced image loading. (Using CGB
There is a better way if you plan on using a different sized image. Convert the image in PCX2GB using
pcx2gb o d filename.pcx filename.c filename.map
This will not only optimize your image so it'll be smaller in code, it'll also decrease the need for a larger cart size. (Thanx go out to Icehawk for making the beginners docs to explain some of these things - www.gbdev.org/news/).
What you need to do is include both your converted image (filename.c) and your tile map (filename.map) into your project. You will then put the following code into your project whereever you want your image to appear:
/* Beginning of code snippet
The following can be changed:
bgpal = the color palette being used
MK = image tile data being used
MKCGBMap = map of how your palettes will be displayed
MKMap = map of how your tiles will be displayed */
// Set palette(s) for
// Set bkg tile data
// Switch to VRAM
VBK_REG = 1;
// Set the map for where your palettes will be
// Switch out of VRAM
VBK_REG = 0;
// Set the map for where the bkg tiles will be
// Show the background
// Turn the display on
That should help. If you have any more questions, feel free to ask.