虽然普通的 ttf 渲染函数采用 const char* 作为文本,但它们将渲染 TTF_RenderUNICODE_Solid() 函数采用 const Uint*。
在使用 ASCII 字符时,我使用此结构从 ttf 表面创建纹理:
Text = TTF_RenderText_Solid(times, title.c_str(), MakeColor(255, 0, 255));
ButtonTexture = SDL_CreateTextureFromSurface(renderer, Text);
.
当我想使用 unicode 时,我尝试了这个:
Text = TTF_RenderUNICODE_Solid(times, title.c_str(), MakeColor(255, 0, 255));
ButtonTexture = SDL_CreateTextureFromSurface(renderer, Text);
.
因为 title.c_str() 是 const char* 并且函数需要 const Uint16 我无法创建纹理。
这就是我传递标题的方式:
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?