TTF_RenderUNICODE_Solid()函数Uint16参数? [英] TTF_RenderUNICODE_Solid() Function Uint16 Parameter?

查看:257
本文介绍了TTF_RenderUNICODE_Solid()函数Uint16参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尽管普通的ttf渲染函数采用const char *作为文本,但它们将渲染TTF_RenderUNICODE_Solid()函数采用const Uint *.

While normal ttf render functions take const char* for the text they're gonna render TTF_RenderUNICODE_Solid() function takes const Uint*.

在使用ASCII字符时,我使用此结构从ttf曲面创建纹理:

I used this structure to create textures from ttf surfaces while working with ASCII characters:

Text = TTF_RenderText_Solid(times, title.c_str(), MakeColor(255, 0, 255));
ButtonTexture = SDL_CreateTextureFromSurface(renderer, Text);

.

当我想使用unicode时,我尝试了以下方法:

And when I wanted to work with unicode I tried this:

Text = TTF_RenderUNICODE_Solid(times, title.c_str(), MakeColor(255, 0, 255));
ButtonTexture = SDL_CreateTextureFromSurface(renderer, Text);

.

因为title.c_str()是const char *,并且该函数需要const Uint16,所以我无法创建纹理.

Because title.c_str() is const char* and the function wants const Uint16 I can't create the texture.

这是我通过标题的方式:

This is how I pass the title:

MenuButtons[0] = new CreateButton("TEXT");

void CreateButton(string title)
{
   Text = TTF_RenderText_Solid(times, title.c_str(), MakeColor(255, 0, 255));
   ButtonTexture = SDL_CreateTextureFromSurface(renderer, Text);
    //or
   Text = TTF_RenderUNICODE_Solid(times, title.c_str(), MakeColor(255, 0, 255));
   ButtonTexture = SDL_CreateTextureFromSurface(renderer, Text);
}

问题:如何将我的字符串转换为Uint16?

推荐答案

我已经看到了TTF_RenderText_Solid的两个版本.一个支持utf-8,另一个支持latin1.当您的版本支持utf-8时,您只需要一个字符串,其中文本以这种格式编码. utf-8latin-1使用简单的char作为存储单元,因此您需要在文档中查找该内容.假设您的版本支持latin1,那么它涵盖的字符数超出了预期的ascii字符范围.

I have seen two versions of TTF_RenderText_Solid. One supports utf-8, one supports latin1. When your version supports utf-8 you simply need a string where the text is encoded in this format. utf-8 and latin-1 use a simple char as storage unit so you need to look that up in the documentation to know that. Let's assume your version supports latin1 then it covers more characters than your expected ascii character range.

但是,那仍然不是您想要的.因此,当您要使用TTF_RenderUNICODE_Solid时,文本生成器必须提供UTF-16字符.因此,您需要知道title中的内容来自何处以及如何编码.

However, that is still not what you want then. So when you want to use TTF_RenderUNICODE_Solid your text-producer must deliver UTF-16 characters. So you need to know where the content from title comes from and how it's encoded.

举个简单的例子,您可以尝试使用静态文本(使用c ++ 11编译器):

For a fast example you can try static text (with a c++11 compiler):

const Uint16 text[]=u"Hello World! \u20AC";

这也应该有助于: 每个软件开发人员绝对,肯定必须了解Unicode和字符集的绝对最低要求(无借口!)

这篇关于TTF_RenderUNICODE_Solid()函数Uint16参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆