]> Pileus Git - grits/blobdiff - src/roam.c
Add cube GtkGL example
[grits] / src / roam.c
index d8bff628b33f939151e1def1c2c1f069a76b17d9..e58cd1d6e3bbf34f99d555cbbe87dd3f359ce62d 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2009-2010 Andy Spencer <andy753421@gmail.com>
+ * Copyright (C) 2009-2011 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
@@ -31,9 +31,8 @@
 #include <glib.h>
 #include <math.h>
 #include <string.h>
-#include <GL/gl.h>
-#include <GL/glu.h>
 
+#include "gtkgl.h"
 #include "gpqueue.h"
 #include "grits-util.h"
 #include "roam.h"
@@ -632,6 +631,7 @@ RoamSphere *roam_sphere_new()
        sphere->polys       = 8;
        sphere->triangles   = g_pqueue_new((GCompareDataFunc)tri_cmp, NULL);
        sphere->diamonds    = g_pqueue_new((GCompareDataFunc)dia_cmp, NULL);
+       sphere->view        = g_new0(RoamView, 1);
 
        RoamPoint *vertexes[] = {
                roam_point_new( 90,   0,  0), // 0 (North)
@@ -685,8 +685,6 @@ RoamSphere *roam_sphere_new()
  */
 void roam_sphere_update_view(RoamSphere *sphere)
 {
-       if (!sphere->view)
-               sphere->view = g_new0(RoamView, 1);
        glGetDoublev (GL_MODELVIEW_MATRIX,  sphere->view->model);
        glGetDoublev (GL_PROJECTION_MATRIX, sphere->view->proj);
        glGetIntegerv(GL_VIEWPORT,          sphere->view->view);
@@ -702,11 +700,15 @@ void roam_sphere_update_view(RoamSphere *sphere)
 void roam_sphere_update_errors(RoamSphere *sphere)
 {
        g_debug("RoamSphere: update_errors - polys=%d", sphere->polys);
+
+       static int version = 0;
+       if (version == sphere->view->version)
+               return;
+       version = sphere->view->version;
+
        GPtrArray *tris = g_pqueue_get_array(sphere->triangles);
        GPtrArray *dias = g_pqueue_get_array(sphere->diamonds);
 
-       roam_sphere_update_view(sphere);
-
        for (int i = 0; i < tris->len; i++) {
                RoamTriangle *triangle = tris->pdata[i];
                roam_triangle_update_errors(triangle, sphere);