Next: MakeMakefile og Up: Grafik Previous: Starbase eksempel

Starbase-on-X11 eksempel

Starbase programmer kan også oversættes til at køre i X11 omgivelser. Det betyder at man kan få output display'et på en anden maskine. Dog er programmet mere omfattende, idet det selv skal åbne et vindue under X11 før man kan bruge starbase-kommandoer.

Eksemplet ovenfor vil komme til at se således ud:


#include <starbase.c.h>
#include <X11/Xlib.h>
#include <stdio.h>
   main()
   {
    Display     *Xdisplay;
    Window      window;
    XEvent      event;
    extern char *make_X11_gopen_string();
    int         display_des;
   
                                       /* open the display */
    if ((Xdisplay = XOpenDisplay(NULL)) == NULL){
        fprintf(stderr,"Can't open %s\n",XDisplayName(NULL));
        exit(1);
    }

                                        /* create a window */
    if ((window = XCreateSimpleWindow(Xdisplay,
               DefaultRootWindow(Xdisplay),
               5, 5, 200, 200, 2,
               WhitePixel(Xdisplay, DefaultScreen(Xdisplay)), 
               BlackPixel(Xdisplay, DefaultScreen(Xdisplay))
               )) == 0 ){
         fprintf(stderr,"Window create failed\n");
         exit(1);
    }
                                  /* select types of input */
    XSelectInput(Xdisplay, window, StructureNotifyMask);

       /* Map the window and make it appear on the display */
    XMapWindow(Xdisplay, window);

                 /* wait until sure that window is visible */
    do {
            XNextEvent(Xdisplay, &event);
    }
    while (event.type != MapNotify ||
           event.xmap.window != window);

         /* the next part is almost in clean starbase code */
    display_des = gopen(make_X11_gopen_string(Xdisplay, 
                        window), OUTDEV, "sox11", INIT);
    move2d(display_des, 0.3, 0.3);    /* draw something !! */
    draw2d(display_des, 0.6, 0.3);
    draw2d(display_des, 0.3, 0.6);
    draw2d(display_des, 0.3, 0.3);
    make_picture_current(display_des);
    sleep(10);                             /* wait 10 sec. */
    gclose(display_des)
                                      /* close the Xwindow */
    XCloseDisplay(Xdisplay);
   }

Programmet oversættes ved at skrive


snake1:/usv2/nn $ cc sox.c -lddsox11 -lsb1 -lsb2 -lXhp11 -lX11


mr@imm.dtu.dk