mirror of
https://github.com/SFML/SFML.git
synced 2024-11-25 12:51:05 +08:00
Added code in sf::Font to handle bitmap glyphs rendered in monochrome mode
git-svn-id: https://sfml.svn.sourceforge.net/svnroot/sfml/branches/sfml2@1479 4e206d99-4929-0410-ac5d-dfc041789085
This commit is contained in:
parent
09a0d11668
commit
87f712e0c6
@ -375,6 +375,23 @@ Glyph Font::LoadGlyph(Uint32 codePoint, unsigned int characterSize, bool bold) c
|
|||||||
// Extract the glyph's pixels from the bitmap
|
// Extract the glyph's pixels from the bitmap
|
||||||
myPixelBuffer.resize(width * height * 4, 255);
|
myPixelBuffer.resize(width * height * 4, 255);
|
||||||
const Uint8* pixels = bitmap.buffer;
|
const Uint8* pixels = bitmap.buffer;
|
||||||
|
if (bitmap.pixel_mode == FT_PIXEL_MODE_MONO)
|
||||||
|
{
|
||||||
|
// Pixels are 1 bit monochrome values
|
||||||
|
for (int y = 0; y < height; ++y)
|
||||||
|
{
|
||||||
|
for (int x = 0; x < width; ++x)
|
||||||
|
{
|
||||||
|
// The color channels remain white, just fill the alpha channel
|
||||||
|
std::size_t index = (x + y * width) * 4 + 3;
|
||||||
|
myPixelBuffer[index] = ((pixels[x / 8]) & (1 << (7 - (x % 8)))) ? 255 : 0;
|
||||||
|
}
|
||||||
|
pixels += bitmap.pitch;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Pixels are 8 bits gray levels
|
||||||
for (int y = 0; y < height; ++y)
|
for (int y = 0; y < height; ++y)
|
||||||
{
|
{
|
||||||
for (int x = 0; x < width; ++x)
|
for (int x = 0; x < width; ++x)
|
||||||
@ -382,12 +399,10 @@ Glyph Font::LoadGlyph(Uint32 codePoint, unsigned int characterSize, bool bold) c
|
|||||||
// The color channels remain white, just fill the alpha channel
|
// The color channels remain white, just fill the alpha channel
|
||||||
std::size_t index = (x + y * width) * 4 + 3;
|
std::size_t index = (x + y * width) * 4 + 3;
|
||||||
myPixelBuffer[index] = pixels[x];
|
myPixelBuffer[index] = pixels[x];
|
||||||
|
|
||||||
// Formula for FT_RENDER_MODE_MONO
|
|
||||||
//myPixelBuffer[index] = ((pixels[x / 8]) & (1 << (7 - (x % 8)))) ? 255 : 0;
|
|
||||||
}
|
}
|
||||||
pixels += bitmap.pitch;
|
pixels += bitmap.pitch;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Write the pixels to the texture
|
// Write the pixels to the texture
|
||||||
IntRect subrect = glyph.SubRect;
|
IntRect subrect = glyph.SubRect;
|
||||||
|
Loading…
Reference in New Issue
Block a user