summaryrefslogtreecommitdiff
path: root/gtk/gtkglarea.c
diff options
context:
space:
mode:
authorEmmanuele Bassi <ebassi@gnome.org>2015-03-26 17:40:40 +0000
committerEmmanuele Bassi <ebassi@gnome.org>2015-03-26 17:40:40 +0000
commit86720b014e40418e94d708815059b835d07ed7ae (patch)
treee3b5e63e27eb545cd3ec96ed8cfad3d768d169c3 /gtk/gtkglarea.c
parentd79bc003455b92f788e27835ea7fc7a44b3501a4 (diff)
downloadgtk+-86720b014e40418e94d708815059b835d07ed7ae.tar.gz
docs: Add initialization example for GtkGLArea
Show how to safely check for errors when initializing the OpenGL pipeline.
Diffstat (limited to 'gtk/gtkglarea.c')
-rw-r--r--gtk/gtkglarea.c41
1 files changed, 40 insertions, 1 deletions
diff --git a/gtk/gtkglarea.c b/gtk/gtkglarea.c
index 90ab9fc523..ef752ab046 100644
--- a/gtk/gtkglarea.c
+++ b/gtk/gtkglarea.c
@@ -91,7 +91,46 @@
*
* If you need to initialize OpenGL state, e.g. buffer objects or
* shaders, you should use the #GtkWidget::realize signal; you
- * can use the #GtkWidget::unrealize signal to clean up.
+ * can use the #GtkWidget::unrealize signal to clean up. Since the
+ * #GdkGLContext creation and initialization may fail, you will
+ * need to check for errors, using gtk_gl_area_get_error(). An example
+ * of how to safely initialize the GL state is:
+ *
+ * |[<!-- language="C" -->
+ * static void
+ * on_realize (GtkGLarea *area)
+ * {
+ * // We need to make the context current if we want to
+ * // call GL API
+ * gtk_gl_area_make_current (area);
+ *
+ * // If there were errors during the initialization or
+ * // when trying to make the context current, this
+ * // function will return a #GError for you to catch
+ * if (gtk_gl_area_get_error (area) != NULL)
+ * return;
+ *
+ * // You can also use gtk_gl_area_set_error() in order
+ * // to show eventual initialization errors on the
+ * // GtkGLArea widget itself
+ * GError *internal_error = NULL;
+ * init_buffer_objects (&error);
+ * if (error != NULL)
+ * {
+ * gtk_gl_area_set_error (area, error);
+ * g_error_free (error);
+ * return;
+ * }
+ *
+ * init_shaders (&error);
+ * if (error != NULL)
+ * {
+ * gtk_gl_area_set_error (area, error);
+ * g_error_free (error);
+ * return;
+ * }
+ * }
+ * ]|
*
* If you need to change the options for creating the #GdkGLContext
* you should use the #GtkGLArea::create-context signal.