How to directly write to display buffer in GTK/GDK
Asked Answered
B

1

8

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.

Brackely answered 3/1, 2011 at 19:28 Comment(1)
I suspect GTK without any auxiliary libraries isn't the right tool for the job. It's a user interface toolkit, not a drawing toolkit.Ddene
I
4

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]

Interlunar answered 8/1, 2011 at 20:1 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.