Is it possible to draw "white" text?

Is there a technique for drawing text in white / off-pixels using the C-API ?

Originally I coded score-functions & what-not to just write the font, but then my pixel-artist supplied black backgrounds, and now the text is invisible.

And for a purely selfish request: I would like a getTextHeight() function please.

PS> Admin: please add a "C-API" tag.

According to @matt, you can use playdate->graphics->setDrawMode() to change the text color (I haven't tested it myself yet).

1 Like

Thanks for that, it works well. I used:

playdate->graphics->setDrawMode( kDrawModeFillWhite );

Then afterwards changed it back to "copy mode". I'm unsure of what the default is.

playdate->graphics->setDrawMode( kDrawModeCopy );

I am pretty sure the default mode is copy :+1:

2 Likes

FWIW, I want white text far more that the reverse... so I just make my fonts in white!

(For one thing, white text can hug the screen edge and still have a nice black bezel around it. Maximum useable screen area.)

2 Likes

I know this is a little bit old, but for people who wants examples and got here in the future, check this, I think it can help

void drawTextColor(LCDBitmap* BitmapContext, LCDFont *font, const void* text, size_t len, PDStringEncoding encoding, int x, int y, LCDColor color, bool inverted)
{
	//grab width & height of our to be rendered text
	pd->graphics->pushContext(BitmapContext);
	int h = pd->graphics->getFontHeight(font);
	
	pd->graphics->setFont(font);
	int w = pd->graphics->getTextWidth(font, text, len, encoding, 0);
	
	//create new bitmap and fillrect with our color / pattern
	LCDBitmap *bitmap = pd->graphics->newBitmap(w, h, kColorClear);
	if (inverted)
		pd->graphics->setDrawMode(kDrawModeInverted);
	pd->graphics->pushContext(bitmap);
	pd->graphics->fillRect(0, 0, w, h, color);
	pd->graphics->popContext();
	
	//create mask with black background and draw text in white on the mask 
	LCDBitmap *bitmapmask = pd->graphics->newBitmap(w, h, kColorBlack);
	pd->graphics->pushContext(bitmapmask);
	pd->graphics->setDrawMode(kDrawModeFillWhite);
	pd->graphics->setFont(font);
	pd->graphics->drawText(text, len, encoding, 0, 0);
	pd->graphics->popContext();

	//set the mask to the bitmap with our pattern, this will make sure only the text
	//part (white in mask is drawn from the bitmap)
	pd->graphics->setBitmapMask(bitmap, bitmapmask);

	//now draw the bitmap containing our text to the x & y position
	pd->graphics->drawBitmap(bitmap, x, y, kBitmapUnflipped);
	pd->graphics->freeBitmap(bitmap);
	pd->graphics->freeBitmap(bitmapmask);
	pd->graphics->popContext();
}

source: https://gist.github.com/joyrider3774/67d6783bfc2fefafc40f3f911ec93205