Take your skills to the next level with these bite-sized tutorials!

Changing The Text Color in SGDK


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.

images/white.png

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_setPaletteColor(15,RGB24_TO_VDPCOLOR(0xff0000));
VDP_drawText("Hello World", 8, 8);
images/red.png

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 have any questions, comments or criticism, post them in the comments below or reach out to me on Twitter @ohsat_games! Special thanks to Stephane Dallongeville for creating SGDK and everyone in the SGDK Discord for their help and keeping the dream alive!

Take It to the Next Level!

Want to boost your Mega Drive coding skills? Get exclusive bonus steps and project files for each tutorial by supporting me on Patreon!

Become a Patron!
Just Want to Buy Me a Coffee?

Check out the rest of this tutorial series!

  • Creating Graphics for the Mega Drive
  • 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
  • Get Words in Your Inbox!

    Be oldschool and sign up for my newsletter to get updates! Just enter your email address, prove you're not part of Skynet and you're good to go!



    Powered by CleverReach. I will not send you spam or sell/give your email address to someone else.  You can of course unsubscribe at any time. By clicking the subscribe button above, you confirm that you have read and agreed to our privacy policy.

    By using the Disqus service you confirm that you have read and agreed to the privacy policy.

    comments powered by Disqus

    Related Posts

    Streets of Rage 2 Design Docs

    A few years ago, Yuzo Koshiro posted a pile of old game design documents for Bare Knuckle 2 aka Streets of Rage 2 on the Ancient blog to commemorate the release of Streets of Rage 2 3D on the Nintendo 3DS. These documents gave a deep insight into the game’s inner workings, technical aspects, designs and even some cut content. They were an awesome resource for one of the most awesome games ever created.

    Read More

    Make a Space Shooter for the Mega Drive!

    It’s time for another SGDK tutorial series! After doing a single player Pong game and an endless runner, it’s time to reach for the stars… and make a space shooter! Apart from things like scrolling and animating sprites, this new series will show you how to deal with multiple entities and their collisions, how to randomly generate backgrounds and more! This project builds upon the previous tutorials, so if you’re new to SGDK programming and have not done those yet, I highly recommend starting with Megapong.
    Read More

    Patreon Revamps

    Hey there, what’s up? Things are continuing to evolve, as I’ve now updated my Patreon to give patrons more perks! Apart from early access to new tutorials and posts, the biggest one is probably the ability to peek behind the scenes…and there will be a lot to peek at in the coming months! This year I’m writing and submitting my MA thesis, meaning that I will have to do more stuff to make ends meet.
    Read More