]> Pileus Git - grits/blobdiff - examples/plugin/teapot.c
Switch from GtkGLExt to internal OpenGL handling
[grits] / examples / plugin / teapot.c
index fd551cc91bbb95a5770b77d5b73caac8d32997fd..2a1201d9c02a0e53d17bdb60eceade1cbb0eaff8 100644 (file)
@@ -1,63 +1,44 @@
 /*
- * Copyright (C) 2009 Andy Spencer <spenceal@rose-hulman.edu>
- * 
+ * Copyright (C) 2009-2010 Andy Spencer <andy753421@gmail.com>
+ *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
  * the Free Software Foundation, either version 3 of the License, or
  * (at your option) any later version.
- * 
+ *
  * This program is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
- * 
+ *
  * You should have received a copy of the GNU General Public License
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-#include <gtk/gtkgl.h>
 #include <GL/gl.h>
+#include <GL/glut.h>
 
-#include <gis.h>
+#include <grits.h>
 
 #include "teapot.h"
 
 /***********
  * Helpers *
  ***********/
-static gboolean rotate(gpointer _self)
+static gboolean rotate(gpointer _teapot)
 {
-       GisPluginTeapot *self = _self;
-       if (gtk_toggle_button_get_active(self->button)) {
-               self->rotation += 1.0;
-               gis_opengl_redraw(self->opengl);
+       GritsPluginTeapot *teapot = _teapot;
+       if (gtk_toggle_button_get_active(teapot->button)) {
+               teapot->rotation += 1.0;
+               gtk_widget_queue_draw(GTK_WIDGET(teapot->viewer));
        }
        return TRUE;
 }
 
-
-/***********
- * Methods *
- ***********/
-GisPluginTeapot *gis_plugin_teapot_new(GisWorld *world, GisView *view, GisOpenGL *opengl)
+static void expose(GritsCallback *callback, GritsOpenGL *opengl, gpointer _teapot)
 {
-       g_debug("GisPluginTeapot: new");
-       GisPluginTeapot *self = g_object_new(GIS_TYPE_PLUGIN_TEAPOT, NULL);
-       self->opengl = opengl;
-
-       return self;
-}
-
-static GtkWidget *gis_plugin_teapot_get_config(GisPlugin *_self)
-{
-       GisPluginTeapot *self = GIS_PLUGIN_TEAPOT(_self);
-       return GTK_WIDGET(self->button);
-}
-
-static void gis_plugin_teapot_expose(GisPlugin *_self)
-{
-       GisPluginTeapot *self = GIS_PLUGIN_TEAPOT(_self);
-       g_debug("GisPluginTeapot: expose");
+       GritsPluginTeapot *teapot = GRITS_PLUGIN_TEAPOT(_teapot);
+       g_debug("GritsPluginTeapot: expose");
 
        glMatrixMode(GL_PROJECTION);
        glLoadIdentity();
@@ -75,10 +56,33 @@ static void gis_plugin_teapot_expose(GisPlugin *_self)
        glEnable(GL_COLOR_MATERIAL);
 
        glTranslatef(-0.5, -0.5, -2);
-       glRotatef(self->rotation, 1, 1, 0);
+       glRotatef(teapot->rotation, 1, 1, 0);
        glColor4f(0.9, 0.9, 0.7, 1.0);
        glDisable(GL_CULL_FACE);
-       gdk_gl_draw_teapot(TRUE, 0.25);
+       glutSolidTeapot(2.5);
+}
+
+
+/***********
+ * Methods *
+ ***********/
+GritsPluginTeapot *grits_plugin_teapot_new(GritsViewer *viewer, GritsPrefs *prefs)
+{
+       g_debug("GritsPluginTeapot: new");
+       GritsPluginTeapot *teapot = g_object_new(GRITS_TYPE_PLUGIN_TEAPOT, NULL);
+       teapot->viewer = viewer;
+
+       /* Add renderers */
+       GritsCallback *callback = grits_callback_new(expose, teapot);
+       grits_viewer_add(viewer, GRITS_OBJECT(callback), GRITS_LEVEL_OVERLAY+1, 0);
+
+       return teapot;
+}
+
+static GtkWidget *grits_plugin_teapot_get_config(GritsPlugin *_teapot)
+{
+       GritsPluginTeapot *teapot = GRITS_PLUGIN_TEAPOT(_teapot);
+       return GTK_WIDGET(teapot->button);
 }
 
 
@@ -86,47 +90,36 @@ static void gis_plugin_teapot_expose(GisPlugin *_self)
  * GObject code *
  ****************/
 /* Plugin init */
-static void gis_plugin_teapot_plugin_init(GisPluginInterface *iface);
-G_DEFINE_TYPE_WITH_CODE(GisPluginTeapot, gis_plugin_teapot, G_TYPE_OBJECT,
-               G_IMPLEMENT_INTERFACE(GIS_TYPE_PLUGIN,
-                       gis_plugin_teapot_plugin_init));
-static void gis_plugin_teapot_plugin_init(GisPluginInterface *iface)
+static void grits_plugin_teapot_plugin_init(GritsPluginInterface *iface);
+G_DEFINE_TYPE_WITH_CODE(GritsPluginTeapot, grits_plugin_teapot, G_TYPE_OBJECT,
+               G_IMPLEMENT_INTERFACE(GRITS_TYPE_PLUGIN,
+                       grits_plugin_teapot_plugin_init));
+static void grits_plugin_teapot_plugin_init(GritsPluginInterface *iface)
 {
-       g_debug("GisPluginTeapot: plugin_init");
+       g_debug("GritsPluginTeapot: plugin_init");
        /* Add methods to the interface */
-       iface->expose     = gis_plugin_teapot_expose;
-       iface->get_config = gis_plugin_teapot_get_config;
+       iface->get_config = grits_plugin_teapot_get_config;
 }
 /* Class/Object init */
-static void gis_plugin_teapot_init(GisPluginTeapot *self)
+static void grits_plugin_teapot_init(GritsPluginTeapot *teapot)
 {
-       g_debug("GisPluginTeapot: init");
+       g_debug("GritsPluginTeapot: init");
        /* Set defaults */
-       self->button    = GTK_TOGGLE_BUTTON(gtk_toggle_button_new_with_label("Rotate"));
-       self->rotate_id = g_timeout_add(1000/60, rotate, self);
-       self->rotation  = 30.0;
-       self->opengl    = NULL;
+       teapot->button    = GTK_TOGGLE_BUTTON(gtk_toggle_button_new_with_label("Rotate"));
+       teapot->rotate_id = g_timeout_add(1000/60, rotate, teapot);
+       teapot->rotation  = 30.0;
 }
-static void gis_plugin_teapot_dispose(GObject *gobject)
+static void grits_plugin_teapot_dispose(GObject *gobject)
 {
-       g_debug("GisPluginTeapot: dispose");
-       GisPluginTeapot *self = GIS_PLUGIN_TEAPOT(gobject);
-       g_source_remove(self->rotate_id);
+       g_debug("GritsPluginTeapot: dispose");
+       GritsPluginTeapot *teapot = GRITS_PLUGIN_TEAPOT(gobject);
+       g_source_remove(teapot->rotate_id);
        /* Drop references */
-       G_OBJECT_CLASS(gis_plugin_teapot_parent_class)->dispose(gobject);
-}
-static void gis_plugin_teapot_finalize(GObject *gobject)
-{
-       g_debug("GisPluginTeapot: finalize");
-       GisPluginTeapot *self = GIS_PLUGIN_TEAPOT(gobject);
-       /* Free data */
-       G_OBJECT_CLASS(gis_plugin_teapot_parent_class)->finalize(gobject);
-
+       G_OBJECT_CLASS(grits_plugin_teapot_parent_class)->dispose(gobject);
 }
-static void gis_plugin_teapot_class_init(GisPluginTeapotClass *klass)
+static void grits_plugin_teapot_class_init(GritsPluginTeapotClass *klass)
 {
-       g_debug("GisPluginTeapot: class_init");
+       g_debug("GritsPluginTeapot: class_init");
        GObjectClass *gobject_class = (GObjectClass*)klass;
-       gobject_class->dispose  = gis_plugin_teapot_dispose;
-       gobject_class->finalize = gis_plugin_teapot_finalize;
+       gobject_class->dispose  = grits_plugin_teapot_dispose;
 }