#165986 - Doogle - Thu Jan 15, 2009 7:20 am
I'm having some difficulties establishing a Font using Tiles.
I've been through the tutorials and examples and think I know what I'm doing but the results indicate that I do not and that I'm missing something fairly fundamental.
The result is a pink background of some wierd character and black space and other wierd characters where the text should be displayed. Clearly either I'm not putting the tiles where I think I am, or I'm not mapping to them correctly.
I'm using the Font.bmp and .Grit file from the nds/2D/customfont example.(renamed to 'font3')
Any suggestions where I'm going wrong, or pointers to additional tutorials / information would be appreciated.
Thanks.
I've been through the tutorials and examples and think I know what I'm doing but the results indicate that I do not and that I'm missing something fairly fundamental.
Code: |
void initVideo(){ powerOn(POWER_ALL_2D); vramSetMainBanks(VRAM_A_MAIN_BG_0x06000000, VRAM_B_MAIN_BG_0x06020000, VRAM_C_SUB_BG_0x06200000, VRAM_D_LCD); /* Set the video mode on the main screen. */ videoSetMode(MODE_0_2D | // Set the graphics mode to Mode 0 DISPLAY_BG2_ACTIVE); // Enable BG2 for display /* Set the video mode on the sub screen. */ videoSetModeSub(MODE_0_2D | // Set the graphics mode to Mode 0 DISPLAY_BG2_ACTIVE); // Enable BG2 for display } uint16* map; //Pointer to the main screen Map uint16* sub_map; //Pointer to the sub-screen Map void initBackgrounds() { REG_BG2CNT = BG_COLOR_256 | BG_TILE_BASE(0) | BG_MAP_BASE(20) | BG_PRIORITY(3); REG_BG2X = 0; //main screen origin REG_BG2Y = 0; REG_BG2CNT_SUB = BG_COLOR_256 | BG_TILE_BASE(0) | BG_MAP_BASE(20) | BG_PRIORITY(3); REG_BG2X_SUB = 0; //sub-screen origin REG_BG2Y_SUB = 0; uint16* tile = (uint16 *) BG_TILE_RAM(0); //Initialise a pointer to the Tile Ram map = (uint16 *) BG_MAP_RAM(20); //Initialise the pointer to the main screen Map uint16* sub_tile = (uint16 *) BG_TILE_RAM_SUB(0); // Initialise a ponter to the sub-screen Tile Ram sub_map = (uint16 *) BG_MAP_RAM_SUB(20); //Initialise the pointer to the sub-screen Map int i; /* Populate the main and sub-screen tile Ram */ for(i=0;i<font3TilesLen/sizeof(uint16);i++){ tile[i]=sub_tile[i]=font3Tiles[i]; } /* Populate the main and sub-screen Palettes */ for(i = 0;i<font3PalLen/sizeof(uint16);i++){ BG_PALETTE[i]=BG_PALETTE_SUB[i]=font3Pal[i]; } } void PrintMsg() { int i; int j; char* msg[] = { "0123456789", "ABCDEFGHIJKLMNOPQRSTUVWXYZ", "abcdefghijklmnopqrstuvwxyz", }; /* Print to the main screen */ for(i = 0; i < sizeof(msg); ++i) { for(j = 0; msg[i][j] != '\0'; ++j) { map[j + (i * 32)] = msg[i][j]-' ' ; //Font starts with a space character //so we have to subtract the offset } } swiWaitForVBlank(); } int main(void) { initVideo(); initBackgrounds(); PrintMsg(); return ; } |
The result is a pink background of some wierd character and black space and other wierd characters where the text should be displayed. Clearly either I'm not putting the tiles where I think I am, or I'm not mapping to them correctly.
I'm using the Font.bmp and .Grit file from the nds/2D/customfont example.(renamed to 'font3')
Any suggestions where I'm going wrong, or pointers to additional tutorials / information would be appreciated.
Thanks.