简体   繁体   English

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

[英]How to directly write to display buffer in GTK/GDK

I have a program that displays an animation with a fixed frame rate (say 30 fps) in a window. 我有一个程序可以在窗口中显示具有固定帧频(例如30 fps)的动画。

Currently I use SDL but unfortunately it lacks desktop integration(like drag & drop) and now I want to use GTK instead. 目前,我使用SDL,但不幸的是它缺少桌面集成(例如拖放),现在我想改用GTK。

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. 除了最基本的GDK / GTK调用之外,我不想使用任何功能来创建和管理窗口以及接收输入事件。

In the FAQ they suggest using GdkRGB. 他们在FAQ中建议使用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. 但是,在GdkRGB的官方文档中,它们使用了不推荐使用的gdk_draw_rgb_image()函数,实际上大多数GdkRGB函数都是。

As an alternative they suggest using OpenGL. 作为替代方案,他们建议使用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). 问题在于它需要一些不常见的库,例如GtkGLArea,它不是GTK的一部分(我不想依赖默认情况下未安装的任何库)。 Also, on my system the driver's OpenGL support is... limited. 另外,在我的系统上,驱动程序的OpenGL支持受限制。

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. 我已经研究了开罗(它是某些不推荐使用的功能的替代产品),但是由于我的相对简单的问题,这将增加更多的样板代码(并且我怀疑会产生额外的开销)。

I personally would say that GdkRGB is a reasonable choice for you. 我个人会说GdkRGB对您来说是一个合理的选择。 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. 样板只不过多了-您应该查看http://cairographics.org/samples/ ,其中包含一些非常小且易于理解的示例。 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. [免责声明:我是GdkRGB的原始作者。 It's sad to see it deprecated now, but I suppose it served its purpose well] 这是可悲的看到它现在已经过时,但我想它功成身退以及]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM