[gtk+] docs: Add initialization example for GtkGLArea
- From: Emmanuele Bassi <ebassi src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+] docs: Add initialization example for GtkGLArea
- Date: Thu, 26 Mar 2015 17:41:19 +0000 (UTC)
commit 86720b014e40418e94d708815059b835d07ed7ae
Author: Emmanuele Bassi <ebassi gnome org>
Date: Thu Mar 26 17:40:40 2015 +0000
docs: Add initialization example for GtkGLArea
Show how to safely check for errors when initializing the OpenGL
pipeline.
gtk/gtkglarea.c | 41 ++++++++++++++++++++++++++++++++++++++++-
1 files changed, 40 insertions(+), 1 deletions(-)
---
diff --git a/gtk/gtkglarea.c b/gtk/gtkglarea.c
index 90ab9fc..ef752ab 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.
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]