2 * Copyright (C) 2009 Andy Spencer <spenceal@rose-hulman.edu>
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 #include <gtk/gtkgl.h>
23 #include "aweather-gui.h"
25 static GtkWidget *rotate_button;
27 static float ang = 30.;
29 static gboolean expose(GtkWidget *da, GdkEventExpose *event, gpointer user_data)
31 glDisable(GL_TEXTURE_2D);
32 glMatrixMode(GL_MODELVIEW ); glPushMatrix(); glLoadIdentity();
33 glMatrixMode(GL_PROJECTION); glPushMatrix(); glLoadIdentity();
34 //glOrtho(-1,1,-1,1,-10,10);
36 glTranslatef(0.5, -0.5, -2);
38 float light_ambient[] = {0.1f, 0.1f, 0.0f};
39 float light_diffuse[] = {0.9f, 0.9f, 0.9f};
40 float light_position[] = {-20.0f, 40.0f, -40.0f, 1.0f};
41 glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient);
42 glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse);
43 glLightfv(GL_LIGHT0, GL_POSITION, light_position);
45 glEnable(GL_LIGHTING);
46 glEnable(GL_COLOR_MATERIAL);
48 glRotatef(ang, 1, 0, 1);
49 glColor4f(0.9, 0.9, 0.7, 1.0);
50 gdk_gl_draw_teapot(TRUE, 0.25);
51 gdk_gl_draw_cube(TRUE, 0.25);
52 glColor4f(1.0, 1.0, 1.0, 1.0);
55 glDisable(GL_LIGHTING);
56 glDisable(GL_COLOR_MATERIAL);
58 glMatrixMode(GL_PROJECTION); glPopMatrix();
59 glMatrixMode(GL_MODELVIEW ); glPopMatrix();
63 static gboolean rotate(gpointer user_data)
65 if (!gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(rotate_button)))
68 GtkWidget *da = GTK_WIDGET (user_data);
72 gdk_window_invalidate_rect(da->window, &da->allocation, FALSE);
73 gdk_window_process_updates(da->window, FALSE);
78 gboolean example_init(AWeatherGui *gui)
80 GtkWidget *drawing = aweather_gui_get_widget(gui, "drawing");
81 GtkWidget *config = aweather_gui_get_widget(gui, "tabs");
83 /* Add configuration tab */
84 GtkWidget *label = gtk_label_new("example");
85 rotate_button = gtk_toggle_button_new_with_label("Rotate");
86 gtk_notebook_append_page(GTK_NOTEBOOK(config), rotate_button, label);
88 /* Set up OpenGL Stuff */
89 g_signal_connect(drawing, "expose-event", G_CALLBACK(expose), NULL);
90 g_timeout_add(1000/60, rotate, drawing);