Reputation: 1553
I'm trying to draw a xpm file in a C++ program with FLTK.
Here's the code
#include <FL/Fl.H>
#include <FL/Fl_Window.H>
#include "image.xpm"
#include <FL/Fl_Pixmap.H>
#include <FL/fl_draw.H>
#include <FL/Fl_Image.H>
int main(int argc, char ** argv)
{
Fl_Window *window = new Fl_Window(800,650);
Fl_Pixmap pix(XFACE);
pix.draw(200,200);
window->end();
window->show(argc,argv);
return Fl::run();
}
XFACE is a valid xpm object inside "image.xpm"
But I'm getting a segmentation fault at the pix.draw() line.
What causes this?
Upvotes: 0
Views: 715
Reputation: 46
/* Try this - this works for me, and I guess is what you meant! */
#include <FL/Fl.H>
#include <FL/Fl_Window.H>
#include <FL/Fl_Box.H>
#include <FL/Fl_Pixmap.H>
#include "image.xpm"
int main(int argc, char ** argv)
{
Fl_Window *window = new Fl_Window(800,650);
Fl_Box *image_box = new Fl_Box(5, 5, 790, 640);
Fl_Pixmap pix(XFACE);
window->end();
image_box->image(pix);
window->show(argc,argv);
return Fl::run();
}
/* end of file */
Upvotes: 3
Reputation: 46
To be honest, that doesn't even look like valid fltk code; you are calling the draw() method directly, and AFAIK that is seldom valid in fltk.
You probably want to ask over on their mailing list - they are pretty responsive.
Also, did you look at the pixmap demo in the "test" folder of the tarball - see what it does, then copy it!
Upvotes: 0