PSP2, Wii: Use a higher-resolution font

This commit is contained in:
Jeffrey Pfau 2016-01-05 21:11:31 -08:00
parent 7b090aa0d1
commit bb5e14ea2d
7 changed files with 38 additions and 36 deletions

BIN
res/font2x.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB

View File

@ -25,7 +25,7 @@ set_target_properties(${BINARY_NAME}.elf PROPERTIES COMPILE_DEFINITIONS "${OS_DE
target_link_libraries(${BINARY_NAME}.elf ${BINARY_NAME} ${OS_LIB}) target_link_libraries(${BINARY_NAME}.elf ${BINARY_NAME} ${OS_LIB})
add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/font.o add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/font.o
COMMAND ${OBJCOPY_CMD} font.png ${CMAKE_CURRENT_BINARY_DIR}/font.o COMMAND ${OBJCOPY_CMD} font2x.png ${CMAKE_CURRENT_BINARY_DIR}/font.o
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/res) WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/res)
add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/backdrop.o add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/backdrop.o

View File

@ -8,11 +8,11 @@
#include <vita2d.h> #include <vita2d.h>
#define CELL_HEIGHT 16 #define CELL_HEIGHT 32
#define CELL_WIDTH 16 #define CELL_WIDTH 32
#define GLYPH_HEIGHT 12 #define GLYPH_HEIGHT 24
extern const uint8_t _binary_font_png_start[]; extern const uint8_t _binary_font2x_png_start[];
struct GUIFont { struct GUIFont {
vita2d_texture* tex; vita2d_texture* tex;
@ -23,7 +23,7 @@ struct GUIFont* GUIFontCreate(void) {
if (!font) { if (!font) {
return 0; return 0;
} }
font->tex = vita2d_load_PNG_buffer(_binary_font_png_start); font->tex = vita2d_load_PNG_buffer(_binary_font2x_png_start);
return font; return font;
} }
@ -34,7 +34,7 @@ void GUIFontDestroy(struct GUIFont* font) {
unsigned GUIFontHeight(const struct GUIFont* font) { unsigned GUIFontHeight(const struct GUIFont* font) {
UNUSED(font); UNUSED(font);
return GLYPH_HEIGHT * 2; return GLYPH_HEIGHT;
} }
unsigned GUIFontGlyphWidth(const struct GUIFont* font, uint32_t glyph) { unsigned GUIFontGlyphWidth(const struct GUIFont* font, uint32_t glyph) {
@ -50,10 +50,10 @@ void GUIFontDrawGlyph(const struct GUIFont* font, int x, int y, uint32_t color,
glyph = '?'; glyph = '?';
} }
struct GUIFontGlyphMetric metric = defaultFontMetrics[glyph]; struct GUIFontGlyphMetric metric = defaultFontMetrics[glyph];
vita2d_draw_texture_tint_part_scale(font->tex, x, y + (-GLYPH_HEIGHT + metric.padding.top) * 2, vita2d_draw_texture_tint_part_scale(font->tex, x, y - GLYPH_HEIGHT + metric.padding.top * 2,
(glyph & 15) * CELL_WIDTH + metric.padding.left, (glyph & 15) * CELL_WIDTH + metric.padding.left * 2,
(glyph >> 4) * CELL_HEIGHT + metric.padding.top, (glyph >> 4) * CELL_HEIGHT + metric.padding.top * 2,
CELL_WIDTH - (metric.padding.left + metric.padding.right), CELL_WIDTH - (metric.padding.left + metric.padding.right) * 2,
CELL_HEIGHT - (metric.padding.top + metric.padding.bottom), CELL_HEIGHT - (metric.padding.top + metric.padding.bottom) * 2,
2, 2, color); 1, 1, color);
} }

View File

@ -24,6 +24,7 @@ target_link_libraries(${BINARY_NAME}.elf ${BINARY_NAME} ${OS_LIB})
add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/font.c add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/font.c
COMMAND ${RAW2C} ${CMAKE_SOURCE_DIR}/src/platform/wii/font.tpl COMMAND ${RAW2C} ${CMAKE_SOURCE_DIR}/src/platform/wii/font.tpl
MAIN_DEPENDENCY ${CMAKE_SOURCE_DIR}/src/platform/wii/font.tpl
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
add_custom_target(${BINARY_NAME}.dol ALL add_custom_target(${BINARY_NAME}.dol ALL

Binary file not shown.

View File

@ -10,9 +10,9 @@
#include <malloc.h> #include <malloc.h>
#include <ogc/tpl.h> #include <ogc/tpl.h>
#define GLYPH_HEIGHT 12 #define GLYPH_HEIGHT 24
#define CELL_HEIGHT 16 #define CELL_HEIGHT 32
#define CELL_WIDTH 16 #define CELL_WIDTH 32
struct GUIFont { struct GUIFont {
TPLFile tdf; TPLFile tdf;
@ -50,7 +50,7 @@ unsigned GUIFontGlyphWidth(const struct GUIFont* font, uint32_t glyph) {
if (glyph > 0x7F) { if (glyph > 0x7F) {
glyph = '?'; glyph = '?';
} }
return defaultFontMetrics[glyph].width; return defaultFontMetrics[glyph].width * 2;
} }
void GUIFontDrawGlyph(const struct GUIFont* font, int x, int y, uint32_t color, uint32_t glyph) { void GUIFontDrawGlyph(const struct GUIFont* font, int x, int y, uint32_t color, uint32_t glyph) {
@ -69,23 +69,23 @@ void GUIFontDrawGlyph(const struct GUIFont* font, int x, int y, uint32_t color,
glyph = '?'; glyph = '?';
} }
struct GUIFontGlyphMetric metric = defaultFontMetrics[glyph]; struct GUIFontGlyphMetric metric = defaultFontMetrics[glyph];
s16 tx = (glyph & 15) * CELL_WIDTH + metric.padding.left; s16 tx = (glyph & 15) * CELL_WIDTH + metric.padding.left * 2;
s16 ty = (glyph >> 4) * CELL_HEIGHT + metric.padding.top; s16 ty = (glyph >> 4) * CELL_HEIGHT + metric.padding.top * 2;
GX_Begin(GX_QUADS, GX_VTXFMT0, 4); GX_Begin(GX_QUADS, GX_VTXFMT0, 4);
GX_Position2s16(x, y - GLYPH_HEIGHT + metric.padding.top); GX_Position2s16(x, y - GLYPH_HEIGHT + metric.padding.top * 2);
GX_Color1u32(color); GX_Color1u32(color);
GX_TexCoord2f32(tx / 256.f, ty / 128.f); GX_TexCoord2f32(tx / 512.f, ty / 256.f);
GX_Position2s16(x + CELL_WIDTH - (metric.padding.left + metric.padding.right), y - GLYPH_HEIGHT + metric.padding.top); GX_Position2s16(x + CELL_WIDTH - (metric.padding.left + metric.padding.right) * 2, y - GLYPH_HEIGHT + metric.padding.top * 2);
GX_Color1u32(color); GX_Color1u32(color);
GX_TexCoord2f32((tx + CELL_WIDTH - (metric.padding.left + metric.padding.right)) / 256.f, ty / 128.f); GX_TexCoord2f32((tx + CELL_WIDTH - (metric.padding.left + metric.padding.right) * 2) / 512.f, ty / 256.f);
GX_Position2s16(x + CELL_WIDTH - (metric.padding.left + metric.padding.right), y - GLYPH_HEIGHT + CELL_HEIGHT - metric.padding.bottom); GX_Position2s16(x + CELL_WIDTH - (metric.padding.left + metric.padding.right) * 2, y - GLYPH_HEIGHT + CELL_HEIGHT - metric.padding.bottom * 2);
GX_Color1u32(color); GX_Color1u32(color);
GX_TexCoord2f32((tx + CELL_WIDTH - (metric.padding.left + metric.padding.right)) / 256.f, (ty + CELL_HEIGHT - (metric.padding.top + metric.padding.bottom)) / 128.f); GX_TexCoord2f32((tx + CELL_WIDTH - (metric.padding.left + metric.padding.right) * 2) / 512.f, (ty + CELL_HEIGHT - (metric.padding.top + metric.padding.bottom) * 2) / 256.f);
GX_Position2s16(x, y - GLYPH_HEIGHT + CELL_HEIGHT - metric.padding.bottom); GX_Position2s16(x, y - GLYPH_HEIGHT + CELL_HEIGHT - metric.padding.bottom * 2);
GX_Color1u32(color); GX_Color1u32(color);
GX_TexCoord2f32(tx / 256.f, (ty + CELL_HEIGHT - (metric.padding.top + metric.padding.bottom)) / 128.f); GX_TexCoord2f32(tx / 512.f, (ty + CELL_HEIGHT - (metric.padding.top + metric.padding.bottom) * 2) / 256.f);
GX_End(); GX_End();
} }

View File

@ -196,7 +196,7 @@ int main() {
struct GBAGUIRunner runner = { struct GBAGUIRunner runner = {
.params = { .params = {
vmode->fbWidth * 0.9, vmode->efbHeight * 0.9, vmode->fbWidth * 1.6, vmode->efbHeight * 1.6,
font, "", font, "",
_drawStart, _drawEnd, _drawStart, _drawEnd,
_pollInput, _pollCursor, _pollInput, _pollCursor,
@ -374,21 +374,22 @@ void _reproj(int w, int h) {
GX_LoadProjectionMtx(proj, GX_ORTHOGRAPHIC); GX_LoadProjectionMtx(proj, GX_ORTHOGRAPHIC);
} }
void _reproj2(int w, int h) {
Mtx44 proj;
s16 top = 20;
guOrtho(proj, -top, top + h, 0, w, 0, 300);
GX_LoadProjectionMtx(proj, GX_ORTHOGRAPHIC);
}
void _guiPrepare(void) { void _guiPrepare(void) {
int w = vmode->fbWidth * 0.9; _reproj2(vmode->fbWidth * 1.6, vmode->efbHeight * 1.6);
int h = vmode->efbHeight * 0.9;
_reproj(w, h);
} }
void _guiFinish(void) { void _guiFinish(void) {
if (screenMode == SM_PA) { if (screenMode == SM_PA) {
_reproj(VIDEO_HORIZONTAL_PIXELS * scaleFactor, VIDEO_VERTICAL_PIXELS * scaleFactor); _reproj(VIDEO_HORIZONTAL_PIXELS * scaleFactor, VIDEO_VERTICAL_PIXELS * scaleFactor);
} else { } else {
Mtx44 proj; _reproj2(VIDEO_HORIZONTAL_PIXELS, VIDEO_VERTICAL_PIXELS);
short top = (CONF_GetAspectRatio() == CONF_ASPECT_16_9) ? 10 : 20;
short bottom = VIDEO_VERTICAL_PIXELS + top;
guOrtho(proj, -top, bottom, 0, VIDEO_HORIZONTAL_PIXELS, 0, 300);
GX_LoadProjectionMtx(proj, GX_ORTHOGRAPHIC);
} }
} }