# To subscribers of the xforms list from Steve Lamont <spl@ncmir.ucsd.edu> :
> I'm using xforms 0.89 and its facilities for image creation.
> I have the following problem: when I draw an image and display it
> several times, it works only the first time.
> I know that I must do a img->modified = 1 to invalidate the buffer
> image. But it doesn't work....
Hm. Works for me. I did have to change the image type from
FL_IMAGE_PACKED to FL_IMAGE_CI due to the limited color capabilities
of my home box (a somewhat ancient SPARC 5) but it worked after that.
If anything, given the code you supplied, I'd expect you to only see
the blue image, since you display the red image and then immediately
replace it with the blue one. I modified the code, as appended, to
switch between the two colors at one second intervals.
I'll try the original packed version when I get into the lab on Monday
if you're still having problems.
spl
- - -
#include <forms.h>
typedef unsigned char uchar;
#define APPNAME "myapp"
#define WIDTH 256
#define HEIGHT 256
void draw_image(FL_IMAGE *img, uchar r, uchar g, uchar b)
{
int i, j;
img->red_lut[0] = r;
img->green_lut[0] = g;
img->blue_lut[0] = b;
for (j = 0; j < img->h; j++) {
for (i = 0; i < img->w; i++) {
img->ci[j][i] = 0;
/* img->packed[j][i] = FL_PACK(r,g,b); */
}
}
img->modified = 1;
}
int main(int argc, char **argv)
{
FL_FORM *form;
FL_IMAGE *img;
FL_OBJECT *canvas;
fl_initialize(&argc, argv, APPNAME, 0, 0);
form = fl_bgn_form(FL_FLAT_BOX, WIDTH, HEIGHT);
canvas = fl_add_canvas(FL_NORMAL_CANVAS, 0, 0, WIDTH, HEIGHT,
"mycanvas");
fl_set_object_boxtype(canvas, FL_FLAT_BOX);
fl_end_form();
fl_show_form(form, FL_PLACE_MOUSE, FL_FULLBORDER, APPNAME);
// create and alloc memory for the image
img = flimage_alloc();
/* img->type = FL_IMAGE_PACKED; */
img->type = FL_IMAGE_CI;
img->w = WIDTH;
img->h = HEIGHT;
img->map_len = 1;
flimage_getmem(img);
while ( 1 ) {
// draw & display the image (red)
draw_image(img, 255,0,0);
flimage_display(img, FL_ObjWin(canvas));
sleep( 1 );
// redraw & redisplay the image (blue)
draw_image(img, 0,0,255);
flimage_display(img, FL_ObjWin(canvas));
sleep( 1 );
}
}
_________________________________________________
To unsubscribe, send the message "unsubscribe" to
xforms-request@bob.usuhs.mil or see
http://bob.usuhs.mil/mailserv/xforms.html
XForms Home Page: http://world.std.com/~xforms
List Archive: http://bob.usuhs.mil/mailserv/list-archives/
This archive was generated by hypermail 2b29 : Sat Aug 19 2000 - 10:29:20 EDT