comparison libinterp/corefcn/gl-render.cc @ 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 6a71e5030df5
children 2ed9498e4a74
comparison
equal deleted inserted replaced
18132:8ca7b1906a41 18133:647d806868ee
440 // FIXME: why did I need to keep the first vertex of the face 440 // FIXME: why did I need to keep the first vertex of the face
441 // in JHandles? I think it's related to the fact that the 441 // in JHandles? I think it's related to the fact that the
442 // tessellation process might re-order the vertices, such that 442 // tessellation process might re-order the vertices, such that
443 // the first one you get here might not be the first one of the face; 443 // the first one you get here might not be the first one of the face;
444 // but I can't figure out the actual reason. 444 // but I can't figure out the actual reason.
445 if (color_mode > 0 && (first || color_mode == 2)) 445 if (color_mode == 2)
446 { 446 {
447 Matrix col = v->color; 447 Matrix col = v->color;
448 448
449 if (col.numel () == 3) 449 if (col.numel () == 3)
450 { 450 {
457 buf[k] = (v->ambient * col(k)); 457 buf[k] = (v->ambient * col(k));
458 glMaterialfv (LIGHT_MODE, GL_AMBIENT, buf); 458 glMaterialfv (LIGHT_MODE, GL_AMBIENT, buf);
459 459
460 for (int k = 0; k < 3; k++) 460 for (int k = 0; k < 3; k++)
461 buf[k] = (v->diffuse * col(k)); 461 buf[k] = (v->diffuse * col(k));
462 glMaterialfv (LIGHT_MODE, GL_AMBIENT, buf); 462 glMaterialfv (LIGHT_MODE, GL_DIFFUSE, buf);
463 } 463 }
464 } 464 }
465 } 465 }
466 466
467 if (light_mode > 0 && (first || light_mode == 2)) 467 if (light_mode > 0 && (first || light_mode == 2))
2335 continue; 2335 continue;
2336 2336
2337 tess.begin_polygon (true); 2337 tess.begin_polygon (true);
2338 tess.begin_contour (); 2338 tess.begin_contour ();
2339 2339
2340 for (int j = 0; j < count_f(i); j++) 2340 if (count_f(i) > 0)
2341 {
2342 vertex_data::vertex_data_rep *vv = vdata[i].get_rep ();
2343
2344 if (fc_mode == 1)
2345 {
2346 // For "flat" shading, use color of 1st vertex.
2347 Matrix col = vv->color;
2348
2349 if (col.numel () == 3)
2350 {
2351 glColor3dv (col.data ());
2352 if (fl_mode > 0)
2353 {
2354 float cb[4] = { 0, 0, 0, 1 };
2355
2356 for (int k = 0; k < 3; k++)
2357 cb[k] = (vv->ambient * col(k));
2358 glMaterialfv (LIGHT_MODE, GL_AMBIENT, cb);
2359
2360 for (int k = 0; k < 3; k++)
2361 cb[k] = (vv->diffuse * col(k));
2362 glMaterialfv (LIGHT_MODE, GL_DIFFUSE, cb);
2363 }
2364 }
2365 }
2366
2367 tess.add_vertex (vv->coords.fortran_vec (), vv);
2368 }
2369
2370 // Add remaining vertices.
2371 for (int j = 1; j < count_f(i); j++)
2341 { 2372 {
2342 vertex_data::vertex_data_rep *vv = vdata[i+j*fr].get_rep (); 2373 vertex_data::vertex_data_rep *vv = vdata[i+j*fr].get_rep ();
2343 2374
2344 tess.add_vertex (vv->coords.fortran_vec (), vv); 2375 tess.add_vertex (vv->coords.fortran_vec (), vv);
2345 } 2376 }