gpt4 book ai didi

c++ - sdl_ttf 文本换行

转载 作者:塔克拉玛干 更新时间:2023-11-03 06:45:34 30 4
gpt4 key购买 nike

当一串文本的长度超过 300 时,我希望它换行并继续。我读到这就是您的做法,但它不起作用 - 它只是延长了文本。

如何实现?

const char* message = "example text to test that it drops to a new line."; 
std::string fontFile = "Font/font.ttf";
int fontSize = 16;

TTF_Font *font = nullptr;
font = TTF_OpenFont(fontFile.c_str(), fontSize);

SDL_Color textColor = { 0, 300, 200 };
SDL_Surface *surf = TTF_RenderText_Blended_Wrapped(font, message, textColor, 300);
texture = SDL_CreateTextureFromSurface(m_p_Renderer, surf);

int w,h;
TTF_SizeText(font,message,&w,&h);

srcRect.x = 0;
srcRect.y = 0;
destRect.x = 0;
destRect.y = 0;

srcRect.w =w;
srcRect.h = h;

destRect.w =w;
destRect.h = h;

最佳答案

A 认为错误出在 TTF_SizeText(...) 调用上。它不知道您设置的边界,也可能会忽略端线。尝试删除该行并将这些改为:

int w, h;
w = surf->w;
h = surf->h;

希望对你有帮助。

关于c++ - sdl_ttf 文本换行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22275899/

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