6 #include "drawing_area.h"
9 * The "draw" signal handler. All the OpenGL re-drawing should
10 * be done here. This is repeatedly called as the painting routine
11 * every time the 'draw' event is signalled.
13 gboolean drawing_area_draw(GtkWidget *widget, cairo_t *cr, gpointer user_data)
15 /*** OpenGL BEGIN ***/
16 if (!gtk_widget_begin_gl (widget)) {
20 // glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
24 glColor3f (1.0, 1.0, 1.0);
25 glBegin(GL_TRIANGLES);
26 glVertex3f( 0.0f, 1.0f, 0.0f); // Top
27 glVertex3f(-1.0f,-1.0f, 0.0f); // Bottom Left
28 glVertex3f( 1.0f,-1.0f, 0.0f); // Bottom Right
32 gtk_widget_end_gl (widget, TRUE);
39 * The "configure_event" signal handler. Any processing required when
40 * the OpenGL-capable drawing area is re-configured should be done here.
41 * Almost always it will be used to resize the OpenGL viewport when
42 * the window is resized.
44 gboolean drawing_area_configure_event (GtkWidget *widget,
45 GdkEventConfigure *event, gpointer data)
47 GtkAllocation allocation;
49 /* OpenGL widget width */
51 /* OpenGL widget height */
54 /* Current page width */
56 /* Current page height */
61 gtk_widget_get_allocation (widget, &allocation);
63 h = allocation.height;
65 /*** OpenGL BEGIN ***/
66 if (!gtk_widget_begin_gl (widget))
69 glViewport (0, 0, w, h);
71 glMatrixMode (GL_PROJECTION);
76 // glFrustum (-aspect, aspect, -1.0, 1.0, 5.0, 60.0);
80 glFrustum (-1.0, 1.0, -aspect, aspect, 5.0, 60.0);
83 glMatrixMode (GL_MODELVIEW);
85 gtk_widget_end_gl (widget, FALSE);
92 * The "realize" signal handler. All the OpenGL initialization
93 * should be performed here, such as default background colour,
96 void drawing_area_realize (GtkWidget *widget, gpointer data)
98 /*** OpenGL BEGIN ***/
99 if (!gtk_widget_begin_gl (widget)) {
103 glClearColor (0.0, 0.0, 0.0, 0.0);
104 glShadeModel (GL_FLAT);
106 gtk_widget_end_gl (widget, FALSE);
113 * The "unrealize" signal handler. Any processing required when
114 * the OpenGL-capable window is unrealized should be done here.
116 void drawing_area_unrealize (GtkWidget *widget, gpointer data)