Direct2D 第3篇 绘制文字

本文是Direct2D系列的第三篇,详细讲解如何使用Direct2D API进行文字绘制,涵盖字体选择、布局、样式设置等关键步骤,适用于Windows平台的2D图形开发,是GDI和VC开发者进阶Direct2D的重要参考。
摘要由CSDN通过智能技术生成



#include <windows.h>
#include <d2d1.h>
#include <d2d1helper.h>
#include <dwrite.h>
#pragma comment(lib, "dwrite.lib")
#pragma comment(lib, "d2d1.lib")

HINSTANCE g_hinst;
HWND g_hwnd;

ID2D1Factory * g_factory;
ID2D1HwndRenderTarget * g_render_target;
ID2D1SolidColorBrush  * g_brush;

IDWriteFactory * g_write_factory;
IDWriteTextFormat * g_text_format;


bool AppInit()
{
	D2D1CreateFactory(D2D1_FACTORY_TYPE_SINGLE_THREADED, &g_factory);

	RECT rc;
	GetClientRect(g_hwnd, &rc);
 
	g_factory->CreateHwndRenderTarget(
		D2D1::RenderTargetProperties(),
		D2D1::HwndRenderTargetProperties(g_hwnd, D2D1::SizeU(rc.right - rc.left, rc.bottom - rc.top)	),
		&g_render_target);

	g_render_target->CreateSolidColorBrush(D2D1::ColorF(D2D1::ColorF::ForestGreen), &g_brush);

	// Init Font
	DWriteCreateFactory(
  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值