' & VR CompleXcope $ % 1 2 509{5292 322{6 1) kage@tokitheorynifsacjp 2) sato@tokitheorynifsacjp
CompleXcope Programming Guide, Ver 1, by A Kageyama and T Sato, August 1998
1 CompleXcope 5 11 : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 5 12 CompleXcope : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 5 13 CompleXcope : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 6 14 : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 7 2 OpenGL 9 21 OpenGL : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 9 22 Web : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 10 23 OpenGL : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 10 24 OpenGL : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 11 25 OpenGL : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 13 26 OpenGL : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 13 27 : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 14 28 : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 17 29 : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 20 210 : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 21 211 : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 23 212 : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 24 2121 : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 24 2122 : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 25 2123 : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 26 2124 : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 27 213 : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 29 214 : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 30 215 : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 31 216 aux : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 31 217 glu library : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 33 218 : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 34 219 : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 35 220 : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 38 221 : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 39 222 ( ) : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 40 223 aux library : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 41 224 ( ) : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 42 225 ( ) : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 46 226 ( ) : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 47 227 : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 47 228 ( ) : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 49 229 : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 51 230 : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 54 231 : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 57 3
4 232 : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 60 3 CAVE 65 31 CompleXcope : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 65 32 : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 65 33 CAVE : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 65 34 CAVE : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 66 35 : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 66 36 Conguration File : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 67 37 CompleXcope : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 67 38 CAVE : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 68 39 : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 69 310 : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 72 311 3( ) : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 74 312 4 : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 76 313 5 : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 78 314 : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 81 315 : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 82 316 : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 82 317 : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 83 318 : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 84 319 : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 84 320 : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 85 321 : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 85 322 : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 86 323 : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 90 324 CompleXcope : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 94 A CAVE 95 B OpenGL 97 C C (diff f c) 101 C1 C : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 101 C2 : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 102 C3 : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 103 C4 : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 103 C5 : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 104 C6 if : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 104 C7 : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 104 C8 for : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 106 C9 while : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 106 C10 : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 107 C11 : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 108 C12 : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 110 D 113 D1 : : : : : : : : : : : : : : : : : : : : : : : : 113 D2 x2texture : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 113
1 CompleXcope 11 ( ) AVS (VR) VR VR VR (Head Mounted Display, HMD) (Univ Illinois, Chicago) Electronic Visualization Laboratory (EVL) 1 CAVE VR VR 1996 ( ) CAVE CAVE 1997 CAVE VR (complex) CompleXcope 12 CompleXcope CompleXcope 10 ( ) ( 1 http://wwwevluicedu/evl/indexhtml 5
6 CompleXcope ) CompleXcope CAVE (10 2 10 3 + 1 ) ( ) ( ) ( ) cm CompleXcope CompleXcope CAVE CompleXcope 13 CompleXcope CAVE CAVE EVL CAVE UNIX VR CompleXcope CAVE 1 2 ( ) 3 ( ) 4 CompleXcope OpenGL 2 OpenGL CompleXcope OpenGL CAVE OpenGL CAVE CompleXcope 2 Iris GL Open Inventor, Iris Performer
8 14 7 9 OpenGL CAVE CompleXcope \ " 14 CompleXcope CompleXcope OpenGL CG CompleXcope OpenGL OpenGL CG CompleXcope OpenGL ( ) OpenGL CG CompleXcope \ OpenGL " AVS OpenGL AVS CAVE library OpenGL CAVE library ( ) Web CAVE library (OpenGL ) OpenGL CompleXcope X ( ) CompleXcope CAVE library Appendix A CAVE Appendix B OpenGL CompleXcope C( C++) Fortran C Appendix C Fortran C C C Appendix D ( ) pict gif
8 CompleXcope
2 OpenGL 21 OpenGL OpenGL 1 SGI (Silicon Graphics, Inc) GL OpenGL ARB (Architecture Review Board) OpenGL (CG) (1) (2) (3) ( ) (4) (5) (6) ( ) (7) CG (1) (5) OpenGL (6) (7) OpenGL (7) OpenGL OpenGL 120 OpenGL X Window Macintosh Windows95/NT Be OpenGL CG OpenGL CG CompleXcope CompleXcope X Window OpenGL X Window OpenGL glut library[1] M Kilgard OpenGL glut library aux library 2 1 \OpenGL" \Open GL" 2 Xlib Motif Tcl/Tk 9
10 OpenGL \aux" aux library CompleXcope (7) CAVE library CAVE library \CAVE" CompleXcope aux library (5) ( ) CompleXcope ( ) OpenGL CompleXcope CAVE CAVE OpenGL 22 Web OpenGL \OpenGL Programming Guide" [2, 3] 1993 [4, 5] 1997 aux library glut library OpenGL OpenGL OpenGL \OpenGL Reference Manual" [6] OpenGL man OpenGL (R) (B) (G) glut \OpenGL Programming for the X Window System"[1] OpenGL [7] OpenGL OpenGL http://wwwopenglorg/ OpenGL WEB OpenGL Japan http://wwwkgtcojp/opengl/ OpenGL FAQ http://wwwsgicom/technology/opengl/ http://techwebcitynejp/~andoh/opengl/openglfaqhtml OpenGL Mesa http://wwwssecwiscedu/~brianp/mesahtml Mesa Avid Technology, Inc Brian Paul 23 OpenGL OpenGL ( ) X
24 OpenGL 11 aux library glu library glx library glut library `aux' aux library `glu' X Window `glx' X Window OpenGL `glut' aux library glu library glx glut 24 OpenGL 76 4 5 simplec aux library OpenGL OpenGL z =0 1: #include <GL/glh> 2: #include "auxh" 3: 4: main() { 5: 6: auxinitdisplaymode (AUX_SINGLE AUX_RGB); 7: auxinitposition (0, 0, 500, 500); 8: auxinitwindow ("simplec"); 9: 10: glclearcolor (00, 00, 00, 00); 11: glclear(gl_color_buffer_bit); 12: glcolor3f(10, 10, 10); 13: glmatrixmode (GL_PROJECTION); 14: glloadidentity (); 15: glortho(-10, 10, -10, 10, -10, 10); 16: glbegin(gl_polygon); 17: glvertex3f(-05, -05, 00); 18: glvertex3f(-05, 05, 00); 19: glvertex3f( 05, 05, 00); 20: glvertex3f( 05, -05, 00); 21: glend(); 22: glflush(); 23: sleep (10); 24:
12 OpenGL OpenGL include 3 OpenGL OpenGL (CompleXcope )OpenGL aux library include aux library OpenGL CompleXcope include main aux library (1) (2) RGB RGB Red, Green, Blue (0,0) (500, 500) (X Window ) +x +y auxinitwindow() \gl" OpenGL glclearcolor() R, G, B, A 0 1 A Alpha RGBA 0 color buer depth buer stencil buer (R; G; B) =(1:0; 1:0; 1:0) glortho() ( ) (glbegin glend ) glbegin() GL_POLYGON x,y,z (-05, -05, 00) glend() glflush() 4 (OpenGL ) C (glflush ) ( ) sleep(10) 10 sleep 3 /usr/local/include/gl/glh 4 OpenGL
25 OpenGL 13 25 OpenGL OpenGL \gl" ( \glclearcolor") \GL_" \glcolor3f()" ( \3f") 3 \glcolor4f()" \3f" \f" oat \3f" --------------------------------------------------------------- OpenGL --------------------------------------------------------------- b 8 GLbyte i 32 GLint f 32 GLfloat d 64 GLdouble --------------------------------------------------------------- C int oat GLint GLoat OpenGL OpenGL \v" \v" ( ) OpenGL float color_array[] = {00, 00, 10; /* */ glcolor3f(10, 10, 00); /* */ glcolor3fv(color_array); /* */ 26 OpenGL OpenGL \ " \ " \ " \ " \ " \glcolor3f" \simplec" 16 glbegin() 21 glend() \draw_rectangle()"
14 OpenGL glcolor3f(10, 10, 10); draw_rectangle(); /* */ glcolor3f(10, 00, 00); draw_rectangle(); /* */ draw_rectangle(); /* */ glcolor3f(10, 10, 00); draw_rectangle(); /* */ glcolor3f() \ " \ " 27 OpenGL (vertex) z = 0 76 4 5 simple2c #include <GL/glh> #include <mathh> /* (sin, cos) */ #include "auxh" main() { float pi; float x0, x1, x2, x3, x4, x5; float y0, y1, y2, y3, y4, y5; auxinitdisplaymode (AUX_SINGLE AUX_RGB); auxinitposition (0, 0, 500, 500);
27 15 auxinitwindow ("simple2c"); glclearcolor (00, 00, 00, 00); /* */ glclear (GL_COLOR_BUFFER_BIT); /* */ glcolor3f(00, 10, 00); /* */ glpointsize (50); /* 5 */ glmatrixmode (GL_PROJECTION); glloadidentity (); glortho (-15, 15, -15, 15, -15, 15); /* */ pi = 3141593; x0 = cos(0*pi/3); y0 = sin(0*pi/3); x1 = cos(1*pi/3); y1 = sin(1*pi/3); x2 = cos(2*pi/3); y2 = sin(2*pi/3); x3 = cos(3*pi/3); y3 = sin(3*pi/3); x4 = cos(4*pi/3); y4 = sin(4*pi/3); x5 = cos(5*pi/3); y5 = sin(5*pi/3); glbegin(gl_points); glvertex3f(x0, y0, 00); /* o o */ glvertex3f(x1, y1, 00); /* */ glvertex3f(x2, y2, 00); /* o o */ glvertex3f(x3, y3, 00); /* */ glvertex3f(x4, y4, 00); /* o o */ glvertex3f(x5, y5, 00); /* */ glend(); glflush(); sleep (10); n end of simple2c / \glbegin" \glend" \glvertex()" glbegin glend glbegin(gl_points); for (i=0; i<6; i++) { x = cos(i*pi/3); y = sin(i*pi/3); glvertex3f(x, y, 00); glend(); 76 4 5 simple3c
16 OpenGL #include <GL/glh> #include <mathh> /* (sin, cos) */ #include "auxh" main() { float pi, x, y; int i; auxinitdisplaymode (AUX_SINGLE AUX_RGB); auxinitposition (0, 0, 500, 500); auxinitwindow ("simple3c"); glclearcolor (00, 00, 00, 00); /* */ glclear (GL_COLOR_BUFFER_BIT); /* */ glcolor3f(00, 10, 00); /* */ glpointsize (50); /* 5 */ glmatrixmode (GL_PROJECTION); glloadidentity (); glortho (-15, 15, -15, 15, -15, 15); /* */ pi = 3141593; glbegin(gl_points); for (i=0; i<6; i++) { x = cos(i*pi/3); y = sin(i*pi/3); glvertex3f(x, y, 00); glend(); glflush(); sleep (10); n end of simple3c / \glbegin()" \GL_POINTS" \GL_POLYGON"
76 4 28 5 17 simple4c #include <GL/glh> #include <mathh> #include "auxh" main() { int i; float pi, x, y; auxinitdisplaymode (AUX_SINGLE AUX_RGB); auxinitposition (0, 0, 500, 500); auxinitwindow ("simple4c"); glclearcolor (00, 00, 00, 00); /* */ glclear (GL_COLOR_BUFFER_BIT); /* */ glcolor3f(00, 10, 00); /* */ glmatrixmode (GL_PROJECTION); glloadidentity (); glortho (-15, 15, -15, 15, -15, 15); /* */ pi = 3141593; glbegin(gl_polygon); /* <---- */ for (i=0; i<6; i++) { x = cos(i*pi/3); y = sin(i*pi/3); glvertex3f(x, y, 00); glend(); glflush(); sleep (10); n end of simple4c / GL_POLYGON GL_POLYGON 28 \glbegin()" \GL_POINTS" \GL_POLYGON" \GL_POLYGON" \GL_POLYGON" v0, v1,, v7 x y z
18 OpenGL float v0[] = {-10, -10, -10; float v1[] = { 10, -10, -10; /* v4 v5 */ glbegin(gl_polygon); /* +------+ */ glvertex3fv(v0); /* / / */ glvertex3fv(v1); /* v2+------+ v7 */ glvertex3fv(v3); /* v3 / */ glvertex3fv(v2); /* / */ glend(); /* +------+ */ /* v0 v1 */ glbegin(gl_polygon); glvertex3fv(v2); glvertex3fv(v3); glvertex3fv(v5); glvertex3fv(v4); glend(); /* glbegin() glend() */ \GL_POLYGON" GL_POINTS GL_LINES GL_POLYGON GL_TRIANGLES GL_QUADS GL_LINE_STRIP GL_LINE_LOOP GL_TRIANGLE_STRIP GL_TRIANGLE_FAN GL_QUAD_STRIP glbegin() 5 5 \ " \ " :::
28 19 v0 v0 v2 v1 v2 x / / / v3 / v3 x x v1 / / v1 v0 x v2 v4 v5 v3 GL_POINTS GL_LINES GL_LINE_STRIP v2 v3 v2 v3 v0 v1 / +------+ +---+ v1 / v1 ++++++++ /+++/ v5 \++++++ /+++/ v4 v5 /\ \++++/ v4 +---+ +------+ v0 / \ v4 \++/ v3 v2 /++++++/ \/ +------+ GL_LINE_LOOP v0 v7 v6 GL_POLYGON GL_QUADS v1 v3 v5 v6 v0 v2 +---+------+--------+ \+++++/ v5 v4 /++++ ++++++ +++++++/ \+++/ ++++/ /+++++ ++++++ ++++++/ \+/ +++/ /++++++ ++++++ +++++/ + ++/ +-------+------+----+ v1 +/ v0 v2 v4 v5 v3 / GL_QUAD_STRIP GL_TRIANGLES v4 v3 v2 +------+------+ v1 v3 v5 \+++++ +++++/+\ v1 +-------+-------+ \++++ ++++/+++\ /+\+++++/+\+++++/ \+++ +++/+++/ /+++\+++/+++\+++/ \++ ++/++/ /+++++\+/+++++\+/ \+ +/+/ +-------+-------+ \ // v0 v2 v4 v0 GL_TRIANGLE_STRIP GL_TRIANGLE_FAN glbegin() glend() glvertex3f glvertex3fv(v0), glvertex3fv(v1), glvertex3fv(v2), glvertex3fv(v3), 111 glbegin()
20 OpenGL glbegin(gl_quad_strip); glvertex3fv(v0); glvertex3fv(v1); glvertex3fv(v2); glvertex3fv(v3); glvertex3fv(v4); glvertex3fv(v5); glvertex3fv(v6); glvertex3fv(v7); glvertex3fv(v0); glvertex3fv(v1); glend(); glbegin(gl_quads); glvertex3fv(v0); glvertex3fv(v4); glvertex3fv(v1); glvertex3fv(v5); glend(); glvertex3fv(v2); glvertex3fv(v6); glvertex3fv(v3); glvertex3fv(v7); 29 3 CG 1 2 ( ) 3 OpenGL OpenGL 2 CG 6 OpenGL OpenGL 6
210 21 7 CG OpenGL ( ) 210 OpenGL 8 o=================================== 36 o======================== 24 o================== 18 o============== 14 o=========== 11 depth buffer 3D OBJECT o========= 9 o======== 8 o======== 8 o========= 9 (depth buer) 9 (= ) (OBJ-X ) OBJ-X ( ) OBJ-X 10 (1) OBJ-X (P ) D (2) P (I,J) (3) (I,J) D D ( P ) P D 7 \ " 8 9 Z 10
22 OpenGL o-----------------------x=========== 36 --> 11 o-----------x============ 24 --> 12 o----x============= 18 --> 13 X============== 14 X o=========== 11 OBJ-X X o========= 9 X o======== 8 X o======== 8 X o========= 9 OpenGL ( ) glenable(gl_depth_test); ( OFF )GL_DEPTH_TEST ON glenable() OpenGL ON 11 ( ) glclear(gl_depth_buffer_bit) ( ) ( ) glclear(gl_color_buffer_bit); glclear(gl_depth_buffer_bit); glclear(gl_color_buffer_bit GL_DEPTH_BUFFER_BIT); glenable() glclear() aux library auxinitdisplaymode ( simplec (p11) ) (AUX_SINGLE AUX_RGB AUX_DEPTH) 11 glenable(gl FOG) ( ) ON glenable(gl LIGHTING) ON (p25)
211 23 211 ON glnormal3f(); ( ) glnormal3fv(); 3 ( (2) ) (1) (2) 1 (3) float n0[] = {00, 00, 10; /* */ float n1[] = {00, 00, 10; /* */ float n2[] = {00, 00, 10; /* */ float v0[] = {10, 00, 00; /* */ float v1[] = {00, 00, 00; /* */ float v2[] = {00, 15, 00; /* */ glbegin(gl_poylgon); /* n1 */ glnormal3fv(n0); /* n0 */ glvertex3fv(v0); /* */ glnormal3fv(n1); /* + n2 */ glvertex3fv(v1); /* + */ glnormal3fv(n2); /* */ glvertex3fv(v2); /* + */ glend(); sqrt() glnormal OpenGL
24 OpenGL 212 2121 OpenGL ( ) OpenGL OpenGL CompleXcope o ( ) o o OFF glcolor CompleXcope \ " ( ) ( ) \ " 12 13 232 12 13 CompleXcope (\Welcome to CompleXcope" )
212 25 o glcolor ( ) o ( ) 2122 OpenGL glenable(gl_ligthting); glenable(gl_ligtht0); glenable() OpenGL ON glenable() ON OpenGL 0 1 2 glenable(gl_light0) 0 glenable(gl_ligthting); glenable(gl_ligtht0); glenable(gl_ligtht1); ( ) (GL_LIGHT0 ) ( ) OpenGL o o RGB o ( ) o o ( RGB ) o o RGB o RGB CG \ "
26 OpenGL 2123 (ambient light) 14 RGB \ / \ / \ / ---- OBJ ---- / \ / \ / \ (diuse light) ( ) ( ) ~s ~n ~s ~n ( ) ~s ~n ( ) 15 \ / \ / -- S -- -- S -- / \ / \ +- -----+ +- -----+ / / / / / / / / / / / / / / / / +-------+ +-------+ ( ) 14 15 ( )
212 27 (specular light) ~s ~n ~v ~s + ~v ~n \ / V1 ( ) -- S -- / \ V2 ( ) +- -----+ / / V3 ( ) / / / / / / +-------+ 2124 CG CG (0; 0; 0) 1 ( ) +z 16 x +1 ( ) 17 ( ) \ " (0; 0; 1) (1; 0; 0) (x < 0) ( ) ( ) ( ) \ " ( ) 16 OpenGL 17 OpenGL
28 OpenGL ( ) ( ) ( ) (CompleXcope ) OpenGL 0 1( ) 0 1 0 gllightf() gllightfv() GLfloat light_position[] = {100, 50, 30, 10; /* */ gllightfv(gl_light0, GL_POSITION, light_position); glenable(gl_lighting); /* ON */ glenable(gl_light0); /* 0 ON */ ( light_position ) x; y; z 1:0 x; y; z gllightfv() (lx; ly; lz; lw) (lx=lw; ly=lw; lz=lw) 00 (lx; ly; lz) OpenGL 00 10
213 29 GLfloat light_position[] = {100, 50, 30, 00; /* */ GLfloat light_diffuse[] = {10, 10, 10, 00; /* */ GLfloat light_ambient[] = {03, 03, 03, 00; /* */ GLfloat light_specular[] = {08, 08, 08, 00; /* */ gllightfv(gl_light0, GL_POSITION, light_position); /* */ gllightfv(gl_light0, GL_DIFFUSE, light_diffuse); /* */ gllightfv(gl_light0, GL_SPECURAR, light_specular); /* */ gllightfv(gl_light0, GL_AMBIENT, light_ambient); /* */ glenable(gl_lighting); /* ON */ glenable(gl_light0); /* 0 ON */ 213 (R,G,B) glmaterialfv() ( ) ( ) GLfloat light_position[] = {100, 50, 30, 00; /* */ GLfloat light_diffuse[] = {10, 10, 10, 00; GLfloat light_ambient[] = {03, 03, 03, 00; GLfloat light_specular[] = {08, 08, 08, 00; GLfloat ball_1_diffuse[] = {10, 00, 00, 00; /* 1 */ GLfloat ball_1_ambient[] = {10, 00, 00, 00; GLfloat ball_1_specular[] = {08, 08, 08, 00; GLfloat ball_2_diffuse[] = {00, 10, 00, 00; /* 2 */
30 OpenGL GLfloat ball_2_ambient[] = {00, 10, 00, 00; GLfloat ball_2_specular[] = {00, 00, 00, 00; gllightfv(gl_light0, GL_POSITION, light_position); /* */ gllightfv(gl_light0, GL_DIFFUSE, light_diffuse); /* */ gllightfv(gl_light0, GL_SPECURAR, light_specular); /* */ gllightfv(gl_light0, GL_AMBIENT, light_ambient); /* */ glenable(gl_lighting); /* ON */ glenable(gl_light0); /* 0 ON */ glenable(gl_depth_test); /* ( ) ON */ glclear(gl_color_buffer_bit GL_DEPTH_BUFFER_BIT); /* */ /* */ glmaterialfv(gl_front, GL_DIFFUSE, ball_1_diffuse); glmaterialfv(gl_front, GL_AMBIENT, ball_1_amnient); glmaterialfv(gl_front, GL_SPECULAR, ball_1_specular); glmaterialf(gl_front, GL_SHININESS, 1100); /* */ make_ball_1(); /* */ /* */ glmaterialfv(gl_front, GL_DIFFUSE, ball_2_diffuse); glmaterialfv(gl_front, GL_AMBIENT, ball_2_amnient); glmaterialfv(gl_front, GL_SPECULAR, ball_2_specular); make_ball_2(); GL_SHININESS 18 00 1280 0 214 18 glmaterialfv() glmaterialf() ( 1100)
215 31 (a) ( )x(r,g,b) (b) (c) OpenGL ( ) (1) (a)-(c) RGB (2) RGB ( ) ( ) 215 OpenGL CG OpenGL \ " ( ) AVS CG OpenGL X Window 21 aux aux 216 aux aux (auxinitdisplaymode ) (auxinitwindow) OpenGL 19 aux auxwiresphere(gldouble radius); auxsolidsphere(gldouble radius); Wire Solid Wire Solid 19
32 OpenGL auxwirecube(gldouble size); auxsolidcube(gldouble size); auxwirebox(gldouble width, GLdouble height, GLdouble depth); auxsolidbox(gldouble width, GLdouble height, GLdouble depth); auxwiretorus(gldouble minorradius, GLdouble majorradius); auxsolidtorus(gldouble minorradius, GLdouble majorradius); auxwirecylinder(gldouble radius, GLdouble height); auxsolidcylinder(gldouble radius, GLdouble height); auxwirecone(gldouble radius); auxsolidcone(gldouble radius); auxwiretetrahedron(gldouble radius); auxsolidtetrahedron(gldouble radius); auxwireoctahedron(gldouble radius); auxsolidoctahedron(gldouble radius); auxwiredodecahedron(gldouble radius); auxsoliddodecahedron(gldouble radius); auxwireicosahedron(gldouble radius); auxsolidicosahedron(gldouble radius);
217 glu library 33 auxwireteapot(gldouble size); auxsolidteapot(gldouble size); "auxh" include 217 glu library aux aux \ " ( ) glu glu glu GLUquadricObj* glunewquadric(void); \Quadric" glu library 2 a 1 x 2 + a 2 y 2 + a 3 z 2 + a 4 xy + a 5 yz + a 6 zx + a 7 x + a 8 y + a 9 z + a 10 =0 glu ( a 1 a 10 ) gluneqquadric glu void glusphere(gluquadricobj *qobj, GLdouble radius, GLinit slices, GLint stacks); glunewquadric slices stacks glu void glucylinder(gluquadricobj *qobj, GLdouble baseradius, GLdouble topradius, GLdouble height, GLinit slices, GLint stacks); glu void gludisk(gluquadricobj *qobj, GLdouble innerradius, GLdouble outerradius, GLinit slices, GLint stacks);
34 OpenGL OpenGL Programming Gluid, Second Edition [4], p431 glusphere (Xballc; p72) 218 (viewing) CG CG CG \ " x{y z ( ) x{y \ " x v OpenGL ( t = 0 ) t x = vt (glvertex3f x vt \( ) " OpenGL (x; y; z; w) 20 1 2 3 4 20 w
219 35 ( ) ( ) OpenGL <-----> <-----> v(x,y,z,w) M v 0 = Mv v 0 P v 00 = Pv 0 = PMv v 00 (x; y; z; x) CG 21 (x; y; z) 0 B @ 1 0 0 x 0 1 0 y 0 0 1 z 0 0 0 1 z ' 0 B @ 1 C A cos ' 0 sin ' 0 0 sin ' cos ' 0 0 0 0 1 0 0 0 0 1 gluperspective(f,aspect,znear,zfarr) 0 B @ 1 C A cot (f=2) aspect 0 0 0 0 cot (f=2) 0 0 23zFar3zNear znear0zfar zfar+znear 0 0 znear0zfar 0 0 01 0 1 C A 219 x{y \F" F \ " x=20 21 OpenGL
36 OpenGL y y=0 +---- x +---+----- x=0 x=20 (x=0) F F \ " drawf() drawf(): (` ') x=0, y=0 F +---- +-- y=0 x=0 drawf() x=20 F (1) (2) OpenGL (1) (2) - - - K' - - K" -
219 37 gltranslatef(glfloat x, GLfloat y, GLfloat z) gltranslatef(200, 00, 00) K x 20 K' ' y y' y=0 +---- x +---- x' x=0 x=20 glrotatef(glfloat angle, GLfloat axis_y, GLfloat axis_y, GLfloat axis_z) glrotatef(300, 00, 00, 10) z 30 x-y 030:0 360 0 30 = 330:0 K' (K ) z 0 +90 " y x" y=0 +---- x y" -----+ x=0 x=20 K"
38 OpenGL x=20 F (1) K" (2) K" y" F K" drawf() 1 x 20 K' 2 z +90 K" 3 K" F OpenGL glpushmatrix(); gltranslatef(200, 00, 00); glrotatef(900, 00, 00, 10); drawf(); glpopmatrix(); glpushmatrix glpopmatrix ( ) 22 220 ( ) CompleXcope CompleXcope 23 CompleXcope CAVE library 24 void gluortho(gldouble left, GLdouble right, GLdouble top, GLdouble bottom, GLdouble near, GLdouble far); 22 23 CompleXcope 24
221 39 z 0z void gluperspective(gldouble fovy, GLdouble aspect, GLdouble znear, GLdouble zfar); 25 (0,0,0) 0z fovy fovy=2 fovy=2 (0 fovy 180:0) aspect / (0; 0; 0) (0; 0; 0) z ( ) gluperspective fovy aspect zfar zfar zfar znear ( ) zfar \ " znear zfar 221 CompleXcope CAVE library X Window OpenGL CG OpenGL OpenGL - gluperspective - z -z - 26 glviewport aux library Window aux library X Window OpenGL \ " 25 glu library OpenGL glu 26
40 OpenGL 222 ( ) z 05 auxwireteapot (p31) (0; 0:0) 0z 5 OpenGL 0z gluperspective znear zfar 3:0 10:0 76 4 5 wire teapotc /* * wire_teapotc \* An OpenGL sample program - A wire teapot by the aux library - No lighting - Perspective view by the glu library - No animation */ #include <GL/glh> #include <GL/gluh> #include "auxh" void display (void) { glclear(gl_color_buffer_bit); glcolor3f (10, 10, 10); glpushmatrix(); gltranslatef (00, 00, -50); auxwireteapot(10); /* */ glpopmatrix(); glflush(); void reshape(int width, int height) { GLdouble ang = 600; GLdouble near = 30; GLdouble far = 100;
223 aux library 41 glviewport (0, 0, width, height); glmatrixmode (GL_PROJECTION); glloadidentity (); gluperspective (ang, (GLdouble)width/(GLdouble)height, near, far); glmatrixmode (GL_MODELVIEW); glloadidentity (); int main(int argc, char** argv) { auxinitdisplaymode (AUX_SINGLE AUX_RGB); auxinitposition (0, 0, 500, 500); auxinitwindow (argv[0]); auxreshapefunc (reshape); auxmainloop(display); n end of wire teapotc / 223 aux library wire teapotc aux library main auxinitdisplaymode ( ) auxinitdisplaymode(aux_single AUX_RGB); ( CG ) [ ] auxinitdisplaymode(aux_single AUX_RGB AUX_DEPTH); ( 27 ) ( CG ) [ ] auxinitdisplaymode(aux_double AUX_RGB AUX_DEPTH); auxinitposition auxinitwindow 27 ( 229 )
42 OpenGL auxinitposition(glint x, GLint y, GLsize width, GLsize height) (x; y) ( ) (width; height) ( ) auxinitwindow(glbyte *titlestring) auxreshapefunc(void (*function)(glsizei, GLsizei)) auxreshapefuc function function auxmainloop(void (*displayfunc)(void)) ( ) displayfunc 224 ( ) 76 45 torusc
224 ( ) 43 /* * torusc \* An OpenGL sample program - A torus by the aux library - With the lighting - Perspective view by the glu library - No animation */ #include <GL/glh> #include <GL/gluh> #include "auxh" void initial(void) { GLfloat light_diffuse[] = { 10, 10, 10, 10 ; GLfloat light_ambient[] = { 05, 05, 05, 10 ; GLfloat light_specular[] = { 10, 10, 10, 10 ; GLfloat light_position[] = { 10, 10, 10, 00 ; gllightfv(gl_light0, GL_AMBIENT, light_ambient); gllightfv(gl_light0, GL_SPECULAR, light_specular); gllightfv(gl_light0, GL_DIFFUSE, light_diffuse); gllightfv(gl_light0, GL_POSITION, light_position); glenable(gl_lighting); glenable(gl_light0); gldepthfunc(gl_less); glenable(gl_depth_test); void display (void) { GLfloat mat_diffuse[] = { 10, 10, 10, 10 ; GLfloat mat_ambient[] = { 01, 01, 01, 10 ; GLfloat mat_specular[] = { 09, 09, 09, 10 ; glclear( GL_COLOR_BUFFER_BIT GL_DEPTH_BUFFER_BIT ); glmaterialfv(gl_front, GL_DIFFUSE, mat_diffuse); glmaterialfv(gl_front, GL_AMBIENT, mat_ambient); glmaterialfv(gl_front, GL_SPECULAR, mat_specular); glmaterialf (GL_FRONT, GL_SHININESS, 640); glpushmatrix(); gltranslatef (00, 00, -50); auxsolidtorus(02,10); /* */ glpopmatrix(); glflush(); void reshape(int width, int height) {
44 OpenGL GLdouble ang = 600; GLdouble near = 30; GLdouble far = 100; glviewport (0, 0, width, height); glmatrixmode (GL_PROJECTION); glloadidentity (); gluperspective (ang, (GLdouble)width/(GLdouble)height, near, far); glmatrixmode (GL_MODELVIEW); glloadidentity (); int main(int argc, char **argv) { auxinitdisplaymode (AUX_SINGLE AUX_RGB AUX_DEPTH); auxinitposition (0, 0, 500, 500); auxinitwindow (argv[0]); initial(); auxreshapefunc (reshape); auxmainloop(display); n end of torusc / 45 torus2c gltranslate 76 (2; 1; 09) /* * torus2c \* An OpenGL sample program - Two tori (see torusc) - No animation */
224 ( ) 45 #include <GL/glh> #include <GL/gluh> #include "auxh" void initial(void) { GLfloat light_diffuse[] = { 10, 10, 10, 10 ; GLfloat light_ambient[] = { 05, 05, 05, 10 ; GLfloat light_specular[] = { 10, 10, 10, 10 ; GLfloat light_position[] = { 10, 10, 10, 00 ; gllightfv(gl_light0, GL_AMBIENT, light_ambient); gllightfv(gl_light0, GL_SPECULAR, light_specular); gllightfv(gl_light0, GL_DIFFUSE, light_diffuse); gllightfv(gl_light0, GL_POSITION, light_position); glenable(gl_lighting); glenable(gl_light0); gldepthfunc(gl_less); glenable(gl_depth_test); void display (void) { GLfloat mat_diffuse[] = { 10, 10, 10, 10 ; GLfloat mat_ambient[] = { 01, 01, 01, 10 ; GLfloat mat_specular[] = { 09, 09, 09, 10 ; glclear( GL_COLOR_BUFFER_BIT GL_DEPTH_BUFFER_BIT ); glmaterialfv(gl_front, GL_DIFFUSE, mat_diffuse); glmaterialfv(gl_front, GL_AMBIENT, mat_ambient); glmaterialfv(gl_front, GL_SPECULAR, mat_specular); glmaterialf (GL_FRONT, GL_SHININESS, 640); glpushmatrix(); gltranslatef (00, 00, -50); auxsolidtorus(02,10); gltranslatef (20, 10, -40); auxsolidtorus(02,10); glpopmatrix(); glflush(); void reshape(int width, int height) { GLdouble ang = 600; GLdouble near = 30; GLdouble far = 100; glviewport (0, 0, width, height); glmatrixmode (GL_PROJECTION); glloadidentity ();
46 OpenGL gluperspective (ang, (GLdouble)width/(GLdouble)height, near, far); glmatrixmode (GL_MODELVIEW); glloadidentity (); int main(int argc, char **argv) { auxinitdisplaymode (AUX_SINGLE AUX_RGB AUX_DEPTH); auxinitposition (0, 0, 500, 500); auxinitwindow (argv[0]); initial(); auxreshapefunc (reshape); auxmainloop(display); n end of torus2c / 225 ( ) ( ) glrotate 76 4 5 torus rotatedc torusc display glpushmatrix glpopmatrix glpushmatrix(); gltranslatef (00, 00, -50); glrotatef (-600, 10, 00, 00); auxsolidtorus(02,10); glpopmatrix(); gltranslatef glrotatef ( )2( ) 6= ( )2( )
226 ( ) 47 226 ( ) 76 5 4 torus2 rotatedc torusc display glpushmatrix glpopmatrix glpushmatrix(); gltranslatef (00, 00, -50); glrotatef(-600, 10, 00, 00); auxsolidtorus(02,10); gltranslatef (00, 40, 00); auxsolidtorus(02,10); glpopmatrix(); 1 ( ) 0z 2 x -60 3 4 y 4 5 227 OpenGL ( ) glpushmatrix glpopmatix()
48 OpenGL 28 current matrix current matrix glpushmatrix push current matrix push current matrix glpopmatrix pop current matrix glpushmatrix current matrix OpenGL ( ) glpushmatrix glpopmatrix OpenGL glpushmatrix glpopmatrix \ " OpenGL glpushmatrix glpopmatrix 29 push pop torus2 rotatedc 76 4 5 torus2 rotated2c torusc display glpushmatrix glpopmatrix gltranslatef (00, 00, -50); glpushmatrix(); glrotatef(-600, 10, 00, 00); auxsolidtorus(02,10); glpopmatrix(); glpushmatrix(); gltranslatef (00, 10, 00); 28 UNIX 29 glmatrixmode
228 ( ) 49 auxsolidtorus(02,10); glpopmatrix(); 228 ( ) push pop 76 4 5 linkc /* * linkc \* An OpenGL sample program - Three linked tori (with a ball) - No animation */ #include <GL/glh> #include <GL/gluh> #include "auxh" void initial(void) { GLfloat light_diffuse[] = { 10, 10, 10, 10 ; GLfloat light_ambient[] = { 05, 05, 05, 10 ; GLfloat light_specular[] = { 10, 10, 10, 10 ; GLfloat light_position[] = { 10, 10, 10, 00 ; gllightfv(gl_light0, GL_AMBIENT, light_ambient); gllightfv(gl_light0, GL_SPECULAR, light_specular); gllightfv(gl_light0, GL_DIFFUSE, light_diffuse); gllightfv(gl_light0, GL_POSITION, light_position); glenable(gl_lighting); glenable(gl_light0);
50 OpenGL gldepthfunc(gl_less); glenable(gl_depth_test); void set_mat_color(glfloat *diffuse, GLfloat *ambient, GLfloat *specular) { glmaterialfv(gl_front, GL_DIFFUSE, diffuse); glmaterialfv(gl_front, GL_AMBIENT, ambient); glmaterialfv(gl_front, GL_SPECULAR, specular); void display (void) { GLfloat diffuse0[] = { 10, 10, 10, 10 ; GLfloat ambient0[] = { 01, 01, 01, 10 ; GLfloat specular0[] = { 09, 09, 09, 10 ; GLfloat diffuse1[] = { 10, 10, 00, 10 ; GLfloat ambient1[] = { 01, 01, 00, 10 ; GLfloat specular1[] = { 09, 09, 00, 10 ; GLfloat diffuse2[] = { 10, 00, 10, 10 ; GLfloat ambient2[] = { 01, 00, 01, 10 ; GLfloat specular2[] = { 09, 00, 09, 10 ; GLfloat diffuse3[] = { 00, 10, 10, 10 ; GLfloat ambient3[] = { 00, 01, 01, 10 ; GLfloat specular3[] = { 00, 09, 09, 10 ; glclear( GL_COLOR_BUFFER_BIT GL_DEPTH_BUFFER_BIT ); glmaterialf (GL_FRONT, GL_SHININESS, 640); gltranslatef(00, 00, -50); glrotatef(-700, 10, 00, 00); glpushmatrix(); set_mat_color(diffuse0, ambient0, specular0); auxsolidtorus(02,10); glpushmatrix(); gltranslatef(10, 00, 00); glrotatef(900, 10, 00, 00); set_mat_color(diffuse1, ambient1, specular1); auxsolidtorus(015,05); glpushmatrix(); glrotatef(300, 00, 00, 10); gltranslatef(05, 00, 00); glrotatef(-500, 00, 10, 00); gltranslatef(02, 00, 00); set_mat_color(diffuse3, ambient3, specular3); auxsolidsphere(005); glpopmatrix(); glpopmatrix(); glpushmatrix(); glrotatef(1200, 00, 00, 10); gltranslatef(10, 00, 00); glrotatef(900, 10, 00, 00); set_mat_color(diffuse2, ambient2, specular2);
229 51 auxsolidtorus(015,05); glpopmatrix(); glpushmatrix(); glrotatef(2400, 00, 00, 10); gltranslatef(10, 00, 00); glrotatef(900, 10, 00, 00); set_mat_color(diffuse3, ambient3, specular3); auxsolidtorus(015,05); glpopmatrix(); glpopmatrix(); glflush(); void reshape(int width, int height) { GLdouble ang = 600; GLdouble near = 30; GLdouble far = 100; glviewport (0, 0, width, height); glmatrixmode (GL_PROJECTION); glloadidentity (); gluperspective (ang, (GLdouble)width/(GLdouble)height, near, far); glmatrixmode (GL_MODELVIEW); glloadidentity (); int main(int argc, char **argv) { auxinitdisplaymode (AUX_SINGLE AUX_RGB AUX_DEPTH); auxinitposition (0, 0, 500, 500); auxinitwindow (argv[0]); initial(); auxreshapefunc (reshape); auxmainloop(display); n end of linkc / 229 ( ) CG ( A ) OpenGL ( B ) A B A ( A) B B OpenGL
52 OpenGL 1 main auxinitdisplaymode() AUX_DOUBLE 2 main auxidlefunc() 3 auxidlefunc() auxmainloop() 4 glflush() glxswapbuffers() glxswapbuers glx glxswapbuers glflush glflush glxswapbuers 76 4 5 swing torusc /* * swing_torusc \* An OpenGL sample program - Animation - A rotating torus (see torusc) */ #include <GL/glh> #include <GL/gluh> #include "auxh" static GLdouble spin=00; void initial(void) { GLfloat light_diffuse[] = { 10, 10, 10, 10 ; GLfloat light_ambient[] = { 05, 05, 05, 10 ; GLfloat light_specular[] = { 10, 10, 10, 10 ; GLfloat light_position[] = { 10, 10, 10, 00 ; gllightfv(gl_light0, GL_AMBIENT, light_ambient);
229 53 gllightfv(gl_light0, GL_SPECULAR, light_specular); gllightfv(gl_light0, GL_DIFFUSE, light_diffuse); gllightfv(gl_light0, GL_POSITION, light_position); glenable(gl_lighting); glenable(gl_light0); glenable(gl_depth_test); void display (void) { GLfloat mat_diffuse[] = { 10, 10, 10, 10 ; GLfloat mat_ambient[] = { 01, 01, 01, 10 ; GLfloat mat_specular[] = { 09, 09, 09, 10 ; glclear( GL_COLOR_BUFFER_BIT GL_DEPTH_BUFFER_BIT ); glmaterialfv(gl_front, GL_DIFFUSE, mat_diffuse); glmaterialfv(gl_front, GL_AMBIENT, mat_ambient); glmaterialfv(gl_front, GL_SPECULAR, mat_specular); glmaterialf (GL_FRONT, GL_SHININESS, 640); glpushmatrix(); gltranslatef (00, 00, -50); glrotatef (spin, 10, 00, 00); glrotatef (spin, 00, 10, 10); auxsolidtorus(02,10); glpopmatrix(); glxswapbuffers(auxxdisplay(), auxxwindow()); void rotation(void) { spin += 15; if (spin > 3600) spin -= 3600; display(); void reshape(int width, int height) { GLdouble ang = 600; GLdouble near = 30; GLdouble far = 100; glviewport (0, 0, width, height); glmatrixmode (GL_PROJECTION); glloadidentity (); gluperspective (ang, (GLdouble)width/(GLdouble)height, near, far); glmatrixmode (GL_MODELVIEW); glloadidentity (); int main(int argc, char **argv) { auxinitdisplaymode (AUX_DOUBLE AUX_RGBA AUX_DEPTH);
54 OpenGL auxinitposition (0, 0, 500, 500); auxinitwindow (argv[0]); initial(); auxreshapefunc (reshape); auxidlefunc(display); auxmainloop(rotation); n end of swing torusc / 230 76 4 5 link animec linkc ( ) ( ) /* * link_anmimec \* An OpenGL sample program - Animation */ #include <GL/glh> #include <GL/gluh> #include "auxh" static GLdouble toroidal_spin = 00; static GLdouble ball1_spin = 00; static GLdouble ball2_spin = 00; static GLdouble ball3_spin = 00; void initial(void) {
230 55 GLfloat light_diffuse[] = { 10, 10, 10, 10 ; GLfloat light_ambient[] = { 05, 05, 05, 10 ; GLfloat light_specular[] = { 10, 10, 10, 10 ; GLfloat light_position[] = { 10, 10, 10, 00 ; gllightfv(gl_light0, GL_AMBIENT, light_ambient); gllightfv(gl_light0, GL_SPECULAR, light_specular); gllightfv(gl_light0, GL_DIFFUSE, light_diffuse); gllightfv(gl_light0, GL_POSITION, light_position); glenable(gl_lighting); glenable(gl_light0); gldepthfunc(gl_less); glenable(gl_depth_test); void set_mat_color(glfloat *diffuse, GLfloat *ambient, GLfloat *specular) { glmaterialfv(gl_front, GL_DIFFUSE, diffuse); glmaterialfv(gl_front, GL_AMBIENT, ambient); glmaterialfv(gl_front, GL_SPECULAR, specular); void display (void) { GLfloat diffuse0[] = { 10, 10, 10, 10 ; GLfloat ambient0[] = { 01, 01, 01, 10 ; GLfloat specular0[] = { 09, 09, 09, 10 ; GLfloat diffuse1[] = { 10, 10, 00, 10 ; GLfloat ambient1[] = { 01, 01, 00, 10 ; GLfloat specular1[] = { 09, 09, 00, 10 ; GLfloat diffuse2[] = { 10, 00, 10, 10 ; GLfloat ambient2[] = { 01, 00, 01, 10 ; GLfloat specular2[] = { 09, 00, 09, 10 ; GLfloat diffuse3[] = { 00, 10, 10, 10 ; GLfloat ambient3[] = { 00, 01, 01, 10 ; GLfloat specular3[] = { 00, 09, 09, 10 ; glclear( GL_COLOR_BUFFER_BIT GL_DEPTH_BUFFER_BIT ); glmaterialf (GL_FRONT, GL_SHININESS, 640); glpushmatrix(); gltranslatef(00, 00, -50); glrotatef(-700, 10, 00, 00); glrotatef(toroidal_spin, 00, 00, 10); glpushmatrix(); set_mat_color(diffuse0, ambient0, specular0); auxsolidtorus(02,10); glpushmatrix(); gltranslatef(10, 00, 00); glrotatef(900, 10, 00, 00); set_mat_color(diffuse1, ambient1, specular1); auxsolidtorus(015,05); glpushmatrix();
56 OpenGL glrotatef(ball1_spin, 00, 00, 10); gltranslatef(05, 00, 00); glrotatef(ball1_spin*5, 00, 10, 00); gltranslatef(018, 00, 00); set_mat_color(diffuse3, ambient3, specular3); auxsolidsphere(005); glpopmatrix(); glpopmatrix(); glpushmatrix(); glrotatef(1200, 00, 00, 10); gltranslatef(10, 00, 00); glrotatef(900, 10, 00, 00); set_mat_color(diffuse2, ambient2, specular2); auxsolidtorus(015,05); glpushmatrix(); glrotatef(ball2_spin, 00, 00, 10); gltranslatef(05, 00, 00); glrotatef(ball2_spin*5, 00, 10, 00); gltranslatef(018, 00, 00); set_mat_color(diffuse1, ambient1, specular1); auxsolidsphere(005); glpopmatrix(); glpopmatrix(); glpushmatrix(); glrotatef(2400, 00, 00, 10); gltranslatef(10, 00, 00); glrotatef(900, 10, 00, 00); set_mat_color(diffuse3, ambient3, specular3); auxsolidtorus(015,05); glpushmatrix(); glrotatef(ball3_spin, 00, 00, 10); gltranslatef(05, 00, 00); glrotatef(ball3_spin*5, 00, 10, 00); gltranslatef(030, 00, 00); set_mat_color(diffuse2, ambient2, specular2); auxsolidcube(020); glpopmatrix(); glpopmatrix(); glpopmatrix(); glpopmatrix(); glxswapbuffers(auxxdisplay(), auxxwindow()); void rotation(void) { toroidal_spin += 10; ball1_spin += 80; ball2_spin += 40; ball3_spin += 10; display();
231 57 void reshape(int width, int height) { GLdouble ang = 600; GLdouble near = 30; GLdouble far = 100; glviewport (0, 0, width, height); glmatrixmode (GL_PROJECTION); glloadidentity (); gluperspective (ang, (GLdouble)width/(GLdouble)height, near, far); glmatrixmode (GL_MODELVIEW); glloadidentity (); int main(int argc, char **argv) { auxinitdisplaymode (AUX_DOUBLE AUX_RGB AUX_DEPTH); auxinitposition (0, 0, 500, 500); auxinitwindow (argv[0]); initial(); auxreshapefunc (reshape); auxidlefunc(display); auxmainloop(rotation); n end of link animec / 231 OpenGL \ " OpenGL ( ) \ " (gltranslatef ) (gluperspective ) CompleXcope p15 simple3c glbegin(gl_points); for (i=0; i<6; i++) { x = cos(i*pi/3); y = sin(i*pi/3); glvertex3f(x, y, 00); glend();
58 OpenGL ( ) OpenGL ( ) OpenGL OpenGL glnewlist glendlist OpenGL GLuint int list_no = 1; glnewlist(list_no, GL_COMPILE); glendlist(); glcalllist(1); (1) (2) (3) (4)
76 4 231 5 59 circlesc /* * circlesc \* An OpenGL sample program - No Lighting - Display List */ #include <mathh> #include <GL/glh> #include <GL/gluh> #include "auxh" #define PI 314159265358979 #define TWOPI (2*PI) GLuint list1 = 1; void initial(void) { int i; GLfloat x,y; glnewlist(list1, GL_COMPILE); glcolor3f(10, 10, 00); gltranslatef(15, 00, 00); glbegin(gl_line_loop); for (i=0; i<100; i++) { x = 08*cos(TWOPI*i/1000); y = 08*sin(TWOPI*i/100); glvertex3f(x,y,00); glend(); gltranslatef(-15, 00, 00); glrotatef(200, 00, 00, 10); gltranslatef(00, 00, -10); glendlist(); glshademodel(gl_flat); void display (void) { int i; glclear(gl_color_buffer_bit); gltranslatef (00, 00, -50); glpushmatrix(); for (i=0; i<200; i++) glcalllist(list1); glpopmatrix(); glflush();
60 OpenGL void reshape(int width, int height) { GLdouble ang = 600; GLdouble near = 30; GLdouble far = 10000; glviewport (0, 0, width, height); glmatrixmode (GL_PROJECTION); glloadidentity (); gluperspective (ang, (GLdouble)width/(GLdouble)height, near, far); glmatrixmode (GL_MODELVIEW); glloadidentity (); int main(int argc, char** argv) { auxinitdisplaymode (AUX_SINGLE AUX_RGB); auxinitposition (0, 0, 500, 500); auxinitwindow (argv[0]); initial(); auxreshapefunc (reshape); auxmainloop(display); n end of circlesc / OpenGL OpenGL GLuint glgenlists(1); n n GLuint glgenlists(n); n ` ` +1, ` +2, 111, ` + n 0 1 232 p24 OpenGL ( ) CG
232 61 RGB GLubyte image[width][height][3] RGB (0 255) R,G,B WIDTH 2 HEIGHT WIDTH HEIGHT 2 64 OpenGL pict gif AVS (*x) AVS width height ARGB 0 255 AVS width height ( A) Appendix D ( \texturesample256x256") OpenGL OpenGL Programming Guide [4, 5] width height 256 76 45 texturec
62 OpenGL /* * texturec \* An OpenGL sample program - Texuture Mapping */ #include <stdioh> #include <GL/glh> #include <GL/gluh> #include "auxh" #define IMAGEWIDTH 256 #define IMAGEHEIGHT 256 char image[imagewidth][imageheight][3]; GLuint texidx = 1; void initial(void) { FILE *fp; fp = fopen("texturesample256x256","r"); if (fp==null) { printf(" open err; image file\n"); exit(9); fread(image, 1, IMAGEWIDTH*IMAGEHEIGHT*3, fp); fclose(fp); glpixelstorei(gl_unpack_alignment, 1); gltexenvf(gl_texture_env, GL_TEXTURE_ENV_MODE, GL_DECAL); gltexparameterf(gl_texture_2d, GL_TEXTURE_MAG_FILTER, GL_NEAREST); gltexparameterf(gl_texture_2d, GL_TEXTURE_MIN_FILTER, GL_NEAREST); gltexparameterf(gl_texture_2d, GL_TEXTURE_WRAP_S, GL_CLAMP); gltexparameterf(gl_texture_2d, GL_TEXTURE_WRAP_T, GL_CLAMP); glnewlist(texidx, GL_COMPILE); glteximage2d(gl_texture_2d, 0, 3, IMAGEWIDTH, IMAGEHEIGHT, 0, GL_RGB, GL_UNSIGNED_BYTE, &image[0][0][0]); glpushmatrix(); glbegin(gl_quads); gltexcoord2f(00, 10); glvertex3f(-10, -10, 00); gltexcoord2f(10, 10); glvertex3f( 10, -10, 00); gltexcoord2f(10, 00); glvertex3f( 10, 10, 00); gltexcoord2f(00, 00); glvertex3f(-10, 10, 00); glend(); glpopmatrix(); glendlist();
232 63 glclearcolor(0, 0, 0, 0); void display (void) { int i; glclear( GL_COLOR_BUFFER_BIT GL_DEPTH_BUFFER_BIT ); gldisable(gl_lighting); glenable(gl_texture_2d); gltranslatef (00, -25, -50); for (i=2; i>=-2; i--) { glpushmatrix(); glrotatef(i*200, 00, 00, 10); gltranslatef(00, 30, 00); glcalllist(texidx); glpopmatrix(); glflush(); void reshape(int width, int height) { GLdouble ang = 600; GLdouble near = 30; GLdouble far = 150; glviewport (0, 0, width, height); glmatrixmode (GL_PROJECTION); glloadidentity (); gluperspective (ang, (GLdouble)width/(GLdouble)height, near, far); glmatrixmode (GL_MODELVIEW); glloadidentity (); int main(int argc, char **argv) { auxinitdisplaymode (AUX_SINGLE AUX_RGB AUX_DEPTH); auxinitposition (0, 0, 500, 500); auxinitwindow (argv[0]); initial(); auxreshapefunc (reshape); auxmainloop(display); n end of texturec /
64 OpenGL
3 CAVE 31 CompleXcope CompleXcope OpenGL CAVE CAVE 1 2 10 x 10 3 4 SGI ONYX, 4 x CPU R4400, Main mem 512MB, 3 x Reality Engine II 5 6 7 8 Ascention Technology "Flock of Bird" 9 32 CompleXcope VR ONYX 316 33 CAVE CAVE CAVE CAVE /usr/local/cave 65
66 CAVE /usr/local/cave/include /usr/local/cave/lib /usr/local/cave/bin 34 CAVE CAVE +x +y +z / y / / / / / / x / / / / / / / / z / / / / / / +---------------------------------+ CompleXcope -5 <= x <= +5 0 <= y <= +10-5 <= z <= +5 35 CompleXcope
36 Conguration File 67 1 display process (1) 2 display process (2) 3 display process (3) 4 application computation process 5 tracking process display process CompleXcope display process application computation process CAVE tracking process ONYX (shared memorry) 36 Conguration File CAVE caverc conguration le # sample of caverc simulator y DisplayMode mono conguration le CAVE simulator on VR CompleXcope ONYX DisplayMode mono CompleXcope CAVE con- guration le 1 ( ) /usr/local/cave/etc/caveconfig /usr/local/cave/etc/asoconfig ~/caverc /caverc (CompleXcope ) ~/caverc /caverc (# ) 37 CompleXcope 76 5 4 (1) (Optional) CompleXcope CompleXcope CAVE ( ) 1 aso CompleXcope ONYX host name
76 4 68 5 CAVE (2) (Required) CAVE conguration CAVE conguration le conguration le 7 6 5 4 (3) (Optional) 7 6 4 5 (4) (Required) CAVE 76 5 4 (5) (Optional) OpenGL display process application computation process tracking process fork CAVE 76 OpenGL ( ) 4 fork ( ) display process CAVE 5 (6) (Required) display 6 4 5 (7) (Optional) computation 7 OpenGL display process CAVE 6 4 5 (8) (Required) CAVE 7 38 CAVE CompleXcope CompleXcope CAVE CAVE CAVE X Window CAVE conguration le simulator y 2 CAVE CompleXcope CAVE 2 on
39 69 CAVE left arrow right arrow Up arrow Down arrow Shift + up arrow Shift + donw arrow Alt + left arrow Alt + right arrow Alt + up arrow Alt + down arrow p move left move right move forward move backward move up move down rotate left rotate right rotate up rotate down reset head and wand to initial CAVE Cntl + mouse movement move wnad left/right/forward/back Shift + mouse movement move wand left/right/up/down Alt + mouse movement rotate wand/left/right/up/down < and > rotate wand about Z Home reset wand to be in front of user F1/F2/F3/ select wand 1/2/3/ as the current wand CAVE mouse left button mouse middle button mouse right button Space + mouse movement wand left button wand middle button wand right button joystick CAVE 1 CAVE 2 CAVE w / u / INSERT CAVE / 39 p42 OpenGL torusc ( ) CompleXcope VR
76 45 70 CAVE Xtorusc /* * Xtorusc \* A CompleXcope sample program - A torus by aux lib; 4 feet off the floor - Copied and changed from /usr/local/cave/src/ogl/ballc - No animation - No interaction - No navigation */ #include <cave_oglh> /* init_gl - GL initialization function This function will be called exactly once by each of the drawing processes, at the beginning of the next frame after the pointer to it is passed to CAVEInitApplication It defines and binds the light and material data for the rendering */ void init_gl(void) { GLfloat mat_diffuse[] = { 10, 10, 10, 10 ; GLfloat mat_ambient[] = { 01, 01, 01, 10 ; GLfloat mat_specular[] = { 09, 09, 09, 10 ; GLfloat light_diffuse[] = { 10, 10, 10, 10 ; GLfloat light_ambient[] = { 05, 05, 05, 10 ; GLfloat light_specular[] = { 10, 10, 10, 10 ; GLfloat light_position[] = { 10, 10, 10, 00 ; glclearcolor(0, 0, 0, 0); gllightfv(gl_light0, GL_AMBIENT, light_ambient); gllightfv(gl_light0, GL_SPECULAR, light_specular); gllightfv(gl_light0, GL_DIFFUSE, light_diffuse); gllightfv(gl_light0, GL_POSITION, light_position); glmaterialfv(gl_front_and_back, GL_DIFFUSE, mat_diffuse); glmaterialfv(gl_front_and_back, GL_AMBIENT, mat_ambient); glmaterialfv(gl_front_and_back, GL_SPECULAR, mat_specular); glmaterialf (GL_FRONT_AND_BACK, GL_SHININESS, 640); glenable(gl_light0); /* draw_torus - the display function This function is called by the CAVE library in the rendering processes' display loop It draws a torus 4 feet off the floor */ void draw_torus(void) { glclear(gl_depth_buffer_bit GL_COLOR_BUFFER_BIT);
39 71 glenable(gl_lighting); glpushmatrix(); gltranslatef(00, 40, -20); auxsolidtorus(02,10); glpopmatrix(); gldisable(gl_lighting); main(int argc,char **argv) { /* Initialize the CAVE */ CAVEConfigure(&argc,argv,NULL); CAVEInit(); /* Give the library a pointer to the GL initialization function */ CAVEInitApplication(init_gl,0); /* Give the library a pointer to the drawing function */ CAVEDisplay(draw_torus,0); /* Wait for the escape key to be hit */ while (!CAVEgetbutton(CAVE_ESCKEY)) sginap(10); /* Nap so that this busy loop doesn't waste CPU time */ /* Clean up & exit */ CAVEExit(); n end of Xtorusc / \CAVE" CAVE CAVEConfigure() Configuration CAVEInit() CAVE fork CAVEInitApplication() OpenGL init_gl() ( ) OpenGL CAVEDisplay() draw_torus() ( )OpenGL
72 CAVE CAVEgetbutton(CAVE_ESCKEY) ESC hit sginap() CAVEExit() 310 Xtoursc \auxsolidtorus" \auxsolidsphere" 6 4 5 Xballc aux 7 glu (p33 ) /* * Xballc \* A CompleXcope sample program - A ball by the glu lib; 1 feet radius, 4 feet off the floor - Copied and changed from /usr/local/cave/src/ogl/ballc - No animation - No interaction - No navigation */ #include <cave_oglh> #include <GL/gluh> static GLUquadricObj *sphereobj; /* init_gl - GL initialization function This function will be called exactly once by each of the drawing processes, at the beginning of the next frame after the pointer to it is passed to CAVEInitApplication It defines and binds the light and material data for the rendering, and creates a quadric object to use when drawing the sphere */ void init_gl(void) { GLfloat mat_diffuse[] = { 10, 10, 10, 10 ; GLfloat mat_ambient[] = { 01, 01, 01, 10 ; GLfloat mat_specular[] = { 09, 09, 09, 10 ; GLfloat light_diffuse[] = { 10, 10, 10, 10 ; GLfloat light_ambient[] = { 05, 05, 05, 10 ; GLfloat light_specular[] = { 10, 10, 10, 10 ;
310 73 GLfloat light_position[] = { 10, 10, 10, 00 ; glclearcolor(0, 0, 0, 0); gllightfv(gl_light0, GL_AMBIENT, light_ambient); gllightfv(gl_light0, GL_SPECULAR, light_specular); gllightfv(gl_light0, GL_DIFFUSE, light_diffuse); gllightfv(gl_light0, GL_POSITION, light_position); glmaterialfv(gl_front, GL_DIFFUSE, mat_diffuse); glmaterialfv(gl_front, GL_AMBIENT, mat_ambient); glmaterialfv(gl_front, GL_SPECULAR, mat_specular); glmaterialf (GL_FRONT, GL_SHININESS, 640); glenable(gl_light0); sphereobj = glunewquadric(); /* draw_ball - the display function This function is called by the CAVE library in the rendering processes' display loop It draws a ball 1 foot in radius, 4 feet off the floor, and 2 foot in front of the front wall (assuming a 10' CAVE) */ void draw_ball(void) { glclear(gl_depth_buffer_bit GL_COLOR_BUFFER_BIT); glenable(gl_lighting); glpushmatrix(); gltranslatef(00, 40, -30); glusphere(sphereobj, 10, 16, 16); glpopmatrix(); gldisable(gl_lighting); main(int argc,char **argv) { /* Initialize the CAVE */ CAVEConfigure(&argc,argv,NULL); CAVEInit(); /* Give the library a pointer to the GL initialization function */ CAVEInitApplication(init_gl,0); /* Give the library a pointer to the drawing function */ CAVEDisplay(draw_ball,0); /* Wait for the escape key to be hit */ while (!CAVEgetbutton(CAVE_ESCKEY)) sginap(10); /* Nap so that this busy loop doesn't waste CPU time */ /* Clean up & exit */ CAVEExit(); n end of Xballc /
74 CAVE 311 3 ( ) p52 swing torusc CompleXcope 7 6 /* \* */ * Xswing_torusc A CompleXcope sample program 4 5 Xswing torusc - Copied and changed from /usr/local/cave/src/ogl/bouncec - A rotating torus - Calculation of their movements are performed in the main process - It is communicated to the three drawing processes through the shared memory - No interaction - No navigation #include <cave_oglh> #include <GL/gluh> /* The data that will be shared between processes */ struct _torusdata { float angle1; float angle2; ; void init_gl(void),draw(struct _torusdata *); struct _torusdata *init_shmem(void); void compute(struct _torusdata *); main(int argc, char **argv) { struct _torusdata *torus; CAVEConfigure(&argc,argv,NULL); torus = init_shmem(); CAVEInit(); CAVEInitApplication(init_gl,0); CAVEDisplay(draw,1,torus); while (!CAVEgetbutton(CAVE_ESCKEY)) { compute(torus); sginap(1); CAVEExit(); struct _torusdata *init_shmem(void) { struct _torusdata *torus; torus = CAVEMalloc(sizeof(struct _torusdata)); bzero(torus,sizeof(struct _torusdata)); return torus;
311 3( ) 75 void compute(struct _torusdata *torus) { float t = CAVEGetTime(); torus->angle1 = t*50; torus->angle2 = t*73; void init_gl(void) { GLfloat light_diffuse[] = { 10, 10, 10, 10 ; GLfloat light_ambient[] = { 05, 05, 05, 10 ; GLfloat light_specular[] = { 10, 10, 10, 10 ; GLfloat light_position[] = { 10, 10, 10, 00 ; glenable(gl_light0); glclearcolor(0, 0, 0, 0); gllightfv(gl_light0, GL_AMBIENT, light_ambient); gllightfv(gl_light0, GL_SPECULAR, light_specular); gllightfv(gl_light0, GL_DIFFUSE, light_diffuse); gllightfv(gl_light0, GL_POSITION, light_position); void draw(struct _torusdata *torus) { glclear(gl_depth_buffer_bit GL_COLOR_BUFFER_BIT); glenable(gl_lighting); gltranslatef(00, 40, -30); glpushmatrix(); glrotatef(torus->angle1, 10, 00, 00); glrotatef(torus->angle2, 00, 10, 10); auxsolidtorus(02, 10); glpopmatrix(); gldisable(gl_lighting); n end of Xswing torusc / Xtorusc Xballc main while() compute() (angle1 angle2) comupte() (application computation process) application computation process 3 CAVE shared memory torus torus shared memory shared memory init shmem() CAVEMalloc()
76 CAVE CAVE shared memory 8MB CAVESetOption(CAVE_SHMEM_SIZE, size_in_bytes) CAVEConfigure() 312 4 76 4 5 Xbouncec /* * Xbouncec \* A CompleXcope sample program - Copied and changed from /usr/local/cave/src/ogl/bouncec - Two bouncing balls - Calculation of their movements are performed in the main process - It is communicated to the three drawing processes through the shared memory - No interaction - No navigation */ #include <cave_oglh> #include <GL/gluh> /* The data that will be shared between processes */ struct _balldata { float y; ; void init_gl(void),draw_balls(struct _balldata *); struct _balldata *init_shmem(void); void compute(struct _balldata *); main(int argc, char **argv) { struct _balldata *ball; CAVEConfigure(&argc,argv,NULL); /* Initialize shared memory */ ball = init_shmem(); CAVEInit(); CAVEInitApplication(init_gl,0); /* Give the library a pointer to the drawing function, plus one argument */ CAVEDisplay(draw_balls,1,ball);
312 4 77 while (!CAVEgetbutton(CAVE_ESCKEY)) { /* Update the balls' positions */ compute(ball); sginap(1); CAVEExit(); /* init_shmem - initializes shared memory The data is allocated from a shared memory arena, and so will be common to all processes forked after this is called */ struct _balldata *init_shmem(void) { struct _balldata *ball; ball = CAVEMalloc(2*sizeof(struct _balldata)); bzero(ball,2*sizeof(struct _balldata)); return ball; /* compute - compute new positions for the balls The height of the balls is a function of the current CAVE time */ void compute(struct _balldata *ball) { float t = CAVEGetTime(); ball[0]y = fabs(sin(t)) * 5 + 1; ball[1]y = fabs(sin(t*12)) * 3 + 1; static GLuint redmat, bluemat; static GLUquadricObj *sphereobj; /* init_gl - initialize GL lighting & materials */ void init_gl(void) { float redmaterial[] = { 1, 0, 0, 1 ; float bluematerial[] = { 0, 0, 1, 1 ; GLfloat light_diffuse[] = { 10, 10, 10, 10 ; GLfloat light_ambient[] = { 05, 05, 05, 10 ; GLfloat light_specular[] = { 10, 10, 10, 10 ; GLfloat light_position[] = { 10, 10, 10, 00 ; glclearcolor(0, 0, 0, 0); glenable(gl_light0); gllightfv(gl_light0, GL_AMBIENT, light_ambient); gllightfv(gl_light0, GL_SPECULAR, light_specular); gllightfv(gl_light0, GL_DIFFUSE, light_diffuse); gllightfv(gl_light0, GL_POSITION, light_position); /* 1st display list */ redmat = glgenlists(1);
78 CAVE glnewlist(redmat, GL_COMPILE); glmaterialfv(gl_front_and_back, GL_AMBIENT_AND_DIFFUSE, redmaterial); glendlist(); /* 2nd display list */ bluemat = glgenlists(1); glnewlist(bluemat, GL_COMPILE); glmaterialfv(gl_front_and_back, GL_AMBIENT_AND_DIFFUSE, bluematerial); glendlist(); sphereobj = glunewquadric(); /* draw_balls - draw the two balls, using the shared data for their y coordinates */ void draw_balls(struct _balldata *ball) { glclear(gl_depth_buffer_bit GL_COLOR_BUFFER_BIT); glenable(gl_lighting); glcalllist(redmat); glpushmatrix(); gltranslatef(30, ball[0]y, 00); glusphere(sphereobj, 10, 16, 16); glpopmatrix(); glcalllist(bluemat); glpushmatrix(); gltranslatef(00, ball[1]y, -30); glusphere(sphereobj, 10, 16, 16); glpopmatrix(); gldisable(gl_lighting); n end of Xbouncec / 313 5 glenable(gl LIGHTING) OpenGL GL LIGHTING 6 5 4 Xsnowfallc o OpenGL 7 CompleXcope /* * Xsnowfallc \* A CompleXcope sample program - Snow fall - No lighting
313 5 79 */ - No interaction - No navigation #include <cave_oglh> #include <GL/gluh> #include <stdlibh> #define NCOMMET 500 #define XMAX 200 #define YMAX 200 #define ZMAX 100 #define XMIN (-200) #define YMIN (-50) #define ZMIN (-200) /* The data that will be shared between processes */ struct _snowdata { float xpos; float ypos; float zpos; float xaxis; float yaxis; float zaxis; float spin; float vx; float vy; float vz; ; void init_gl(void),draw(struct _snowdata *); struct _snowdata *init_shmem(void); void compute(struct _snowdata *); static GLuint flake_indx; main(int argc, char **argv) { struct _snowdata *snows; CAVEConfigure(&argc,argv,NULL); snows = init_shmem(); CAVEInit(); CAVEInitApplication(init_gl,0); CAVEDisplay(draw,1,snows); while (!CAVEgetbutton(CAVE_ESCKEY)) { compute(snows); sginap(1); CAVEExit(); float ransu(void) {
80 CAVE float r = rand() / 327680; return r; struct _snowdata *init_shmem(void) { int i; struct _snowdata *snows; snows = CAVEMalloc(NCOMMET*sizeof(struct _snowdata)); bzero(snows,ncommet*sizeof(struct _snowdata)); for (i=0; i<ncommet; i++) { snows[i]xpos = XMIN + (XMAX-XMIN)*ransu(); snows[i]ypos = YMIN + (YMAX-YMIN)*ransu(); snows[i]zpos = ZMIN + (ZMAX-ZMIN)*ransu(); snows[i]xaxis = ransu(); snows[i]yaxis = ransu(); snows[i]zaxis = ransu(); return snows; void compute(struct _snowdata *snows) { intsnows
314 81 glvertex3f(-flake_size/2, 00, 00); glend(); glendlist(); flake_indx = glgenlists(1); glnewlist(flake_indx, GL_COMPILE); glpushmatrix(); glcalllist(tmp_indx); glpushmatrix(); glrotatef(1800, 10, 00, 00); gltranslatef(00, -flake_size/sqrt(30), 00); glcalllist(tmp_indx); glpopmatrix(); glendlist(); void draw(struct _snowdata *snows) { int i; glclear(gl_depth_buffer_bit GL_COLOR_BUFFER_BIT); for (i=0; i<ncommet; i++) { glpushmatrix(); gltranslatef(snows[i]xpos, snows[i]ypos, snows[i]zpos); glrotatef(snows[i]spin, snows[i]xaxis, snows[i]yaxis, snows[i]zaxis); glcalllist(flake_indx); glpopmatrix(); n end of Xsnowfallc / VR 3 ( draw) glenable(gl LIGHTING) gldisable(gl LIGHTING) 314 on CAVE p39 OpenGL ( ) CAVE CAVENear CAVE- Far global oat CAVENear = 01 ( ) CAVEFar = 100 ( ) 3
82 CAVE 315 CAVE CAVEMalloc() ( ) CAVEExit() 4 ( ) CAVEMalloc() ipcs {m {b active % ipcs -m -b IPC status from /dev/kmem as of Mon Jul 13 11:52:15 1998 T ID KEY MODE OWNER GROUP SEGSZ Shared Memory: m 0 0x53637444 --rw-r--r-- root sys 136 m 1 0x00002648 --rw-rw-rw- root sys 228 m 2 0x00002649 --rw-rw-rw- root sys 140 m 3 0x000007c8 --rw-rw-rw- root sys 4 m 4 0x000009a4 --rw-rw-rw- guest guest 55912 guest 55912 \ipcrm {m <ID>" aso% ipcrm -m 4 aso% ipcs -m -b IPC status from /dev/kmem as of Mon Jul 13 11:52:27 1998 T ID KEY MODE OWNER GROUP SEGSZ Shared Memory: m 0 0x53637444 --rw-r--r-- root sys 136 m 1 0x00002648 --rw-rw-rw- root sys 228 m 2 0x00002649 --rw-rw-rw- root sys 140 m 3 0x000007c8 --rw-rw-rw- root sys 4 316 CompleXcope 5 x-y (jxj 1, jyj 1) 4 CAVEFree() 5 CAVE
317 83 /1 2 3\ / O O O \ / J \ J: \ \ / / \ / : y +----- x CAVE 1 2 ( ) 3 (push/nonpush) 4 5 ( ) (x,y) 317 CAVE tracking process tracking process CAVEInit CAVElibrary tracking process void CAVEGetPosition(CAVEID posid, float position[3]) posid CAVE HEAD, CAVE WAND, CAVE LEFT EYE, CAVE RIGHT EYE, CAVE HEAD NAV, CAVE WAND NAV, CAVE LEFT EYE NAV, CAVE RIGHT EYE NAV CAVE_HEAD : ( ) CAVE_WAND : CAVE_LEFT_EYE : CAVE_RIGHT_EYE : CAVE_HEAD_NAV : CAVE_WAND_NAV : CAVE_LEFT_EYE_NAV : CAVE_RIGHT_EYE_NAV :
84 CAVE CAVE 05 x 5, 0 y 10, 05 z 5 (feet) 318 void CAVEGetVector(CAVEID vectorid, float vector[3]) vectorid CAVE_HEAD_FRONT, CAVE_HEAD_BACK, CAVE_HEAD_LEFT, CAVE_HEAD_RIGHT, CAVE_HEAD_UP, CAVE_HEAD_DOWN, CAVE_WAND_FRONT, CAVE_WAND_BACK, CAVE_WAND_LEFT, CAVE_WAND_RIGHT, CAVE_WAND_UP, CAVE_WAND_DOWN, CAVE_HEAD_FRONT_NAV, CAVE_HEAD_BACK_NAV, CAVE_HEAD_LEFT_NAV, CAVE_HEAD_RIGHT_NAV, CAVE_HEAD_UP_NAV, CAVE_HEAD_DOWN_NAV, CAVE_WAND_FRONT_NAV, CAVE_WAND_BACK_NAV, CAVE_WAND_LEFT_NAV, CAVE_WAND_RIGHT_NAV, CAVE_WAND_UP_NAV, CAVE_WAND_DOWN, CAVE WAND FRONT CAVEGetVector vector 319 ( ) ( ) int CAVEButtonChange(int button) /* button = 1,2, or 3 */ 0 1 2
320 85 320 CompleXcope CAVEBUTTON1 CAVEBUTTON2 CAVEBUTTON3 1 2 3 1 0 if (CAVEBUTTON1) { procedure to be done when button 1 (left) is pressed if (!CAVEBUTTON2) { procedure to be done when button 2 (middle) is not pressed 321 CAVE_JOYSTIC_X CAVE_JOYSTIC_Y x,y [01:0; 1:0] oat ( ) 00
86 CAVE if (fabs(cave_joystic_y)>02) { /* procedure to be done when joystick is pushed forward or backward */ 322 \ " 76 45 interactc /* * interactc \* A CompleXcope sample program - Copied and changed from /usr/local/cave/src/ogl/interactc - A sample program for the CAVE interaction procedure - A ball appears when wand left button is pressed at the wand tip - The ball is grabbed when wand middle button is pressed - The ball is destroyed when wand right button is pressed - No navigation */ #include <cave_oglh> #include <GL/gluh> #define SQR(x) ((x)*(x)) struct _balldata { float x,y,z; float radius; int grabbed; int exist; ; static GLuint mat0, mat1; void init_gl(void);
322 87 void draw_ball(struct _balldata *); void check_add(struct _balldata *); struct _balldata * init_shmem(void); void update_held(struct _balldata *); void check_grab(struct _balldata *); main(int argc,char **argv) { struct _balldata *ball; CAVEConfigure(&argc,argv,NULL); ball = init_shmem(); CAVEInit(); CAVEInitApplication(init_gl, 0); CAVEDisplay(draw_ball, 1, ball); while (!CAVEgetbutton(CAVE_ESCKEY)) { check_add(ball); if ( ball->grabbed ) update_held(ball); else check_grab(ball); sginap(1); CAVEExit(); /************\ > check_add < \************/ void check_add(struct _balldata *ball) { float wandpos[3], wandfront[3]; if (CAVEButtonChange(1) == -1) { /* left button is released */ CAVEGetPosition(CAVE_WAND, wandpos); /* wand position */ CAVEGetVector(CAVE_WAND_FRONT, wandfront); /* wand direction */ ball->x = wandpos[0] + wandfront[0]*05; ball->y = wandpos[1] + wandfront[1]*05; ball->z = wandpos[2] + wandfront[2]*05; ball->radius = 1; ball->grabbed = 0; ball->exist = 1; if (CAVEButtonChange(3) == 1) ball->exist = 0; /*************\ > init_shmem < \*************/ struct _balldata * init_shmem(void) { struct _balldata *ball; ball = (struct _balldata *)CAVEMalloc(sizeof(struct _balldata)); bzero(ball, sizeof(struct _balldata));
88 CAVE return ball; /**************\ > update_held < \**************/ void update_held(struct _balldata *ball) { float wandpos[3]; if (!CAVEBUTTON2) { CAVEGetPosition(CAVE_WAND, wandpos); ball->x = wandpos[0]; ball->y = wandpos[1]; ball->z = wandpos[2]; ball->grabbed = 0; else { if (CAVE_JOYSTICK_Y > 5) /* Joystick pushed forward */ ball->radius *= 1005; else if (CAVE_JOYSTICK_Y < -5) /* Joystick pushed backward */ ball->radius /= 1005; /*************\ > check_grab < \*************/ void check_grab(struct _balldata *ball) { float wandpos[3]; float distsq; if (CAVEButtonChange(2) == 1) { /* wand middle button is pressed */ CAVEGetPosition(CAVE_WAND, wandpos); if (ball->exist) { distsq = SQR(ball->x - wandpos[0]) + SQR(ball->y - wandpos[1]) + SQR(ball->z - wandpos[2]); if (distsq < SQR(ball->radius)) { ball->grabbed = 1; static GLUquadricObj *sphereobj; /**********\ > init_gl < \**********/ void init_gl(void) { GLfloat diffuse0[] = { 00, 00, 10, 10 ;
322 89 GLfloat ambient0[] = { 00, 03, 03, 10 ; GLfloat specular0[] = { 04, 04, 04, 10 ; GLfloat diffuse1[] = { 10, 10, 00, 10 ; GLfloat ambient1[] = { 03, 03, 00, 10 ; GLfloat specular1[] = { 04, 04, 04, 10 ; GLfloat light_diffuse[] = { 10, 10, 10, 00 ; GLfloat light_ambient[] = { 03, 03, 03, 00 ; GLfloat light_specular[] = { 10, 10, 10, 00 ; GLfloat light_position[] = { 10, 10, 10, 00 ; glenable(gl_light0); glclearcolor(0, 0, 0, 0); gllightfv(gl_light0, GL_AMBIENT, light_ambient); gllightfv(gl_light0, GL_SPECULAR, light_specular); gllightfv(gl_light0, GL_DIFFUSE, light_diffuse); gllightfv(gl_light0, GL_POSITION, light_position); sphereobj = glunewquadric(); mat0 = glgenlists(1); glnewlist(mat0, GL_COMPILE); glmaterialfv(gl_front_and_back, GL_DIFFUSE, diffuse0); glmaterialfv(gl_front_and_back, GL_AMBIENT, ambient0); glmaterialfv(gl_front_and_back, GL_SPECULAR, specular0); glmaterialf (GL_FRONT_AND_BACK, GL_SHININESS, 1000); glendlist(); mat1 = glgenlists(1); glnewlist(mat1, GL_COMPILE); glmaterialfv(gl_front_and_back, GL_DIFFUSE, diffuse1); glmaterialfv(gl_front_and_back, GL_AMBIENT, ambient1); glmaterialfv(gl_front_and_back, GL_SPECULAR, specular1); glmaterialf (GL_FRONT_AND_BACK, GL_SHININESS, 1000); glendlist(); /************\ > draw_ball < \************/ void draw_ball(struct _balldata *ball) { glclear(gl_depth_buffer_bit GL_COLOR_BUFFER_BIT); glenable(gl_lighting); if (ball->exist) { if (ball->grabbed) { glpushmatrix(); CAVEWandTransform(); glcalllist(mat1); glusphere(sphereobj, ball->radius, 32, 32); glpopmatrix();
90 CAVE else { glpushmatrix(); gltranslatef(ball->x, ball->y, ball->z); glcalllist(mat0); glusphere(sphereobj, ball->radius, 32, 32); glpopmatrix(); gldisable(gl_lighting); n end of interactc / 323 CompleXCope 10 CompleXcope (x=0,y=5,z=0) CompleXcope ( x=0, y=5, z=-8) VR CompleXcope VR CompleXcope CompleXcope interactc CompleXcope ( ) (CompleXcope ) ( ) (CompleXcope ) interactc CAVEGetPosition() CAVE WAND NAV \ NAV" CAVE navigate() void CAVENavTranslate(float x,float y,float z) void CAVENavRot(float angle, char axis) navigate() applicatin computation process draw ball (display process) void CAVENavTransform(void)
76 4 323 5 91 navigatec /* * navigatec \* A CompleXcope sample program - Copied and changed from /usr/local/cave/src/ogl/navigatec - A sample program for the CAVE navigation function - A ball appears when wand left button is pressed at the wand tip - The ball is destroyed when wand right button is pressed */ #include <cave_oglh> #include <GL/gluh> struct _balldata { float x,y,z; float radius; int exist; ; static GLuint mat0, boundary; void init_gl(void); void draw_ball(struct _balldata *); void check_add(struct _balldata *); struct _balldata * init_shmem(void); void navigate(void); main(int argc,char **argv) { struct _balldata *ball; CAVEConfigure(&argc,argv,NULL); ball = init_shmem(); CAVEInit(); CAVEInitApplication(init_gl, 0); CAVEDisplay(draw_ball, 1, ball); while (!CAVEgetbutton(CAVE_ESCKEY)) { navigate(); check_add(ball); sginap(1); CAVEExit(); #define SPEED 50f /* Max navigation speed in feet per second */ /* navigate - perform the navigation calculations This checks the joystick state and uses that to move and rotate The Y position of the joystick determines the speed of motion in the direction of the wand The X position
92 CAVE of the joystick determines the speed of rotation about the CAVE's Y axis Joystick values in the range -2 to 2 are ignored; this provides a dead zone to eliminate noise The motion is scaled by dt, the time passed since the last call to navigate(), in order to maintain a smooth speed */ void navigate(void) { float jx=cave_joystick_x,jy=cave_joystick_y,dt,t; static float prevtime = 0; t = CAVEGetTime(); dt = t - prevtime; prevtime = t; if (fabs(jy)>02) { float wandfront[3]; CAVEGetVector(CAVE_WAND_FRONT,wandFront); CAVENavTranslate(wandFront[0]*jy*SPEED*dt, wandfront[1]*jy*speed*dt, wandfront[2]*jy*speed*dt); if (fabs(jx)>02) CAVENavRot(-jx*900f*dt,'y'); /************\ > check_add < \************/ void check_add(struct _balldata *ball) { float wandpos[3], wandfront[3]; if (CAVEButtonChange(1) == -1) { /* left button is released */ CAVEGetPosition(CAVE_WAND_NAV, wandpos); /* wand position */ CAVEGetVector(CAVE_WAND_FRONT_NAV, wandfront); /* wand direction */ ball->x = wandpos[0] + wandfront[0]*05; ball->y = wandpos[1] + wandfront[1]*05; ball->z = wandpos[2] + wandfront[2]*05; ball->radius = 1; ball->exist = 1; if (CAVEButtonChange(3) == 1) ball->exist = 0; /*************\ > init_shmem < \*************/ struct _balldata * init_shmem(void) { struct _balldata *ball; ball = (struct _balldata *)CAVEMalloc(sizeof(struct _balldata)); bzero(ball, sizeof(struct _balldata)); return ball; static GLUquadricObj *sphereobj;
323 93 /**********\ > init_gl < \**********/ void init_gl(void) { GLfloat diffuse0[] = { 10, 10, 10, 10 ; GLfloat ambient0[] = { 00, 03, 03, 10 ; GLfloat specular0[] = { 04, 04, 04, 10 ; GLfloat light_diffuse[] = { 10, 10, 10, 00 ; GLfloat light_ambient[] = { 03, 03, 03, 00 ; GLfloat light_specular[] = { 10, 10, 10, 00 ; GLfloat light_position[] = { 10, 10, 10, 00 ; glenable(gl_light0); glclearcolor(0, 0, 0, 0); gllightfv(gl_light0, GL_AMBIENT, light_ambient); gllightfv(gl_light0, GL_SPECULAR, light_specular); gllightfv(gl_light0, GL_DIFFUSE, light_diffuse); gllightfv(gl_light0, GL_POSITION, light_position); sphereobj = glunewquadric(); mat0 = glgenlists(1); glnewlist(mat0, GL_COMPILE); glmaterialfv(gl_front_and_back, GL_DIFFUSE, diffuse0); glmaterialfv(gl_front_and_back, GL_AMBIENT, ambient0); glmaterialfv(gl_front_and_back, GL_SPECULAR, specular0); glmaterialf (GL_FRONT_AND_BACK, GL_SHININESS, 1000); glendlist(); boundary = glgenlists(1); /* boundary of the CAVE room */ glnewlist(boundary, GL_COMPILE); glcolor3f(0,1,0); glbegin(gl_line_loop); glvertex3f( 5, 0,-5); glvertex3f( 5,10,-5); glvertex3f(-5,10,-5); glvertex3f(-5, 0,-5); glend(); glcolor3f(0,0,1); glbegin(gl_line_loop); glvertex3f( 5, 0, 5); glvertex3f( 5,10, 5); glvertex3f(-5,10, 5); glvertex3f(-5, 0, 5); glend(); glcolor3f(1,0,0); glbegin(gl_lines); glvertex3f( 5, 0,-5); glvertex3f( 5, 0, 5); glvertex3f(-5, 0,-5); glvertex3f(-5, 0, 5); glvertex3f( 5,10,-5); glvertex3f( 5,10, 5); glvertex3f(-5,10,-5); glvertex3f(-5,10, 5); glend(); glendlist();
94 CAVE /************\ > draw_ball < \************/ void draw_ball(struct _balldata *ball) { glclear(gl_depth_buffer_bit GL_COLOR_BUFFER_BIT); glenable(gl_lighting); /* Apply the navigation transformation */ CAVENavTransform(); if (ball->exist) { glpushmatrix(); gltranslatef(ball->x, ball->y, ball->z); glcalllist(mat0); glusphere(sphereobj, ball->radius, 32, 32); glpopmatrix(); gldisable(gl_lighting); glcalllist(boundary); n end of navigatec / 324 CompleXcope CompleXcope CAVE CAVE OpenGL OpenGL CAVE CompleXcope Virtual LHD CompleXcope OpenGL CAVE OpenGL Iris Performer Performer Performer ( OpenGL ) OpenGL CAVE Dave Pape CAVE User's Guide CAVE EVL WEB (http://wwwevluicedu/evl/indexhtml)
A CAVE CompleXcope 1 2 ( ) 3 /usr/local/cave/bin/cavevars CompleXcope /usr/local/cave/bin/nifsuniversal right left right left CompleXcope 95
96 CAVE
B OpenGL OpenGL X Window SGI snapshot ( pict) OpenGL pict glreadpixels() ( ) pict pict AVS (*x) pict AVS width height alpha, red, green, blue ( ) ( ) OpenGL AVS ( p42 torusc ) glreadpixels() toavsx() /* * saveimagec \* An OpenGL sample program - Read the color buffer and make an AVS image file (*x) from it by "glreadpixels" command - An AVS image file named "picturex" is automatically generated - AVS image file has a simple data structure; int width int height char alpha <-+ 1st pixel char red char green char blue <-+ char alpha <-+ 2nd pixel 97
98 OpenGL */ char red char green char blue <-+ char alpha <-+ 3rd pixel char red char green char blue <-+ - Here, it is supposed that the window size is 600x500 pixels and the position of its upper-left corner is (0,0) - A torus is drawn by the aux library - With a blue lighting - Perspective view by the glu library - No animation #include <GL/glh> #include <GL/gluh> #include <stdioh> #include "auxh" void initial(void) { GLfloat light_diffuse[] = { 05, 05, 10, 10 ; GLfloat light_ambient[] = { 05, 05, 10, 10 ; GLfloat light_specular[] = { 10, 10, 10, 10 ; GLfloat light_position[] = { 10, 10, 10, 00 ; gllightfv(gl_light0, GL_AMBIENT, light_ambient); gllightfv(gl_light0, GL_SPECULAR, light_specular); gllightfv(gl_light0, GL_DIFFUSE, light_diffuse); gllightfv(gl_light0, GL_POSITION, light_position); glenable(gl_lighting); glenable(gl_light0); gldepthfunc(gl_less); glenable(gl_depth_test); glclearcolor(02, 02, 02, 10); void toavsx(void) { FILE *fp; char *file1 = "/picturex"; /* Here we supposed that (1) the window size is 600 x 500 pixels, (2) The position of the window's upper left corner is (0,0) */
OpenGL 99 char pic_red [600*500]; char pic_green[600*500]; char pic_blue [600*500]; char pic_alpha[600*500]; char pic_rgba [600*500*4]; /* R,G,B and Alpha */ int pic_size [2]; /* width and height */ int i; /* */ We cannot use the this (simpler) command; glreadpixels(0, 0, 600, 500, GL_RGBA, GL_UNSIGNED_BYTE, pic), since the each element of RGBA in the color buffer isn't necessarily the same as that in the AVS-X image file (which is "A-R-G-B") glreadpixels(0, 0, 600, 500, GL_RED, GL_UNSIGNED_BYTE, pic_red); glreadpixels(0, 0, 600, 500, GL_GREEN, GL_UNSIGNED_BYTE, pic_green); glreadpixels(0, 0, 600, 500, GL_BLUE, GL_UNSIGNED_BYTE, pic_blue); glreadpixels(0, 0, 600, 500, GL_ALPHA, GL_UNSIGNED_BYTE, pic_alpha); pic_size[0] = 600; /* width in pixel */ pic_size[1] = 500; /* height in pixel */ for (i=0; i<600*500; i++) { pic_rgba[4*i+0] = pic_alpha[i]; pic_rgba[4*i+1] = pic_red [i]; pic_rgba[4*i+2] = pic_green[i]; pic_rgba[4*i+3] = pic_blue [i]; fp = fopen(file1, "w"); if (fp == NULL) { printf(" open error : %s\n", file1); exit(1); fwrite(pic_size, sizeof(pic_size), 1, fp); fwrite(pic_rgba, sizeof(pic_rgba), 1, fp); fclose(fp); void display (void) { GLfloat mat_diffuse[] = { 10, 10, 10, 10 ; GLfloat mat_ambient[] = { 01, 01, 01, 10 ; GLfloat mat_specular[] = { 09, 09, 09, 10 ; glclear( GL_COLOR_BUFFER_BIT GL_DEPTH_BUFFER_BIT ); glmaterialfv(gl_front, GL_DIFFUSE, mat_diffuse); glmaterialfv(gl_front, GL_AMBIENT, mat_ambient);
100 OpenGL glmaterialfv(gl_front, GL_SPECULAR, mat_specular); glmaterialf (GL_FRONT, GL_SHININESS, 640); glpushmatrix(); gltranslatef (00, 00, -50); auxsolidtorus(02,10); glpopmatrix(); glflush(); toavsx(); /****** This is it ******/ void reshape(int width, int height) { GLdouble ang = 600; GLdouble near = 30; GLdouble far = 100; glviewport (0, 0, width, height); glmatrixmode (GL_PROJECTION); glloadidentity (); gluperspective (ang, (GLdouble)width/(GLdouble)height, near, far); glmatrixmode (GL_MODELVIEW); glloadidentity (); int main(int argc, char **argv) { auxinitdisplaymode (AUX_SINGLE AUX_RGBA AUX_DEPTH); auxinitposition (0, 0, 600, 500); auxinitwindow (argv[0]); initial(); auxreshapefunc (reshape); auxmainloop(display);
C C (diff f c) CompleXcope C CAVE OpenGL C Appendix Fortran C C Fortran C C C C1 C C \main" \c" \cc" Fortran \aout" sample01c C /* sample01c */ #include <stdioh> int func1(int); main() { int i,j,k; i=3; j=i*i; printf("calling func1\n"); k = func1(j); /* function call */ printf(" k = %d\n",k); int func1(int k) { int m; printf("i am in func1\n"); m = 3*k; return(m); Fortran 101
102 C (diff f c) c c i = 3 j = i**2 write(6,*)' calling nfunc1' k = nfunc1(j) write(6,*)' k = ',k stop end function nfunc1(k) write(6,*)'i am in nfunc1' nfunc = 3*k return end C \{" \" \;" ( i=1; j=2; ) \/*" \*/" (stdio) stdioh include C2 \/*" \*/" i = 3; /* comment 1 */ /* * * * * comment 2 * * * * */ /*--------------------- comment 3 ---------------------*/
C3 103 /* * * This
104 C (diff f c) C5 Fortran >= /* GE */ > /* GT */ <= /* LE */ < /* LT */ == /* EQ */!= /* NE */ C6 if if Fortran if (y>=0) ; if (y==1) { /* if (y==1) */ 1; /* { 1; */ 2; /* 2; */ 3; /* 3; */ /* */ if(y!=0) { 1; 2; else { 1; 2; 3; C7 Fortran C
C7 105 /* sample03c */ float sum(float,float); /* */ main() { float a; a=sum(20,30); float sum(float a,float b) { return(a+b); Fortran \void" \void" \ " Fortran \ " Fortran c i=2 call sub1(i) stop end subroutine sub1(j) j=0 return end sub1 i 0 C
106 C (diff f c) main() { i=2; sub1(i); void sub1(int j) { j=0; sub1() i 2 Fortran C C ( ) C8 for Fortran do C for func() 10 call for (i=0; i<10; i++) { /* do i = 1, 10 */ func(); /* in Fortran */ for () ( ; ; ) C9 while C FORTRAN77 while()
C10 107 /* sample04c */ #include <stdioh> void func1(int); void func2(int); main() { int n = 10; puts("----------------"); /* "puts" is a standard function */ func1(n); puts("----------------"); func2(n); /* the value n is not changed */ void func1(int i) { while (i>0) { printf(" int = %d\n",i); i--; /* i = i-1 */ void func2(int i) { while (i>0) printf(" int = %d\n",i--); func1() func2() void func3(int i) { while (i) /* ( ) 0 */ printf(" inn = %d\n",i--); C10 C Fortran t[n] /* t(n) in Fortarn */ Fortran t t(1),t(2),t(3),,t(n) C t[0],t[1],t[2],,t[n-1] 0 N-1 2
108 C (diff f c) t[m][n] /* */ 0 M-1 0 N-1 t N*M Fortran Fortran 3 2 4 t(3,4) t(1,1) t(2,1) t(3,1) t(1,2) t(2,2) t(3,4) C t[3][4] t[0][0] t[0][1] t[0][2] t[0][3] t[1][0] t[2][3] Fortran C ( ) t[l][m][n] C11 C 1 ( ) ap float *ap; ( ) temp[100] temp[0], temp[1], temp[2],, temp[99] 1 x &x
C11 109 ( ) ( )4 temp[0] 4100 temp[1], temp[2], 4104, 4108, temp 4100 temp[100] temp temp 4100 func() temp func() (100 )2(4 ) 2 ( 100 func() ) func() 4100 func() temp void func(float *); /* */ /* void func(float *t) */ /* void func(float t[]) */ /* void func(float t[100]) */ main() { float temp[100]; func(temp); void func(float *t) { /* void func(float t[]) */ /* void func(float t[100]) */ a2 = t[2]; a5 = t[5]; func() 4100 func() t[2] 4108 temp[0] (4100 ) 2 C
110 C (diff f c) C12 C CompleXcope VR /* j */ /* j i x */ /* j i y */ /* j i z */ /* */ /* ( ) */ draw() 10 Fortran ( 1000 ) integer nten(10) /* j */ real xpos(10,1000) /* j i x */ real ypos(10,1000) /* j i y */ real zpos(10,1000) /* j i z */ real curr(10,1000) /* */ draw ( ) C \ " magline struct magline { int nten; float xpos[1000]; float ypos[1000]; float zpos[1000]; float curr[1000]; ; magline int oat \ " magline ( ) line_1 struct magline line_1; line_1 line_1 struct magline lines[10];
C12 111 draw() draw(lines);
112 C (diff f c)
D 232 OpenGL 2562256 C (p61) AVS (*x) (x2texture ) D1 imtools imscale 2562256 AVS x imscale AVS (*x) width height (64 )2 (width height )7 6 #!/bin/csh -f # # mktexture 4 5 mktexture # To make a texture data with 256x256 pixels from # any image file, via AVS image file format # if ( $2 == "" ) then echo usage: $0 file1rgb keyword echo output: keyword256x256 exit endif /usr/sdsc_imtools/imtools/bin/imscale -xsize 256 -ysize 256 \ -infile $1 -outfile /tmp/$2x x2texture /tmp/$2x $2 # cc -o x2texure x2texturec rm /tmp/$2x D2 x2texture n end of mktexture / mktexture x2texture 113
76 45 114 x2texturec /* * x2texurec * To make a texture data from an AVS image file */ #include <stdioh> main(int argc,char **argv) { FILE *fpin,*fpout; int i; char red, green, blue, alpha; char sizeinfo[20]; int nx,ny; if (argc<3) { fprintf(stderr," usage: %s file_in file_out\n", argv[0]); exit(8); fpin = fopen(argv[1],"r"); if(fpin==null) { fprintf(stderr," infile open error\n"); exit(9); fread((char *)&nx, sizeof(int), 1, fpin); fread((char *)&ny, sizeof(int), 1, fpin); sprintf(sizeinfo,"%dx%d\0",nx,ny); printf(" size = %s\n", sizeinfo); fpout = fopen((char *)strcat(argv[2],sizeinfo),"w"); if(fpout==null) { fprintf(stderr," outfile open error\n"); exit(9); for (i=0; i<nx*ny; i++) { fread((char *)&alpha, sizeof(char), 1, fpin); fread((char *)&red, sizeof(char), 1, fpin); fread((char *)&green, sizeof(char), 1, fpin); fread((char *)&blue, sizeof(char), 1, fpin); fwrite((char *)&red, sizeof(char), 1, fpout); fwrite((char *)&green, sizeof(char), 1, fpout); fwrite((char *)&blue, sizeof(char), 1, fpout); n end of x2texturec /
[1] MJ Kilgard, OpenGL Programming for the X Window System, Addison-Wesley, 1996 [2] OpenGL Architecture Review Board, J Neider, T Davis and M Woo, OpenGL TM Programming Guide, Adison-Wesley, 1993 [3], OpenGL TM Programming Guide ( ),, 1993 [4] OpenGL Architecture Review Board, J Neider, T Davis and M Woo, OpenGL TM Programming Guide, Second Edition, Adison-Wesley, 1997 [5], OpenGL TM Programming Guide, Second Edition ( ),, 1997 [6] OpenGL Architecture Review Board, OpenGL TM Reference Manual, Second Edition, Adison-Wesley, 1996 [7], OpenGL TM 3D,, 1995 115