2 2 OpenGL OpenGL OpenGL(Open Graphics Library) Silicon Graphics (SGI) 3D OpenGL SGI HP, SUN,

Similar documents
2 3 OpenGL 2 OpenGL OpenGL(Open Graphics Library) Silicon Graphics (SGI) 3D OpenGL SGI HP, SUN, IBM UNIX Linux, FreeBSD PC UNIX Windows, Mac OS API PD

2 2 OpenGL ( ) OpenGL ( ) glclearcolor(glclampf red, GLclampf green, GLclampf

2 2 OpenGL ( ) 2 OpenGL ( ) glclearcolor(glclampf red, GLclampf green, GLclampf blu

第3章 OpenGL の基礎

第3章 OpenGL の基礎

libaux.dvi

OpenGL Programming Course OpenGL Programming Course FAQ

untitled

OpenGL & GLUTの基本関数の説明

3D グラフィックス処理の一般過程 1. 3D グラフィックス処理の一般過程

謗域・ュ逕ィppt

#include <stdio.h> 2 #include <stdlib.h> 3 #include <GL/glut.h> 4 Program 1 (OpenGL GameSample001) 5 // 6 static bool KeyUpON = false; // 7 sta

1 1. Program 1 OpenCV (OpenCV Sample001) 1 /* 2 - > - > - >VC++ 3 ( ) 4 C:\opencv\build\include 5 ( ) 6 C:\opencv\build\x86\vc10\lib 7 - > - > - > - >

2 2 GLUI 2 GLUI 2.1 GLUI GLUI OpenGL OpenGL glut OpenGL glut C++ Linux, Windows (Visual C++, gcc), Macintosh glut glut GUI glut GUI CG glmultmatrix()

/*p7-1-1*/

$ ls -l $ ls -l -a $ ls -la $ ls -F $ ls <dirname> <dirname> $ cd <dirname> <dirname> $ cd $ pwd $ cat <filename> <filename> $ less <filename> <filena

2 2 2 OpenGL (R,G,B,A) 2.1 OpenGL (x y) width height pixels void glreadpixels(glint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum t

( ) 1 1: 1 #include <s t d i o. h> 2 #include <GL/ g l u t. h> 3 #include <math. h> 4 #include <s t d l i b. h> 5 #include <time. h>

演算増幅器

/* drawing function */ function_graph();// drawing graph glflush(); int main(int argc, char **argv ) glutinit( &argc, argv ); glutinitdisplaymode( GLU

j x j j j + 1 l j l j = x j+1 x j, n x n x 1 = n 1 l j j=1 H j j + 1 l j l j E

謗域・ュ逕ィppt

2 : 2008/12/ /01/ G :

謗域・ュ逕ィppt

1 3 2 OpenGL 4 3 OpenGL 5 4 OpenGL 6 OpenGl : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 6 : : : : : : : : : : : : : : : : : : : : :

準備 計算結果を可視化するために OpenGL を 利用する. 2

manual.dvi

$ pwd /home1/t0/t0903 / / /home1/t0/t0903 / / /home1/t0/t0903 / /... ~ $ ls $ ls -a

double rx[natom], ry[natom], rz[natom]; 原子の座標 速度 力 ポテンシャルエ double vx[natom], vy[natom], vz[natom]; ネルギーを受ける配列を準備 double fx[natom], fy[natom], fz[natom

2 2 2 OpenGL (R,G,B,A) 2.1 OpenGL (x y) width height pixels void glreadpixels(glint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum t

演算増幅器

第7章 レンダリング

第7章 レンダリング

DrawArrays DrawElements References Kageyama (Kobe Univ.) Visualization / 34

TA TA TA abcdefgh abcdefgh C PC Wii bluetooth 2.2 Bluetooth USB Princeton PTM-UBT3S 1 1

Kageyama (Kobe Univ.) / 36

WebGL OpenGL GLSL Kageyama (Kobe Univ.) Visualization / 57

2 T ax 2 + 2bxy + cy 2 + dx + ey + f = 0 a + b + c > 0 a, b, c A xy ( ) ( ) ( ) ( ) u = u 0 + a cos θ, v = v 0 + b sin θ 0 θ 2π u = u 0 ± a

OpenGL GLSL References Kageyama (Kobe Univ.) Visualization / 58

Graphics Performance Tuning () Z 2

沼津工業高等専門学校

JAPLAシンポジウム資料 2009/12/5

10 B 3. ( ) (3)

C B

1 OpenGL OpenGL OpenGL OpenGL

1) OOP 2) ( ) 3.2) printf Number3-2.cpp #include <stdio.h> class Number Number(); // ~Number(); // void setnumber(float n); float getnumber();

1 level Level swtich ButtonPress ButtonRelease Expose Level

JAPLA研究会資料 2013/5/25

Microsoft Word - mediaJikkenCG_no2_2007.doc

JAPLA研究会資料 2012/8/2

Microsoft PowerPoint - 04.pptx

複雑系科学演習1 コンピュータグラフィックス

Microsoft Word - mediaJikkenCG_no2_2012.doc

£Ã¥×¥í¥°¥é¥ß¥ó¥°ÆþÌç (2018) - Â裵²ó ¨¡ À©¸æ¹½Â¤¡§¾ò·ïʬ´ô ¨¡

Kageyama (Kobe Univ.) / 41

コンピュータグラフィックスS 演習資料

免許法認定公開講座: コンピュータグラフィックス

JAPLA研究会資料 2010/4/24

Tekutama AR ~ 拡張現実感によるオーバーレイ表示と動作 ~ 情報物理研究室 渡部 修平 1

19_OpenGLES.key

JAPLA研究会資料 /6/15

コンピューターグラフィックスS

Microsoft Word - C.....u.K...doc

コンピュータグラフィックスS 演習資料

Microsoft PowerPoint - info_eng3_05ppt.pptx

NB

double float

JAPLA研究会資料 2017/5/20

(7) u 1 θ A {u 1, u, u 3 } U = (u 1, u, u 3 ) A = UT (θ) + tu t UAU = T (θ) + () θ x z cos θ 0 sin θ cos θ sin θ 0 X(θ) = 0 cos θ sin θ, Y (θ) =

£Ã¥×¥í¥°¥é¥ß¥ó¥°ÆþÌç (2018) - Â裶²ó ¨¡ À©¸æ¹½Â¤¡§·«¤êÊÖ¤· ¨¡

5. p.1/37


r08.dvi

CM-3G 周辺モジュール拡張技術文書 MS5607センサ(温度、気圧)

ohp08.dvi

C

2 2 2 OpenGL Linux Linux Video for Linux(Video4Linux, v4l ) API Video4Linux USB IEEE1394 API Linux Video for Linux 2(Video4Linux2, v4l2 ) OpenCV API U

test_cylpyd

Microsoft Word - opengl講義資料ha.doc

Microsoft Word - opengl講義資料2013.doc

新版明解C言語 実践編

3. OpenGL を利用するための準備作業 1) Tao Framework をダウンロードしてインストールする. Download から taoframework setup.exe をダウン

x h = (b a)/n [x i, x i+1 ] = [a+i h, a+ (i + 1) h] A(x i ) A(x i ) = h 2 {f(x i) + f(x i+1 ) = h {f(a + i h) + f(a + (i + 1) h), (2) 2 a b n A(x i )


コンピュータグラフィックス特論Ⅱ

Condition DAQ condition condition 2 3 XML key value

slide5.pptx

ProVisionaire Control V3.0セットアップガイド

1 1.1 (VR) [1] * * /3/5 1

joho07-1.ppt

コンピュータグラフィクス論

Presentation

JAPLA研究会資料 2010/1/23

(300, 150) 120 getchar() HgBox(x, y, w, h) (x, y), w, h #include <stdio.h> #include <handy.h> int main(void) { int i; double w, h; } HgO

FFTSS Library Version 3.0 User's Guide

AutoTuned-RB

ex12.dvi

II 3 yacc (2) 2005 : Yacc 0 ~nakai/ipp2 1 C main main 1 NULL NULL for 2 (a) Yacc 2 (b) 2 3 y

PowerPoint プレゼンテーション

r07.dvi

Transcription:

1 20 (1) OpenGL TA 2008 10 20 1 C OpenGL (3DCG) OS Linux (Open SUSE 10.3) 3DCG OpenGL GUI GLUT OpenGL GLUT GLUI USB EyeToy 1.1 1 3DCG 2 3DCG GUI 2 USB EyeToy) 10/20( ) 10/27( ) 3DCG OpenGL OpenGL+GUI(GLUI) 3DCG 1.2 TA

2 2 OpenGL 1.3 http://www.cyber.t.u-tokyo.ac.jp/~kuni/enshu2008/ 2 OpenGL OpenGL(Open Graphics Library) Silicon Graphics (SGI) 3D OpenGL SGI HP, SUN, IBM UNIX Linux, FreeBSD PC UNIX Windows, Mac OS API PDA OpenGL OpenGL ES 3D 2.1 OpenGL OpenGL OpenGL OpenGL GLUT OpenGL GL OpenGL OpenGL gl GLU OpenGL Utility Library OpenGL GLU glu Window OpenGL (Window ) X Window System GLX, Windows NT/98/95 WGL, OS/2 PGL, Power Mac AGL OS, Window GLUT OpenGL Utility Toolkit(Window ) OpenGL

2.1 OpenGL 3 GLUT glut OpenGL 1 OpenGL

4 3 OpenGL 3 OpenGL 3.1 OpenGL OpenGL OpenGL 2 OpenGL ( ) ( ) 4x4 ( ) ( ) OpenGL OpenGL ( )

3.2 OpenGL 5 3.2 OpenGL main() /* Window */ InitializeAWindowPlease(); /* */ glclearcolor (0.0, 0.0, 0.0, 0.0); glclear (GL_COLOR_BUFFER_BIT); /* */ glcolor3f (1.0, 1.0, 1.0); /* */ glortho(0.0, 1.0, 0.0, 1.0, -1.0, 1.0); /* */ glbegin(gl_polygon); glvertex3f (0.25, 0.25, 0.0); glvertex3f (0.75, 0.25, 0.0); glvertex3f (0.75, 0.75, 0.0); glvertex3f (0.25, 0.75, 0.0); glend(); /* */ glflush (); /* Window */ UpdateTheWindowAndCheckForEvents(); 3.3 OpenGL GLUT OpenGL (sample clr.c) Web 3.4 3.4.1 glclearcolor(glclampf red, GLclampf green, GLclampf blue, GLclampfalpha); GLglampf 0.0 1.0

6 3 OpenGL 3 OpenGL (sample-clr.c) alpha glutclearcolor(0.0, 0.0, 0.0, 0.0); 3.4.2 glclearcolor glclear(gl_color_buffer_bit); 3.4.3 glflush(); 1 3.5 glut GLUT(OpenGL Utility Toolkit) GLUT Windows X window system GLUT 3.7 GLU 3

3.5 glut 7 GLUT glutinit void glutinit(int *argcp, char **argv); argcp main argc GLUT argv main argv GLUT X Window System GLUT -display, -geometry man X void glutinitwindowposition(int x, int y); void glutinitwindowsize(int width, int height); x, y width, height 4 OpenGL glutinitwindow* OpenGL glutinitwindow* (OpenGL )

8 4 2 glutinitdisplaymode void glutinitdisplaymode(unsigned int mode); mode RGBA (GLUT RGBA or GLUT INDEX) (GLUT DEPTH) (GLUT SINGLE or GLUT DOUBLE) RGBA glutinitdisplaymode(glut_rgba GLUT_DOUBLE GLUT_DEPTH); OpenGL int glutcreatewindow(char *titlestring); titlestring OpenGL OpenGL void glutpostredisplay(void); display 1 1 void glutmainloop(void); glutdisplayfunc 4 2 2 ( ) (sample-hello.c)

4.1 OpenGL 9 5 OpenGL (sample-hello.c) 4.1 OpenGL glcolor3f(glclampf red, GLclampf green, GLclampf blue); 0.0 1.0 3 glcolor3f(1.0f, 1.0f, 0.0f); glbegin(glenum mode); mode (GL POLYGON) (GL TRIANGLE FAN) ( ) (GL TRIANGLE STRIP) (GL LINES) (GL POINTS)

10 4 2 glend(); glvertex3f(glfloat x, GLfloat y, GLfloat z); glvertex* 3 3 (x, y, z) f 32bit (GLfloat) 4.2 OpenGL gluortho2d 6 gluortho2d(x1,x2,y1,y2); OpenGL 3 3 1 void glmatrixmode(glenum mode); mode

4.3 11 (GL PROJECTION) (GL MODELVIEW) (GL TEXTURE) void glloadidentity(void); 2 ( ) void gluortho2d(gldouble left, GLdouble right, GLdouble bottom, GLdouble top); gluortho2d 3 glortho near, far -1.0, 1.0 OpenGL 2 3-1.0 1.0 gluortho2d(-1.0, 1.0, -1.0, 1.0); glortho(-1.0, 1.0, -1.0, 1.0, -1.0, 1.0); 1. glmatrixmode(gl_projection); 2. glloadidentity(void); 3. gluortho2d(left, right, bottom, top); 4. glmatrixmode(gl_modelview); 4.3 OpenGL OpenGL ( ) void glviewport(glint x, GLint y, GLsizei width, GLsizei height);

12 4 2 7 (x,y) width height glutreshapefunc void glutreshapefunc(void (*func)(int width, int height)); OpenGL 2

13 5 OpenGL 5.1 OpenGL OpenGL 3 glut #include <GL/gl.h> /* */ #include <GL/glu.h> /* glu */ #include <GL/glx.h> /* X Window System */ GLUT #include <GL/glut.h> gl.h glu.h glut.h glut.h window.h UNIX WIndows GLUT -lglut -lglu -lgl simple.c. simple % gcc simple.c -o simple -lglut -lglu -lgl

14 5 OpenGL 5.2 Makefile #MAKEFILE CC = gcc RM = rm -f CFLAGS = -Wall LDFLAGS = -lglut -lglu -lgl -lm TARGET OBJS = sample-clr = sample-clr.o.c.o: $CC -c $CFLAGS $< TARGET: $OBJS $CC -o $TARGET $OBJS $LDFLAGS clean: $RM $TARGET *.o *~ 5.3 1 1. sample-clr.c 2. 3. sample-hello.c 4. glortho() glvertex3f()

15 6 6.1 1. 2. 3. 4. OpenGL 1. ( ) 2. ( ) 3. ( ) ( ) 4. ( ) 8 OpenGL OpenGL 4x4 M v v = Mv v 4 (x, y, z, w) w 1

16 6 w 9 OpenGL 6.2 (sample-cube.c) void init(void) glclearcolor (0.0, 0.0, 0.0, 0.0); glshademodel (GL_FLAT); void display(void) glclear (GL_COLOR_BUFFER_BIT); glcolor3f (1.0, 1.0, 1.0); glloadidentity (); /* clear the matrix */ /* viewing transformation */ glulookat (0.0, 0.0, 5.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0); glscalef (1.0, 2.0, 1.0); /* modeling transformation */ glutwirecube (1.0); glflush ();

6.2 17 void reshape (int w, int h) glviewport (0, 0, (GLsizei) w, (GLsizei) h); glmatrixmode (GL_PROJECTION); glloadidentity (); glfrustum (-1.0, 1.0, -1.0, 1.0, 1.5, 20.0); glmatrixmode (GL_MODELVIEW); /* ARGSUSED1 */ void keyboard(unsigned char key, int x, int y) switch (key) case 27: exit(0); break; int main(int argc, char** argv) glutinit(&argc, argv); glutinitdisplaymode (GLUT_SINGLE GLUT_RGB); glutinitwindowsize (500, 500); glutinitwindowposition (100, 100); glutcreatewindow (argv[0]); init (); glutdisplayfunc(display); glutreshapefunc(reshape); glutkeyboardfunc(keyboard); glutmainloop(); return 0; glulookat() glfrustum() glviewport()

18 6 6.3 glloadidentity() (current matrix) glulookat() (0, 0, 5) (0, 0, 0) (0, 1, 0) glulookat() z (0, 1, 0) glulookat() z 5. glscalef() 3 y 2 ( ) ( ) glulookat() gltranslatef(0.0, 0.0, -5.0) OpenGL (modelview matrix) glutwirecube() display() glutdisplayfunc display() OpenGL 2 (perspective) glfrustum() (orthographic) CAD reshape() glmatrixmode(gl PROJECTION) glloadidentity() glfrustum()

6.4 OpenGL 19 glviewport() ( (0, 0)) ( ) reshape() ( ) reshape() 6.4 OpenGL glmatrixmode() void glmatrixmode(glenum mode); mode GL MODELVIEW GL PROJECTION GL TEXTURE. glloadidentity() void glloadidentity(void); 4x4 3 OpenGL gltranslate*() glrotate*() glscale*() ( ) 3. void gltranslatefd(type x, TYPE y, TYPE z);

20 6 x, y, z ( ) void glrotatefd(type angle, TYPE x, TYPE y, TYPE z); (x, y, z) ( ) angle glrotatef(45.0, 0.0, 0.0, 1.0) z 45 void glscalefd(type x, TYPE y, TYPE z); x, y, z x, y, z x, y, z (gltranslate*() glrotate*()) OpenGL Utility Library(GLU) glulookat(). void glulookat(gldouble eyex, GLdouble eyey, GLdouble eyez, GLdouble centerx, GLdouble centery, GLdouble centerz, GLdouble upx, GLdouble upy, GLdouble upz); eyex, eyey, eyez centerx, centery, centerz upx, upy, upz z y glfrustum() glperspective() glortho() glortho2d().

6.4 OpenGL 21 glmatrixmode(gl_projection); glloadidentity(); void glfrustum(gldouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble near, GLdouble far); (left, bottom, -near) (right, top, -near) near far ( ). 10 glfrustum() void glperspective(gldouble fovy, GLdouble aspect, GLdouble near, GLdouble far); fovy x-z [0.0, 180.0] aspect near far z ( ) 11 glperspective()

22 6 void glortho(gldouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble near, GLdouble far); (left, bottom, -near) (right, top, -near) (left, bottom, -far) (right, top, -far) near far 12 glortho() void glortho2d(gldouble left, GLdouble right, GLdouble bottom, GLdouble top); 2 (left, bottom) (right, top) z -1.0 1.0 glortho() 2 z 0.0 glviewport() 2 void glviewport(glint x, GLint y, GLsizei width, GLsizei height);

6.4 OpenGL 23 (x, y) width height (0, 0, winwidth, winheight) winwidth, winheight

24 7 7 7.1 OpenGL (geometric primitive) (Vertex) 3 2 (x, y) z 0 Vertex OpenGL (convex). GLU 7.2 OpenGL OpenGL glvertex*() void glvertex234sifd[v](type coords) : glvertex2s(2, 3); glvertex3f(2.3, 1.1, -2.2); GLdouble dvect[3]=5.0, 9.0, 1992.0; glvertex3dv(dvect);

7.2 OpenGL 25 glvertex*() glbegin() glend() glbegin() : glbegin(gl_polygon); glvertex2f(0.0, 0.0); glvertex2f(0.0, 3.0); glvertex2f(4.0, 3.0); glvertex2f(6.0, 1.5); glvertex2f(4.0, 0.0); glend(); glbegin(gl_polygon); glend(); glbegin(gl_triangle_fan); glend(); glbegin(gl_triangle_strip); glend(); glbegin(gl_lines); glend(); GL_POINTS, GL_LINES, GL_LINE_STRIP, GL_LINE_LOOP, GL_TRIANGLES, GL_TRIANGLE_STRIP, GL_TRIANGLE_FAN, GL_QUADS, GL_QUAD_STRIP, and GL_POLYGON. glbegin() glend() glvertex*() :

26 7 13 OpenGL glbegin(gl_points); glcolor3f(0.0, 1.0, 0.0); glvertex(...); glcolor3f(1.0, 1.0, 0.0); glvertex(...); glvertex(...); glend();. : #define PI 3.1415926535898 GLint circle_points=100; glbegin(gl_line_loop); for(i=0; i<circle_points; i++) angle = 2*PI*i/circle_points; glvirtex2f(cos(angle), sin(angle)); glend();

7.3 27 7.3 glpointsize() void glpointsize(glfloat size); 1.0 void gllinewidth(glfloat width); void gllinestipple(glint factor, GLushort pattern); (width) pattern 16 0 1 1 0 factor pattern gllinestipple(1, 0x3F07); glenable(gl_line_stapple); 0x3f07 (2 0011111100000111 ) 3 ON 5 OFF 6 ON 2 OFF factor 2 6 ON 10 OFF 12 ON 4 OFF gllinestipple() glenable() glpolygonmode() void glpolygonmode(glenum face, GLenum mode); face GL FRONT AND BACK, GL FRONT, GL BACK mode GL POINT( ), GL LINE( ), GL FILL( )

28 7 void glfrontface(glenum mode); void glcullface(glenum mode); ( ) glfrontface() glcullface(gl BACK) glenable(gl CULL FACE). 7.4 GLUT GLUT 9 2 OpenGL void glutwiresphere(gldouble radius, GLint slices, GLint stacks); void glutsolidsphere(gldouble radius, GLint slices, GLint stacks); glutsolidsphere glutwiresphere radius radius slices Z ( ) stacks Z ( ) void glutwirecube(gldouble size); void glutsolidcube(gldouble size); glutwirecube glutsolidcube size size

7.4 GLUT 29 void glutwiretorus(gldouble innerradius, GLdouble outerradius, GLint nsides, GLint rings); void glutsolidtorus(gldouble innerradius, GLdouble outerradius, GLint nsides, GLint rings); glutsolidtorus glutwiretorus Z innerradius outerradius nsides rings void glutwireicosahedron(void); void glutsolidicosahedron(void); void glutwireoctahedron(void); void glutsolidoctahedron(void); void glutwiretetrahedron(void); void glutsolidtetrahedron(void); void glutwiredodecahedron(void); void glutsoliddodecahedron(void); glutsolidisosahedron glutwireisosahedron 1.0 20 glutsolidoctahedron glutwireoctahedron 1.0 8 glutsolidtetrahedron glutwiretetrahedron 3 4 glutsoliddodecahedron glutwiredodecahedron 3 12 void glutwirecone(gldouble radius, GLdouble height, GLint slices, GLint stacks); void glutsolidcone(gldouble radius, GLdouble height, GLint slices, GLint stacks); glutsolidcone glutwirecone Z Z=0 Z=height Z slices

30 7 Z stacks base height slices Z stacks Z void glutwireteapot(gldouble size); void glutsolidteapot(gldouble size); glutsolidteapot glutwireteapot OpenGL size 2 1. sample-cube.c make 2. cube 3. 4. glutlookat() gltranslatef(0.0, 0.0, -5.0) 5. glfrustum() gluperspective(60.0. 1.0, 1.5, 20.0) fovy aspect 6. cube

31 8 8.1 (glloadmatrix(), glmultmatrix(), glloadidentity() ) glpushmatrix() glpopmatrix() ( ) glpushmatrix() glpopmatrix() 14 void glpushmatrix(void); 1 2 glmatrixmode() void glpopmatrix(void); 2

32 8 glmatrixmode() glpopmatrix() 32 4x4 glloadidentity() 2 2 3 glmatrixmode(gl_projection); glpushmatrix(); /* save the current projection */ glloadidentity(); glortho(...); /* set up for displaying help */ display_the_help(); glpopmatrix(); 8.2 4 5 ( ) 4 5

8.2 33 15 draw_wheel_and_bolts() long i; draw_wheel(); for(i=0;i<5;i++) glpushmatrix(); glrotatef(72.0*i,0.0,0.0,1.0); gltranslatef(3.0,0.0,0.0); draw_bolt(); glpopmatrix();

34 8 draw_body_and_wheel_and_bolts() draw_car_body(); glpushmatrix(); gltranslatef(40,0,30); /*move to first wheel position*/ draw_wheel_and_bolts(); glpopmatrix(); glpushmatrix(); gltranslatef(40,0,-30); /*move to 2nd wheel position*/ draw_wheel_and_bolts(); glpopmatrix();... /*draw last two wheel similarly*/ 72 3 40 30 8.3 glrotate*() gltranslate*() glutwiresphere() 2 glpushmatrix(); glutwiresphere(1.0, 20, 16); /* draw sun */ glrotatef ((GLfloat) year, 0.0, 1.0, 0.0); gltranslatef (2.0, 0.0, 0.0); glrotatef ((GLfloat) day, 0.0, 1.0, 0.0); glutwiresphere(0.2, 10, 8); /* draw smaller planet */ glpopmatrix(); glrotate*() gltranslate*()

8.3 35 glrotate*() ( ) 2 glrotate*() ( ) 16 #include <GL/glut.h> #include <stdlib.h> static int year = 0, day = 0; void init(void) glclearcolor (0.0, 0.0, 0.0, 0.0); glshademodel (GL_FLAT); void display(void) glclear (GL_COLOR_BUFFER_BIT); glcolor3f (1.0, 1.0, 1.0); glpushmatrix(); glutwiresphere(1.0, 20, 16); /* draw sun */ glrotatef ((GLfloat) year, 0.0, 1.0, 0.0); gltranslatef (2.0, 0.0, 0.0); glrotatef ((GLfloat) day, 0.0, 1.0, 0.0); glutwiresphere(0.2, 10, 8); /* draw smaller planet */ glpopmatrix(); glutswapbuffers();

36 8 void reshape (int w, int h) glviewport (0, 0, (GLsizei) w, (GLsizei) h); glmatrixmode (GL_PROJECTION); glloadidentity (); gluperspective(60.0, (GLfloat) w/(glfloat) h, 1.0, 20.0); glmatrixmode(gl_modelview); glloadidentity(); glulookat (0.0, 0.0, 5.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0); /* ARGSUSED1 */ void keyboard (unsigned char key, int x, int y) switch (key) case d : day = (day + 10) % 360; glutpostredisplay(); break; case D : day = (day - 10) % 360; glutpostredisplay(); break; case y : year = (year + 5) % 360; glutpostredisplay(); break; case Y : year = (year - 5) % 360; glutpostredisplay(); break; case 27: exit(0); break; default: break;

8.4 37 int main(int argc, char** argv) glutinit(&argc, argv); glutinitdisplaymode (GLUT_DOUBLE GLUT_RGB); glutinitwindowsize (500, 500); glutinitwindowposition (100, 100); glutcreatewindow (argv[0]); init (); glutdisplayfunc(display); glutreshapefunc(reshape); glutkeyboardfunc(keyboard); glutmainloop(); return 0; 8.4 2 17 gltranslate*() glrotate*() glpushmatrix() glpopmatrix() glscale*()

38 8 gltranslatef (-1.0, 0.0, 0.0); glrotatef ((GLfloat) shoulder, 0.0, 0.0, 1.0); gltranslatef (1.0, 0.0, 0.0); glpushmatrix(); glscalef (2.0, 0.4, 1.0); glutwirecube (1.0); glpopmatrix(); 2 x x 2 gltranslatef (1.0, 0.0, 0.0); glrotatef ((GLfloat) elbow, 0.0, 0.0, 1.0); gltranslatef (1.0, 0.0, 0.0); glpushmatrix(); glscalef (2.0, 0.4, 1.0); glutwirecube (1.0); glpopmatrix(); ( ) #include <GL/glut.h> #include <stdlib.h> static int shoulder = 0, elbow = 0; void init(void) glclearcolor (0.0, 0.0, 0.0, 0.0); glshademodel (GL_FLAT);

8.4 39 void display(void) glclear (GL_COLOR_BUFFER_BIT); glpushmatrix(); gltranslatef (-1.0, 0.0, 0.0); glrotatef ((GLfloat) shoulder, 0.0, 0.0, 1.0); gltranslatef (1.0, 0.0, 0.0); glpushmatrix(); glscalef (2.0, 0.4, 1.0); glutwirecube (1.0); glpopmatrix(); gltranslatef (1.0, 0.0, 0.0); glrotatef ((GLfloat) elbow, 0.0, 0.0, 1.0); gltranslatef (1.0, 0.0, 0.0); glpushmatrix(); glscalef (2.0, 0.4, 1.0); glutwirecube (1.0); glpopmatrix(); glpopmatrix(); glutswapbuffers(); void reshape (int w, int h) glviewport (0, 0, (GLsizei) w, (GLsizei) h); glmatrixmode (GL_PROJECTION); glloadidentity (); gluperspective(65.0, (GLfloat) w/(glfloat) h, 1.0, 20.0); glmatrixmode(gl_modelview); glloadidentity(); gltranslatef (0.0, 0.0, -5.0);

40 8 /* ARGSUSED1 */ void keyboard (unsigned char key, int x, int y) switch (key) case s : shoulder = (shoulder + 5) % 360; glutpostredisplay(); break; case S : shoulder = (shoulder - 5) % 360; glutpostredisplay(); break; case e : elbow = (elbow + 5) % 360; glutpostredisplay(); break; case E : elbow = (elbow - 5) % 360; glutpostredisplay(); break; case 27: exit(0); break; default: break; int main(int argc, char** argv) glutinit(&argc, argv); glutinitdisplaymode (GLUT_DOUBLE GLUT_RGB); glutinitwindowsize (500, 500); glutinitwindowposition (100, 100); glutcreatewindow (argv[0]); init (); glutdisplayfunc(display); glutreshapefunc(reshape); glutkeyboardfunc(keyboard); glutmainloop(); return 0;

41 9 9.1 GLUT GLUT void glutdisplayfunc(void (*func)(void)); glutpostredisplay() void glutreshapefunc(void (*func)(void)); func 2 func glviewport() glutreshapefunc() NULL glviewport(0, 0, width, height) void glutkeyboadfunc(void (*func)(unsigned int key, int x, int y)); ASCII func key ASCII x, y ( ) void glutmousefunc(void (*func)(int button, int state, int x, int y)); func button GLUT LEFT BUTTON, GLUT MIDDLE BUTTON, GLUT RIGHT BUTTON state GLUT UP GLUT DOWN x y ( ) void glutmotionfunc(void (*func)(int x, int y));

42 9 func x y ( ) void glutpostredisplay(void); glutdisplayfunc() glutidlefunc() void glutidlefunc(void (*func)(void)); func NULL func GLUT glutmainloop() void glutmainloop(void); GLUT 9.2 OpenGL ( ) 1 OpenGL 2 (double-buffer) 2 GLUT void glutswapbuffers(void); (viewpoint)

9.2 43 #include <GL/glut.h> static GLfloat spin = 0.0; void display(void) glclear(gl_color_buffer_bit); glpushmatrix(); glrotatef(spin, 0.0, 0.0, 1.0); glcolor3f(1.0, 1.0, 1.0); glrectf(-25.0, -25.0, 25.0, 25.0); glpopmatrix(); glutswapbuffers(); void spindisplay(void) spin = spin + 2.0; if (spin > 360.0) spin = spin - 360.0; glutpostredisplay(); void init(void) glclearcolor (0.0, 0.0, 0.0, 0.0); glshademodel (GL_FLAT); void reshape(int w, int h) glviewport (0, 0, (GLsizei) w, (GLsizei) h); glmatrixmode(gl_projection); glloadidentity(); glortho(-50.0, 50.0, -50.0, 50.0, -1.0, 1.0); glmatrixmode(gl_modelview); glloadidentity();

44 9 /* ARGSUSED2 */ void mouse(int button, int state, int x, int y) switch (button) case GLUT_LEFT_BUTTON: if (state == GLUT_DOWN) glutidlefunc(spindisplay); break; case GLUT_MIDDLE_BUTTON: if (state == GLUT_DOWN) glutidlefunc(null); break; default: break; /* * Request double buffer display mode. * Register mouse input callback functions */ int main(int argc, char** argv) glutinit(&argc, argv); glutinitdisplaymode (GLUT_DOUBLE GLUT_RGB); glutinitwindowsize (250, 250); glutinitwindowposition (100, 100); glutcreatewindow (argv[0]); init (); glutdisplayfunc(display); glutreshapefunc(reshape); glutmousefunc(mouse); glutmainloop(); return 0; glutswapbuffers() GLUT

9.2 45 3 1. sample-teapot.c 2. planet.tar.gz planet ex.c glpushmatrix() glpopmatrix() 3. planet ex.c 4. planet ex.c 5. sample-robot.c ( glpushmatrix() glpopmatrix() ( ) 18