SDL:简单位图的 FPS 问题

发布于 2024-09-19 00:09:56 字数 363 浏览 4 评论 0原文

我目前正在 SDL 中开发一款具有可破坏地形的游戏。目前地形是一张随机生成的大位图(5000*500,用于测试)。

每一帧主表面都会被清除,地形位图会被位图传输到其中。目前的分辨率是1200 * 700,所以当我测试1200 * 500像素时,大部分点都是可见的。

现在的问题是:FPS 已经在下降!我认为一个简单的位图不应该显示任何效果 - 但我已经下降到 ~24 FPS 了!

  • 为什么是位块传送 &绘制那么大小的位图这么慢?
  • 我是否在可破坏地形上采取了错误进场?

  • 像《百战天虫》这样的游戏是如何做到这一点的?尽管确实绘制了很多像素,但 FPS 看起来确实很高

I am currently working on a game in SDL which has destructible terrain. At the moment the terrain is one large (5000*500, for testing) bitmap which is randomly generated.

Each frame the main surface is cleared and the terrain bitmap is blitted into it. The current resolution is 1200 * 700, so when I was testing 1200 * 500 pixels were visible at most of the points.

Now the problem is: The FPS are already dropping! I thought one simple bitmap shouldn't show any effect - but I am already falling down to ~24 FPS with this!

  • Why is blitting & drawing a bitmap of that size so slow?
  • Am I taking a false approach at destructible terrain?

  • How have games like Worms done this? The FPS seem really high although there's definitely a lot of pixels drawn in there

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

顾北清歌寒 2024-09-26 00:10:00

SDL 中的 2d 速度相当慢,您没有什么办法可以让它更快(在 Windows 上至少它默认使用 GDI 进行绘图)。您的选择是:

  1. 使用 opengl 并开始使用带纹理的四边形作为精灵。
  2. 尝试 SFML。它提供了硬件加速的 2d 环境。
  3. 使用 SDL 1.3 获取源快照,它不稳定且仍在开发中,但硬件加速 2d 应该是主要卖点之一。

2d in SDL is pretty slow and there isn't much you can do to make it faster (on windows at least it uses GDI for drawing by default.) Your options are:

  1. Go opengl and start using textured quads for sprites.
  2. Try SFML. It provides a hardware accelerated 2d environment.
  3. Use SDL 1.3 Get a source snapshot it is unstable and still under development but hardware accelerated 2d is supposed to be one of the main selling points.
月光色 2024-09-26 00:09:59

如果你在每一帧重新绘制整个屏幕,你的 FPS 总是很差。您必须仅重画已更改的屏幕部分。您还可以尝试使用 SDL_HWSURFACE 来使用硬件,但它不适用于所有图形卡。

If you redraw the whole screen at each frame your will always get a bad FPS. You have to redraw only part of the screen which have changed. You can also try to use SDL_HWSURFACE to use hardware but it won't work on every graphical card.

多情癖 2024-09-26 00:09:58

每当初始化表面时,请按以下方式执行:

SDL_Surface* mySurface;
SDL_Surface* tempSurface;
tempSurface = SDL_LoadIMG("./path/to/image/image.jpg_or_whatever"); 
/* SDL_LoadIMG() is correct name? Not sure now, I`m at work, so I can`t verify it. */
mySurface = SDL_DisplayFormat(tempSurface);
SDL_FreeSurface(tempSurface);

SDL_DisplayFormat() 方法将表面的像素格式转换为视频表面使用的格式。如果您不按照我上面描述的方式执行此操作,SDL 会在每次表面被位块传输时执行此操作。

永远记住:只需位块传输真正对玩家可见的必要部分即可。

这是我的第一个猜测,为什么你会遇到性能问题。如果您需要更多提示,请发布您的代码或提出更具体的问题。祝你游戏顺利。

Whenever you initialize a surface, do it the following way:

SDL_Surface* mySurface;
SDL_Surface* tempSurface;
tempSurface = SDL_LoadIMG("./path/to/image/image.jpg_or_whatever"); 
/* SDL_LoadIMG() is correct name? Not sure now, I`m at work, so I can`t verify it. */
mySurface = SDL_DisplayFormat(tempSurface);
SDL_FreeSurface(tempSurface);

The SDL_DisplayFormat() method converts the pixel format of your surface to the format the video surface uses. If you don`t do it the way I described above, SDL does this each time the surface is blitted.

And always remember: just blit the necessary parts that really are visible to the player.

That`s my first guess, why you are having performance problems. Post your code or ask more specific questions, if you want more tipps. Good luck with your game.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文