可以用Python编写一个显示FPS(每秒帧数)的程序吗?
我想知道...
可以做到吗?
一个简单的基于控制台命令的程序,显示您当前运行的游戏/程序的 FPS 怎么样?
I was wondering...
It's possible to do it?
A simple console command based program that shows how are your FPS, for your currently running game/program?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
简短回答:是的。
长答案:除了当你在被测程序中有钩子时收集统计数据要简单得多,还可以在较低级别上钩子:直接连接到 DirectX 或 OpenGL。从一些现有帖子。它们是用 C++ 编写的,但那是另一回事:您可以使用 SWIG 在之间进行互操作Python 和 C/C++。
作为一个证明。有著名的 Fraps 应用程序可以执行您所说的操作。
Short answer: Yes.
Long answer: Beside that it is much simpler to gather statistics when you have hooks inside the measured program, it is possible also to hook on lower level: directly to DirectX or OpenGL. Start your discovery from some existing posts. They are in C++ but that's another deal: you can use SWIG to interop between Python and C/C++.
As a proof. There is famous Fraps applications that does what you say.
简短回答:不。
详细回答:如果不了解应用程序的内部结构,并且应用程序没有适当的挂钩来执行此类测量,则不会。
Short answer: No.
Long answer: Not without knowing the internals of the application, and without the application having the appropriate hooks to perform such a measurement.
只要您有可用的绑定/挂钩来读取该应用程序通过它使用的任何库正在执行的操作,就可以。
这些计数器通常作为对通过 OpenGL(或 directX)绘制的程序的查询来实现。
如果它是一个 OGL 应用程序,pyOpenGL 提供了大量的功能,可能值得您花时间研究它。我没有使用 directX 的经验,但我假设您可能会找到类似的绑定。
http://www.cs.man.ac.uk/~toby/ frameratedisplayer.htm 如果你想要一个简单的例子来看看它就可以做到这一点(假设你可以理解很少的 C 语法)
As long as you have the available bindings/hooks to read what that application is doing through whatever library it uses, yes.
Those counters are normally implemented as queries to a program drawing through OpenGL (or directX).
If it's an OGL app, pyOpenGL provides a decent amount of functionality, might be worth your time looking into it. I have no experience with directX, but I assume you might find similar bindings.
http://www.cs.man.ac.uk/~toby/frameratedisplayer.htm if you want a simple example to look at that does just that (assuming you're ok puzzling out very little C syntax)