comparison src/gl-render.cc @ 9798:2d6a5af744b6

printing for fltk backend using gl2ps
author Shai Ayal <shaiay@users.sourceforge.net>
date Tue, 10 Nov 2009 19:48:02 -0500
parents 86aa08bbc887
children 92d8f35ff217
comparison
equal deleted inserted replaced
9797:f569f46a1c34 9798:2d6a5af744b6
533 void 533 void
534 opengl_renderer::draw (const graphics_object& go) 534 opengl_renderer::draw (const graphics_object& go)
535 { 535 {
536 if (! go.valid_object ()) 536 if (! go.valid_object ())
537 return; 537 return;
538 538
539 const base_properties& props = go.get_properties (); 539 const base_properties& props = go.get_properties ();
540 540
541 if (go.isa ("figure")) 541 if (go.isa ("figure"))
542 draw (dynamic_cast<const figure::properties&> (props)); 542 draw_figure (dynamic_cast<const figure::properties&> (props));
543 else if (go.isa ("axes")) 543 else if (go.isa ("axes"))
544 draw (dynamic_cast<const axes::properties&> (props)); 544 draw_axes (dynamic_cast<const axes::properties&> (props));
545 else if (go.isa ("line")) 545 else if (go.isa ("line"))
546 draw (dynamic_cast<const line::properties&> (props)); 546 draw_line (dynamic_cast<const line::properties&> (props));
547 else if (go.isa ("surface")) 547 else if (go.isa ("surface"))
548 draw (dynamic_cast<const surface::properties&> (props)); 548 draw_surface (dynamic_cast<const surface::properties&> (props));
549 else if (go.isa ("patch")) 549 else if (go.isa ("patch"))
550 draw (dynamic_cast<const patch::properties&> (props)); 550 draw_patch (dynamic_cast<const patch::properties&> (props));
551 else if (go.isa ("hggroup")) 551 else if (go.isa ("hggroup"))
552 draw (dynamic_cast<const hggroup::properties&> (props)); 552 draw_hggroup (dynamic_cast<const hggroup::properties&> (props));
553 else if (go.isa ("text")) 553 else if (go.isa ("text"))
554 draw (dynamic_cast<const text::properties&> (props)); 554 draw_text (dynamic_cast<const text::properties&> (props));
555 else if (go.isa ("image")) 555 else if (go.isa ("image"))
556 draw (dynamic_cast<const image::properties&> (props)); 556 draw_image (dynamic_cast<const image::properties&> (props));
557 else 557 else
558 warning ("opengl_renderer: cannot render object of type `%s'", 558 warning ("opengl_renderer: cannot render object of type `%s'",
559 props.graphics_object_name ().c_str ()); 559 props.graphics_object_name ().c_str ());
560 } 560 }
561 561
562 void 562 void
563 opengl_renderer::draw (const figure::properties& props) 563 opengl_renderer::draw_figure (const figure::properties& props)
564 { 564 {
565 backend = props.get_backend (); 565 backend = props.get_backend ();
566 566
567 // Initialize OpenGL context 567 // Initialize OpenGL context
568 568
597 597
598 draw (props.get_all_children ()); 598 draw (props.get_all_children ());
599 } 599 }
600 600
601 void 601 void
602 opengl_renderer::draw (const axes::properties& props) 602 opengl_renderer::draw_axes (const axes::properties& props)
603 { 603 {
604 // setup OpenGL transformation 604 // setup OpenGL transformation
605 605
606 Matrix x_zlim = props.get_transform_zlim (); 606 Matrix x_zlim = props.get_transform_zlim ();
607 Matrix x_mat1 = props.get_opengl_matrix_1 (); 607 Matrix x_mat1 = props.get_opengl_matrix_1 ();
984 984
985 for (int i = 0; i < n; i++) 985 for (int i = 0; i < n; i++)
986 { 986 {
987 // FIXME: as tick text is transparent, shouldn't be 987 // FIXME: as tick text is transparent, shouldn't be
988 // drawn after axes object, for correct rendering? 988 // drawn after axes object, for correct rendering?
989 Matrix b = draw_text (xticklabels(i), 989 Matrix b = render_text (xticklabels(i),
990 tickpos(i,0), tickpos(i,1), tickpos(i,2), 990 tickpos(i,0), tickpos(i,1), tickpos(i,2),
991 halign, valign); 991 halign, valign);
992 992
993 wmax = std::max (wmax, static_cast<int> (b(2))); 993 wmax = std::max (wmax, static_cast<int> (b(2)));
994 hmax = std::max (hmax, static_cast<int> (b(3))); 994 hmax = std::max (hmax, static_cast<int> (b(3)));
1194 1194
1195 for (int i = 0; i < n; i++) 1195 for (int i = 0; i < n; i++)
1196 { 1196 {
1197 // FIXME: as tick text is transparent, shouldn't be 1197 // FIXME: as tick text is transparent, shouldn't be
1198 // drawn after axes object, for correct rendering? 1198 // drawn after axes object, for correct rendering?
1199 Matrix b = draw_text (yticklabels(i), 1199 Matrix b = render_text (yticklabels(i),
1200 tickpos(i,0), tickpos(i,1), tickpos(i,2), 1200 tickpos(i,0), tickpos(i,1), tickpos(i,2),
1201 halign, valign); 1201 halign, valign);
1202 1202
1203 wmax = std::max (wmax, static_cast<int> (b(2))); 1203 wmax = std::max (wmax, static_cast<int> (b(2)));
1204 hmax = std::max (hmax, static_cast<int> (b(3))); 1204 hmax = std::max (hmax, static_cast<int> (b(3)));
1436 1436
1437 for (int i = 0; i < n; i++) 1437 for (int i = 0; i < n; i++)
1438 { 1438 {
1439 // FIXME: as tick text is transparent, shouldn't be 1439 // FIXME: as tick text is transparent, shouldn't be
1440 // drawn after axes object, for correct rendering? 1440 // drawn after axes object, for correct rendering?
1441 Matrix b = draw_text (zticklabels(i), 1441 Matrix b = render_text (zticklabels(i),
1442 tickpos(i,0), tickpos(i,1), tickpos(i,2), 1442 tickpos(i,0), tickpos(i,1), tickpos(i,2),
1443 halign, valign); 1443 halign, valign);
1444 1444
1445 wmax = std::max (wmax, static_cast<int> (b(2))); 1445 wmax = std::max (wmax, static_cast<int> (b(2)));
1446 hmax = std::max (hmax, static_cast<int> (b(3))); 1446 hmax = std::max (hmax, static_cast<int> (b(3)));
1677 // FIXME: finalize rendering (transparency processing) 1677 // FIXME: finalize rendering (transparency processing)
1678 // FIXME: draw zoom box, if needed 1678 // FIXME: draw zoom box, if needed
1679 } 1679 }
1680 1680
1681 void 1681 void
1682 opengl_renderer::draw (const line::properties& props) 1682 opengl_renderer::draw_line (const line::properties& props)
1683 { 1683 {
1684 Matrix x = xform.xscale (props.get_xdata ().matrix_value ()); 1684 Matrix x = xform.xscale (props.get_xdata ().matrix_value ());
1685 Matrix y = xform.yscale (props.get_ydata ().matrix_value ()); 1685 Matrix y = xform.yscale (props.get_ydata ().matrix_value ());
1686 Matrix z = xform.zscale (props.get_zdata ().matrix_value ()); 1686 Matrix z = xform.zscale (props.get_zdata ().matrix_value ());
1687 1687
1797 1797
1798 set_clipping (props.is_clipping ()); 1798 set_clipping (props.is_clipping ());
1799 } 1799 }
1800 1800
1801 void 1801 void
1802 opengl_renderer::draw (const surface::properties& props) 1802 opengl_renderer::draw_surface (const surface::properties& props)
1803 { 1803 {
1804 const Matrix x = xform.xscale (props.get_xdata ().matrix_value ()); 1804 const Matrix x = xform.xscale (props.get_xdata ().matrix_value ());
1805 const Matrix y = xform.yscale (props.get_ydata ().matrix_value ()); 1805 const Matrix y = xform.yscale (props.get_ydata ().matrix_value ());
1806 const Matrix z = xform.zscale (props.get_zdata ().matrix_value ()); 1806 const Matrix z = xform.zscale (props.get_zdata ().matrix_value ());
1807 1807
2344 } 2344 }
2345 2345
2346 // FIXME: global optimization (rendering, data structures...), there 2346 // FIXME: global optimization (rendering, data structures...), there
2347 // is probably a smarter/faster/less-memory-consuming way to do this. 2347 // is probably a smarter/faster/less-memory-consuming way to do this.
2348 void 2348 void
2349 opengl_renderer::draw (const patch::properties &props) 2349 opengl_renderer::draw_patch (const patch::properties &props)
2350 { 2350 {
2351 const Matrix f = props.get_faces ().matrix_value (); 2351 const Matrix f = props.get_faces ().matrix_value ();
2352 const Matrix v = xform.scale (props.get_vertices ().matrix_value ()); 2352 const Matrix v = xform.scale (props.get_vertices ().matrix_value ());
2353 Matrix c; 2353 Matrix c;
2354 const Matrix n = props.get_vertexnormals ().matrix_value (); 2354 const Matrix n = props.get_vertexnormals ().matrix_value ();
2652 end_marker (); 2652 end_marker ();
2653 } 2653 }
2654 } 2654 }
2655 2655
2656 void 2656 void
2657 opengl_renderer::draw (const hggroup::properties &props) 2657 opengl_renderer::draw_hggroup (const hggroup::properties &props)
2658 { 2658 {
2659 draw (props.get_children ()); 2659 draw (props.get_children ());
2660 } 2660 }
2661 2661
2662 void 2662 void
2663 opengl_renderer::draw (const text::properties& props) 2663 opengl_renderer::draw_text (const text::properties& props)
2664 { 2664 {
2665 if (props.get_string ().empty ()) 2665 if (props.get_string ().empty ())
2666 return; 2666 return;
2667 2667
2668 set_font (props); 2668 set_font (props);
2684 else if (props.verticalalignment_is ("middle")) 2684 else if (props.verticalalignment_is ("middle"))
2685 valign = 1; 2685 valign = 1;
2686 2686
2687 // FIXME: handle margin and surrounding box 2687 // FIXME: handle margin and surrounding box
2688 2688
2689 draw_text (props.get_string (), 2689 render_text (props.get_string (),
2690 pos(0), pos(1), pos(2), 2690 pos(0), pos(1), pos(2),
2691 halign, valign, props.get_rotation ()); 2691 halign, valign, props.get_rotation ());
2692 } 2692 }
2693 2693
2694 void 2694 void
2695 opengl_renderer::draw (const image::properties& props) 2695 opengl_renderer::draw_image (const image::properties& props)
2696 { 2696 {
2697 octave_value cdata = props.get_cdata (); 2697 octave_value cdata = props.get_cdata ();
2698 dim_vector dv (cdata.dims ()); 2698 dim_vector dv (cdata.dims ());
2699 int h = dv(0), w = dv(1); 2699 int h = dv(0), w = dv(1);
2700 bool ok = true; 2700 bool ok = true;
3139 3139
3140 return ID; 3140 return ID;
3141 } 3141 }
3142 3142
3143 Matrix 3143 Matrix
3144 opengl_renderer::draw_text (const std::string& txt, 3144 opengl_renderer::render_text (const std::string& txt,
3145 double x, double y, double z, 3145 double x, double y, double z,
3146 int halign, int valign, double rotation) 3146 int halign, int valign, double rotation)
3147 { 3147 {
3148 #if HAVE_FREETYPE 3148 #if HAVE_FREETYPE
3149 if (txt.empty ()) 3149 if (txt.empty ())
3218 3218
3219 delete elt; 3219 delete elt;
3220 3220
3221 return bbox; 3221 return bbox;
3222 #else 3222 #else
3223 ::warning ("draw_text: cannot render text, Freetype library not available"); 3223 ::warning ("render_text: cannot render text, Freetype library not available");
3224 return Matrix (1, 4, 0.0); 3224 return Matrix (1, 4, 0.0);
3225 #endif 3225 #endif
3226 } 3226 }
3227 3227
3228 #endif 3228 #endif