UNIX 4 2D/3D Grahpics,GUI :2-3 - 045708G 045726E 045730C 045735D 045759B 045762B
1 level1 1 11 2 12 4 13 6 14 6 2 Level2 6 21 6 211 swtich 11 212 ButtonPress 11 213 ButtonRelease 12 214 Expose 12 22 12 23 12 3 Level3 3 13 31 13 32 13 33 14 34 15 4 Level 4 15 41 level4c 15 411 16 412 16 42 18 43 18 44 19 5 level5 20 51 20 52 20 53 20 54 20 55 21 56 21 57 22 58 23 1
6 Level6: 2D 23 61 24 62 24 63 24 64 26 65 27 7 levelx 28 71 28 72 28 73 28 74 29 75 30 751 30 752 30 2
1 level1 RGB 8bit 24bit RGB struct bitmap{ unsigned char r,g,b; } frame_buffer[x][y]; RGB X Window System X Window System (X ) (X ) / (γ) 1 1
2 (x, y) (x, y, 1) (x, y) (x, y ) (x 0, y 0 x, y ) [ x y 1 ] = [ x y 1 ] [ 1 0 0 0 1 0 x 0 y 0 1 ] (S x, S y x, y ) [ x y 1 ] = [ x y 1 ] [ S x 0 0 0 S y 0 0 0 1 ] (θ ) [ x y 1 ] = [ x y 1 ] [ cosθ sinθ 0 sinθ cosθ 0 0 0 1 ] 11 d = XOpenDisplay(NULL); XOpenDisplay() X Display ( Display *d) XOpenDisplay() DISPLAY NULL depth = DefaultDepth(d,0); ( 0 ) w = XCreateSimpleWindow(d,RootWindow(d,0),0,0,WIN WIDTH,WIN HEIGHT,0,0,0); X Window ID 1 Display* 2
2 Window ID 3,4 int (x,y) 5,6 unsigned int 7 unsigned int 8,9 unsigned long XSelectIinput(d,w,ExposureMask ButtonPressMask); 3 X ExposureMask ButtonPressMask XMapWindow(d,w); gc = XCreateGC(d,w,0,0); GC GC GC XCreateGC() pm = XCreatePixmap(d,w,WIN WIDTH,WIN HEIGHT,depth); ID 3 5 int 0 XPutImage(d,pm,gc,campusxim,0,0,0,0,WIN WIDTH,WIN HEIGHT); Display * 4 Ximage * 3
5,6 int Ximage X Y 7,8 int XNextEvent(d&event) XSelectInput CopyArea(d,pm,w,gc,0,0,WIN WIDTH,WIN HEIGHT,0,0); 2,3 Pixmap,Window 4 GC 5,6 int 7,8 unsigned int 9,10 int XFlush(d) Xlib X X XFlush() X XCloseDisplay(d) XOpenDisplay() X 12 [j04026@pw017 level1]% /level1 seaxwd 1: 2: 3:RGB 4: 5: 6: 4
7: >5 8: >07 1: 2: 3:RGB 4: 5: 6: 7: 8: >3 1: 2: 3:RGB 4: 5: 6: 7: 8: >4 >45 1: 2: 3:RGB 4: 5: 6: 7: 8: >8 [j04026@pw017 level1]% 1,2,3,4 1: 2: 5
3: RGB 4: 13 XWDSet() XWDSet() 14 xwd xwd ( ) xwd Level1 : 2 Level2 frame buffer 21 1: #include <X11/Xlibh> 2: #include <X11/Xutilh> 6
Xlib X11/Xlibh X11/Xutilh include 17: main() 18: { 19: Display *d; 20: Window r, w, sw1, sw2, sw3, sw4, sw5, sw6, sw7, sw8, sw9; 21: GC gc; 22: Colormap colmap; 23: XColor col, exact; 24: XEvent event; Display Window 1 1 11 11 GC Graphic Context Colormap ColorMap XColor XColor Colormap 36: w = XCreateSimpleWindow (d, r, 100, 100, 480, 360, 2, BlackPixel(d, 0), WhitePixel(d, 0)); 38: sw1 = XCreateSimpleWindow (d, w, 10, 5, 40, 20, 1, BlackPixel(d,0), WhitePixel(d,0)); 39: sw2 = XCreateSimpleWindow (d, w, 55, 5, 40, 20, 1, BlackPixel(d,0), WhitePixel(d,0)); 40: sw3 = XCreateSimpleWindow (d, w, 100, 5, 40, 20, 1, BlackPixel(d,0), WhitePixel(d,0)); 41: sw4 = XCreateSimpleWindow (d, w, 150, 5, 40, 20, 1, BlackPixel(d,0), WhitePixel(d,0)); 42: sw5 = XCreateSimpleWindow (d, w, 200, 5, 40, 20, 1, BlackPixel(d,0), WhitePixel(d,0)); 43: sw6 = XCreateSimpleWindow (d, w, 250, 5, 40, 20, 1, BlackPixel(d,0), WhitePixel(d,0)); 44: sw7 = XCreateSimpleWindow (d, w, 300, 5, 40, 20, 1, BlackPixel(d,0), WhitePixel(d,0)); 45: sw8 = XCreateSimpleWindow (d, w, 350, 5, 40, 20, 1, BlackPixel(d,0), WhitePixel(d,0)); 46: sw9 = XCreateSimpleWindow (d, w, 400, 5, 40, 20, 1, BlackPixel(d,0), WhitePixel(d,0)); 7
49: XMapWindow (d, w); 50: XMapSubwindows (d, w); 51: gc = XCreateGC (d, w, 0, 0); XCreateSimpleWindow ID ID ID ID X Y XMapWindow ID ID XMapSubwindows XCreateGC 54: XSelectInput (d, w, ButtonPressMask ButtonReleaseMask ExposureMask ); 55: XSelectInput (d, sw1, ButtonPressMask ExposureMask); 56: XSelectInput (d, sw2, ButtonPressMask ExposureMask); 57: XSelectInput (d, sw3, ButtonPressMask ExposureMask); 58: XSelectInput (d, sw4, ButtonPressMask ExposureMask); 59: XSelectInput (d, sw5, ButtonPressMask ExposureMask); 60: XSelectInput (d, sw6, ButtonPressMask ExposureMask); 61: XSelectInput (d, sw7, ButtonPressMask ExposureMask); 62: XSelectInput (d, sw8, ButtonPressMask ExposureMask); 63: XSelectInput (d, sw9, ButtonPressMask ExposureMask); Xclient XSelectInput() Prototype XSelectInput( Display* display, Window window, long event\_mask ); 8
event mask 7 1 ButtonPressMask ButtonPress 2 ButtonReleaseMask ButtonRelease 3 PointerMotionMask MotionNotify 4 ButtonMotionMask MotionNotify ( ) 5 Button1MotionMask MotionNotify 6 Button2MotionMask MotionNotify 7 Button3MotionMask MotionNotify ( ) event mask Expose Expose Expose X Expose X Expose 1 2 3 9
Expose 75: XDrawString(d, sw1, gc, 5, 10, "RESET", strlen("reset")); 77: XDrawString(d, sw2, gc, 5, 10, "QUIT", strlen("quit")); 79: XDrawString(d, sw3, gc, 10, 10, "STRAIGHT", strlen("straight")); 81: XDrawString(d, sw4, gc, 10, 10, "DOTT", strlen("dott")); 83: XDrawString(d, sw5, gc, 10, 10, "STRIPES", strlen("stripes")); 85: XDrawString(d, sw6, gc, 5, 10, "RED", strlen("red")); 87: XDrawString(d, sw7, gc, 5, 10, "BLUE", strlen("blue")); 89: XDrawString(d, sw8, gc, 5, 10, "YELLOW", strlen("yellow")); 91: XDrawString(d, sw9, gc, 5, 10, "PURPLE", strlen("purple")); 93: XNextEvent (d, &event); Display 97: switch (eventtype) { 99: case ButtonPress : 101: if(eventxanywindow == sw1) { 102: XClearWindow (d, w); 103: } 106: if(eventxanywindow == sw2){ 107: XCloseDisplay(d); 108: } 111: if(eventxanywindow == sw3){ 112: XSetLineAttributes (d, gc, 4, LineSolid, CapButt, JoinMiter); 10
114: XAllocNamedColor (d, colmap, color, &col, &exact); 115: XSetForeground(d, gc, colpixel); 116: } 160: if(eventxanywindow == sw9){ 161: strcpy(color, "purple"); 163: XAllocNamedColor (d, colmap, color, &col, &exact); 164: XSetForeground(d, gc, colpixel); 165: } 211 swtich swtich 212 ButtonPress 101 103 XClearWindow sw1 (RESET) 106 108 XCloseDisplay Xserver sw2 (QUIT) 111 133 XSetLineAttributes 2(current pen ) LineSolid CapRound JoinMiter XAllocNamedColor() colmap DefaultColormap() ID color &col XColor 11
136 165 strcpy color 213 ButtonRelease XSetForeground draw line (ButtonPress) (ButtonRelease) 214 Expose Expose draw line 22 5: 23 12
frame buffer XClearWindow frame buffer XClearWindow XCleaWindow Level2 : 3 Level3 3 frame buffer 3 3 frame buffer 3 3 4 4 frame buffer 31 l => r => l u => d => u 32 dat dat x,y,z 2 x,y,z coord[] cnct[] 13
redraw() trans() main(), 33 3 (cubedat,tridat,theagdat) #/level3 cubedat 6: cubedat #/level3 tridat 7: tridat #/level3 theagdat 14
8: theagdat 34 3 Level3 : 4 Level 4 frame_buffer ( 4 )? 41 level4c 2006 Watering KissMint 15
411 void makecolor(rcol,gcol,bcol,light,x,y) void afin(x0,y0,z0,x,y,z,xa,ya,za,a,b,c,mx,my,mz) void refresh() frame_buffer void plerefresh(int rco,int gco,int bco) buffer void makecube(display *dis,window W,GC gc,colormap cm) x void makecube2(display *dis,window W,GC gc,colormap cm) y void makecube3(display *dis,window W,GC gc,colormap cm) z void redraw(display *d, Window w, GC gc, Colormap cm) 412 #define X 500 /* */ #define Y 500 /* */ void makecube2(display *dis,window W,GC gc,colormap cm){ if( AY > 90 && AY < 270 ){ 16
plerefresh(0,1,0); afin(0,1,1,&x,&y,&z,ax,ay,az,ti,ti,ti,xmo,ymo,zmo); } allpaint(dis,w,gc,cm,start_xpoint,start_ypoint,finish_xpoint,finish_ypoint); void makecube3(display *dis,window W,GC gc,colormap cm){ } allpaint(dis,w,gc,cm,start_xpoint,start_ypoint,finish_xpoint,finish_ypoint); x y z x int main(){ start = clock(); end = clock(); } time time clock() 1 17
42 9: 1 10: 2 43 6 6 6 [nw0459:~/info4/unix/lev4] j04059% /level4 time = 0800000 x = 10000000 y = 10000000 z = 10000000 time = 0740000 x = 10000000 y = 10000000 z = 10000000 time = 0760000 x = 10000000 y = 20000000 z = 10000000 time = 0750000 x = 10000000 y = 30000000 z = 10000000 time = 0740000 x = 10000000 y = 40000000 z = 10000000 time = 0680000 x = 10000000 y = 50000000 z = 10000000 time = 0570000 x = 10000000 y = 60000000 z = 10000000 time = 0640000 x = 10000000 y = 70000000 z = 10000000 time = 0610000 x = 10000000 y = 80000000 z = 10000000 time = 0520000 x = 10000000 y = 90000000 z = 10000000 [nw0459:~/info4/unix/lev4_1] j04059% /level4 time = 0620000 x = 10000000 y = 10000000 z = 10000000 time = 0630000 x = 10000000 y = 10000000 z = 10000000 18
time = 0650000 x = 10000000 y = 20000000 z = 10000000 time = 0720000 x = 10000000 y = 30000000 z = 10000000 time = 0790000 x = 10000000 y = 40000000 z = 10000000 time = 0610000 x = 10000000 y = 50000000 z = 10000000 time = 0700000 x = 10000000 y = 60000000 z = 10000000 time = 0620000 x = 10000000 y = 70000000 z = 10000000 time = 0470000 x = 10000000 y = 80000000 z = 10000000 time = 0350000 x = 10000000 y = 90000000 z = 10000000 6 0677 0609 y 180 1 y 90 double float double float double 0,609 float 0623 C double float double float C double 44 x,y,z x,y,z 19
Level4 ; 5 level5 Mesa OpenGL 51 OS Mac OSX 1046 C (gcc version 400 20041026) OpenGL,GLUT 52 OpenGL GLUT 1 clock 53 54 vertex 8 3 8*3 face A 0, 1, 2, 3 0 vertex[0] color (R,G,B) R G B,, float 0 1 20
55 49 56 49: glbegin(gl_quads); 50: for (j = 0; j < 6; j++) { 51: glcolor3dv(color[j]); 52: for (i = 0; i < 4; i++) { 53: glvertex3dv(vertex[face[j][i]]); 54: } 55: } 56: glend(); 57: glutswapbuffers(); glbegin() GL QUADS 4 glcolor glvertex glcolor glvertex 3dv 6 for 6 57 glutswapbuffers() 2 2 56 93:int main(int argc, char *argv[]) 94:{ 95: clock_t start,end; //clock 96: start=clock(); // 97: 98: glutinit(&argc, argv); 99: glutinitdisplaymode(glut_rgba GLUT_DOUBLE GLUT_DEPTH); 100: glutcreatewindow("level5"); 101: glutdisplayfunc(display); 102: glutreshapefunc(resize); 21
103: glutkeyboardfunc(keyboard); 104: init(); 105: 106: end=clock(); // 107: // 108: printf("%f\n", (double)(end - start) / CLOCKS_PER_SEC); 109: 110: glutmainloop(); // 111: return 0; 112:} 95 96 start 98 GLUT OpenGL X Window -display 99 3 GLUT RGBA RGB GLUT DOUBLE GLUT DEPTH 100 101 104 106 108 end 110 57 [nw0408:~/desktop/level5] j04008% aout 0190000 22
11: level5 58 10 01950 level4 06094 3 1 level4 X Window system Xlib OpenGL Xlib GLUT glutsolidcube() frame buffer Level5 : 6 Level6: 2D 2D 23
SVG XML 61 Mac OSX 1039 java version 142 09 62 12: 63 init() start() paint() 24
START init() start() paint() update() 13: - : ----Linejava------------------------ import javaawt*; class Line extends Shape{ Line(Color c){ super(c); changepoints = new int[2][2]; thissetchangepoints(); } public void draw(graphics g){ gsetcolor(color); gdrawline(x1, y1, x2, y2); } public void setchangepoints(){ changepoints[0][0] = x1; changepoints[0][1] = y1; changepoints[1][0] = x2; changepoints[1][1] = y2; } public void setpoint(int n){ x1 = changepoints[0][0]; y1 = changepoints[0][1]; x2 = changepoints[1][0]; y2 = changepoints[1][1]; 25
setcenter(); } public boolean isintershape(int x, int y){ return false; } } --------------------------------- ---AppletDrawTooljava----------- { } public void actionperformed(actionevent e){ String s = ((Button)egetSource())getLabel(); { } if(sequals("line")){ shapesadd(new Line(color)); } --------------------------------- update() paint() 64 ------- ----------- ---AppletDrawTooljava------------ 26
{ } public int whichdragg(int x, int y){ for(int i=shapessize()-1; i>=0; i--){ dragnum = ((Shape)shapesget(i))isInter(x, y); if(dragnum >= 0){ return i; } } return -99999; } public int whichinter(int x, int y){ for(int i=shapessize()-1; i>=0; i--){ if(((shape)shapesget(i))isintershape(x, y)) return i; } return -99999; } ---------------------------------- 65 vector shapes Level6 SVG XML Java Applet XML java XMLEncoder XML FileOutputStream 27
Level6 : 7 levelx : Draw Tool Draw Tool 71 OS Mac OSX 1046 java (java version 142 09 ) 72 level6 73 String String str stringjava string String 228: if(sequals("string")){ 229: if ((tfgettext())length() >=1){ 230: String str=tfgettext(); 231: shapesadd(new string(color,str)); 232: tfsettext(""); 234: } 235: } 28
stringjava 5:public string(color c,string s){ 6: super(c,s); 7: changepoints = new int[0][0]; 8: thissetchangepoints(); 9: } 10: public void draw(graphics g){ 11: gsetcolor(color); 12: gsetfont(new Font("Serif",FontPLAIN,36)); 13: gdrawstring(str,xcenter, ycenter); 14: } string s 2 super() Shape draw gdrawstring(str,x,y) (x,y) str 74 14: level6 29
75 751 ( ) enter 752 ( ) LevelX :, [1] 2006 UNIX Watering KissMint http://wwwieu-ryukyuacjp/ j04053/unixhtml [2] 2006 UNIX http://wwwieu-ryukyuacjp/ j04051/unixreport/indexhtml [3] X Window System(X ) X http://wwwstackasteriskjp/tech/engineer/xwindow01 01jsp [4] Quick introduction to XWindow Graphics http://www-cmsphyssu-tokyoacjp/ naoki/cipintro/xlib/indexhtml [5] X http://x68000q-e-dnet/ 68user/xprogram/ 30
[6] Electronic Textbook index0 http://nis-labissu-tokyoacjp/ nis/cg/cgtxt/indexhtm [7] Welcome to Rio s Laboratory http://homepage3niftycom/rio i/lab/ [8] http://lunasitacjp/idolab/ [9] OpenGL http://wisdomsakuranejp/system/opengl/ [10] GLUT OpenGL http://wwwwakayama-uacjp/ tokoi/opengl/libgluthtml [11] X Japanese Documentation Pro ject http://xjmandslgrjp/ [12] http://www-antennaeetitechacjp/ hira/hobby/edu/afin trans/math html [13] X-Window Programming http://www-yanoistokushima-uacjp/ mituhara/software e/indexhtml [14] Xlib-C Language X interface http://xjmandslgrjp/x11r6/x11/ [15] Java [16] Java [17] II http://wwwieu-ryukyuacjp/ j02039/unix4/unix4html [18] JavaWorldOnline http://wwwjavaworldjp/ 31