Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to directly write to display buffer in GTK/GDK

Tags:

c

linux

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 additional overhead) for my relatively simple problem.

like image 537
maep Avatar asked Jan 03 '11 19:01

maep


1 Answers

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]

like image 133
Raph Levien Avatar answered Oct 18 '22 01:10

Raph Levien