Page 1 of 1
Colorful text without sprites
Posted: Sun Sep 15, 2013 5:17 pm
by epiplon
Hello.
I just got here a few days ago and the SGDK impressed me, because I thought that would take me weeks to set up and get the Megadrive to print just a color on the screen. Now, I achieved it with just some hours!
So, by looking at the tutorials and source codes, I thought if would be possible to:
1. change the colors of the PALs, and then making each letter with const u32 tile[8] = {...}
2. Actually change the color on the VDP_drawText function, somehow.
Is it possible just by using the devkit, without messing with ASM codes?
Really thanks!

Re: Colorful text without sprites
Posted: Sun Sep 15, 2013 7:14 pm
by Stef
epiplon wrote:Hello.
I just got here a few days ago and the SGDK impressed me, because I thought that would take me weeks to set up and get the Megadrive to print just a color on the screen. Now, I achieved it with just some hours!
So, by looking at the tutorials and source codes, I thought if would be possible to:
1. change the colors of the PALs, and then making each letter with const u32 tile[8] = {...}
2. Actually change the color on the VDP_drawText function, somehow.
Is it possible just by using the devkit, without messing with ASM codes?
Really thanks!

Hello Epiplon
Glad you get SGDK setup that quickly ! The next version of SGDK will provide a better font system so you can upload easily your own font from a bitmap file as well (the system font will also appears in .bmp format).
You can replace the system font by using the following method :
Code: Select all
/**
* \brief
* Load font tile data in VRAM.
*
* \param font
* Pointer to font tile data.
* \param use_dma
* Use DMA transfert (faster but can lock Z80 execution).
*
* This fonction permits to replace system font by user font.<br/>
* Font tile data are loaded to TILE_FONTINDEX and the font should contains FONT_LEN characters.
* See also VDP_loadTileData().
*/
void VDP_loadFont(const u32 *font, u8 use_dma);
Your font should be FONT_LEN character ideally but can be less.
You have to respect the default charset used in SGDK (based on default US charset starting a 32 ascii code)
So you define your font this way :
Code: Select all
const u32 font[8 * FONT_LEN] = {...};
VDP_loadFont(font, TRUE);
and you can change the font palette used to draw text with this method:
Hope that helps !
Posted: Mon Sep 16, 2013 12:30 am
by epiplon
Yeah, it help! However, I used the default font and did the following:
Code: Select all
VDP_loadTileData( (const u32 *)tile, 1, 1, 0);
VDP_setTileMap(APLAN, TILE_ATTR_FULL(PAL0, 0, 1, 0, 1), 6, 5);
VDP_setPaletteColor(PAL2, 0x000E );
VDP_setTextPalette(PAL2);
VDP_drawText("Hello Genie!", 10, 12);
0x000E is a Red pallet which I found it here:
http://bigevilcorp.wordpress.com/2012/0 ... llo-world/
Also, not all colors seems to work. Yet the tile turned red, but the text is green, the default PAL2 color.
Why is that?
Posted: Mon Sep 16, 2013 11:48 am
by Moon-Watcher
epiplon wrote:
Code: Select all
VDP_setPaletteColor(PAL2, 0x000E );
Code: Select all
/**
* \brief
* Set RGB color to specified palette entry.
*
* \param index
* Color index to set (0-63).
* \param value
* RGB intensity to set in the specified color index.
*/
void VDP_setPaletteColor(u16 index, u16 value);
VDP_setPaletteColor doesn't accept "PAL2" as first parameter.
Posted: Mon Sep 16, 2013 6:00 pm
by Stef
Indeed you should not set color this way :p
The megadrive has 4 palettes of 16 colors, by default the draw text methods are setup to use the first palette (PAL0) so it you modify colors from PAL0 you will change the text color. Actually the system font only use 2 colors from the set palette :
- color 0 (background)
- color 15 (foreground)
So you just need to set the color 15:
Code: Select all
// set foreground color for system font
VDP_setPaletteColor((PAL0 * 16) + 15, 0x000E);
VDP_drawText("Hello Genie!", 10, 12);
Of course you can use another of the 4 palettes to draw text:
Code: Select all
// set foreground color for system font
VDP_setPaletteColor((PAL2 * 16) + 15, 0x000E);
VDP_setTextPalette(PAL2);
VDP_drawText("Hello Genie!", 10, 12);
Posted: Fri Sep 27, 2013 10:40 pm
by epiplon
Oh, now I see!
Really thanks, that's was helpful.
