createCharacterSurface function
Implementation
Pointer<SdlSurface> createCharacterSurface(int c, int rotation) {
Pointer<SdlSurface> rotatedCharacter;
Pointer<SdlSurface> character;
Pointer<Uint32> pixels;
int ix, iy;
int patt;
int linepos;
/*
* Redraw character into surface
*/
character = sdlCreateSurface(charWidth, charHeight, SDL_PIXELFORMAT_RGBA8888);
if (character == nullptr) {
return nullptr;
}
var charpos = c * charSize;
pixels = character.ref.pixels.cast<Uint32>();
/*
* Drawing loop
*/
patt = 0;
linepos = 0;
for (iy = 0; iy < charHeight; iy++) {
patt = currentFontdata[charpos + iy];
for (ix = 0; ix < charWidth; ix++) {
var pixel = pixels + linepos;
if (patt & 0x80 != 0) {
pixel.value = 0xffffffff;
} else {
pixel.value = 0;
}
linepos++;
patt = patt << 1;
}
}
/* Maybe rotate and replace cached image */
if (rotation > 0) {
rotatedCharacter = rotateSurface90Degrees(character, rotation);
sdlDestroySurface(character);
character = rotatedCharacter;
}
return character;
}