子像素渲染

This commit is contained in:
Nanako 2025-03-28 15:51:33 +08:00
parent 2a84cd6c4e
commit 765617d538
6 changed files with 43 additions and 4 deletions

View File

@ -40,6 +40,7 @@ include(cmake/retrieve_files.cmake)
include(cmake/detect_os.cmake) include(cmake/detect_os.cmake)
include(cmake/config_macos.cmake) include(cmake/config_macos.cmake)
include(cmake/compile_shaders.cmake) include(cmake/compile_shaders.cmake)
include(cmake/mingw_dll.cmake)
# Debug, # Debug,
if (CMAKE_BUILD_TYPE STREQUAL "Debug") if (CMAKE_BUILD_TYPE STREQUAL "Debug")

29
cmake/mingw_dll.cmake Normal file
View File

@ -0,0 +1,29 @@
function(auto_copy_mingw_dll target)
if(MINGW)
# MinGW
get_filename_component(MINGW_DIR ${CMAKE_CXX_COMPILER} PATH)
# DLL
set(MINGW_DLLS
"libstdc++-6.dll"
# "libgcc_s_dw2-1.dll"
"libgcc_s_seh-1.dll"
"libwinpthread-1.dll"
)
foreach(DLL ${MINGW_DLLS})
#
if(EXISTS "${MINGW_DIR}/${DLL}")
add_custom_command(TARGET ${target} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
"${MINGW_DIR}/${DLL}"
"$<TARGET_FILE_DIR:${target}>"
COMMENT "Copying ${DLL} to output directory"
VERBATIM)
else()
message(WARNING "DLL not found: ${MINGW_DIR}/${DLL}")
endif()
endforeach()
endif()
endfunction()

View File

@ -8,3 +8,5 @@ target_link_libraries(${PROJECT_NAME} PRIVATE mirage_app)
if (MSVC) if (MSVC)
target_link_options(${PROJECT_NAME} PRIVATE "/SUBSYSTEM:WINDOWS" "/ENTRY:mainCRTStartup") target_link_options(${PROJECT_NAME} PRIVATE "/SUBSYSTEM:WINDOWS" "/ENTRY:mainCRTStartup")
endif() endif()
auto_copy_mingw_dll(${PROJECT_NAME})

View File

@ -10,7 +10,7 @@ int main(int argc, char* argv[]) {
mirage_app::get().init(); mirage_app::get().init();
auto& manager = font_manager::instance(); auto& manager = font_manager::instance();
manager.add_font(L"C:/Users/46944/AppData/Local/Microsoft/Windows/Fonts/MapleMono-NF-CN-Regular.ttf"); // manager.add_font(L"C:/Users/46944/AppData/Local/Microsoft/Windows/Fonts/MapleMono-NF-CN-Regular.ttf");
manager.add_font(L"C:/Windows/Fonts/msyh.ttc"); manager.add_font(L"C:/Windows/Fonts/msyh.ttc");
manager.add_font(L"C:/Windows/Fonts/seguiemj.ttf"); manager.add_font(L"C:/Windows/Fonts/seguiemj.ttf");

View File

@ -14,7 +14,11 @@ std::optional<bitmap_t> standard_bitmap_renderer_t::render_bitmap(
// 获取字形边界 // 获取字形边界
int x0, y0, x1, y1; int x0, y0, x1, y1;
stbtt_GetGlyphBitmapBox(&font_info, glyph_index, scale, scale, &x0, &y0, &x1, &y1); stbtt_GetGlyphBitmapBoxSubpixel(&font_info,
glyph_index,
scale, scale,
0.5f, 0,
&x0, &y0, &x1, &y1);
const int width = x1 - x0; const int width = x1 - x0;
const int height = y1 - y0; const int height = y1 - y0;
@ -33,11 +37,12 @@ std::optional<bitmap_t> standard_bitmap_renderer_t::render_bitmap(
bitmap.data.resize(width * height); bitmap.data.resize(width * height);
// 渲染字形 // 渲染字形
stbtt_MakeGlyphBitmap( stbtt_MakeGlyphBitmapSubpixel(
&font_info, &font_info,
bitmap.data.data(), bitmap.data.data(),
width, height, width, width, height, width,
scale, scale, scale, scale,
0.5f, 0,
glyph_index glyph_index
); );

View File

@ -31,5 +31,7 @@ PSInput vertex_main(VSInput input)
float4 pixel_main(PSInput input) : SV_Target float4 pixel_main(PSInput input) : SV_Target
{ {
float4 color = texture.Sample(textureSampler, input.uv); float4 color = texture.Sample(textureSampler, input.uv);
return float4(color.r) * input.color; float4 final_color = input.color;
final_color.a *= color.r;
return final_color;
} }