]> Pileus Git - grits/blob - src/plugin-example.c
Adding copyright statements and a few bug fixes (hacks) for shading radar data
[grits] / src / plugin-example.c
1 /*
2  * Copyright (C) 2009 Andy Spencer <spenceal@rose-hulman.edu>
3  * 
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.
8  * 
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.
13  * 
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/>.
16  */
17
18 #include <config.h>
19 #include <gtk/gtk.h>
20 #include <gtk/gtkgl.h>
21 #include <GL/gl.h>
22
23 #include "aweather-gui.h"
24
25 static GtkWidget *rotate_button;
26
27 static float ang = 30.;
28
29 static gboolean expose(GtkWidget *da, GdkEventExpose *event, gpointer user_data)
30 {
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);
35
36         glTranslatef(0.5, -0.5, -2);
37
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);
44         glEnable(GL_LIGHT0);
45         glEnable(GL_LIGHTING);
46         glEnable(GL_COLOR_MATERIAL);
47
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);
53
54         glDisable(GL_LIGHT0);
55         glDisable(GL_LIGHTING);
56         glDisable(GL_COLOR_MATERIAL);
57
58         glMatrixMode(GL_PROJECTION); glPopMatrix(); 
59         glMatrixMode(GL_MODELVIEW ); glPopMatrix();
60         return FALSE;
61 }
62
63 static gboolean rotate(gpointer user_data)
64 {
65         if (!gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(rotate_button)))
66                 return TRUE;
67
68         GtkWidget *da = GTK_WIDGET (user_data);
69
70         ang++;
71
72         gdk_window_invalidate_rect(da->window, &da->allocation, FALSE);
73         gdk_window_process_updates(da->window, FALSE);
74
75         return TRUE;
76 }
77
78 gboolean example_init(AWeatherGui *gui)
79 {
80         GtkWidget *drawing = aweather_gui_get_widget(gui, "drawing");
81         GtkWidget *config  = aweather_gui_get_widget(gui, "tabs");
82
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);
87
88         /* Set up OpenGL Stuff */
89         g_signal_connect(drawing, "expose-event", G_CALLBACK(expose), NULL);
90         g_timeout_add(1000/60, rotate, drawing);
91         return TRUE;
92 }