开发者

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.

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 addition开发者_如何学运维al overhead) for my relatively simple problem.


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]

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜