diff --git a/Common/Context.h b/Common/Context.h
index 441ab6d2196a23061ebff15bc0516cc53e16cfc7..7adc19487455eabc5bc9adeca0707ece2c491da3 100644
--- a/Common/Context.h
+++ b/Common/Context.h
@@ -155,7 +155,7 @@ public :
   // mesh options 
   struct {
     double msh_file_version;
-    int vis_type, changed, display_lists;
+    int vis_type, changed, vertex_arrays;
     int draw;
     int points, lines, surfaces_edges, surfaces_faces, volumes_edges, volumes_faces;
     int points_num, lines_num, surfaces_num, volumes_num;
diff --git a/Common/DefaultOptions.h b/Common/DefaultOptions.h
index a88f0148df5b27ae445ada8f3c4f09f1754d2c81..d5561089ba2667ad75e7a3ad8970d70803db4f28 100644
--- a/Common/DefaultOptions.h
+++ b/Common/DefaultOptions.h
@@ -725,8 +725,6 @@ StringXNumber MeshOptions_Number[] = {
   { F,   "CutPlaneD" , opt_mesh_cut_planed , 0. , 
     "Fourth cut plane equation coefficient (`D' in `AX+BY+CZ+D=0')" },
 
-  { F|O, "DisplayLists" , opt_mesh_display_lists , 0. ,
-    "Use OpenGL display lists for drawing meshes" },
   { F|O, "Dual" , opt_mesh_dual , 0. ,
     "Display the dual mesh obtained by barycentric subdivision" },
 
@@ -818,6 +816,8 @@ StringXNumber MeshOptions_Number[] = {
   { F|O, "Tangents" , opt_mesh_tangents , 0.0 , 
     "Display size of tangent vectors (in pixels)" }, 
 
+  { F|O, "VertexArrays" , opt_mesh_vertex_arrays , 0. , 
+    "Use OpenGL vertex arrays to draw meshes?" },
   { F|O, "VolumeEdges" , opt_mesh_volumes_edges , 1. , 
     "Display edges of volume mesh?" },
   { F|O, "VolumeFaces" , opt_mesh_volumes_faces , 0. , 
diff --git a/Common/Options.cpp b/Common/Options.cpp
index 467550dc551bacc2bee8af6aff5d83ad4dc43c0b..d4708ebe62d511f3eca7188b0aaabb5b42836dd9 100644
--- a/Common/Options.cpp
+++ b/Common/Options.cpp
@@ -1,4 +1,4 @@
-// $Id: Options.cpp,v 1.156 2004-05-25 04:10:03 geuzaine Exp $
+// $Id: Options.cpp,v 1.157 2004-05-28 19:22:12 geuzaine Exp $
 //
 // Copyright (C) 1997-2004 C. Geuzaine, J.-F. Remacle
 //
@@ -120,6 +120,7 @@ void Init_Options(int num)
   CTX.print.gl_fonts = 1;
   CTX.threads_lock = 0; //very primitive locking during mesh generation
   CTX.mesh.histogram = 0;
+  CTX.mesh.changed = 1;
   CTX.mesh.oldxtrude = CTX.mesh.oldxtrude_recombine = 0;        //old extrusion mesh generator
   CTX.mesh.check_duplicates = 0;        //check for duplicate nodes in Read_Mesh
   CTX.post.combine_time = 0; // try to combine_time views at startup
@@ -3103,7 +3104,6 @@ double opt_mesh_normals(OPT_ARGS_NUM)
 {
   if(action & GMSH_SET) {
     CTX.mesh.normals = val;
-    CTX.mesh.changed = 1;
   }
 #if defined(HAVE_FLTK)
   if(WID && (action & GMSH_GUI))
@@ -3116,7 +3116,6 @@ double opt_mesh_tangents(OPT_ARGS_NUM)
 {
   if(action & GMSH_SET) {
     CTX.mesh.tangents = val;
-    CTX.mesh.changed = 1;
   }
 #if defined(HAVE_FLTK)
   if(WID && (action & GMSH_GUI))
@@ -3128,8 +3127,8 @@ double opt_mesh_tangents(OPT_ARGS_NUM)
 double opt_mesh_explode(OPT_ARGS_NUM)
 {
   if(action & GMSH_SET) {
+    if(CTX.mesh.explode != val) CTX.mesh.changed = 1;
     CTX.mesh.explode = val;
-    CTX.mesh.changed = 1;
   }
 #if defined(HAVE_FLTK)
   if(WID && (action & GMSH_GUI))
@@ -3174,8 +3173,8 @@ double opt_mesh_rand_factor(OPT_ARGS_NUM)
 double opt_mesh_gamma_inf(OPT_ARGS_NUM)
 {
   if(action & GMSH_SET) {
+    if(CTX.mesh.gamma_inf != val) CTX.mesh.changed = 1;
     CTX.mesh.gamma_inf = val;
-    CTX.mesh.changed = 1;
   }
 #if defined(HAVE_FLTK)
   if(WID && (action & GMSH_GUI))
@@ -3187,8 +3186,8 @@ double opt_mesh_gamma_inf(OPT_ARGS_NUM)
 double opt_mesh_gamma_sup(OPT_ARGS_NUM)
 {
   if(action & GMSH_SET) {
+    if(CTX.mesh.gamma_sup != val) CTX.mesh.changed = 1;
     CTX.mesh.gamma_sup = val;
-    CTX.mesh.changed = 1;
   }
 #if defined(HAVE_FLTK)
   if(WID && (action & GMSH_GUI))
@@ -3200,8 +3199,8 @@ double opt_mesh_gamma_sup(OPT_ARGS_NUM)
 double opt_mesh_radius_inf(OPT_ARGS_NUM)
 {
   if(action & GMSH_SET) {
+    if(CTX.mesh.radius_inf != val) CTX.mesh.changed = 1;
     CTX.mesh.radius_inf = val;
-    CTX.mesh.changed = 1;
   }
 #if defined(HAVE_FLTK)
   if(WID && (action & GMSH_GUI))
@@ -3213,8 +3212,8 @@ double opt_mesh_radius_inf(OPT_ARGS_NUM)
 double opt_mesh_radius_sup(OPT_ARGS_NUM)
 {
   if(action & GMSH_SET) {
+    if(CTX.mesh.radius_sup != val) CTX.mesh.changed = 1;
     CTX.mesh.radius_sup = val;
-    CTX.mesh.changed = 1;
   }
 #if defined(HAVE_FLTK)
   if(WID && (action & GMSH_GUI))
@@ -3227,7 +3226,6 @@ double opt_mesh_points(OPT_ARGS_NUM)
 {
   if(action & GMSH_SET) {
     CTX.mesh.points = (int)val;
-    CTX.mesh.changed = 1;
   }
 #if defined(HAVE_FLTK)
   if(WID && (action & GMSH_GUI))
@@ -3240,7 +3238,6 @@ double opt_mesh_lines(OPT_ARGS_NUM)
 {
   if(action & GMSH_SET) {
     CTX.mesh.lines = (int)val;
-    CTX.mesh.changed = 1;
   }
 #if defined(HAVE_FLTK)
   if(WID && (action & GMSH_GUI))
@@ -3253,7 +3250,6 @@ double opt_mesh_surfaces_edges(OPT_ARGS_NUM)
 {
   if(action & GMSH_SET) {
     CTX.mesh.surfaces_edges = (int)val;
-    CTX.mesh.changed = 1;
   }
 #if defined(HAVE_FLTK)
   if(WID && (action & GMSH_GUI))
@@ -3266,7 +3262,6 @@ double opt_mesh_surfaces_faces(OPT_ARGS_NUM)
 {
   if(action & GMSH_SET) {
     CTX.mesh.surfaces_faces = (int)val;
-    CTX.mesh.changed = 1;
   }
 #if defined(HAVE_FLTK)
   if(WID && (action & GMSH_GUI))
@@ -3279,7 +3274,6 @@ double opt_mesh_volumes_edges(OPT_ARGS_NUM)
 {
   if(action & GMSH_SET) {
     CTX.mesh.volumes_edges = (int)val;
-    CTX.mesh.changed = 1;
   }
 #if defined(HAVE_FLTK)
   if(WID && (action & GMSH_GUI))
@@ -3292,7 +3286,6 @@ double opt_mesh_volumes_faces(OPT_ARGS_NUM)
 {
   if(action & GMSH_SET) {
     CTX.mesh.volumes_faces = (int)val;
-    CTX.mesh.changed = 1;
   }
 #if defined(HAVE_FLTK)
   if(WID && (action & GMSH_GUI))
@@ -3305,7 +3298,6 @@ double opt_mesh_points_num(OPT_ARGS_NUM)
 {
   if(action & GMSH_SET) {
     CTX.mesh.points_num = (int)val;
-    CTX.mesh.changed = 1;
   }
 #if defined(HAVE_FLTK)
   if(WID && (action & GMSH_GUI))
@@ -3318,7 +3310,6 @@ double opt_mesh_lines_num(OPT_ARGS_NUM)
 {
   if(action & GMSH_SET) {
     CTX.mesh.lines_num = (int)val;
-    CTX.mesh.changed = 1;
   }
 #if defined(HAVE_FLTK)
   if(WID && (action & GMSH_GUI))
@@ -3331,7 +3322,6 @@ double opt_mesh_surfaces_num(OPT_ARGS_NUM)
 {
   if(action & GMSH_SET) {
     CTX.mesh.surfaces_num = (int)val;
-    CTX.mesh.changed = 1;
   }
 #if defined(HAVE_FLTK)
   if(WID && (action & GMSH_GUI))
@@ -3344,7 +3334,6 @@ double opt_mesh_volumes_num(OPT_ARGS_NUM)
 {
   if(action & GMSH_SET) {
     CTX.mesh.volumes_num = (int)val;
-    CTX.mesh.changed = 1;
   }
 #if defined(HAVE_FLTK)
   if(WID && (action & GMSH_GUI))
@@ -3357,7 +3346,6 @@ double opt_mesh_point_size(OPT_ARGS_NUM)
 {
   if(action & GMSH_SET) {
     CTX.mesh.point_size = val;
-    CTX.mesh.changed = 1;
   }
 #if defined(HAVE_FLTK)
   if(WID && (action & GMSH_GUI))
@@ -3370,7 +3358,6 @@ double opt_mesh_point_type(OPT_ARGS_NUM)
 {
   if(action & GMSH_SET) {
     CTX.mesh.point_type = (int)val;
-    CTX.mesh.changed = 1;
   }
 #if defined(HAVE_FLTK)
   if(WID && (action & GMSH_GUI)) {
@@ -3384,7 +3371,6 @@ double opt_mesh_line_width(OPT_ARGS_NUM)
 {
   if(action & GMSH_SET) {
     CTX.mesh.line_width = val;
-    CTX.mesh.changed = 1;
   }
 #if defined(HAVE_FLTK)
   if(WID && (action & GMSH_GUI))
@@ -3397,7 +3383,6 @@ double opt_mesh_line_type(OPT_ARGS_NUM)
 {
   if(action & GMSH_SET) {
     CTX.mesh.line_type = (int)val;
-    CTX.mesh.changed = 1;
   }
 #if defined(HAVE_FLTK)
   if(WID && (action & GMSH_GUI)) {
@@ -3407,6 +3392,14 @@ double opt_mesh_line_type(OPT_ARGS_NUM)
   return CTX.mesh.line_type;
 }
 
+double opt_mesh_vertex_arrays(OPT_ARGS_NUM)
+{
+  if(action & GMSH_SET) {
+    CTX.mesh.vertex_arrays = (int)val;
+  }
+  return CTX.mesh.vertex_arrays;
+}
+
 double opt_mesh_light(OPT_ARGS_NUM)
 {
   if(action & GMSH_SET)
@@ -3513,7 +3506,6 @@ double opt_mesh_dual(OPT_ARGS_NUM)
 {
   if(action & GMSH_SET) {
     CTX.mesh.dual = (int)val;
-    CTX.mesh.changed = 1;
   }
   return CTX.mesh.dual;
 }
@@ -3531,8 +3523,10 @@ double opt_mesh_interactive(OPT_ARGS_NUM)
 
 double opt_mesh_use_cut_plane(OPT_ARGS_NUM)
 {
-  if(action & GMSH_SET)
+  if(action & GMSH_SET){
+    if(CTX.mesh.use_cut_plane != (int)val) CTX.mesh.changed = 1;
     CTX.mesh.use_cut_plane = (int)val;
+  }
 #if defined(HAVE_FLTK)
   if(WID && (action & GMSH_GUI))
     WID->mesh_butt[16]->value(CTX.mesh.use_cut_plane);
@@ -3542,8 +3536,10 @@ double opt_mesh_use_cut_plane(OPT_ARGS_NUM)
 
 double opt_mesh_cut_plane_as_surface(OPT_ARGS_NUM)
 {
-  if(action & GMSH_SET)
+  if(action & GMSH_SET){
+    if(CTX.mesh.cut_plane_as_surface != (int)val) CTX.mesh.changed = 1;
     CTX.mesh.cut_plane_as_surface = (int)val;
+  }
 #if defined(HAVE_FLTK)
   if(WID && (action & GMSH_GUI))
     WID->mesh_butt[22]->value(CTX.mesh.cut_plane_as_surface);
@@ -3553,8 +3549,10 @@ double opt_mesh_cut_plane_as_surface(OPT_ARGS_NUM)
 
 double opt_mesh_cut_planea(OPT_ARGS_NUM)
 {
-  if(action & GMSH_SET)
+  if(action & GMSH_SET){
+    if(CTX.mesh.cut_planea != val) CTX.mesh.changed = 1;
     CTX.mesh.cut_planea = val;
+  }
 #if defined(HAVE_FLTK)
   if(WID && (action & GMSH_GUI))
     WID->mesh_value[14]->value(CTX.mesh.cut_planea);
@@ -3564,8 +3562,10 @@ double opt_mesh_cut_planea(OPT_ARGS_NUM)
 
 double opt_mesh_cut_planeb(OPT_ARGS_NUM)
 {
-  if(action & GMSH_SET)
+  if(action & GMSH_SET){
+    if(CTX.mesh.cut_planeb != val) CTX.mesh.changed = 1;
     CTX.mesh.cut_planeb = val;
+  }
 #if defined(HAVE_FLTK)
   if(WID && (action & GMSH_GUI))
     WID->mesh_value[15]->value(CTX.mesh.cut_planeb);
@@ -3575,8 +3575,10 @@ double opt_mesh_cut_planeb(OPT_ARGS_NUM)
 
 double opt_mesh_cut_planec(OPT_ARGS_NUM)
 {
-  if(action & GMSH_SET)
+  if(action & GMSH_SET){
+    if(CTX.mesh.cut_planec != val) CTX.mesh.changed = 1;
     CTX.mesh.cut_planec = val;
+  }
 #if defined(HAVE_FLTK)
   if(WID && (action & GMSH_GUI))
     WID->mesh_value[16]->value(CTX.mesh.cut_planec);
@@ -3586,8 +3588,10 @@ double opt_mesh_cut_planec(OPT_ARGS_NUM)
 
 double opt_mesh_cut_planed(OPT_ARGS_NUM)
 {
-  if(action & GMSH_SET)
+  if(action & GMSH_SET){
+    if(CTX.mesh.cut_planed != val) CTX.mesh.changed = 1;
     CTX.mesh.cut_planed = val;
+  }
 #if defined(HAVE_FLTK)
   if(WID && (action & GMSH_GUI))
     WID->mesh_value[17]->value(CTX.mesh.cut_planed);
@@ -3629,7 +3633,6 @@ double opt_mesh_color_carousel(OPT_ARGS_NUM)
 {
   if(action & GMSH_SET) {
     CTX.mesh.color_carousel = (int)val;
-    CTX.mesh.changed = 1;
   }
 #if defined(HAVE_FLTK)
   if(WID && (action & GMSH_GUI)){
@@ -3698,19 +3701,6 @@ double opt_mesh_cpu_time(OPT_ARGS_NUM)
   return s[13] + s[14] + s[15];
 }
 
-double opt_mesh_display_lists(OPT_ARGS_NUM)
-{
-  if(action & GMSH_SET) {
-    CTX.mesh.display_lists = (int)val;
-    CTX.mesh.changed = 1;
-  }
-#if defined(HAVE_FLTK)
-  //if(WID && (action & GMSH_GUI))
-  //WID->mesh_butt[??]->value(CTX.mesh.display_lists);
-#endif
-  return CTX.mesh.display_lists;
-}
-
 double opt_solver_client_server(OPT_ARGS_NUM)
 {
 #if defined(HAVE_FLTK)
@@ -5103,7 +5093,6 @@ unsigned int opt_mesh_color_points(OPT_ARGS_COL)
 {
   if(action & GMSH_SET) {
     CTX.color.mesh.vertex = val;
-    CTX.mesh.changed = 1;
   }
 #if defined(HAVE_FLTK)
   CCC(CTX.color.mesh.vertex, WID->mesh_col[0]);
@@ -5114,7 +5103,6 @@ unsigned int opt_mesh_color_points_deg2(OPT_ARGS_COL)
 {
   if(action & GMSH_SET) {
     CTX.color.mesh.vertex_deg2 = val;
-    CTX.mesh.changed = 1;
   }
 #if defined(HAVE_FLTK)
   CCC(CTX.color.mesh.vertex_deg2, WID->mesh_col[1]);
@@ -5125,7 +5113,6 @@ unsigned int opt_mesh_color_lines(OPT_ARGS_COL)
 {
   if(action & GMSH_SET) {
     CTX.color.mesh.line = val;
-    CTX.mesh.changed = 1;
   }
 #if defined(HAVE_FLTK)
   CCC(CTX.color.mesh.line, WID->mesh_col[2]);
@@ -5136,7 +5123,6 @@ unsigned int opt_mesh_color_triangles(OPT_ARGS_COL)
 {
   if(action & GMSH_SET) {
     CTX.color.mesh.triangle = val;
-    CTX.mesh.changed = 1;
   }
 #if defined(HAVE_FLTK)
   CCC(CTX.color.mesh.triangle, WID->mesh_col[3]);
@@ -5147,7 +5133,6 @@ unsigned int opt_mesh_color_quadrangles(OPT_ARGS_COL)
 {
   if(action & GMSH_SET) {
     CTX.color.mesh.quadrangle = val;
-    CTX.mesh.changed = 1;
   }
 #if defined(HAVE_FLTK)
   CCC(CTX.color.mesh.quadrangle, WID->mesh_col[4]);
@@ -5158,7 +5143,6 @@ unsigned int opt_mesh_color_tetrahedra(OPT_ARGS_COL)
 {
   if(action & GMSH_SET) {
     CTX.color.mesh.tetrahedron = val;
-    CTX.mesh.changed = 1;
   }
 #if defined(HAVE_FLTK)
   CCC(CTX.color.mesh.tetrahedron, WID->mesh_col[5]);
@@ -5169,7 +5153,6 @@ unsigned int opt_mesh_color_hexahedra(OPT_ARGS_COL)
 {
   if(action & GMSH_SET) {
     CTX.color.mesh.hexahedron = val;
-    CTX.mesh.changed = 1;
   }
 #if defined(HAVE_FLTK)
   CCC(CTX.color.mesh.hexahedron, WID->mesh_col[6]);
@@ -5180,7 +5163,6 @@ unsigned int opt_mesh_color_prisms(OPT_ARGS_COL)
 {
   if(action & GMSH_SET) {
     CTX.color.mesh.prism = val;
-    CTX.mesh.changed = 1;
   }
 #if defined(HAVE_FLTK)
   CCC(CTX.color.mesh.prism, WID->mesh_col[7]);
@@ -5191,7 +5173,6 @@ unsigned int opt_mesh_color_pyramid(OPT_ARGS_COL)
 {
   if(action & GMSH_SET) {
     CTX.color.mesh.pyramid = val;
-    CTX.mesh.changed = 1;
   }
 #if defined(HAVE_FLTK)
   CCC(CTX.color.mesh.pyramid, WID->mesh_col[8]);
@@ -5202,7 +5183,6 @@ unsigned int opt_mesh_color_tangents(OPT_ARGS_COL)
 {
   if(action & GMSH_SET) {
     CTX.color.mesh.tangents = val;
-    CTX.mesh.changed = 1;
   }
 #if defined(HAVE_FLTK)
   CCC(CTX.color.mesh.tangents, WID->mesh_col[9]);
@@ -5213,7 +5193,6 @@ unsigned int opt_mesh_color_normals(OPT_ARGS_COL)
 {
   if(action & GMSH_SET) {
     CTX.color.mesh.normals = val;
-    CTX.mesh.changed = 1;
   }
 #if defined(HAVE_FLTK)
   CCC(CTX.color.mesh.normals, WID->mesh_col[10]);
@@ -5224,7 +5203,6 @@ unsigned int opt_mesh_color_1(OPT_ARGS_COL)
 {
   if(action & GMSH_SET) {
     CTX.color.mesh.carousel[0] = val;
-    CTX.mesh.changed = 1;
   }
 #if defined(HAVE_FLTK)
   CCC(CTX.color.mesh.carousel[0], WID->mesh_col[11]);
@@ -5235,7 +5213,6 @@ unsigned int opt_mesh_color_2(OPT_ARGS_COL)
 {
   if(action & GMSH_SET) {
     CTX.color.mesh.carousel[1] = val;
-    CTX.mesh.changed = 1;
   }
 #if defined(HAVE_FLTK)
   CCC(CTX.color.mesh.carousel[1], WID->mesh_col[12]);
@@ -5246,7 +5223,6 @@ unsigned int opt_mesh_color_3(OPT_ARGS_COL)
 {
   if(action & GMSH_SET) {
     CTX.color.mesh.carousel[2] = val;
-    CTX.mesh.changed = 1;
   }
 #if defined(HAVE_FLTK)
   CCC(CTX.color.mesh.carousel[2], WID->mesh_col[13]);
@@ -5257,7 +5233,6 @@ unsigned int opt_mesh_color_4(OPT_ARGS_COL)
 {
   if(action & GMSH_SET) {
     CTX.color.mesh.carousel[3] = val;
-    CTX.mesh.changed = 1;
   }
 #if defined(HAVE_FLTK)
   CCC(CTX.color.mesh.carousel[3], WID->mesh_col[14]);
@@ -5268,7 +5243,6 @@ unsigned int opt_mesh_color_5(OPT_ARGS_COL)
 {
   if(action & GMSH_SET) {
     CTX.color.mesh.carousel[4] = val;
-    CTX.mesh.changed = 1;
   }
 #if defined(HAVE_FLTK)
   CCC(CTX.color.mesh.carousel[4], WID->mesh_col[15]);
@@ -5279,7 +5253,6 @@ unsigned int opt_mesh_color_6(OPT_ARGS_COL)
 {
   if(action & GMSH_SET) {
     CTX.color.mesh.carousel[5] = val;
-    CTX.mesh.changed = 1;
   }
 #if defined(HAVE_FLTK)
   CCC(CTX.color.mesh.carousel[5], WID->mesh_col[16]);
@@ -5290,7 +5263,6 @@ unsigned int opt_mesh_color_7(OPT_ARGS_COL)
 {
   if(action & GMSH_SET) {
     CTX.color.mesh.carousel[6] = val;
-    CTX.mesh.changed = 1;
   }
 #if defined(HAVE_FLTK)
   CCC(CTX.color.mesh.carousel[6], WID->mesh_col[17]);
@@ -5301,7 +5273,6 @@ unsigned int opt_mesh_color_8(OPT_ARGS_COL)
 {
   if(action & GMSH_SET) {
     CTX.color.mesh.carousel[7] = val;
-    CTX.mesh.changed = 1;
   }
 #if defined(HAVE_FLTK)
   CCC(CTX.color.mesh.carousel[7], WID->mesh_col[18]);
@@ -5312,7 +5283,6 @@ unsigned int opt_mesh_color_9(OPT_ARGS_COL)
 {
   if(action & GMSH_SET) {
     CTX.color.mesh.carousel[8] = val;
-    CTX.mesh.changed = 1;
   }
 #if defined(HAVE_FLTK)
   CCC(CTX.color.mesh.carousel[8], WID->mesh_col[19]);
@@ -5323,7 +5293,6 @@ unsigned int opt_mesh_color_10(OPT_ARGS_COL)
 {
   if(action & GMSH_SET) {
     CTX.color.mesh.carousel[9] = val;
-    CTX.mesh.changed = 1;
   }
 #if defined(HAVE_FLTK)
   CCC(CTX.color.mesh.carousel[9], WID->mesh_col[20]);
diff --git a/Common/Options.h b/Common/Options.h
index d4421709d5e7744531db15296e271aaccec1a8e5..ea9f3794962333fd2c1ac614cabc310085e76cf4 100644
--- a/Common/Options.h
+++ b/Common/Options.h
@@ -360,6 +360,7 @@ double opt_mesh_point_size(OPT_ARGS_NUM);
 double opt_mesh_point_type(OPT_ARGS_NUM);
 double opt_mesh_line_width(OPT_ARGS_NUM);
 double opt_mesh_line_type(OPT_ARGS_NUM);
+double opt_mesh_vertex_arrays(OPT_ARGS_NUM);
 double opt_mesh_light(OPT_ARGS_NUM);
 double opt_mesh_format(OPT_ARGS_NUM);
 double opt_mesh_msh_file_version(OPT_ARGS_NUM);
@@ -390,7 +391,6 @@ double opt_mesh_nb_hexahedra(OPT_ARGS_NUM);
 double opt_mesh_nb_prisms(OPT_ARGS_NUM);
 double opt_mesh_nb_pyramids(OPT_ARGS_NUM);
 double opt_mesh_cpu_time(OPT_ARGS_NUM);
-double opt_mesh_display_lists(OPT_ARGS_NUM);
 double opt_solver_client_server(OPT_ARGS_NUM);
 double opt_solver_client_server0(OPT_ARGS_NUM);
 double opt_solver_client_server1(OPT_ARGS_NUM);
diff --git a/Fltk/Callbacks.cpp b/Fltk/Callbacks.cpp
index ceb633ec775f58cb2041c84eea2df9189fc1d4c3..5107ee1287d8430d79ef3fd139d03bf817b092f5 100644
--- a/Fltk/Callbacks.cpp
+++ b/Fltk/Callbacks.cpp
@@ -1,4 +1,4 @@
-// $Id: Callbacks.cpp,v 1.240 2004-05-22 01:24:16 geuzaine Exp $
+// $Id: Callbacks.cpp,v 1.241 2004-05-28 19:22:12 geuzaine Exp $
 //
 // Copyright (C) 1997-2004 C. Geuzaine, J.-F. Remacle
 //
@@ -1219,12 +1219,14 @@ void visibility_ok_cb(CALLBACK_ARGS)
   switch (WID->vis_browser_mode->value()) {
   case 0:
     mode = VIS_GEOM | VIS_MESH;
+    CTX.mesh.changed = 1;
     break;
   case 1:
     mode = VIS_GEOM;
     break;
   default:
     mode = VIS_MESH;
+    CTX.mesh.changed = 1;
     break;
   }
 
@@ -1297,17 +1299,20 @@ void visibility_number_cb(CALLBACK_ARGS)
     switch (WID->vis_browser_mode->value()) {
     case 0:
       mode = VIS_GEOM | VIS_MESH;
+      CTX.mesh.changed = 1;
       break;
     case 1:
       mode = VIS_GEOM;
       break;
     default:
       mode = VIS_MESH;
+      CTX.mesh.changed = 1;
       break;
     }
   }
   else{ // hide
     mode = 0;
+    CTX.mesh.changed = 1;
   }
 
   SetVisibilityByNumber(str, type, mode);
diff --git a/Graphics/Draw.h b/Graphics/Draw.h
index 844d0dc8049cfcb450c4b3ae90bfebd42dcd308e..1ddd6237a412ef44405512b536a521874bf4fe34 100644
--- a/Graphics/Draw.h
+++ b/Graphics/Draw.h
@@ -88,6 +88,7 @@ void Draw_Mesh_Curve(void *a, void *b);
 void Draw_Mesh_Point(void *a, void *b);
 void Draw_Mesh_Line(void *a, void *b);
 void Draw_Mesh_Triangle(void *a, void *b);
+void Draw_Mesh_Triangle_Array(triangleVertexArray *va);
 void Draw_Mesh_Quadrangle(void *a, void *b);
 void Draw_Mesh_Tetrahedron(void *a, void *b);
 void Draw_Mesh_Hexahedron(void *a, void *b);
diff --git a/Graphics/Mesh.cpp b/Graphics/Mesh.cpp
index 0c91c78655331cba6760cd454287323edfbe4f43..8abb9e4c9019b7c4ca18cecc68b173bc5af5cd35 100644
--- a/Graphics/Mesh.cpp
+++ b/Graphics/Mesh.cpp
@@ -1,4 +1,4 @@
-// $Id: Mesh.cpp,v 1.86 2004-05-27 06:23:48 geuzaine Exp $
+// $Id: Mesh.cpp,v 1.87 2004-05-28 19:22:12 geuzaine Exp $
 //
 // Copyright (C) 1997-2004 C. Geuzaine, J.-F. Remacle
 //
@@ -40,6 +40,9 @@ extern int edges_pyramid[8][2];
 
 static DrawingColor theColor;
 static int thePhysical = 0;
+static triangleVertexArray *theVertexArray = NULL;
+static int fillTheVertexArray = 0;
+static int useTheVertexArray = 0;
 
 void draw_polygon_2d(double r, double g, double b, int n,
                      double *x, double *y, double *z)
@@ -65,11 +68,6 @@ void draw_polygon_2d(double r, double g, double b, int n,
   glEnable(GL_DEPTH_TEST);
 }
 
-void ColorSwitch(int i)
-{
-  glColor4ubv((GLubyte *) & CTX.color.mesh.carousel[abs(i % 10)]);
-}
-
 int getFirstPhysical(int type, int num)
 {
   for(int i = 0; i < List_Nbr(THEM->PhysicalGroups); i++){
@@ -80,6 +78,33 @@ int getFirstPhysical(int type, int num)
   return 0;
 }
 
+double intersectCutPlane(int num, Vertex **v, int *edges, int *faces)
+{
+  if(!CTX.mesh.use_cut_plane)
+    return 0;
+
+  double val = CTX.mesh.evalCutPlane(v[0]->Pos.X, v[0]->Pos.Y, v[0]->Pos.Z);
+  for(int i = 1; i < num; i++){
+    if(val * CTX.mesh.evalCutPlane(v[i]->Pos.X, v[i]->Pos.Y, v[i]->Pos.Z) <= 0){
+      // the element intersects the cut plane
+      if(CTX.mesh.cut_plane_as_surface){
+	if(!*edges)
+	  *edges = CTX.mesh.surfaces_edges;
+	if(!*faces)
+	  *faces = CTX.mesh.surfaces_faces;
+      }
+      return 1.;
+    }
+  }
+  return val;
+}
+
+double intersectCutPlane(int num, Vertex **v)
+{
+  int dummy;
+  return intersectCutPlane(num, v, &dummy, &dummy);
+}
+
 void Draw_Mesh(Mesh * M)
 {
   int i;
@@ -96,9 +121,14 @@ void Draw_Mesh(Mesh * M)
   if(M->status >= 0)
     Draw_Geom(M);
 
+  // if we're in selection mode, we're done
+
+  if(CTX.render_mode == GMSH_SELECT)
+    return;
+
   // draw the bounding box of the mesh if we are in fast redraw mode
   // and there is no geometry
-  
+ 
   if(!CTX.mesh.draw && Tree_Nbr(M->Vertices) && !Tree_Nbr(M->Points)) {
     glColor4ubv((GLubyte *) & CTX.color.fg);
     glLineWidth(CTX.line_width);
@@ -139,76 +169,47 @@ void Draw_Mesh(Mesh * M)
   }
 
   // draw the mesh
-  
-  glPointSize(CTX.mesh.point_size);
-  gl2psPointSize(CTX.mesh.point_size * CTX.print.eps_point_size_factor);
-
-  glLineWidth(CTX.mesh.line_width);
-  gl2psLineWidth(CTX.mesh.line_width * CTX.print.eps_line_width_factor);
-
-  if(CTX.mesh.draw && CTX.render_mode != GMSH_SELECT) {
 
-    static int first = 1, listnum;
-
-    if(CTX.mesh.display_lists && CTX.mesh.changed) {
-      if(first)
-        listnum = glGenLists(1);
-      first = 0;
-      //printf("new mesh display list\n");
-      glNewList(listnum, GL_COMPILE_AND_EXECUTE);
+  if(CTX.mesh.draw) {  
+    glPointSize(CTX.mesh.point_size);
+    gl2psPointSize(CTX.mesh.point_size * CTX.print.eps_point_size_factor);
+    glLineWidth(CTX.mesh.line_width);
+    gl2psLineWidth(CTX.mesh.line_width * CTX.print.eps_line_width_factor);
+   
+    if(M->status >= 3 && (CTX.mesh.volumes_faces || CTX.mesh.volumes_edges ||
+			  CTX.mesh.volumes_num || 
+			  (CTX.mesh.use_cut_plane && CTX.mesh.cut_plane_as_surface &&
+			   (CTX.mesh.surfaces_edges || CTX.mesh.surfaces_faces)))) {
+      Tree_Action(M->Volumes, Draw_Mesh_Volume);
     }
-
-    if(!CTX.mesh.display_lists || (CTX.mesh.display_lists && CTX.mesh.changed)) {
-
-      //printf("normal mesh drawing\n");
-
-      if(M->status >= 3 && (CTX.mesh.volumes_faces || CTX.mesh.volumes_edges ||
-			    CTX.mesh.volumes_num || 
-			    (CTX.mesh.use_cut_plane && CTX.mesh.cut_plane_as_surface &&
-			     (CTX.mesh.surfaces_edges || CTX.mesh.surfaces_faces)))) {
-	Tree_Action(M->Volumes, Draw_Mesh_Volume);
-      }
-
-      if(M->status >= 2 && (CTX.mesh.surfaces_faces || CTX.mesh.surfaces_edges ||
-			    CTX.mesh.surfaces_num || CTX.mesh.normals)) {
-        Tree_Action(M->Surfaces, Draw_Mesh_Surface);
-        if(CTX.mesh.oldxtrude)  //old extrusion algo
-          Tree_Action(M->Volumes, Draw_Mesh_Extruded_Surfaces);
-      }
-
-      if(M->status >= 1 && (CTX.mesh.lines || CTX.mesh.lines_num || 
-			    CTX.mesh.tangents)) {
-        Tree_Action(M->Curves, Draw_Mesh_Curve);
-      }
-
-      if(M->status >= 0 && (CTX.mesh.points || CTX.mesh.points_num)) {
-        Tree_Action(M->Vertices, Draw_Mesh_Point);
-      }
-
+   
+    if(M->status >= 2 && (CTX.mesh.surfaces_faces || CTX.mesh.surfaces_edges ||
+			  CTX.mesh.surfaces_num || CTX.mesh.normals)) {
+      Tree_Action(M->Surfaces, Draw_Mesh_Surface);
+      if(CTX.mesh.oldxtrude)  //old extrusion algo
+	Tree_Action(M->Volumes, Draw_Mesh_Extruded_Surfaces);
     }
-    else {
-
-      //printf("calling mesh display list\n");
-      glCallList(listnum);
-
+    
+    if(M->status >= 1 && (CTX.mesh.lines || CTX.mesh.lines_num || 
+			  CTX.mesh.tangents)) {
+      Tree_Action(M->Curves, Draw_Mesh_Curve);
     }
-
-    if(CTX.mesh.display_lists) {
-      if(CTX.mesh.changed) {
-        glEndList();
-        CTX.mesh.changed = 0;
-      }
+    
+    if(M->status >= 0 && (CTX.mesh.points || CTX.mesh.points_num)) {
+      Tree_Action(M->Vertices, Draw_Mesh_Point);
     }
-
+    CTX.mesh.changed = 0;
   }
 
+  // draw the big moving axes
+
+  if(CTX.axes)
+    Draw_Axes(CTX.lc_middle / 4.);
+
   // draw the post-processing views
 
-  if(CTX.render_mode != GMSH_SELECT) {
-    if(CTX.axes)
-      Draw_Axes(CTX.lc_middle / 4.);
-    Draw_Post();
-  }
+  Draw_Post();
+
 }
 
 void Draw_Mesh_Volume(void *a, void *b)
@@ -227,7 +228,35 @@ void Draw_Mesh_Surface(void *a, void *b)
   thePhysical = getFirstPhysical(MSH_PHYSICAL_SURFACE, s->Num);
   if(!(s->Visible & VIS_MESH))
     return;
-  Tree_Action(s->Simplexes, Draw_Mesh_Triangle);
+
+  if(Tree_Nbr(s->Simplexes)){
+    
+    if(CTX.mesh.vertex_arrays && !CTX.threads_lock){
+      CTX.threads_lock = 1;
+      if(CTX.mesh.changed){
+	printf("generate vertex array\n");
+	if(s->vertexArray) delete s->vertexArray;
+	s->vertexArray = new triangleVertexArray(Tree_Nbr(s->Simplexes));
+	theVertexArray = s->vertexArray;
+	fillTheVertexArray = 1;
+	useTheVertexArray = 1;
+	Tree_Action(s->Simplexes, Draw_Mesh_Triangle);
+	fillTheVertexArray = 0;
+      }
+      CTX.threads_lock = 0;
+    }
+    else{
+      useTheVertexArray = 0;
+    }
+    
+    if(s->vertexArray && useTheVertexArray)
+      Draw_Mesh_Triangle_Array(s->vertexArray);
+    
+    if(!useTheVertexArray || CTX.mesh.dual || 
+       CTX.mesh.surfaces_num || CTX.mesh.normals)
+      Tree_Action(s->Simplexes, Draw_Mesh_Triangle);
+  }
+  
   Tree_Action(s->Quadrangles, Draw_Mesh_Quadrangle);
 }
 
@@ -253,33 +282,6 @@ void Draw_Mesh_Curve(void *a, void *b)
   Tree_Action(c->Simplexes, Draw_Mesh_Line);
 }
 
-double intersectCutPlane(int num, Vertex **v, int *edges, int *faces)
-{
-  if(!CTX.mesh.use_cut_plane)
-    return 0;
-
-  double val = CTX.mesh.evalCutPlane(v[0]->Pos.X, v[0]->Pos.Y, v[0]->Pos.Z);
-  for(int i = 1; i < num; i++){
-    if(val * CTX.mesh.evalCutPlane(v[i]->Pos.X, v[i]->Pos.Y, v[i]->Pos.Z) <= 0){
-      // the element intersects the cut plane
-      if(CTX.mesh.cut_plane_as_surface){
-	if(!*edges)
-	  *edges = CTX.mesh.surfaces_edges;
-	if(!*faces)
-	  *faces = CTX.mesh.surfaces_faces;
-      }
-      return 1.;
-    }
-  }
-  return val;
-}
-
-double intersectCutPlane(int num, Vertex **v)
-{
-  int dummy;
-  return intersectCutPlane(num, v, &dummy, &dummy);
-}
-
 void Draw_Mesh_Point(void *a, void *b)
 {
   Vertex *v;
@@ -372,11 +374,11 @@ void Draw_Mesh_Line(void *a, void *b)
   if(theColor.type)
     glColor4ubv((GLubyte *) & theColor.mesh);
   else if(CTX.mesh.color_carousel == 1)
-    ColorSwitch(s->iEnt);
+    glColor4ubv((GLubyte *) & CTX.color.mesh.carousel[abs(s->iEnt % 10)]);
   else if(CTX.mesh.color_carousel == 2)
-    ColorSwitch(thePhysical);
+    glColor4ubv((GLubyte *) & CTX.color.mesh.carousel[abs(thePhysical % 10)]);
   else if(CTX.mesh.color_carousel == 3)
-    ColorSwitch(s->iPart);
+    glColor4ubv((GLubyte *) & CTX.color.mesh.carousel[abs(s->iPart % 10)]);
   else
     glColor4ubv((GLubyte *) & CTX.color.mesh.line);
 
@@ -502,6 +504,18 @@ void Draw_Mesh_Triangle(void *a, void *b)
   if(intersectCutPlane(3, s->V) < 0)
     return;
 
+  unsigned int col;
+  if(theColor.type)
+    col = theColor.mesh;
+  else if(CTX.mesh.color_carousel == 1)
+    col = CTX.color.mesh.carousel[abs(s->iEnt % 10)];
+  else if(CTX.mesh.color_carousel == 2)
+    col = CTX.color.mesh.carousel[abs(thePhysical % 10)];
+  else if(CTX.mesh.color_carousel == 3)
+    col = CTX.color.mesh.carousel[abs(s->iPart % 10)];
+  else
+    col = CTX.color.mesh.triangle;
+
   double Xc = (s->V[0]->Pos.X + s->V[1]->Pos.X + s->V[2]->Pos.X) / 3.;
   double Yc = (s->V[0]->Pos.Y + s->V[1]->Pos.Y + s->V[2]->Pos.Y) / 3.;
   double Zc = (s->V[0]->Pos.Z + s->V[1]->Pos.Z + s->V[2]->Pos.Z) / 3.;
@@ -512,6 +526,7 @@ void Draw_Mesh_Triangle(void *a, void *b)
     Z[i] = Zc + CTX.mesh.explode * (s->V[i]->Pos.Z - Zc);
   }
   if(s->VSUP){
+    useTheVertexArray = 0;
     for(int i = 0; i < 3; i++) {
       X2[i] = Xc + CTX.mesh.explode * (s->VSUP[i]->Pos.X - Xc);
       Y2[i] = Yc + CTX.mesh.explode * (s->VSUP[i]->Pos.Y - Yc);
@@ -519,6 +534,64 @@ void Draw_Mesh_Triangle(void *a, void *b)
     }
   }
 
+  if(CTX.mesh.normals || CTX.mesh.light || fillTheVertexArray)
+    _normal3points(X[0], Y[0], Z[0], 
+		   X[1], Y[1], Z[1],
+		   X[2], Y[2], Z[2], n);
+
+  if(fillTheVertexArray && !s->VSUP){
+    int iv = theVertexArray->num_triangles * 9;
+    int in = theVertexArray->num_triangles * 9;
+    int ic = theVertexArray->num_triangles * 12;
+    for(int i = 0; i < 3; i++) {
+      theVertexArray->vertices[iv++] = X[i];
+      theVertexArray->vertices[iv++] = Y[i];
+      theVertexArray->vertices[iv++] = Z[i];
+      theVertexArray->normals[in++] = n[0];
+      theVertexArray->normals[in++] = n[1];
+      theVertexArray->normals[in++] = n[2];
+      theVertexArray->colors[ic++] = UNPACK_RED(col);
+      theVertexArray->colors[ic++] = UNPACK_GREEN(col);
+      theVertexArray->colors[ic++] = UNPACK_BLUE(col);
+      theVertexArray->colors[ic++] = UNPACK_ALPHA(col);
+    }
+    theVertexArray->num_triangles++;
+  }    
+
+  if(!useTheVertexArray){
+    if(CTX.mesh.surfaces_edges){
+      if(CTX.mesh.surfaces_faces)
+	glColor4ubv((GLubyte *) & CTX.color.mesh.line);
+      else
+	glColor4ubv((GLubyte *) & col);
+      glBegin(GL_LINE_LOOP);
+      for(int i = 0; i < 3; i++){
+	glVertex3d(X[i], Y[i], Z[i]);
+	if(s->VSUP) glVertex3d(X2[i], Y2[i], Z2[i]);
+      }
+      glEnd();
+    }
+    if(CTX.mesh.surfaces_faces) {
+      glColor4ubv((GLubyte *) & col);      
+      if(CTX.mesh.light) glEnable(GL_LIGHTING);
+      glEnable(GL_POLYGON_OFFSET_FILL);
+      if(!s->VSUP) {
+	glBegin(GL_TRIANGLES);
+	glVertex3d(X[0], Y[0], Z[0]);
+	glVertex3d(X[1], Y[1], Z[1]);
+	glVertex3d(X[2], Y[2], Z[2]);
+	glEnd();
+      }
+      else {
+	glBegin(GL_TRIANGLES);
+	_triFace2(X, Y, Z, X2, Y2, Z2, 0, 1, 2, 0, 1, 2);
+	glEnd();
+      }		    
+      glDisable(GL_POLYGON_OFFSET_FILL);
+      glDisable(GL_LIGHTING);
+    }
+  }
+
   if(CTX.mesh.dual) {
     glColor4ubv((GLubyte *) & CTX.color.fg);
     glEnable(GL_LINE_STIPPLE);
@@ -535,71 +608,11 @@ void Draw_Mesh_Triangle(void *a, void *b)
     gl2psDisable(GL2PS_LINE_STIPPLE);
   }
 
-  if(CTX.mesh.normals || CTX.mesh.light)
-    _normal3points(X[0], Y[0], Z[0], 
-		   X[1], Y[1], Z[1],
-		   X[2], Y[2], Z[2], n);
-
-  if(CTX.mesh.surfaces_faces){
-    glColor4ubv((GLubyte *) & CTX.color.mesh.line);
-  }
-  else{
-    if(theColor.type)
-      glColor4ubv((GLubyte *) & theColor.mesh);
-    else if(CTX.mesh.color_carousel == 1)
-      ColorSwitch(s->iEnt);
-    else if(CTX.mesh.color_carousel == 2)
-      ColorSwitch(thePhysical);
-    else if(CTX.mesh.color_carousel == 3)
-      ColorSwitch(s->iPart);
-    else
-      glColor4ubv((GLubyte *) & CTX.color.mesh.triangle);
-  }
-
-  if(CTX.mesh.surfaces_edges){
-    glBegin(GL_LINE_LOOP);
-    for(int i = 0; i < 3; i++){
-      glVertex3d(X[i], Y[i], Z[i]);
-      if(s->VSUP) glVertex3d(X2[i], Y2[i], Z2[i]);
-    }
-    glEnd();
-  }
-
-  if(CTX.mesh.surfaces_faces) {
-
-    if(theColor.type)
-      glColor4ubv((GLubyte *) & theColor.mesh);
-    else if(CTX.mesh.color_carousel == 1)
-      ColorSwitch(s->iEnt);
-    else if(CTX.mesh.color_carousel == 2)
-      ColorSwitch(thePhysical);
-    else if(CTX.mesh.color_carousel == 3)
-      ColorSwitch(s->iPart);
-    else
-      glColor4ubv((GLubyte *) & CTX.color.mesh.triangle);
-
-    if(CTX.mesh.light) glEnable(GL_LIGHTING);
-    glEnable(GL_POLYGON_OFFSET_FILL);
-
-    if(!s->VSUP) {
-      glBegin(GL_TRIANGLES);
-      glVertex3d(X[0], Y[0], Z[0]);
-      glVertex3d(X[1], Y[1], Z[1]);
-      glVertex3d(X[2], Y[2], Z[2]);
-      glEnd();
-    }
-    else {
-      glBegin(GL_TRIANGLES);
-      _triFace2(X, Y, Z, X2, Y2, Z2, 0, 1, 2, 0, 1, 2);
-      glEnd();
-    }		    
-    glDisable(GL_POLYGON_OFFSET_FILL);
-    glDisable(GL_LIGHTING);
-  }
-
   if(CTX.mesh.surfaces_num) {
     if(CTX.mesh.surfaces_faces)
       glColor4ubv((GLubyte *) & CTX.color.mesh.line);
+    else
+      glColor4ubv((GLubyte *) & col);
     sprintf(Num, "%d", s->Num);
     glRasterPos3d(Xc, Yc, Zc);
     Draw_String(Num);
@@ -617,6 +630,47 @@ void Draw_Mesh_Triangle(void *a, void *b)
   }
 }
 
+void Draw_Mesh_Triangle_Array(triangleVertexArray *va)
+{
+  if(!va->num_triangles)
+    return;
+
+  glVertexPointer(3, GL_FLOAT, 0, va->vertices);
+  glNormalPointer(GL_FLOAT, 0, va->normals);
+  glColorPointer(4, GL_UNSIGNED_BYTE, 0, va->colors);
+
+  glEnableClientState(GL_VERTEX_ARRAY);
+  glEnableClientState(GL_COLOR_ARRAY);
+  glEnableClientState(GL_NORMAL_ARRAY);
+      
+  if(CTX.mesh.surfaces_faces){
+    if(CTX.mesh.surfaces_edges)
+      glEnable(GL_POLYGON_OFFSET_FILL);
+    if(CTX.mesh.light)
+      glEnable(GL_LIGHTING);
+    else
+      glDisableClientState(GL_NORMAL_ARRAY);
+    glDrawArrays(GL_TRIANGLES, 0, 3 * va->num_triangles);
+    glDisable(GL_POLYGON_OFFSET_FILL);
+    glDisable(GL_LIGHTING);
+  }
+      
+  if(CTX.mesh.surfaces_edges){
+    if(CTX.mesh.surfaces_faces){
+      glDisableClientState(GL_COLOR_ARRAY);
+      glColor4ubv((GLubyte *) & CTX.color.mesh.line);
+    }
+    glDisableClientState(GL_NORMAL_ARRAY);
+    glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
+    glDrawArrays(GL_TRIANGLES, 0, 3 * va->num_triangles);
+    glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
+  }
+
+  glDisableClientState(GL_VERTEX_ARRAY);
+  glDisableClientState(GL_COLOR_ARRAY);
+  glDisableClientState(GL_NORMAL_ARRAY);
+}
+
 void Draw_Mesh_Quadrangle(void *a, void *b)
 {
   double X[4], Y[4], Z[4], X2[5], Y2[5], Z2[5];
@@ -635,6 +689,18 @@ void Draw_Mesh_Quadrangle(void *a, void *b)
   if(intersectCutPlane(4, q->V) < 0)
     return;
 
+  unsigned int col;
+  if(theColor.type)
+    col = theColor.mesh;
+  else if(CTX.mesh.color_carousel == 1)
+    col = CTX.color.mesh.carousel[abs(q->iEnt % 10)];
+  else if(CTX.mesh.color_carousel == 2)
+    col = CTX.color.mesh.carousel[abs(thePhysical % 10)];
+  else if(CTX.mesh.color_carousel == 3)
+    col = CTX.color.mesh.carousel[abs(q->iPart % 10)];
+  else
+    col = CTX.color.mesh.quadrangle;
+
   double Xc = 0.25 * (q->V[0]->Pos.X + q->V[1]->Pos.X + 
 		      q->V[2]->Pos.X + q->V[3]->Pos.X);
   double Yc = 0.25 * (q->V[0]->Pos.Y + q->V[1]->Pos.Y + 
@@ -655,44 +721,16 @@ void Draw_Mesh_Quadrangle(void *a, void *b)
     }
   }
 
-  if(CTX.mesh.dual) {
-    glColor4ubv((GLubyte *) & CTX.color.fg);
-    glEnable(GL_LINE_STIPPLE);
-    glLineStipple(1, 0x0F0F);
-    gl2psEnable(GL2PS_LINE_STIPPLE);
-    glBegin(GL_LINES);
-    for(int i = 0; i < 4; i++) {
-      int j = i ? (i - 1) : 3;
-      glVertex3d(Xc, Yc, Zc);
-      glVertex3d((X[i] + X[j]) / 2., (Y[i] + Y[j]) / 2., (Z[i] + Z[j]) / 2.);
-    }
-    glEnd();
-    glDisable(GL_LINE_STIPPLE);
-    gl2psDisable(GL2PS_LINE_STIPPLE);
-  }
-
   if(CTX.mesh.normals || CTX.mesh.light)
     _normal3points(X[0], Y[0], Z[0], 
 		   X[1], Y[1], Z[1],
 		   X[2], Y[2], Z[2], n);
 
-  if(CTX.mesh.surfaces_faces){
-    glColor4ubv((GLubyte *) & CTX.color.mesh.line);
-  }
-  else{
-    if(theColor.type)
-      glColor4ubv((GLubyte *) & theColor.mesh);
-    else if(CTX.mesh.color_carousel == 1)
-      ColorSwitch(q->iEnt);
-    else if(CTX.mesh.color_carousel == 2)
-      ColorSwitch(thePhysical);
-    else if(CTX.mesh.color_carousel == 3)
-      ColorSwitch(q->iPart);
-    else
-      glColor4ubv((GLubyte *) & CTX.color.mesh.quadrangle);
-  }
-
   if(CTX.mesh.surfaces_edges){
+    if(CTX.mesh.surfaces_faces)
+      glColor4ubv((GLubyte *) & CTX.color.mesh.line);
+    else
+      glColor4ubv((GLubyte *) & col);
     glBegin(GL_LINE_LOOP);
     for(int i = 0; i < 4; i++){
       glVertex3d(X[i], Y[i], Z[i]);
@@ -703,18 +741,7 @@ void Draw_Mesh_Quadrangle(void *a, void *b)
   }
 
   if(CTX.mesh.surfaces_faces) {
-
-    if(theColor.type)
-      glColor4ubv((GLubyte *) & theColor.mesh);
-    else if(CTX.mesh.color_carousel == 1)
-      ColorSwitch(q->iEnt);
-    else if(CTX.mesh.color_carousel == 2)
-      ColorSwitch(thePhysical);
-    else if(CTX.mesh.color_carousel == 3)
-      ColorSwitch(q->iPart);
-    else
-      glColor4ubv((GLubyte *) & CTX.color.mesh.quadrangle);
-
+    glColor4ubv((GLubyte *) & col);
     if(CTX.mesh.light) glEnable(GL_LIGHTING);
     glEnable(GL_POLYGON_OFFSET_FILL);
     if(!q->VSUP) {
@@ -734,9 +761,27 @@ void Draw_Mesh_Quadrangle(void *a, void *b)
     glDisable(GL_LIGHTING);
   }
 
+  if(CTX.mesh.dual) {
+    glColor4ubv((GLubyte *) & CTX.color.fg);
+    glEnable(GL_LINE_STIPPLE);
+    glLineStipple(1, 0x0F0F);
+    gl2psEnable(GL2PS_LINE_STIPPLE);
+    glBegin(GL_LINES);
+    for(int i = 0; i < 4; i++) {
+      int j = i ? (i - 1) : 3;
+      glVertex3d(Xc, Yc, Zc);
+      glVertex3d((X[i] + X[j]) / 2., (Y[i] + Y[j]) / 2., (Z[i] + Z[j]) / 2.);
+    }
+    glEnd();
+    glDisable(GL_LINE_STIPPLE);
+    gl2psDisable(GL2PS_LINE_STIPPLE);
+  }
+
   if(CTX.mesh.surfaces_num) {
     if(CTX.mesh.surfaces_faces)
       glColor4ubv((GLubyte *) & CTX.color.mesh.line);
+    else
+      glColor4ubv((GLubyte *) & col);
     sprintf(Num, "%d", q->Num);
     glRasterPos3d(Xc, Yc, Zc);
     Draw_String(Num);
@@ -797,6 +842,18 @@ void Draw_Mesh_Tetrahedron(void *a, void *b)
   if(intersectCutPlane(4, s->V, &edges, &faces) < 0)
     return;
 
+  unsigned int col;
+  if(theColor.type)
+    col = theColor.mesh;
+  else if(CTX.mesh.color_carousel == 1)
+    col = CTX.color.mesh.carousel[abs(s->iEnt % 10)];
+  else if(CTX.mesh.color_carousel == 2)
+    col = CTX.color.mesh.carousel[abs(thePhysical % 10)];
+  else if(CTX.mesh.color_carousel == 3)
+    col = CTX.color.mesh.carousel[abs(s->iPart % 10)];
+  else
+    col = CTX.color.mesh.tetrahedron;
+
   double Xc = .25 * (s->V[0]->Pos.X + s->V[1]->Pos.X +
                      s->V[2]->Pos.X + s->V[3]->Pos.X);
   double Yc = .25 * (s->V[0]->Pos.Y + s->V[1]->Pos.Y +
@@ -804,22 +861,6 @@ void Draw_Mesh_Tetrahedron(void *a, void *b)
   double Zc = .25 * (s->V[0]->Pos.Z + s->V[1]->Pos.Z +
                      s->V[2]->Pos.Z + s->V[3]->Pos.Z);
 
-  if(CTX.mesh.surfaces_faces || faces){
-    glColor4ubv((GLubyte *) & CTX.color.mesh.line);
-  }
-  else{
-    if(theColor.type)
-      glColor4ubv((GLubyte *) & theColor.mesh);
-    else if(CTX.mesh.color_carousel == 1)
-      ColorSwitch(s->iEnt);
-    else if(CTX.mesh.color_carousel == 2)
-      ColorSwitch(thePhysical);
-    else if(CTX.mesh.color_carousel == 3)
-      ColorSwitch(s->iPart);
-    else
-      glColor4ubv((GLubyte *) & CTX.color.mesh.tetrahedron);
-  }
-
   for(int i = 0; i < 4; i++) {
     X[i] = Xc + CTX.mesh.explode * (s->V[i]->Pos.X - Xc);
     Y[i] = Yc + CTX.mesh.explode * (s->V[i]->Pos.Y - Yc);
@@ -834,6 +875,10 @@ void Draw_Mesh_Tetrahedron(void *a, void *b)
   }
 
   if(edges) {
+    if(CTX.mesh.surfaces_faces || faces)
+      glColor4ubv((GLubyte *) & CTX.color.mesh.line);
+    else
+      glColor4ubv((GLubyte *) & col);
     glBegin(GL_LINES);
     for(int i = 0; i < 6; i++){
       int j = edges_tetra[i][0];
@@ -848,10 +893,28 @@ void Draw_Mesh_Tetrahedron(void *a, void *b)
     glEnd();
   }
 
-  if(CTX.mesh.volumes_num) {
-    sprintf(Num, "%d", s->Num);
-    glRasterPos3d(Xc, Yc, Zc);
-    Draw_String(Num);
+  if(faces){
+    glColor4ubv((GLubyte *) & col);
+    if(CTX.mesh.light) glEnable(GL_LIGHTING);
+    if(CTX.mesh.surfaces_edges || edges) glEnable(GL_POLYGON_OFFSET_FILL);
+    if(!s->VSUP){
+      glBegin(GL_TRIANGLES);
+      _triFace(X[0], Y[0], Z[0], X[2], Y[2], Z[2], X[1], Y[1], Z[1]);
+      _triFace(X[0], Y[0], Z[0], X[1], Y[1], Z[1], X[3], Y[3], Z[3]);
+      _triFace(X[0], Y[0], Z[0], X[3], Y[3], Z[3], X[2], Y[2], Z[2]);
+      _triFace(X[3], Y[3], Z[3], X[1], Y[1], Z[1], X[2], Y[2], Z[2]);
+      glEnd();
+    }
+    else{
+      glBegin(GL_TRIANGLES);
+      _triFace2(X, Y, Z, X2, Y2, Z2, 0, 2, 1, 2, 1, 0);
+      _triFace2(X, Y, Z, X2, Y2, Z2, 0, 1, 3, 0, 5, 3);
+      _triFace2(X, Y, Z, X2, Y2, Z2, 0, 3, 2, 3, 4, 2);
+      _triFace2(X, Y, Z, X2, Y2, Z2, 3, 1, 2, 5, 1, 4);
+      glEnd();
+    }
+    glDisable(GL_POLYGON_OFFSET_FILL);
+    glDisable(GL_LIGHTING);
   }
 
   if(CTX.mesh.dual) {
@@ -877,38 +940,14 @@ void Draw_Mesh_Tetrahedron(void *a, void *b)
     gl2psDisable(GL2PS_LINE_STIPPLE);
   }
 
-  if(faces){
-    if(theColor.type)
-      glColor4ubv((GLubyte *) & theColor.mesh);
-    else if(CTX.mesh.color_carousel == 1)
-      ColorSwitch(s->iEnt);
-    else if(CTX.mesh.color_carousel == 2)
-      ColorSwitch(thePhysical);
-    else if(CTX.mesh.color_carousel == 3)
-      ColorSwitch(s->iPart);
+  if(CTX.mesh.volumes_num) {
+    if(CTX.mesh.surfaces_faces || faces)
+      glColor4ubv((GLubyte *) & CTX.color.mesh.line);
     else
-      glColor4ubv((GLubyte *) & CTX.color.mesh.tetrahedron);
-
-    if(CTX.mesh.light) glEnable(GL_LIGHTING);
-    if(CTX.mesh.surfaces_edges || edges) glEnable(GL_POLYGON_OFFSET_FILL);
-    if(!s->VSUP){
-      glBegin(GL_TRIANGLES);
-      _triFace(X[0], Y[0], Z[0], X[2], Y[2], Z[2], X[1], Y[1], Z[1]);
-      _triFace(X[0], Y[0], Z[0], X[1], Y[1], Z[1], X[3], Y[3], Z[3]);
-      _triFace(X[0], Y[0], Z[0], X[3], Y[3], Z[3], X[2], Y[2], Z[2]);
-      _triFace(X[3], Y[3], Z[3], X[1], Y[1], Z[1], X[2], Y[2], Z[2]);
-      glEnd();
-    }
-    else{
-      glBegin(GL_TRIANGLES);
-      _triFace2(X, Y, Z, X2, Y2, Z2, 0, 2, 1, 2, 1, 0);
-      _triFace2(X, Y, Z, X2, Y2, Z2, 0, 1, 3, 0, 5, 3);
-      _triFace2(X, Y, Z, X2, Y2, Z2, 0, 3, 2, 3, 4, 2);
-      _triFace2(X, Y, Z, X2, Y2, Z2, 3, 1, 2, 5, 1, 4);
-      glEnd();
-    }
-    glDisable(GL_POLYGON_OFFSET_FILL);
-    glDisable(GL_LIGHTING);
+      glColor4ubv((GLubyte *) & col);
+    sprintf(Num, "%d", s->Num);
+    glRasterPos3d(Xc, Yc, Zc);
+    Draw_String(Num);
   }
 }
 
@@ -944,6 +983,18 @@ void Draw_Mesh_Hexahedron(void *a, void *b)
   if(intersectCutPlane(8, h->V, &edges, &faces) < 0)
     return;
 
+  unsigned int col;
+  if(theColor.type)
+    col = theColor.mesh;
+  else if(CTX.mesh.color_carousel == 1)
+    col = CTX.color.mesh.carousel[abs(h->iEnt % 10)];
+  else if(CTX.mesh.color_carousel == 2)
+    col = CTX.color.mesh.carousel[abs(thePhysical % 10)];
+  else if(CTX.mesh.color_carousel == 3)
+    col = CTX.color.mesh.carousel[abs(h->iPart % 10)];
+  else
+    col = CTX.color.mesh.hexahedron;
+
   for(int i = 0; i < 8; i++) {
     Xc += h->V[i]->Pos.X;
     Yc += h->V[i]->Pos.Y;
@@ -953,22 +1004,6 @@ void Draw_Mesh_Hexahedron(void *a, void *b)
   Zc *= .125;
   Yc *= .125;
 
-  if(CTX.mesh.surfaces_faces || faces){
-    glColor4ubv((GLubyte *) & CTX.color.mesh.line);
-  }
-  else{
-    if(theColor.type)
-      glColor4ubv((GLubyte *) & theColor.mesh);
-    else if(CTX.mesh.color_carousel == 1)
-      ColorSwitch(h->iEnt);
-    else if(CTX.mesh.color_carousel == 2)
-      ColorSwitch(thePhysical);
-    else if(CTX.mesh.color_carousel == 3)
-      ColorSwitch(h->iPart);
-    else
-      glColor4ubv((GLubyte *) & CTX.color.mesh.hexahedron);
-  }
-
   for(int i = 0; i < 8; i++) {
     X[i] = Xc + CTX.mesh.explode * (h->V[i]->Pos.X - Xc);
     Y[i] = Yc + CTX.mesh.explode * (h->V[i]->Pos.Y - Yc);
@@ -983,6 +1018,10 @@ void Draw_Mesh_Hexahedron(void *a, void *b)
   }
 
   if(edges){
+    if(CTX.mesh.surfaces_faces || faces)
+      glColor4ubv((GLubyte *) & CTX.color.mesh.line);
+    else
+      glColor4ubv((GLubyte *) & col);
     glBegin(GL_LINES);
     for(int i = 0; i < 12; i++){
       int j = edges_hexa[i][0];
@@ -997,10 +1036,32 @@ void Draw_Mesh_Hexahedron(void *a, void *b)
     glEnd();
   }
 
-  if(CTX.mesh.volumes_num) {
-    sprintf(Num, "%d", h->Num);
-    glRasterPos3d(Xc, Yc, Zc);
-    Draw_String(Num);
+  if(faces){
+    glColor4ubv((GLubyte *) & col);
+    if(CTX.mesh.light) glEnable(GL_LIGHTING);
+    if(CTX.mesh.surfaces_edges || edges) glEnable(GL_POLYGON_OFFSET_FILL);
+    if(!h->VSUP){
+      glBegin(GL_QUADS);
+      _quadFace(X, Y, Z, 0, 3, 2, 1);
+      _quadFace(X, Y, Z, 4, 5, 6, 7);
+      _quadFace(X, Y, Z, 0, 1, 5, 4);
+      _quadFace(X, Y, Z, 1, 2, 6, 5);
+      _quadFace(X, Y, Z, 2, 3, 7, 6);
+      _quadFace(X, Y, Z, 0, 4, 7, 3);
+      glEnd();
+    }
+    else{
+      glBegin(GL_TRIANGLES);
+      _quadFace2(X, Y, Z, X2, Y2, Z2, 0, 3, 2, 1, 1, 5, 3, 0, 12);
+      _quadFace2(X, Y, Z, X2, Y2, Z2, 4, 5, 6, 7, 8, 10, 11, 9, 17);
+      _quadFace2(X, Y, Z, X2, Y2, Z2, 0, 1, 5, 4, 0, 4, 8, 2, 13);
+      _quadFace2(X, Y, Z, X2, Y2, Z2, 1, 2, 6, 5, 3, 6, 10, 4, 15);
+      _quadFace2(X, Y, Z, X2, Y2, Z2, 2, 3, 7, 6, 5, 7, 11, 6, 16);
+      _quadFace2(X, Y, Z, X2, Y2, Z2, 0, 4, 7, 3, 2, 9, 7, 1, 14);
+      glEnd();
+    }
+    glDisable(GL_POLYGON_OFFSET_FILL);
+    glDisable(GL_LIGHTING);
   }
 
   if(CTX.mesh.dual) {
@@ -1032,44 +1093,15 @@ void Draw_Mesh_Hexahedron(void *a, void *b)
     gl2psDisable(GL2PS_LINE_STIPPLE);
   }
 
-  if(faces){
-    if(theColor.type)
-      glColor4ubv((GLubyte *) & theColor.mesh);
-    else if(CTX.mesh.color_carousel == 1)
-      ColorSwitch(h->iEnt);
-    else if(CTX.mesh.color_carousel == 2)
-      ColorSwitch(thePhysical);
-    else if(CTX.mesh.color_carousel == 3)
-      ColorSwitch(h->iPart);
+  if(CTX.mesh.volumes_num) {
+    if(CTX.mesh.surfaces_faces || faces)
+      glColor4ubv((GLubyte *) & CTX.color.mesh.line);
     else
-      glColor4ubv((GLubyte *) & CTX.color.mesh.hexahedron);
-
-    if(CTX.mesh.light) glEnable(GL_LIGHTING);
-    if(CTX.mesh.surfaces_edges || edges) glEnable(GL_POLYGON_OFFSET_FILL);
-    if(!h->VSUP){
-      glBegin(GL_QUADS);
-      _quadFace(X, Y, Z, 0, 3, 2, 1);
-      _quadFace(X, Y, Z, 4, 5, 6, 7);
-      _quadFace(X, Y, Z, 0, 1, 5, 4);
-      _quadFace(X, Y, Z, 1, 2, 6, 5);
-      _quadFace(X, Y, Z, 2, 3, 7, 6);
-      _quadFace(X, Y, Z, 0, 4, 7, 3);
-      glEnd();
-    }
-    else{
-      glBegin(GL_TRIANGLES);
-      _quadFace2(X, Y, Z, X2, Y2, Z2, 0, 3, 2, 1, 1, 5, 3, 0, 12);
-      _quadFace2(X, Y, Z, X2, Y2, Z2, 4, 5, 6, 7, 8, 10, 11, 9, 17);
-      _quadFace2(X, Y, Z, X2, Y2, Z2, 0, 1, 5, 4, 0, 4, 8, 2, 13);
-      _quadFace2(X, Y, Z, X2, Y2, Z2, 1, 2, 6, 5, 3, 6, 10, 4, 15);
-      _quadFace2(X, Y, Z, X2, Y2, Z2, 2, 3, 7, 6, 5, 7, 11, 6, 16);
-      _quadFace2(X, Y, Z, X2, Y2, Z2, 0, 4, 7, 3, 2, 9, 7, 1, 14);
-      glEnd();
-    }
-    glDisable(GL_POLYGON_OFFSET_FILL);
-    glDisable(GL_LIGHTING);
+      glColor4ubv((GLubyte *) & col);
+    sprintf(Num, "%d", h->Num);
+    glRasterPos3d(Xc, Yc, Zc);
+    Draw_String(Num);
   }
-
 }
 
 void Draw_Mesh_Prism(void *a, void *b)
@@ -1104,6 +1136,18 @@ void Draw_Mesh_Prism(void *a, void *b)
   if(intersectCutPlane(6, p->V, &edges, &faces) < 0)
     return;
 
+  unsigned int col;
+  if(theColor.type)
+    col = theColor.mesh;
+  else if(CTX.mesh.color_carousel == 1)
+    col = CTX.color.mesh.carousel[abs(p->iEnt % 10)];
+  else if(CTX.mesh.color_carousel == 2)
+    col = CTX.color.mesh.carousel[abs(thePhysical % 10)];
+  else if(CTX.mesh.color_carousel == 3)
+    col = CTX.color.mesh.carousel[abs(p->iPart % 10)];
+  else
+    col = CTX.color.mesh.prism;
+
   for(int i = 0; i < 6; i++) {
     Xc += p->V[i]->Pos.X;
     Yc += p->V[i]->Pos.Y;
@@ -1113,22 +1157,6 @@ void Draw_Mesh_Prism(void *a, void *b)
   Zc /= 6.;
   Yc /= 6.;
 
-  if(CTX.mesh.surfaces_faces || faces){
-    glColor4ubv((GLubyte *) & CTX.color.mesh.line);
-  }
-  else{
-    if(theColor.type)
-      glColor4ubv((GLubyte *) & theColor.mesh);
-    else if(CTX.mesh.color_carousel == 1)
-      ColorSwitch(p->iEnt);
-    else if(CTX.mesh.color_carousel == 2)
-      ColorSwitch(thePhysical);
-    else if(CTX.mesh.color_carousel == 3)
-      ColorSwitch(p->iPart);
-    else
-      glColor4ubv((GLubyte *) & CTX.color.mesh.prism);
-  }
-
   for(int i = 0; i < 6; i++) {
     X[i] = Xc + CTX.mesh.explode * (p->V[i]->Pos.X - Xc);
     Y[i] = Yc + CTX.mesh.explode * (p->V[i]->Pos.Y - Yc);
@@ -1143,6 +1171,10 @@ void Draw_Mesh_Prism(void *a, void *b)
   }
 
   if(edges){
+    if(CTX.mesh.surfaces_faces || faces)
+      glColor4ubv((GLubyte *) & CTX.color.mesh.line);
+    else
+      glColor4ubv((GLubyte *) & col);
     glBegin(GL_LINES);
     for(int i = 0; i < 9; i++){
       int j = edges_prism[i][0];
@@ -1157,10 +1189,32 @@ void Draw_Mesh_Prism(void *a, void *b)
     glEnd();
   }
 
-  if(CTX.mesh.volumes_num) {
-    sprintf(Num, "%d", p->Num);
-    glRasterPos3d(Xc, Yc, Zc);
-    Draw_String(Num);
+  if(faces){
+    glColor4ubv((GLubyte *) & col);
+    if(CTX.mesh.light) glEnable(GL_LIGHTING);
+    if(CTX.mesh.surfaces_edges || edges) glEnable(GL_POLYGON_OFFSET_FILL);
+    if(!p->VSUP){
+      glBegin(GL_TRIANGLES);
+      _triFace(X[0], Y[0], Z[0], X[2], Y[2], Z[2], X[1], Y[1], Z[1]);
+      _triFace(X[3], Y[3], Z[3], X[4], Y[4], Z[4], X[5], Y[5], Z[5]);
+      glEnd();
+      glBegin(GL_QUADS);
+      _quadFace(X, Y, Z, 0, 1, 4, 3);
+      _quadFace(X, Y, Z, 1, 2, 5, 4);
+      _quadFace(X, Y, Z, 0, 3, 5, 2);
+      glEnd();
+    }
+    else{
+      glBegin(GL_TRIANGLES);
+      _triFace2(X, Y, Z, X2, Y2, Z2, 0, 2, 1, 1, 3, 0);
+      _triFace2(X, Y, Z, X2, Y2, Z2, 3, 4, 5, 6, 8, 7);
+      _quadFace2(X, Y, Z, X2, Y2, Z2, 0, 1, 4, 3, 0, 4, 6, 2, 9);
+      _quadFace2(X, Y, Z, X2, Y2, Z2, 1, 2, 5, 4, 3, 5, 8, 4, 11);
+      _quadFace2(X, Y, Z, X2, Y2, Z2, 0, 3, 5, 2, 2, 7, 5, 1, 10);
+      glEnd();
+    }
+    glDisable(GL_POLYGON_OFFSET_FILL);
+    glDisable(GL_LIGHTING);
   }
 
   if(CTX.mesh.dual) {
@@ -1189,42 +1243,14 @@ void Draw_Mesh_Prism(void *a, void *b)
     gl2psDisable(GL2PS_LINE_STIPPLE);
   }
 
-  if(faces){
-    if(theColor.type)
-      glColor4ubv((GLubyte *) & theColor.mesh);
-    else if(CTX.mesh.color_carousel == 1)
-      ColorSwitch(p->iEnt);
-    else if(CTX.mesh.color_carousel == 2)
-      ColorSwitch(thePhysical);
-    else if(CTX.mesh.color_carousel == 3)
-      ColorSwitch(p->iPart);
+  if(CTX.mesh.volumes_num) {
+    if(CTX.mesh.surfaces_faces || faces)
+      glColor4ubv((GLubyte *) & CTX.color.mesh.line);
     else
-      glColor4ubv((GLubyte *) & CTX.color.mesh.prism);
-
-    if(CTX.mesh.light) glEnable(GL_LIGHTING);
-    if(CTX.mesh.surfaces_edges || edges) glEnable(GL_POLYGON_OFFSET_FILL);
-    if(!p->VSUP){
-      glBegin(GL_TRIANGLES);
-      _triFace(X[0], Y[0], Z[0], X[2], Y[2], Z[2], X[1], Y[1], Z[1]);
-      _triFace(X[3], Y[3], Z[3], X[4], Y[4], Z[4], X[5], Y[5], Z[5]);
-      glEnd();
-      glBegin(GL_QUADS);
-      _quadFace(X, Y, Z, 0, 1, 4, 3);
-      _quadFace(X, Y, Z, 1, 2, 5, 4);
-      _quadFace(X, Y, Z, 0, 3, 5, 2);
-      glEnd();
-    }
-    else{
-      glBegin(GL_TRIANGLES);
-      _triFace2(X, Y, Z, X2, Y2, Z2, 0, 2, 1, 1, 3, 0);
-      _triFace2(X, Y, Z, X2, Y2, Z2, 3, 4, 5, 6, 8, 7);
-      _quadFace2(X, Y, Z, X2, Y2, Z2, 0, 1, 4, 3, 0, 4, 6, 2, 9);
-      _quadFace2(X, Y, Z, X2, Y2, Z2, 1, 2, 5, 4, 3, 5, 8, 4, 11);
-      _quadFace2(X, Y, Z, X2, Y2, Z2, 0, 3, 5, 2, 2, 7, 5, 1, 10);
-      glEnd();
-    }
-    glDisable(GL_POLYGON_OFFSET_FILL);
-    glDisable(GL_LIGHTING);
+      glColor4ubv((GLubyte *) & col);
+    sprintf(Num, "%d", p->Num);
+    glRasterPos3d(Xc, Yc, Zc);
+    Draw_String(Num);
   }
 }
 
@@ -1260,6 +1286,18 @@ void Draw_Mesh_Pyramid(void *a, void *b)
   if(intersectCutPlane(5, p->V, &edges, &faces) < 0)
     return;
 
+  unsigned int col;
+  if(theColor.type)
+    col = theColor.mesh;
+  else if(CTX.mesh.color_carousel == 1)
+    col = CTX.color.mesh.carousel[abs(p->iEnt % 10)];
+  else if(CTX.mesh.color_carousel == 2)
+    col = CTX.color.mesh.carousel[abs(thePhysical % 10)];
+  else if(CTX.mesh.color_carousel == 3)
+    col = CTX.color.mesh.carousel[abs(p->iPart % 10)];
+  else
+    col = CTX.color.mesh.pyramid;
+
   for(int i = 0; i < 5; i++) {
     Xc += p->V[i]->Pos.X;
     Yc += p->V[i]->Pos.Y;
@@ -1269,22 +1307,6 @@ void Draw_Mesh_Pyramid(void *a, void *b)
   Zc /= 5.;
   Yc /= 5.;
 
-  if(CTX.mesh.surfaces_faces || faces){
-    glColor4ubv((GLubyte *) & CTX.color.mesh.line);
-  }
-  else{
-    if(theColor.type)
-      glColor4ubv((GLubyte *) & theColor.mesh);
-    else if(CTX.mesh.color_carousel == 1)
-      ColorSwitch(p->iEnt);
-    else if(CTX.mesh.color_carousel == 2)
-      ColorSwitch(thePhysical);
-    else if(CTX.mesh.color_carousel == 3)
-      ColorSwitch(p->iPart);
-    else
-      glColor4ubv((GLubyte *) & CTX.color.mesh.pyramid);
-  }
-
   for(int i = 0; i < 5; i++) {
     X[i] = Xc + CTX.mesh.explode * (p->V[i]->Pos.X - Xc);
     Y[i] = Yc + CTX.mesh.explode * (p->V[i]->Pos.Y - Yc);
@@ -1299,6 +1321,10 @@ void Draw_Mesh_Pyramid(void *a, void *b)
   }
 
   if(edges){
+    if(CTX.mesh.surfaces_faces || faces)
+      glColor4ubv((GLubyte *) & CTX.color.mesh.line);
+    else
+      glColor4ubv((GLubyte *) & col);
     glBegin(GL_LINES);
     for(int i = 0; i < 8; i++){
       int j = edges_pyramid[i][0];
@@ -1313,24 +1339,8 @@ void Draw_Mesh_Pyramid(void *a, void *b)
     glEnd();
   }
 
-  if(CTX.mesh.volumes_num) {
-    sprintf(Num, "%d", p->Num);
-    glRasterPos3d(Xc, Yc, Zc);
-    Draw_String(Num);
-  }
-
   if(faces){
-    if(theColor.type)
-      glColor4ubv((GLubyte *) & theColor.mesh);
-    else if(CTX.mesh.color_carousel == 1)
-      ColorSwitch(p->iEnt);
-    else if(CTX.mesh.color_carousel == 2)
-      ColorSwitch(thePhysical);
-    else if(CTX.mesh.color_carousel == 3)
-      ColorSwitch(p->iPart);
-    else
-      glColor4ubv((GLubyte *) & CTX.color.mesh.pyramid);
-
+    glColor4ubv((GLubyte *) & col);
     if(CTX.mesh.light) glEnable(GL_LIGHTING);
     if(CTX.mesh.surfaces_edges || edges) glEnable(GL_POLYGON_OFFSET_FILL);
     if(!p->VSUP){
@@ -1357,4 +1367,13 @@ void Draw_Mesh_Pyramid(void *a, void *b)
     glDisable(GL_LIGHTING);
   }
 
+  if(CTX.mesh.volumes_num) {
+    if(CTX.mesh.surfaces_faces || faces)
+      glColor4ubv((GLubyte *) & CTX.color.mesh.line);
+    else
+      glColor4ubv((GLubyte *) & col);
+    sprintf(Num, "%d", p->Num);
+    glRasterPos3d(Xc, Yc, Zc);
+    Draw_String(Num);
+  }
 }
diff --git a/Mesh/Create.cpp b/Mesh/Create.cpp
index 9f02e1281ac6cb88f99ae7f72e7399762e11353c..07143044cf3d4a7683730f59845c6626449d5dde 100644
--- a/Mesh/Create.cpp
+++ b/Mesh/Create.cpp
@@ -1,4 +1,4 @@
-// $Id: Create.cpp,v 1.56 2004-05-25 23:16:26 geuzaine Exp $
+// $Id: Create.cpp,v 1.57 2004-05-28 19:22:13 geuzaine Exp $
 //
 // Copyright (C) 1997-2004 C. Geuzaine, J.-F. Remacle
 //
@@ -669,6 +669,7 @@ Surface *Create_Surface(int Num, int Typ)
   pS->Edges = NULL;
   pS->Extrude = NULL;
   pS->STL = NULL;
+  pS->vertexArray = NULL;
   return (pS);
 }
 
@@ -691,6 +692,8 @@ void Free_Surface(void *a, void *b)
       Tree_Action(pS->Edges, Free_Edge);
       Tree_Delete(pS->Edges);
     }
+    if(pS->vertexArray)
+      delete pS->vertexArray;
     Free(pS);
     pS = NULL;
   }
diff --git a/Mesh/Mesh.h b/Mesh/Mesh.h
index 56ca1379f9e62728baab9f6e291c2b0aadc48ab1..6b86c995915da6b40cf80011f804977bbb553585 100644
--- a/Mesh/Mesh.h
+++ b/Mesh/Mesh.h
@@ -223,6 +223,24 @@ class DrawingColor{
   unsigned int geom, mesh;
 };
 
+class triangleVertexArray{
+ public:
+  int num_triangles;
+  float *vertices, *normals;
+  unsigned char *colors;
+  triangleVertexArray(int nb){
+    num_triangles = 0;
+    vertices = new float[nb * 3 * 3];
+    normals = new float[nb * 3 * 3];
+    colors = new unsigned char[nb * 3 * 4];
+  }
+  ~triangleVertexArray(){
+    delete [] vertices;
+    delete [] normals;
+    delete [] colors;
+  }
+};
+
 struct _Surf{
   int Num;
   int Typ;
@@ -255,7 +273,7 @@ struct _Surf{
   POLY_rep *thePolyRep;
   int Dirty; // flag to prevent any meshing
   DrawingColor Color;
-  void * aSolidModelEntity; // pointer to a solid model entity
+  triangleVertexArray * vertexArray;
 };
 
 typedef struct _Surf Surface;