> Fabio Bracci wrote: > > > The problem is that this is the only working sequence: > > performing a fl_read_image *after* fl_end_offscreen() simply causes an > > ugly segmentation fault. > > This is because fl_read_image() does not have any argument to specify > from WHICH drawable the image pixels should be read, so it always reads > from CURRENT drawable. Normally during Fl::flush() the drawable is a > screen window. But outside this, there is no current drawable set so > fl_read_image() does not know from where to read the pixels an it is > probably accessing a NULL pointer. To read the pixels from your your > offscreen, this offscreen needs to be current and you can set this as > current by fl_begin_offscreen(my_ofscreen). The function > fl_end_offscreen() sets back the previous active drawable as current, > and if it happens to be 0, then fl_read_image() crashes. > > Your offscreen remains persistent until you call > fl_delete_offscreen(my_offscreen), but to access it, you have to make it > current again by encapsulating it within > fl_begin_offscreen()/fl_end_offscreen() brackets like > > fl_begin_ofscreen(my_offscreen); // makes my_offscreen current > fl_read_image(...); // reads from current drawable > fl_end_offscreen(); //sets back previous drawable as current > > > Roman
Very clear, I was getting some intuition about this mechanism, wouldn't it be better to document this? all the fltk functions related to the offscreen are rather minimalistically documented and their relationship is rather hidden ... >From the point of view of usability, the behaviour isn't very intuitive ... >wouldn't be an idea to add a couple of functions with some offscreen as an >explicit parameter? maybe even better would be to promote the Fl_Offscreen to a first class object, right now most of offscreen related functions are just #defines relying on (hidden) state variables of fltk. This makes it difficult to learn, use and it leads to error prone programming, isn't it? Fabio _______________________________________________ fltk mailing list [email protected] http://lists.easysw.com/mailman/listinfo/fltk

