子像素渲染
This commit is contained in:
parent
2a84cd6c4e
commit
765617d538
@ -40,6 +40,7 @@ include(cmake/retrieve_files.cmake)
|
||||
include(cmake/detect_os.cmake)
|
||||
include(cmake/config_macos.cmake)
|
||||
include(cmake/compile_shaders.cmake)
|
||||
include(cmake/mingw_dll.cmake)
|
||||
|
||||
# 如果是Debug模式, 添加宏定义
|
||||
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
|
||||
|
29
cmake/mingw_dll.cmake
Normal file
29
cmake/mingw_dll.cmake
Normal 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()
|
@ -8,3 +8,5 @@ target_link_libraries(${PROJECT_NAME} PRIVATE mirage_app)
|
||||
if (MSVC)
|
||||
target_link_options(${PROJECT_NAME} PRIVATE "/SUBSYSTEM:WINDOWS" "/ENTRY:mainCRTStartup")
|
||||
endif()
|
||||
|
||||
auto_copy_mingw_dll(${PROJECT_NAME})
|
||||
|
@ -10,7 +10,7 @@ int main(int argc, char* argv[]) {
|
||||
mirage_app::get().init();
|
||||
|
||||
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/seguiemj.ttf");
|
||||
|
||||
|
@ -14,7 +14,11 @@ std::optional<bitmap_t> standard_bitmap_renderer_t::render_bitmap(
|
||||
|
||||
// 获取字形边界
|
||||
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 height = y1 - y0;
|
||||
@ -33,11 +37,12 @@ std::optional<bitmap_t> standard_bitmap_renderer_t::render_bitmap(
|
||||
bitmap.data.resize(width * height);
|
||||
|
||||
// 渲染字形
|
||||
stbtt_MakeGlyphBitmap(
|
||||
stbtt_MakeGlyphBitmapSubpixel(
|
||||
&font_info,
|
||||
bitmap.data.data(),
|
||||
width, height, width,
|
||||
scale, scale,
|
||||
0.5f, 0,
|
||||
glyph_index
|
||||
);
|
||||
|
||||
|
@ -31,5 +31,7 @@ PSInput vertex_main(VSInput input)
|
||||
float4 pixel_main(PSInput input) : SV_Target
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user