Colorful text without sprites
Moderator: Stef
Colorful text without sprites
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!
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!
-
- Very interested
- Posts: 3131
- Joined: Thu Nov 30, 2006 9:46 pm
- Location: France - Sevres
- Contact:
Re: Colorful text without sprites
Hello Epiplonepiplon 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!
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);
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);
Code: Select all
VDP_setTextPalette(PAL0);
Yeah, it help! However, I used the default font and did the following:
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?
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);
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?
-
- Very interested
- Posts: 117
- Joined: Sun Jan 02, 2011 9:14 pm
- Contact:
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);
-
- Very interested
- Posts: 3131
- Joined: Thu Nov 30, 2006 9:46 pm
- Location: France - Sevres
- Contact:
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:
Of course you can use another of the 4 palettes to draw text:
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);
Code: Select all
// set foreground color for system font
VDP_setPaletteColor((PAL2 * 16) + 15, 0x000E);
VDP_setTextPalette(PAL2);
VDP_drawText("Hello Genie!", 10, 12);