Re: recommended way to create a render loop with gtkglext



Chris H wrote:
Hello,
I'm writing a GLSL shader editor and I need to be able to create a loop that
will force the gtkglext widget to constantly refresh at 60Hz or less if the
frames take too long to render. I've tried to copy the code from the
logo.cexample but it just isn't refreshing. Honestly I'd rather stay
away from
g_timeout for this task. I tried using threads but it became really unstable
(segfaults) when calling
  /* Invalidate the whole window. */
  gdk_window_invalidate_rect (widget->window, &widget->allocation, FALSE);

  /* Update synchronously. */
  gdk_window_process_updates (widget->window, FALSE);
in the separate thread. Is there a way I could simply have the separate
thread send a redraw signal to the widget, and would that event work? I'm
open to just about any ideas that don't involve g_timeout.

gdk_window_invalidate_rect() *is* the way to send a redraw signal to the widget's underlying GdkWindow. Give gtk_widget_queue_draw_area() a try instead.

If you're calling this from a separate thread, be sure you've initialized gthread (with g_thread_init()) and gdk's locking (with gdk_threads_init()) before gtk_init() in main(). You'll need to surround your call to gtk_main() with gdk_threads_enter() and gdk_threads_leave(), and you'll have to do the same for any gtk/gdk calls you make in other threads.

Alternatively, you can *not* initialise gdk's threading at all, and use g_idle_add() from your worker thread to schedule a function to call gtk_widget_queue_draw_area() (the idle function will run in the main thread, regardless of where you call g_idle_add()).

        -brian



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]