From f9039b2ae21988783feae9b362818e7923e82d14 Mon Sep 17 00:00:00 2001 From: Michael R Sweet Date: Tue, 6 Oct 1998 18:21:25 +0000 Subject: Initial revision git-svn-id: file:///fltk/svn/fltk/trunk@2 ea41ed52-d2ee-0310-a9c1-e6b18d33e121 --- test/doublebuffer.cxx | 99 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 99 insertions(+) create mode 100644 test/doublebuffer.cxx (limited to 'test/doublebuffer.cxx') diff --git a/test/doublebuffer.cxx b/test/doublebuffer.cxx new file mode 100644 index 000000000..b15bc02c3 --- /dev/null +++ b/test/doublebuffer.cxx @@ -0,0 +1,99 @@ +// Double-buffering test. + +// This demo shows how double buffering helps, by drawing the +// window in a particularily bad way. + +// The single-buffered window will blink as it updates. The +// double buffered one will not. It will take just as long +// (or longer) to update, but often it will appear to be faster. + +// This demo should work for both the GL and X versions of Fl, +// even though the double buffering mechanism is totally different. + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +// this purposely draws each line 10 times to be slow: +void star(int w, int h, int n) { + fl_push_matrix(); + fl_translate(w/2, h/2); + fl_scale(w/2, h/2); + for (int i = 0; i < n; i++) { + for (int j = i+1; j < n; j++)/* for (int k=0; k<10; k++)*/ { + fl_begin_line(); + fl_vertex(cos(2*M_PI*i/n+.1), sin(2*M_PI*i/n+.1)); + fl_vertex(cos(2*M_PI*j/n+.1), sin(2*M_PI*j/n+.1)); + fl_end_line(); + } + } + fl_pop_matrix(); +} + +int sides[2] = {20,20}; + +void slider_cb(Fl_Widget* o, long v) { + sides[v] = int(((Fl_Slider*)o)->value()); + o->parent()->redraw(); +} + +void bad_draw(int w,int h,int which) { +// for (int i=0; i<10; i++) { +// fl_color(7); fl_rectf(0,0,w,h); fl_color(0); star(w,h); +// fl_color(0); fl_rectf(0,0,w,h); fl_color(7); star(w,h); +// } + fl_color(FL_BLACK); fl_rectf(0,0,w,h); + fl_color(FL_WHITE); star(w,h,sides[which]); + // for (int x=0; x