Rayilb库实现中文打印函数

该代码示例展示了如何利用Raylib库加载字体文件,生成图像并实现中文文本的打印。主要函数包括LoadFileData用于读取字体文件,GenImageColor创建图像,以及自定义的ch_text函数用于显示中文字符。
摘要由CSDN通过智能技术生成

Rayilb库实现中文打印函数

#include<raylib.h>
using namespace std;
unsigned int fileSize;
unsigned char *fontFileData = LoadFileData("c:\\windows\\fonts\\simhei.ttf", &fileSize);
Image img=GenImageColor(800,600,WHITE);
void ch_text(char text[],Vector2 xy,float space,float size,Color color){//中文打印函数
	int codepointsCount;
	int *codepoints=LoadCodepoints(text,&codepointsCount);
	Font font = LoadFontFromMemory(".ttf",fontFileData,fileSize,32,codepoints,codepointsCount);
	UnloadCodepoints(codepoints);
	DrawTextEx(font,text,xy,size,space,color);
}
int main(){
	InitWindow(400,400,"?");
	SetTargetFPS(1000);
	while(!WindowShouldClose()){
		BeginDrawing();
		ClearBackground(WHITE);
			ch_text("hello",(Vector2){50,50},2,10,BLACK);
		EndDrawing();
	}
	UnloadImage(img);
	UnloadFileData(fontFileData);
}

关注

方法来源

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值