# HG changeset patch # User Rik # Date 1387002931 28800 # Node ID 647d806868ee1973fea56ae15be7bdcc7e57975a # Parent 8ca7b1906a41506cfc1b1cc95fe595aa79549606 Color patch face based upon first vertex (bug #40247). * gl-render.cc (opengl_renderer::patch_tesselator::vertex): Only set per-vertex color if "interp" is set. Use GL_DIFFUSE when setting diffuse lighting (was inccorrectly GL_AMBIENT). * gl-render.cc (draw_patch): If using "flat" shading and no "facecolor" specified then choose the color from the first vertex. diff -r 8ca7b1906a41 -r 647d806868ee libinterp/corefcn/gl-render.cc --- a/libinterp/corefcn/gl-render.cc Fri Dec 13 20:25:48 2013 -0800 +++ b/libinterp/corefcn/gl-render.cc Fri Dec 13 22:35:31 2013 -0800 @@ -442,7 +442,7 @@ // tessellation process might re-order the vertices, such that // the first one you get here might not be the first one of the face; // but I can't figure out the actual reason. - if (color_mode > 0 && (first || color_mode == 2)) + if (color_mode == 2) { Matrix col = v->color; @@ -459,7 +459,7 @@ for (int k = 0; k < 3; k++) buf[k] = (v->diffuse * col(k)); - glMaterialfv (LIGHT_MODE, GL_AMBIENT, buf); + glMaterialfv (LIGHT_MODE, GL_DIFFUSE, buf); } } } @@ -2337,7 +2337,38 @@ tess.begin_polygon (true); tess.begin_contour (); - for (int j = 0; j < count_f(i); j++) + if (count_f(i) > 0) + { + vertex_data::vertex_data_rep *vv = vdata[i].get_rep (); + + if (fc_mode == 1) + { + // For "flat" shading, use color of 1st vertex. + Matrix col = vv->color; + + if (col.numel () == 3) + { + glColor3dv (col.data ()); + if (fl_mode > 0) + { + float cb[4] = { 0, 0, 0, 1 }; + + for (int k = 0; k < 3; k++) + cb[k] = (vv->ambient * col(k)); + glMaterialfv (LIGHT_MODE, GL_AMBIENT, cb); + + for (int k = 0; k < 3; k++) + cb[k] = (vv->diffuse * col(k)); + glMaterialfv (LIGHT_MODE, GL_DIFFUSE, cb); + } + } + } + + tess.add_vertex (vv->coords.fortran_vec (), vv); + } + + // Add remaining vertices. + for (int j = 1; j < count_f(i); j++) { vertex_data::vertex_data_rep *vv = vdata[i+j*fr].get_rep ();