C++/SDL 渲染文本
我有一个使用 SDL_ttf 来显示文本的小应用程序。这通过以下方式工作得很好: TTF_RenderText_Solid( font, "text here", textColor );
但是,我想知道如何渲染整数。我假设它们需要首先转换为字符串,但我遇到了一个问题。特别是当我想像这样显示鼠标的 x 和 y 位置时:
if( event.type == SDL_MOUSEMOTION )
{
mouse_move = TTF_RenderText_Solid( font, "need mouse x and y here", textColor );
}
我相信我可以通过 event.motion.x
和 event.motion.y< 获取 x 和 y 坐标/代码>。这是正确的吗?
I have a little application which uses SDL_ttf to display text. This works just fine via: TTF_RenderText_Solid( font, "text here", textColor );
However, I was wondering how I would go about rendering integers. I am assuming they would need to be casted to strings first, but I am running into a problem with this. Specifically when I want to display the x and y position of the mouse like such:
if( event.type == SDL_MOUSEMOTION )
{
mouse_move = TTF_RenderText_Solid( font, "need mouse x and y here", textColor );
}
I believe I can grab the x and y coordinates via event.motion.x
and event.motion.y
. Is this correct?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
不,不是转换而是转换。最简单的方法是使用流,例如:
Nope, not casted but converted. The simplest way is using streams, something like:
通常我使用诸如
boost::lexical_cast
或boost::format
我倾向于避免
std::stringstream
除非它是迭代的。您必须检查.good()
或类似的内容来查看它是否失败,而且它并不像您希望的那么常见。Usually I use something like
boost::lexical_cast
orboost::format
I tend to avoid
std::stringstream
unless its iterative. You have to check.good()
or the like to see if it failed, and it's not as common as you'd hope.