chiark / gitweb /
found in ijackson@chiark:things/moebius.old-before-cvs
[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   for (i=0; i<2; i++) {
33     gcvalues.plane_mask= planemasks[i];
34     // First, the fabric
35     gcvalues.function= GXclear;
36     fabric[i]= XCreateGC(display,window,
37                          GCFunction|GCPlaneMask,
38                          &gcvalues);
39     // Then, the mesh
40     gcvalues.function= GXset;
41     mesh[i]= XCreateGC(display,window,
42                        GCFunction|GCPlaneMask,
43                        &gcvalues);
44   }
45   XSelectInput(display,window,0);
46   XMapWindow(display,window);
47   XFlush(display);
48 }
49
50 void DualX11Output::startimage() {
51   XClearWindow(display,window);
52 }
53
54 void DualX11Output::endimage() {
55   XFlush(display);
56 }
57
58 DualX11Output::~DualX11Output() {
59   XCloseDisplay(display);
60 }
61
62 void DualX11Output::drawcell(const Point* list, int n) {
63   static Parameter<double> eyeseparation("eyesep",
64                                          "Distance from projection eye to origin", 
65                                          0.3, .1, 0., 100.);
66   for (int i=0; i<2; i++) {
67     Point::seteyex(eyeseparation*(i-0.5));
68     XPoint xp[n+1];
69     for (int j=0; j<n; j++) {
70       Onscreen here= Onscreen(list[j]);
71       xp[j].x= (int)((here.x+1.0)*250.0);
72       xp[j].y= (int)((-here.y+1.0)*250.0);
73     }
74     XFillPolygon(display,window,fabric[i],xp,n,Nonconvex,CoordModeOrigin);
75     xp[n]= xp[0];
76     XDrawLines(display,window,mesh[i],xp,n+1,CoordModeOrigin);
77   }
78   Point::seteyex(0);
79 }