Font rendering code runs but it sure ain't right

This commit is contained in:
Henrik Rydgård
2017-06-05 23:09:11 +02:00
parent d9c43642c2
commit 0bf92a4fa2
3 changed files with 9 additions and 3 deletions
@@ -18,10 +18,11 @@ public class TextRenderer {
Rect bound = new Rect();
p.setTextSize(textSize);
p.getTextBounds(string, 0, string.length(), bound);
float baseline = -p.ascent();
Bitmap bmp = Bitmap.createBitmap(bound.width(), bound.height(), Bitmap.Config.ARGB_4444);
Canvas canvas = new Canvas(bmp);
p.setColor(Color.WHITE);
canvas.drawText(string, 0, 0, p);
canvas.drawText(string, 0, baseline, p);
int bufSize = bmp.getRowBytes() * bmp.getHeight() * 2; // 2 = sizeof(ARGB_4444)
ByteBuffer buf = ByteBuffer.allocate(bufSize);
@@ -37,7 +38,6 @@ public class TextRenderer {
int dstOffset = y * bound.width();
for (int x = 0; x < bound.width(); x++) {
int val = bytes[srcOffset + x * 2];
val = (val << 12) | 0xFFF;
output[dstOffset + x] = (short)val;
}
}
+4 -1
View File
@@ -135,7 +135,10 @@ void TextDrawerAndroid::DrawString(DrawBuffer &target, const char *str, float x,
jshort* jimage = env_->GetShortArrayElements(imageData, nullptr);
for (int x = 0; x < entry->bmWidth; x++) {
for (int y = 0; y < entry->bmHeight; y++) {
bitmapData[entry->bmWidth * y + x] = jimage[imageWidth * y + x];
int v = jimage[imageWidth * y + x];
v = (v << 4) | v;
v = (v << 8) | v;
bitmapData[entry->bmWidth * y + x] = v;
}
}
env_->ReleaseShortArrayElements(imageData, jimage, 0);
+3
View File
@@ -675,6 +675,9 @@ enum class TextureState {
};
bool VKTexture::Create(const TextureDesc &desc) {
// Zero-sized textures not allowed.
if (desc.width * desc.height * desc.depth == 0)
return false;
format_ = desc.format;
mipLevels_ = desc.mipLevels;
width_ = desc.width;