SDL 编写文本
我在 SDL 项目中遇到问题,我想在窗口上显示文本并允许用户输入文本。据我所知,没有简单的方法可以实现这一目标。你有什么建议吗? 注意:我使用C编程语言。我知道有一个名为 SDL_ttf 的库,它似乎无法完成我想要的工作。
I'm having a problem for a SDL project, I'd like to show text on the window and allow the user to input text. As much as I know, there is no simple way to achieve that. Do you hava any suggestion?
Note: I use C programming langage. I know there is a library called SDL_ttf which doesn't seems to make the job I want.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我必须说实话,当我读到你的问题时,SDL_ttf 立即浮现在我的脑海中。使用起来并不太难,并且有很多可用的文档。
听起来您正在寻找的是一个提供简单控制台界面的库,您的主要编程交互是
write(...)
和read(...)< /code> 文本,它处理显示、滚动等。
此项目有很多内容显示如何在 SDL 中实现简单“控制台”的代码,并且它确实使用 SDL_ttf 来执行此操作。
我不相信你会避免它,除非你抓住某人的图书馆,将它隐藏起来,就像 这个 但您对其提供的显示和交互性的控制将会减少。
I have to be honest, as I was reading your question, SDL_ttf immediately sprang to mind. It's not too hard to use and there are plenty of docs available.
What it sounds like you are looking for, is a library that provides a simple console interface, where your main programming interaction is to
write(...)
andread(...)
text and it handles display, scrolling and so on.This project has a lot of code showing how to implement a simple 'console' in SDL, and it does use SDL_ttf to do so.
I'm not convinced you are going to avoid it, unless you grab someone's library that hides it away from you like this one but you are going to have less control over the display and interactivity this provides.
我必须选择 benosteen,SDL_ttf 是一个非常好的选择。就我而言,我使用了本教程 使其在我的项目中工作。这真的非常简单明了。
编辑:
我在使用 SDL_ttf 的混合功能时遇到了一些麻烦,但在 QuasarDonkey 在 这个问题。
查看有关如何使用它和创建文本表面的直接示例。
I must go with benosteen, SDL_ttf is a really good option. For my part, I used this tutorial to make it work in my project. It's really simple and straightforward.
EDIT:
I had some troubles with the Blending functionality of SDL_ttf, but I managed to make it work after QuasarDonkey found the problem in this question.
Have a look for a straight forward example on how to use it and create text surface.