Difference between revisions of "Displaying full-screen images"

From GbdevWiki
Jump to: navigation, search
(Addresses an error that LCC may throw during compilation)
 
(2 intermediate revisions by 2 users not shown)
Line 1: Line 1:
== Software Needed ==
+
== Software needed ==
 
* [http://gbdk.sourceforge.net GBDK]
 
* [http://gbdk.sourceforge.net GBDK]
 
* [http://www.yvan256.net/projects/gameboy/PCX2GB-v215.zip pcx2gb]
 
* [http://www.yvan256.net/projects/gameboy/PCX2GB-v215.zip pcx2gb]
Line 29: Line 29:
  
 
Press enter a few times and your tiles and map files will be generated.<br>
 
Press enter a few times and your tiles and map files will be generated.<br>
 
+
Note: the screen may "glitch" up a few times and then turn black. This is normal. If you're stuck in the window, then CTRL+Tab out to return back. Also, the filename may need to be limited to 6 characters and not use hyphens. If the program doesn't work it's possible that the image was not in proper 4 color mode, but PCX2GB will not warn you of this.
  
 
== Step 3 ==
 
== Step 3 ==
Line 69: Line 69:
 
After compiling and running my output looked like:<br>
 
After compiling and running my output looked like:<br>
 
[[Image:Gbburger.PNG]]
 
[[Image:Gbburger.PNG]]
 +
 +
Your compiler may give the error "abnormal program termination". To fix this, modify your .c and .map files so that the data is an "unsigned const char" instead of "unsigned char". This will keep this data in ROM, as opposed to loading it in memory.

Latest revision as of 17:23, 17 July 2016

Software needed

Step 1

Open the image you want to be displayed on the GB in the GIMP.
Burger1.png

Now we need to make this image an 8 bit pcx file.
Burger2.png

Go to Image -> Mode -> Indexed and change the max number of colors to 8.
Burger3.png

Resize the image to fit the GB's screen size.
Burger4.png

Save the image as a pcx file.
Burger5.png


Step 2

Now use this command with the image you saved in the same folder as pcx2gb:

 pcx2gb n d *imagenameyousaved*.pcx *tilesfilename*.c *mapfilename*.map

Press enter a few times and your tiles and map files will be generated.
Note: the screen may "glitch" up a few times and then turn black. This is normal. If you're stuck in the window, then CTRL+Tab out to return back. Also, the filename may need to be limited to 6 characters and not use hyphens. If the program doesn't work it's possible that the image was not in proper 4 color mode, but PCX2GB will not warn you of this.

Step 3

Now create your file to actually display the image on the GB.

 
#include <gb/gb.h>

#include "tiles.c"
#include "map.map"

void main()
{
     // Load up the tile data
     set_bkg_data(0,255,tiledata);

     // Switch to VRAM
     VBK_REG = 1;

     // Switch out of VRAM
     VBK_REG = 0;

     // Set screen x,y pos to 0,0 and draw the map 20,18(size of the screen)
     set_bkg_tiles(0,0,20,18,tilemap);

     // Show the background
     SHOW_BKG;

     // Turn the display on
     DISPLAY_ON; 
}


Compile and done

After compiling and running my output looked like:
Gbburger.PNG

Your compiler may give the error "abnormal program termination". To fix this, modify your .c and .map files so that the data is an "unsigned const char" instead of "unsigned char". This will keep this data in ROM, as opposed to loading it in memory.