Changing The Text Color in SGDK

Posted June 22, 2020

This tutorial is most likely not compatible with versions of SGDK above 1.70. Unfortunately, I simply do not have the capacity or ability to update them right now. Read more about it here. Sorry.

Hold up!

If you like 90s platformers, check out my new game Kid Bubblegum!

SGDK makes it easy to put text on screen, using functions such as VDP_drawText(). By default this text is always rendered in white, but there is an easy (but also a bit tricky) way to change the text color in your Mega Drive game!

The Mega Drive uses a total of 64 colors which are spread across 4 palettes (PAL0PAL3). Each of these palettes therefore stores 16 colors, spanning across indexes 015 (because the colors are stored in an array, which start at index 0). Each visual asset you add to your game uses the colors from one of these 4 palettes… and text is no different! In fact, each character of a font is basically just a tile, meaning it follows the same rules as tiles you import yourself.


But where does text get the white color? The answer: By default, text in SGDK uses the last color of a palette, so the color at index 15. Change that color and you’ll change the color of your text!

Also by default, text uses PAL0. However, you can change that to a different palette by using VDP_setTextPalette(u16 palette). Keep in mind however that the overall index then would not be 15, but change depending on what palette you end up using! For example, if you use PAL1, the index used for text would become 31 (because you have to factor in the 16 colors in PAL0).

To change the color in index 15 you can either simply load a palette from an image where the color is already set to what you want, or you can use functions like VDP_setPaletteColor. Check out my post on Color Swapping for a more detailed explanation on how that works!

So for example, to draw a string in red on the screen, you could do:

VDP_drawText("Hello World", 8, 8);

So while changing the text color in SGDK is easy to do, you still have to keep in mind the palette limitations of the Mega Drive. It’s a good idea to decide early on what color you’ll be using for your text and in what palette it should be stored, so that you can reserve that index!

If you've got problems or questions, join the official SGDK Discord! It's full of people a lot smarter and skilled than me. Of course you're also welcome to just hang out and have fun!

Join my Discord Server!

Hang out, get news, be excellent!

Come hang out!

Want To Buy Me a Coffee?

Coffee rules, and it keeps me going! I'll take beer too, though.

Check out the rest of this tutorial series!

  • Creating Graphics for the Mega Drive
  • How to Quickly Generate C Prototype Functions in VSCode
  • Color Swapping
  • 4 Programs For Creating Mega Drive Graphics
  • Editing the Rom Header
  • Simple Game States
  • Creating a Simple Menu
  • Changing The Text Color in SGDK
  • Playing Music in SGDK
  • Converting VGZ to VGM
  • Processing Resets
  • Drawing Tiles From Code
  • Make a Text Crawl, Streets of Rage Style
  • Scrolling Maps
  • Placing Tiles
  • Simple Animated Tiles in SGDK
  • Simple Password System
  • Checking the Region
  • Playing Multiple Music Tracks
  • By using the Disqus service you confirm that you have read and agreed to the privacy policy.

    comments powered by Disqus