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/>.
18 #include <gtk/gtkgl.h>
28 static gboolean rotate(gpointer _self)
30 GisPluginTeapot *self = _self;
31 if (gtk_toggle_button_get_active(self->button)) {
32 self->rotation += 1.0;
33 gtk_widget_queue_draw(GTK_WIDGET(self->viewer));
42 GisPluginTeapot *gis_plugin_teapot_new(GisViewer *viewer, GisPrefs *prefs)
44 g_debug("GisPluginTeapot: new");
45 GisPluginTeapot *self = g_object_new(GIS_TYPE_PLUGIN_TEAPOT, NULL);
46 self->viewer = viewer;
50 static GtkWidget *gis_plugin_teapot_get_config(GisPlugin *_self)
52 GisPluginTeapot *self = GIS_PLUGIN_TEAPOT(_self);
53 return GTK_WIDGET(self->button);
56 static void gis_plugin_teapot_expose(GisPlugin *_self)
58 GisPluginTeapot *self = GIS_PLUGIN_TEAPOT(_self);
59 g_debug("GisPluginTeapot: expose");
61 glMatrixMode(GL_PROJECTION);
63 glOrtho(1,-1, -1,1, -10,10);
65 glMatrixMode(GL_MODELVIEW);
68 float light_ambient[] = {0.1f, 0.1f, 0.0f, 1.0f};
69 float light_diffuse[] = {0.9f, 0.9f, 0.9f, 1.0f};
70 float light_position[] = {-30.0f, 50.0f, 40.0f, 1.0f};
71 glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient);
72 glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse);
73 glLightfv(GL_LIGHT0, GL_POSITION, light_position);
74 glEnable(GL_COLOR_MATERIAL);
76 glTranslatef(-0.5, -0.5, -2);
77 glRotatef(self->rotation, 1, 1, 0);
78 glColor4f(0.9, 0.9, 0.7, 1.0);
79 glDisable(GL_CULL_FACE);
80 gdk_gl_draw_teapot(TRUE, 0.25);
88 static void gis_plugin_teapot_plugin_init(GisPluginInterface *iface);
89 G_DEFINE_TYPE_WITH_CODE(GisPluginTeapot, gis_plugin_teapot, G_TYPE_OBJECT,
90 G_IMPLEMENT_INTERFACE(GIS_TYPE_PLUGIN,
91 gis_plugin_teapot_plugin_init));
92 static void gis_plugin_teapot_plugin_init(GisPluginInterface *iface)
94 g_debug("GisPluginTeapot: plugin_init");
95 /* Add methods to the interface */
96 iface->expose = gis_plugin_teapot_expose;
97 iface->get_config = gis_plugin_teapot_get_config;
99 /* Class/Object init */
100 static void gis_plugin_teapot_init(GisPluginTeapot *self)
102 g_debug("GisPluginTeapot: init");
104 self->button = GTK_TOGGLE_BUTTON(gtk_toggle_button_new_with_label("Rotate"));
105 self->rotate_id = g_timeout_add(1000/60, rotate, self);
106 self->rotation = 30.0;
108 static void gis_plugin_teapot_dispose(GObject *gobject)
110 g_debug("GisPluginTeapot: dispose");
111 GisPluginTeapot *self = GIS_PLUGIN_TEAPOT(gobject);
112 g_source_remove(self->rotate_id);
113 /* Drop references */
114 G_OBJECT_CLASS(gis_plugin_teapot_parent_class)->dispose(gobject);
116 static void gis_plugin_teapot_class_init(GisPluginTeapotClass *klass)
118 g_debug("GisPluginTeapot: class_init");
119 GObjectClass *gobject_class = (GObjectClass*)klass;
120 gobject_class->dispose = gis_plugin_teapot_dispose;