MSDFフォントを使った文字効果
もじさん 2025/02/01(Sat) 15:19
Reputeless 2025/02/04(Tue) 12:08
@ 輪郭の二重化
# include <Siv3D.hpp>
void Main()
{
Scene::SetBackground(ColorF{ 0.6, 0.8, 0.7 });
const Font font{ FontMethod::MSDF, 48, Typeface::Bold };
while (System::Update())
{
font(U"Hello, Siv3D!")
.draw(TextStyle::Outline(0.2, 0.0, ColorF{ 1.0 }), 80, Vec2{ 40, 40 }, ColorF{ 0.2, 0.4, 1.0 });
font(U"Hello, Siv3D!")
.draw(TextStyle::Outline(0.0, 0.2, ColorF{ 0.0 }), 80, Vec2{ 40, 40 }, ColorF{ 0.0, 0.0 });
}
}
A カラーグラデーション
# include <Siv3D.hpp>
BlendState MakeBlendState()
{
BlendState blendState = BlendState::Default2D;
blendState.srcAlpha = Blend::SrcAlpha;
blendState.dstAlpha = Blend::DestAlpha;
blendState.opAlpha = BlendOp::Max;
return blendState;
}
void RenderText(const Font& font, const RenderTexture& renderTexture, const double fontSize, const StringView text)
{
// レンダーターゲットを renderTexture に変更する
const ScopedRenderTarget2D target{ renderTexture.clear(ColorF{ 1.0, 0.0 }) };
// 描画された最大のアルファ成分を保持するブレンドステート
const ScopedRenderStates2D blend{ MakeBlendState() };
// テキストを描画する
font(text).draw(fontSize, Vec2{ 0, 0 });
}
void Main()
{
Scene::SetBackground(ColorF{ 0.6, 0.8, 0.7 });
const Font font{ FontMethod::MSDF, 48, Typeface::Bold };
const RenderTexture renderTexture{ Size{ 800, 120 } };
RenderText(font, renderTexture, 90, U"Hello, Siv3D!");
while (System::Update())
{
renderTexture.draw(Arg::top(0.2, 0.8, 0.4), Arg::bottom(0.2, 0.4, 0.8));
Rect{ renderTexture.size() }.drawFrame(1, 0, Palette::Black);
}
}
もじさん 2025/02/04(Tue) 22:00
Reputeless 2025/02/05(Wed) 01:15
もじさん 2025/02/05(Wed) 21:53
ご回答ありがとうございます。
もう一点、ご教示いただきたいのですが、
Aのカラーグラデーションのサンプルコードで、Main関数を以下の様に変更し、
2回描画させると、2回目の描画が残像が残った形になり、うまくいきません。
これを回避するには、RenderTextureをもうひとつ用意する必要がありますでしょうか。
宜しくお願い致します。
void Main()
{
Scene::SetBackground(ColorF{ 0.6, 0.8, 0.7 });
const Font font{ FontMethod::MSDF, 48, Typeface::Bold };
const RenderTexture renderTexture{ Size{ 800, 120 } };
while (System::Update())
{
RenderText(font, renderTexture, 90, U"Hello, Siv3D!");
renderTexture.draw(Arg::top(0.2, 0.8, 0.4), Arg::bottom(0.2, 0.4, 0.8));
RenderText(font, renderTexture, 100, U"Hello, Siv3D!");
renderTexture.draw(0, 200, Arg::top(0.2, 0.8, 0.4), Arg::bottom(0.2, 0.4, 0.8));
}
}
Reputeless 2025/02/05(Wed) 23:09