chiark / gitweb /
Compiles with libc6.
[moebius.git] / dualx11.cc
1 /*
2  * X11 functions
3  */
4
5 #include "dualx11.hh"
6 #include "parameter.hh"
7
8 DualX11Output::DualX11Output() {
9   display= XOpenDisplay(0);
10   Colormap cmap= DefaultColormap(display,DefaultScreen(display));
11
12   XAllocColorCells(display,cmap,
13                    False, // contig
14                    planemasks,
15                    2, // nplanes
16                    &pixelbase,
17                    1); // ncolors
18   XColor colours[4], *cp= colours;
19   for (int i=0; i<2; i++)
20     for (int j=0; j<2; j++, cp++) {
21       cp->pixel= pixelbase + (i? planemasks[0] :0) + (j? planemasks[1] :0);
22       cp->red= i?65535:0;  cp->green= j?/*65535*/32000:0;  cp->blue= 0;
23       cp->flags= DoRed|DoGreen|DoBlue;
24     }
25   XStoreColors(display,cmap,colours,4);
26   
27   window= XCreateSimpleWindow(display,
28                               DefaultRootWindow(display),
29                               0,0, 500,500, 0,0, pixelbase);
30
31   XGCValues gcvalues;
32   int i;
33   for (i=0; i<2; i++) {
34     gcvalues.plane_mask= planemasks[i];
35     // First, the fabric
36     gcvalues.function= GXclear;
37     fabric[i]= XCreateGC(display,window,
38                          GCFunction|GCPlaneMask,
39                          &gcvalues);
40     // Then, the mesh
41     gcvalues.function= GXset;
42     mesh[i]= XCreateGC(display,window,
43                        GCFunction|GCPlaneMask,
44                        &gcvalues);
45   }
46   XSelectInput(display,window,0);
47   XMapWindow(display,window);
48   XFlush(display);
49 }
50
51 void DualX11Output::startimage() {
52   XClearWindow(display,window);
53 }
54
55 void DualX11Output::endimage() {
56   XFlush(display);
57 }
58
59 DualX11Output::~DualX11Output() {
60   XCloseDisplay(display);
61 }
62
63 void DualX11Output::drawcell(const Point* list, int n) {
64   static Parameter<double> eyeseparation("eyesep",
65                                          "Distance from projection eye to origin", 
66                                          0.3, .1, 0., 100.);
67   for (int i=0; i<2; i++) {
68     Point::seteyex(eyeseparation*(i-0.5));
69     XPoint xp[n+1];
70     for (int j=0; j<n; j++) {
71       Onscreen here= Onscreen(list[j]);
72       xp[j].x= (int)((here.x+1.0)*250.0);
73       xp[j].y= (int)((-here.y+1.0)*250.0);
74     }
75     XFillPolygon(display,window,fabric[i],xp,n,Nonconvex,CoordModeOrigin);
76     xp[n]= xp[0];
77     XDrawLines(display,window,mesh[i],xp,n+1,CoordModeOrigin);
78   }
79   Point::seteyex(0);
80 }