> I was not aware of the possibility of using of-screen buffers in ftlk.
> How do you do it?

There were some bugs (now fixed AFAIK) in the OSX implementation
recently so I posted a worked example to use for testing, refer to the
following STR for details:

  http://www.fltk.org/str.php?L2257 

A simpler, more self-contained example is pasted below: Neither of these
examples use GL for the rendering, so not directly applicable to your
use-case, but hopefully they'll give you some ideas for things to try.

------------------------------------
// fltk-config --compile scope-view.cxx
#include <FL/Fl.H>
#include <FL/Fl_Double_Window.H>
#include <FL/Fl_Box.H>
#include <FL/fl_draw.H>
#include <FL/x.H>

#include <stdio.h>
#include <math.h>

const int trace_max = 1024;
const int view_width = 512;
const int view_height = 200;
static int trace_pos = 0;
static int view_pos = 0;
static int view_break = 0;
static float trace[trace_max];
static float view[view_width];

static Fl_Offscreen osc; // offscreen drawing buffer

class scope_view: public Fl_Box
{
        void draw();
public:
        scope_view(int x, int y,int w,int h, const char *l=0) : Fl_Box 
(x,y,w,h,l) {}
};

void scope_view::draw()
{
        int wd = w();
        int ht = h();
        int xo = x();
        int yo = y();

        fl_copy_offscreen(xo, yo, wd, ht, osc, 0, 0);
} /* end of draw() method */

static scope_view *scope = 0;


static void offscreen_draw()
{
        int wd = view_width;
        int ht = view_height;
        int xo = 0; //x();
        int yo = 0; //y();

        fl_begin_offscreen(osc);

        fl_color(FL_BLACK);
        fl_rectf(xo, yo, wd, ht);
        fl_color(FL_GREEN);

        fl_push_matrix();
        fl_translate(xo, (yo + (ht/2)));
        fl_scale(wd, ht/2);

        fl_begin_line();
        for (int i = 0; i < view_width; i++) {
                if(i == view_break) {
                        fl_end_line();
                        fl_begin_line();
                }
                fl_vertex(((float)i/(float)view_width), view[i]);
        }
        fl_end_line();

        fl_pop_matrix();

        fl_end_offscreen();
} /* end of offscreen draw function */

void update_offscreen(void *)
{
        if (!osc) {
                // now create the offscreen buffer - you can't do this
until
                // *after* the main_window is mapped...
                osc = fl_create_offscreen(view_width, view_height);
        }

        for (int i = 0; i < 7; i++) {
                view[view_pos] = trace[trace_pos];
                trace_pos++;
                if(trace_pos >= trace_max) trace_pos = 0;
                view_pos++;
                if(view_pos >= view_width) view_pos = 0;
        }
        view_break = view_pos;
        
        offscreen_draw();
        
        Fl::repeat_timeout(0.05, update_offscreen);
        scope->redraw();
}

int main(int argc, char **argv)
{
        Fl_Window *main_win = new Fl_Window(522, 210, "Scope Window");
        main_win->begin();
        scope = new scope_view(5, 5, view_width, view_height);
        main_win->end();
        
        // now create the trace - a sine wave
        for (int i = 0; i < trace_max; i++) {
                trace[i] = -sin((double)(i*5*2*M_PI/(double)trace_max));
        }
        for (int i = 0; i < view_width; i++) {
                view[i] = trace[i];
        }
        trace_pos = view_width;
        main_win->show(argc, argv);
        
        Fl::add_timeout(0.1, update_offscreen);
        
        return Fl::run();
}

/* end of file */
------------------------------------




SELEX Galileo Ltd
Registered Office: Sigma House, Christopher Martin Road, Basildon, Essex SS14 
3EL
A company registered in England & Wales.  Company no. 02426132
********************************************************************
This email and any attachments are confidential to the intended
recipient and may also be privileged. If you are not the intended
recipient please delete it from your system and notify the sender.
You should not copy it or use it for any purpose nor disclose or
distribute its contents to any other person.
********************************************************************

_______________________________________________
fltk mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk

Reply via email to