Mercurial > hg > octave-nkf
changeset 18133:647d806868ee
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.
author | Rik <rik@octave.org> |
---|---|
date | Fri, 13 Dec 2013 22:35:31 -0800 |
parents | 8ca7b1906a41 |
children | 181bbce78595 |
files | libinterp/corefcn/gl-render.cc |
diffstat | 1 files changed, 34 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/libinterp/corefcn/gl-render.cc +++ b/libinterp/corefcn/gl-render.cc @@ -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 ();