[grits] Add GritsPoly for drawing sets of polygons
- From: Andy Spencer <andys src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [grits] Add GritsPoly for drawing sets of polygons
- Date: Mon, 24 Jan 2011 05:31:15 +0000 (UTC)
commit 12e39aa0ca2c7e6843bf1a1e0a9d73c3c84cc166
Author: Andy Spencer <andy753421 gmail com>
Date: Mon Jan 24 03:42:45 2011 +0000
Add GritsPoly for drawing sets of polygons
Currently uses OpenGL display lists for performance reasons.
src/grits.h | 1 +
src/objects/Makefile.am | 2 +
src/objects/grits-poly.c | 132 ++++++++++++++++++++++++++++++++++++++++++++++
src/objects/grits-poly.h | 52 ++++++++++++++++++
4 files changed, 187 insertions(+), 0 deletions(-)
---
diff --git a/src/grits.h b/src/grits.h
index 6885042..127f5ef 100644
--- a/src/grits.h
+++ b/src/grits.h
@@ -35,6 +35,7 @@
#include <objects/grits-marker.h>
#include <objects/grits-callback.h>
#include <objects/grits-volume.h>
+#include <objects/grits-poly.h>
/* Plugins */
#include <grits-plugin.h>
diff --git a/src/objects/Makefile.am b/src/objects/Makefile.am
index bb1a2a4..ff20786 100644
--- a/src/objects/Makefile.am
+++ b/src/objects/Makefile.am
@@ -11,6 +11,7 @@ grits_objects_include_HEADERS = \
grits-callback.h \
grits-tile.h \
grits-volume.h \
+ grits-poly.h \
marching.h
noinst_LTLIBRARIES = libgrits-objects.la
@@ -20,6 +21,7 @@ libgrits_objects_la_SOURCES = \
grits-callback.c grits-callback.h \
grits-tile.c grits-tile.h \
grits-volume.c grits-volume.h \
+ grits-poly.c grits-poly.h \
marching.c marching.h
libgrits_objects_la_LDFLAGS = -static
diff --git a/src/objects/grits-poly.c b/src/objects/grits-poly.c
new file mode 100644
index 0000000..865d288
--- /dev/null
+++ b/src/objects/grits-poly.c
@@ -0,0 +1,132 @@
+/*
+ * Copyright (C) 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/>.
+ */
+
+/**
+ * SECTION:grits-poly
+ * @short_description: Single point polys
+ *
+ * Each #GritsPoly represents a 3 dimentional polygon.
+ */
+
+#include <config.h>
+#include <GL/gl.h>
+#include <GL/glu.h>
+#include "grits-poly.h"
+
+/* Drawing */
+static void grits_poly_tess(gdouble (**points)[3])
+{
+ //g_debug("GritsPoly: tess");
+
+ /* Tesselate */
+ GLUtesselator *tess = gluNewTess();
+ gluTessCallback(tess, GLU_TESS_BEGIN, glBegin);
+ gluTessCallback(tess, GLU_TESS_VERTEX, glVertex3dv);
+ gluTessCallback(tess, GLU_TESS_END, glEnd);
+ gluTessBeginPolygon(tess, NULL);
+ for (int pi = 0; points[pi]; pi++) {
+ gluTessBeginContour(tess);
+ for (int ci = 0; points[pi][ci][0]; ci++) {
+ gluTessVertex(tess,
+ points[pi][ci],
+ points[pi][ci]);
+ }
+ gluTessEndContour(tess);
+ }
+ gluTessEndPolygon(tess);
+ gluDeleteTess(tess);
+
+ /* Outline */
+ for (int pi = 0; points[pi]; pi++) {
+ glColor4d(1,1,1,0.2);
+ glBegin(GL_LINE_LOOP);
+ for (int ci = 0; points[pi][ci][0]; ci++)
+ glVertex3dv(points[pi][ci]);
+ glEnd();
+ }
+}
+static gboolean grits_poly_genlist(gpointer _poly)
+{
+ //g_debug("GritsPoly: genlist");
+ GritsPoly *poly = GRITS_POLY(_poly);
+ guint list = glGenLists(1);
+ glNewList(list, GL_COMPILE);
+ grits_poly_tess(poly->points);
+ glEndList();
+ poly->list = list;
+ return FALSE;
+}
+
+static void grits_poly_draw(GritsObject *_poly, GritsOpenGL *opengl)
+{
+ //g_debug("GritsPoly: draw");
+ GritsPoly *poly = GRITS_POLY(_poly);
+
+ if (!poly->list)
+ return;
+
+ glPushAttrib(GL_COLOR_BUFFER_BIT | GL_ENABLE_BIT | GL_CURRENT_BIT);
+ glDisable(GL_TEXTURE_2D);
+ glDisable(GL_ALPHA_TEST);
+ glDisable(GL_CULL_FACE);
+ glDisable(GL_LIGHTING);
+ glColor4dv(poly->color);
+ glCallList(poly->list);
+ glPopAttrib();
+}
+
+/**
+ * grits_poly_new:
+ * @points: TODO
+ * @npoints: TODO
+ *
+ * Create a new GritsPoly which TODO.
+ *
+ * Returns: the new #GritsPoly.
+ */
+GritsPoly *grits_poly_new(gdouble (**points)[3])
+{
+ //g_debug("GritsPoly: new - %p", points);
+ GritsPoly *poly = g_object_new(GRITS_TYPE_POLY, NULL);
+ poly->points = points;
+ g_idle_add(grits_poly_genlist, poly);
+ return poly;
+}
+
+/* GObject code */
+G_DEFINE_TYPE(GritsPoly, grits_poly, GRITS_TYPE_OBJECT);
+static void grits_poly_init(GritsPoly *poly)
+{
+}
+
+static void grits_poly_finalize(GObject *_poly)
+{
+ g_debug("GritsPoly: finalize");
+ GritsPoly *poly = GRITS_POLY(_poly);
+ (void)poly;
+ // TODO: free points
+}
+
+static void grits_poly_class_init(GritsPolyClass *klass)
+{
+ g_debug("GritsPoly: class_init");
+ GObjectClass *gobject_class = G_OBJECT_CLASS(klass);
+ gobject_class->finalize = grits_poly_finalize;
+
+ GritsObjectClass *object_class = GRITS_OBJECT_CLASS(klass);
+ object_class->draw = grits_poly_draw;
+}
diff --git a/src/objects/grits-poly.h b/src/objects/grits-poly.h
new file mode 100644
index 0000000..4368df9
--- /dev/null
+++ b/src/objects/grits-poly.h
@@ -0,0 +1,52 @@
+/*
+ * Copyright (C) 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/>.
+ */
+
+#ifndef __GRITS_POLY_H__
+#define __GRITS_POLY_H__
+
+#include <glib.h>
+#include <glib-object.h>
+#include <cairo.h>
+#include <objects/grits-object.h>
+
+/* GritsPoly */
+#define GRITS_TYPE_POLY (grits_poly_get_type())
+#define GRITS_POLY(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), GRITS_TYPE_POLY, GritsPoly))
+#define GRITS_IS_POLY(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), GRITS_TYPE_POLY))
+#define GRITS_POLY_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GRITS_TYPE_POLY, GritsPolyClass))
+#define GRITS_IS_POLY_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GRITS_TYPE_POLY))
+#define GRITS_POLY_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GRITS_TYPE_POLY, GritsPolyClass))
+
+typedef struct _GritsPoly GritsPoly;
+typedef struct _GritsPolyClass GritsPolyClass;
+
+struct _GritsPoly {
+ GritsObject parent_instance;
+ gdouble (**points)[3];
+ gdouble color[4];
+ guint list;
+};
+
+struct _GritsPolyClass {
+ GritsObjectClass parent_class;
+};
+
+GType grits_poly_get_type(void);
+
+GritsPoly *grits_poly_new(gdouble (**points)[3]);
+
+#endif
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]