Salut,
Voila je suis en train de faire un petit programme qui genere une carte (un plan), genre vue de dessus, et je met les icones dans des pixmap sous la forme de fichiers .XPM. C'est de la programmation XLib bas niveau, en creant a la main les fenetres, lignes, rectangles...
Donc mon probleme se pose quand je veux utiliser la fonction XpmReadFileToPixmap(), qui vient de la librairie XPM (installee, et qui marche car j'ai deja reussi a compiler un programme avec et il marche).
L'erreur que j'ai :
/usr/libexec/ld.so: Undefined symbol "_XDefaultScreen" called from ship_radarusr/X11R6/lib/libXpm.so.4.11 at 0x400be138
Je vous met le code en entier :
Makefile
LIB = /usr/X11R6/lib/libX11.a -lXpm -lm
CCOPT = -c -O2
ship_radar: ship_radar.o radar_functions.o output.o drawing_functions.o
cc ship_radar.o radar_functions.o output.o drawing_functions.o -o ship_radar $(LIB)
ship_radar.o: ship_radar.c Makefile
cc $(CCOPT) ship_radar.c
radar_functions.o: radar_functions.c Makefile
cc $(CCOPT) radar_functions.c
output.o: output.c Makefile
cc $(CCOPT) output.c
drawing_functions.o: drawing_functions.c Makefile
cc $(CCOPT) drawing_functions.c -I/usr/X11R6/include/
clean:
rm -f *.o ship_radar
drawing_functions.c
#include <stdio.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/xpm.h> /* for Xpm functions */
#include <stdlib.h> /* for getenv() */
#include <unistd.h> /* for sleep() */
/*
* function: create_simple_window. Creates a window with a white background
* in the given size.
* input: display, size of the window (in pixels), and location of the window
* (in pixels).
* output: the window's ID.
* notes: window is created with a black border, 2 pixels wide.
* the window is automatically mapped after its creation.
*/
Display* display; /* pointer to X Display structure. */
Window win; /* pointer to the newly created window. */
GC gc; /* GC (graphics context) used for drawing */
/* in our window. */
void window_setup(unsigned int width, unsigned int height, char *title)
{
XTextProperty window_title_property;
int screen_num; /* number of screen to place the window on. */
char *display_name = getenv("DISPLAY" ); /* address of the X display. */
int i;
int win_border_width = 2;
int x = 0, y = 0;
unsigned long valuemask = 0; /* which values in 'values' to */
/* check when creating the GC. */
XGCValues values; /* initial values for the GC. */
unsigned int line_width = 1; /* line width for the GC. */
int line_style = LineSolid; /* style for lines drawing and */
int cap_style = CapButt; /* style of the line's edje and */
int join_style = JoinBevel; /* joined lines. */
XColor bg_colour, fg_colour;
Colormap screen_colormap; /* color map to use for allocating colors. */
/* create 2 pixmaps, one for the aircraft and one for the ship */
Pixmap aircraft;
Pixmap ship;
/* open connection with the X server. */
display = XOpenDisplay(display_name);
if (display == NULL)
{
fprintf(stderr, "Cannot connect to X server '%s'\n", display_name);
exit(1);
}
/* get the geometry of the default screen for our display. */
screen_num = DefaultScreen(display);
/* get access to the screen's color map. */
screen_colormap = DefaultColormap(display, screen_num);
/* allocate foreground and background colors for this GC. */
bg_colour.red = 200*256;
bg_colour.green = 200*256;
bg_colour.blue = 200*256;
XAllocColor(display, screen_colormap, &bg_colour);
fg_colour.red = 20*256;
fg_colour.green = 20*256;
fg_colour.blue = 20*256;
XAllocColor(display, screen_colormap, &fg_colour);
/* create a simple window, as a direct child of the screen's */
/* root window. Use the screen's black and white colors as */
/* the foreground and background colors of the window, */
/* respectively. Place the new window's top-left corner at */
/* the given 'x,y' coordinates. */
win = XCreateSimpleWindow(display, RootWindow(display, screen_num),
x, y, width, height, win_border_width,
fg_colour.pixel,
bg_colour.pixel);
/* make the window actually appear on the screen. */
XMapWindow(display, win);
/* flush all pending requests to the X server. */
XFlush(display);
/* allocate a new GC (graphics context) for drawing in the window. */
gc = XCreateGC(display, win, valuemask, &values);
/* define the style of lines that will be drawn using this GC. */
XSetLineAttributes(display, gc, line_width, line_style, cap_style, join_style);
/* define the fill style for the GC. to be 'solid filling'. */
XSetFillStyle(display, gc, FillSolid);
/* draw the large square composing the map, 400-pixel wide */
XDrawRectangle(display, win, gc, 100, 100, 400, 400);
/* draw the lines of the map, every 40 pixels, horizontally and vertically */
for (i=140; i<500; i += 40)
{
XDrawLine(display, win, gc, 100, i, 500, i);
XDrawLine(display, win, gc, i, 100, i, 500);
}
XpmReadFileToPixmap(display, win, "aircraft.xpm", &aircraft, NULL, NULL);
XFreePixmap(display, aircraft);
XSync(display, False);
/* set title of the window according to `title' */
XStringListToTextProperty(&title, 1, &window_title_property);
XSetWMName(display, win, &window_title_property);
}
void draw_aircraft(int x, int y)
{
XDrawRectangle(display, win, gc, x, y, 10, 10);
}
void window_close(void)
{
/* flush all pending requests to the X server. */
XFlush(display);
/* make a delay for a short period. */
sleep(4);
/* close the connection to the X server. */
XCloseDisplay(display);
}
En fait, je ne fais qu'executer la fonction window_setup() dans le fichier <output.c>, dont rien de bien complexe.
Donc si quelqu'un a une idee, ca m'arrangerait, je galere bien la. Sinon en utilisant les .XBM, des bitmap noir et blanc, ca marche impec, sauf que moi je veux des couleurs.
Pour info je compile sous OpenBSD 3.0 avec la librairie XPM 3.4k.
Merci, @+.
PS : le forum pour la couleur c'est pas ca, ou alors g pas tout compris.
[jfdsdjhfuetppo]--Message édité par snotling--[/jfdsdjhfuetppo]