Reputation: 175
I recently asked some questions here and here concerning a program I am working on and that offers a visualization interface for molecules, atomic systems ... as mentioned in these previous messages I do have 3 different versions of my program:
While I am still working on (c), some things came up while I was trying to find out the origin of some behavior differences between (a) and (b). The OpenGL rendering is significantly slower in (b) than in (a), or I thought that was the case. If you check this link you will see that I got some help and manage to find out that GTK+ signals were not handled in the same way between GTK+2 (a) and GTK+3 (b), and (c) even if I only got a black screen in that case (but that is another issue), here is how I prepare(d) the GtkWidget(s) and the corresponding signals, note that I only present hereafter the GTK+ related commands:
(a)
GtkWidget * drawing_area = gtk_drawing_area_new ();
g_signal_connect (G_OBJECT (drawing_area), "expose-event", G_CALLBACK (on_expose), data);
(b)
GtkWidget * drawing_area = gtk_drawing_area_new ();
g_signal_connect (G_OBJECT (drawing_area), "draw", G_CALLBACK(on_expose), data);
(c)
GtkWidget * drawing_area = gtk_gl_area_new ();
g_signal_connect (G_OBJECT (drawing_area), "render", G_CALLBACK(on_expose), data);
Using the tool Apitrace I noticed in case (a) that each OpenGL frame was drawn once, while it was drawn 5 times in cases (b) and (c). Then just adding a basic counter in the callback I confirmed that for each "expose/draw/render" the signal was emitted (and thus the "drawing-area" was rendered that many times, for the same frame):
(a) is GTK+2, (b) and (c) are GTK+3 ... now my question will be rather obvious, but how can I changed or maybe should I say correct the GTK+3 version of my program to make it as smooth, on an OpenGL rendering point of view, as the GTK+2 version, or if you prefer to have signal emitted only once with GTK+3 instead of 5 times ?
Thanks in advance !
Upvotes: 5
Views: 2061
Reputation: 175
Answering my own question, hopefully to help someone to avoid the same mistake I did.
To re-draw my OpenGL window I was using:
void update (GtkWidget * plot)
{
gtk_widget_hide (plot);
gtw_widget_show (plot);
}
Instead I should have been using:
gtk_widget_queue_draw (plot);
All problems solved !
Upvotes: 3