TTF_RenderText_Shaded(3)

πŸ’– TTF_RenderText_Shaded(3) πŸ’–

okay so bestie, we're in the SDL_ttf3 FUNCTIONS section of the manual and this one is a whole vibe, fr fr. it's giving "render me text, but make it 8-bit and cute". let's get into it πŸŽ€


✨ NAME ✨

TTF_RenderText_Shaded β€” Render UTF-8 text at high quality to a new 8-bit surface. slay


πŸ“ HEADER FILE πŸ“

Defined in SDL3_ttf/SDL_ttf.h β€” that's the one you gotta include, no cap. πŸ’…


πŸ¦‹ SYNOPSIS πŸ¦‹

#include "SDL3_ttf/SDL_ttf.h"

SDL_Surface * TTF_RenderText_Shaded(TTF_Font *font, const char *text, size_t length, SDL_Color fg, SDL_Color bg);

πŸ’œ DESCRIPTION πŸ’œ

so this function? it allocates a brand new 8-bit, palettized surface for you. the way it works is: pixel 0 on that surface is literally the background color you specified, and all the other pixels are varying degrees of your foreground color. it's giving gradient, it's giving ✨depth✨.

it hands you back that new surface, or NULL if something went wrong. 😭

real talk: this will NOT word-wrap your string. you get a surface with a single line of text, as long as the string needs to be. one line. that's it. that's the whole thing.

if you actually need the output wrapped onto multiple lines, use TTF_RenderText_Shaded_Wrapped() instead. 🫢

and just so we're clear β€” this also does not wrap on newline characters. nope. not happening. πŸ™ˆ

you can render at other quality levels with TTF_RenderText_Solid, TTF_RenderText_Blended, and TTF_RenderText_LCD. pick your fighter, they're all iconic in their own way πŸ‘‘


πŸŽ€ FUNCTION PARAMETERS πŸŽ€

  • font β€” the font you're rendering with. your main character. πŸ’–
  • text β€” the text to render, in UTF-8 encoding. yes bestie, UTF-8, we're not doing anything cursed here.
  • length β€” the length of the text, in bytes, or 0 for null terminated text. pro tip from the manual: 0 = just read till the null, easy. ⭐
  • fg β€” the foreground color for the text. the glow-up color. 🌸
  • bg β€” the background color for the text. the canvas. the vibe. 🌈

🫢 RETURN VALUE 🫢

Returns a new 8-bit, palettized surface, or NULL if there was an error. that's it. if you get NULL, something went sideways and you should go check. πŸ’€


🧡 THREAD SAFETY 🧡

This function should be called on the thread that created the font. like, the same thread. don't be out here passing your font around to other threads, that's not the move. 🚫


⭐ AVAILABILITY ⭐

This function is available since SDL_ttf 3.0.0. so if you're on anything older... bestie. update. 😭


πŸ‘€ SEE ALSO πŸ‘€


and that's the whole page, bestie!! πŸ’… this one came to you straight from the SDL_ttf manual, version SDL_ttf 3.2.2, and it's filed under TTF_RenderText_Shaded(3). go render something gorgeous with it. mwah 🩷✨

πŸ“¦ where this page comes from