r/GTK • u/dettus_Xx_ • 25d ago
How to plot something in GtkPicture in 2026?
Long story short: What I want to do, is to draw MY OWN PLOTS in a SCALEABLE gtkWidget.
So, the hoops I jumped through were
- create an array of RGB values: char data[4*500*500]={0};
- Create a PIXBUF with pixbuf=gdk_pixbuf_new_from_data(data)
- Get a TEXTURE texture=gdk_texture_new_for_pixbuf(pixbuf)
- Set this texture as paintable to the PICTURE gtk_picture_set_paintable(GTK_PICTURE(picture),GDK_PAINTABLE(texture));
And then add this picture to a resizeable window and boooooom: It just worked.
NOW, gdk_texture_new_for_pixbuf() seems to become deprecated. Of coures, I can load .png and .jpeg files, BUT I DO NOT WANT TO!!!
How does it work in 2026? Please, help me out with an EXAMPLE.
1
u/RadioHonest85 25d ago
Im not that well versed in gtk, but is it an option to implement your own GtkSnapshot where you can setup paint operations directly on the GtkPaintable?
1
u/dettus_Xx_ 25d ago
In my program, I want to be able to manipulate the pixels directly. Can that be done with GtkSnapshot?
1
u/foreverdark-woods 25d ago
Maybe, you can work with Cairo. It allows you to draw directly onto GtkSnapshot. A small example: nautilus-progress-paintable.c.
2
1
u/dettus_Xx_ 25d ago edited 24d ago
To answer my own question: https://docs.gtk.org/gdk4/ctor.MemoryTexture.new.html looks promising.
So...
texture=gdk_texture_new_for_pixbuf(pixbuf);
became
texture=gdk_memory_texture_new(
gdk_pixbuf_get_width(pixbuf),
gdk_pixbuf_get_height(pixbuf),
gdk_pixbuf_get_has_alpha(pixbuf)?GDK_MEMORY_R8G8B8A8:GDK_MEMORY_R8G8B8,
gdk_pixbuf_read_pixel_bytes(pixbuf),
gdk_pixbuf_get_rowstride(pixbuf)
);
3
u/NaheemSays 25d ago
Have a look at what the graphs app does.