/* * test_x11.c: * * Tests the X driver libx.c. Makes direct calls to the device * dependent X library routines. Thus there is no lib2d involved * and therefore no set_window or viewport. * * Compilation: * cc test_x11.c libx.c -lm -lX11 -o test_x11 * * I have added trivial versions of the routines device independent * init_graphics(), move(), cont(), etc which just convert any coords * to INTEGER coords on the 512x512 screen and then calls the * device dependent _init_graphics(), _move(), etc routine. * * This makes it very easy to test the X11 driber libx.c standalone. * Once that is working, you can begin interfacing to your graphics * package, i.e. including libindep.c. * */ #include <math.h>
main() { int nvert,col,i,nslice; double vx[10],vy[10],dth,x,y,xlast,ylast;
init_graphics(); /* sets screen to 0,511 x 0,511 */
set_color_from_table(1); line(.1,.1,.9,.1); set_color_from_table(2); line(.9,.1,.9,.9); set_color_from_table(3); line(.9,.9,.1,.9); set_color_from_table(4); line(.1,.9,.1,.1);
col = 5; nvert = 3; vx[0] = .2; vx[1] = .8; vx[2] = .5; vy[0] = .2; vy[1] = .2; vy[2] = .8; polygon(col,nvert,vx,vy);
set_color_from_table(3); text("FIRST FRAME"); end_frame();
nslice = 8; dth = 2.0*M_PI/nslice; for (i=0; i<=nslice; i++) { col = i-1; nvert = 3; x = .5 + .4*cos(i*dth); y = .5 + .4*sin(i*dth); if (i!=0) { vx[0] = .5; vx[1] = xlast; vx[2] = x; vy[0] = .5; vy[1] = ylast; vy[2] = y; polygon(col,nvert,vx,vy); } xlast = x; ylast = y; } move(.4,.95); set_color_from_palette(.5); text("TABLE PIE"); end_frame();
nslice = 100; dth = 2.0*M_PI/nslice; for (i=0; i<=nslice; i++) { col = 8+i-1; nvert = 3; x = .5 + .4*cos(i*dth); y = .5 + .4*sin(i*dth); if (i!=0) { vx[0] = .5; vx[1] = xlast; vx[2] = x; vy[0] = .5; vy[1] = ylast; vy[2] = y; polygon(col,nvert,vx,vy); } xlast = x; ylast = y; } move(.4,.95); set_color_from_palette(.5); text("PALETTE PIE"); end_frame();
col = 5; nvert = 3; vx[0] = .2; vx[1] = .6; vx[2] = .5; vy[0] = .2; vy[1] = .2; vy[2] = .8; polygon(col,nvert,vx,vy);
set_color_from_table(6); text("LAST FRAME"); end_frame(); }
static int XMAX, YMAX; /* Width of screen */
init_graphics() { _init_graphics(); XMAX = YMAX = 511; }
move(x,y) double x,y; { _move((int)(x*XMAX), (int)(y*YMAX)); }
cont(x,y) double x,y; { _cont((int)(x*XMAX), (int)(y*YMAX)); }
line(x1,y1,x2,y2) double x1,y1,x2,y2; { move(x1,y1); cont(x2,y2); }
polygon(col,n,vx,vy) int col,n; double *vx,*vy; { static int ivx[20],ivy[20]; int i;
for (i=0; i<n; i++) { ivx[i] = (int)(vx[i]*XMAX); ivy[i] = (int)(vy[i]*YMAX); } _polygon(col,n,ivx,ivy); }
text(str) char *str; { _text(str); }
end_frame() { _end_frame(); } --