標準コンソール16色フォント変更+パレット番号変更サンプル。


examples/nds/Graphics/Printing/custom_font/ をちょいと弄ってみました。
表示を上画面に変更して記述を少し簡略化したのと、
任意のパレット番号(0 番〜 15 番)にフォントカラー(16色)を読み込ますようにしてみました。


chgfont2


プロジェクト一式
ttp://page.freett.com/ntr/example/chgfont2.zip


ソース


main.c

/*---------------------------------------------------------------------------------
	
	change font 2 (change 4bpp font & change palette number)
	
	version 0.01
	Api 08, 2010
	
	original By libnds example custom_font
	modified By REGEKATSU
	
---------------------------------------------------------------------------------*/

#include <stdio.h>
#include <nds.h>

//grit で画像変換時に生成される画像のヘッダファイルをインクルードする。
#include "font.h"


//---------------------------------------------------------------------------------
int main(void) {
//---------------------------------------------------------------------------------
	
	//コンソール設定を取得するための構造体を用意する。
	PrintConsole console;
	
	//画面モードの初期化を行う(メインスクリーンを使用するように設定してる。)。
	videoSetMode(MODE_3_2D);
	vramSetBankA(VRAM_A_MAIN_BG);
	
	//デフォルトのフォント画像は取り込まず、コンソールの初期化のみ行う。
	console = *consoleInit(0, 0, BgType_Text4bpp, BgSize_T_256x256, 0, 1, true, false);
	
	//用意した 4 ビットカラーフォント画像を取り込む為の設定を行う。
	console.font.gfx = (u16*)fontTiles;
	console.font.pal = (u16*)fontPal;
	console.font.numChars = 96;
	console.font.numColors = fontPalLen / 2;
	console.font.bpp = 4;
	console.font.asciiOffset = 32;
	console.font.convertSingleColor = false;
	
	//パレット番号 0 番〜 15 番のうち、何番目のパレットにフォントカラーを読み込むか指定する。
	console.fontCurPal = 15;
	
	//フォントの設定を適用する。
	consoleSetFont(&console, &console.font);
	
	//自前 4 ビットカラーフォントによる文字列の表示(現在のパレット番号は 15 となっている。)。
	printf("change font 2 \n(change 4bpp font &\n change palette number)\n\n");
	printf("version 0.01\n");
	printf("Apr 08, 2010\n\n");
	printf("original By\n libnds example custom_font\n");
	printf("modified By REGEKATSU\n\n%c", '~' + 1);
	
	while(1) {
		swiWaitForVBlank();
	}
	
	return 0;
	
}

//---------------------------------------------------------------------------------


font.grit

#-------------------------------------------------------
# graphics in tile format
#-------------------------------------------------------
-gt

#-------------------------------------------------------
# output first 16 colors of the palette
#-------------------------------------------------------
-pw16

#-------------------------------------------------------
# no tile reduction
#-------------------------------------------------------
-mR!

#-------------------------------------------------------
# no map output
#-------------------------------------------------------
-m!

#-------------------------------------------------------
# graphics bit depth is 4 (16 color)
#-------------------------------------------------------
-gB4