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>
30 static gboolean rotate(gpointer _self)
32 GisPluginExample *self = _self;
33 if (gtk_toggle_button_get_active(self->button)) {
34 self->rotation += 1.0;
35 gis_opengl_redraw(self->opengl);
44 GisPluginExample *gis_plugin_example_new(GisWorld *world, GisView *view, GisOpenGL *opengl)
46 g_debug("GisPluginExample: new");
47 GisPluginExample *self = g_object_new(GIS_TYPE_PLUGIN_EXAMPLE, NULL);
48 self->opengl = opengl;
53 static GtkWidget *gis_plugin_example_get_config(GisPlugin *_self)
55 GisPluginExample *self = GIS_PLUGIN_EXAMPLE(_self);
56 return GTK_WIDGET(self->button);
59 static void gis_plugin_example_expose(GisPlugin *_self)
61 GisPluginExample *self = GIS_PLUGIN_EXAMPLE(_self);
62 g_debug("GisPluginExample: expose");
64 glMatrixMode(GL_PROJECTION);
66 glOrtho(1,-1, -1,1, -10,10);
68 glMatrixMode(GL_MODELVIEW);
71 float light_ambient[] = {0.1f, 0.1f, 0.0f, 1.0f};
72 float light_diffuse[] = {0.9f, 0.9f, 0.9f, 1.0f};
73 float light_position[] = {-30.0f, 50.0f, 40.0f, 1.0f};
74 glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient);
75 glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse);
76 glLightfv(GL_LIGHT0, GL_POSITION, light_position);
77 glEnable(GL_COLOR_MATERIAL);
79 glTranslatef(-0.5, -0.5, -2);
80 glRotatef(self->rotation, 1, 1, 0);
81 glColor4f(0.9, 0.9, 0.7, 1.0);
82 glDisable(GL_CULL_FACE);
83 gdk_gl_draw_teapot(TRUE, 0.25);
91 static void gis_plugin_example_plugin_init(GisPluginInterface *iface);
92 G_DEFINE_TYPE_WITH_CODE(GisPluginExample, gis_plugin_example, G_TYPE_OBJECT,
93 G_IMPLEMENT_INTERFACE(GIS_TYPE_PLUGIN,
94 gis_plugin_example_plugin_init));
95 static void gis_plugin_example_plugin_init(GisPluginInterface *iface)
97 g_debug("GisPluginExample: plugin_init");
98 /* Add methods to the interface */
99 iface->expose = gis_plugin_example_expose;
100 iface->get_config = gis_plugin_example_get_config;
102 /* Class/Object init */
103 static void gis_plugin_example_init(GisPluginExample *self)
105 g_debug("GisPluginExample: init");
107 self->button = GTK_TOGGLE_BUTTON(gtk_toggle_button_new_with_label("Rotate"));
108 self->rotate_id = g_timeout_add(1000/60, rotate, self);
109 self->rotation = 30.0;
112 static void gis_plugin_example_dispose(GObject *gobject)
114 g_debug("GisPluginExample: dispose");
115 GisPluginExample *self = GIS_PLUGIN_EXAMPLE(gobject);
116 g_source_remove(self->rotate_id);
117 /* Drop references */
118 G_OBJECT_CLASS(gis_plugin_example_parent_class)->dispose(gobject);
120 static void gis_plugin_example_finalize(GObject *gobject)
122 g_debug("GisPluginExample: finalize");
123 GisPluginExample *self = GIS_PLUGIN_EXAMPLE(gobject);
125 G_OBJECT_CLASS(gis_plugin_example_parent_class)->finalize(gobject);
128 static void gis_plugin_example_class_init(GisPluginExampleClass *klass)
130 g_debug("GisPluginExample: class_init");
131 GObjectClass *gobject_class = (GObjectClass*)klass;
132 gobject_class->dispose = gis_plugin_example_dispose;
133 gobject_class->finalize = gis_plugin_example_finalize;