gpt4 book ai didi

c++ - 使用 SDL TTF for SDL 2 看不到我的文本

转载 作者:行者123 更新时间:2023-11-30 02:51:55 25 4
gpt4 key购买 nike

我想我做的很好,但无论如何我没有看到我的文字。 Official docs很差(或对于 SDL 2 而言已过时)。

if (TTF_Init())
printf("%s\n", TTF_GetError());
font = TTF_OpenFont("Fonts/DinCompRegular.ttf", 24);
if (!font)
printf("%s\n", TTF_GetError());
SDL_Color fontColor = { 255, 0, 0, 255 };
u16 text[] = { '2', 's', 'ä', 'Щ' };
SDL_Surface *info = TTF_RenderUNICODE_Solid(font, text, fontColor);
SDL_Rect rect = { info->w, info->h, 0, 0 };
SDL_Surface *place = SDL_CreateRGBSurface(0, info->w, info->h, 32, 0, 0, 0, 0);

在主循环中:

    SDL_BlitSurface(info, 0, place, &rect);
SDL_FreeSurface(info);
SDL_RenderPresent(renderer);

最佳答案

我自己解决的:

u16 text[] = { '2', L'Щ', L'ä', L'Ø', '\0' };
SDL_Surface *info = TTF_RenderUNICODE_Blended(font, text, fontColor);

循环:

    SDL_Texture *texture = SDL_CreateTextureFromSurface(renderer, info);
SDL_Rect src = { 0, 0, info->w, info->h };
SDL_Rect dst = { 0, 0, info->w, info->h };
SDL_RenderCopy(renderer, texture, &src, &dst);
SDL_DestroyTexture(texture);

关于c++ - 使用 SDL TTF for SDL 2 看不到我的文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19369203/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com