GTK/GDK中如何直接写入显示缓冲区

发布于 2024-10-10 11:36:15 字数 703 浏览 0 评论 0原文

我有一个程序,可以在窗口中显示固定帧速率(例如 30 fps)的动画。

目前我使用 SDL,但不幸的是它缺乏桌面集成(如拖放),现在我想使用 GTK。

所以我想做的(假设窗口是双缓冲的):

1 obtain off-screen buffer
2 render my stuff to buffer
3 tell the toolkit to swap buffers
4 update window
5 repeat

除了非常基本的 GDK/GTK 调用来创建和管理窗口并接收输入事件之外,我不想使用任何功能。

FAQ 中,他们建议使用 GdkRGB。然而,在 GdkRGB 的官方文档中,他们使用了已弃用的 gdk_draw_rgb_image() 函数,事实上大多数 GdkRGB 函数都是如此。

作为替代方案,他们建议使用 OpenGL。问题是它需要一些不常见的库,例如 GtkGLArea,它不是 GTK 的一部分(我不想依赖任何默认情况下未安装的库)。另外,在我的系统上,驱动程序的 OpenGL 支持...有限。

我研究过 Cairo (它是作为某些已弃用函数的替代方案提供的),但这会为我相对简单的问题添加更多的样板代码(并且我怀疑会有额外的开销)。

I have a program that displays an animation with a fixed frame rate (say 30 fps) in a window.

Currently I use SDL but unfortunately it lacks desktop integration(like drag & drop) and now I want to use GTK instead.

so what I want to do (assuming the window is double buffered):

1 obtain off-screen buffer
2 render my stuff to buffer
3 tell the toolkit to swap buffers
4 update window
5 repeat

I don't want to use any features except very basic GDK/GTK calls to create and manage the window and receive input events.

In the FAQ they suggest using GdkRGB. However, in the official documentation for GdkRGB they use the gdk_draw_rgb_image() function which is deprecated, in fact most GdkRGB functions are.

As an alternative they suggest using OpenGL. The problem with that is it requires some uncommon lib like GtkGLArea that is not part of GTK (I don't want to depend on any libs that aren't installed by default). Also, on my system the driver's OpenGL support is... limited.

I've looked into Cairo (which is offered as the alternative for some deprecated functions) but that would add even more boilerplate code (and I suspect additional overhead) for my relatively simple problem.

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

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

发布评论

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

评论(1

丢了幸福的猪 2024-10-17 11:36:15

我个人认为 GdkRGB 对您来说是一个合理的选择。它的设计很简单,而且它的范围几乎正是您所描述的。使用已弃用的代码是有风险的——如果您现在想让某些东西正常工作,那么它可能是一个不错的选择,但如果您希望您的代码能够增长并在未来得到维护,您应该考虑替代方案。

其中,开罗可能是您最好的选择。只有一点样板文件 - 你应该看看 http://cairgraphics.org/samples/ 其中有一些非常小的且易于理解的示例。 Cairo 的潜在好处之一是它更有可能进行硬件加速。

[免责声明:我是GdkRGB的原作者。很遗憾看到它现在被弃用了,但我认为它很好地达到了它的目的]

I personally would say that GdkRGB is a reasonable choice for you. It was designed to be simple, and its scope is pretty much exactly what you describe. Using deprecated code is chancy - it can be a fine choice if you want to get something working now, but if you want your code to grow and be maintained into the future, you should look at the alternatives.

Of those, Cairo is probably your best bet. There's only a little more boilerplate - you should look at http://cairographics.org/samples/ which has some pretty small and easy to understand examples. One of the potential benefits of Cairo is that it's more likely to be hardware accelerated.

[disclaimer: I'm the original author of GdkRGB. It's sad to see it deprecated now, but I suppose it served its purpose well]

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