OpenGL, (OpenGL GL, Graphics Library ). OpenGL 3.,,. OpenGL. 14. 3. 1, OpenGL OpenGL., OpenGL. 2, 3. 3, 3 2.. 4,.
26 Ope ngl Progra mming Guide - OpenGL 1.2 5,, (, ). 3 3. 3. OpenGL.. 6,,,.,,. 7, OpenGL. OpenGL. 8,,,, 2.. 9, 1 2 3.. 10, OpenGL.,,,, DOF. 11, GLU(OpenGL Utility Library). 12, NURBS.
27 13, OpenGL.,, OpenGL. 14, OpenGL. OpenGL OpenGL IRIS Graphics Library.,. A, OpenGL,. B, OpenGL,. C, OpenGL OpenGL. X Window System Apple Macintosh, IBM OS/2, MS Windows NT, Windows 95. D, GLUT OpenGL. GLUT,. E,. F,. G, OpenGL OpenGL. H, OpenGL OpenGL, OpenGL.
28 Ope ngl Progra mming Guide - OpenGL 1.2 OpenGL 3. OpenGL 1.2 - - rescaling - (packed BGRA) - 3D,, LOD, specular highlights OpenGL 1.2 - OpenGL - GLU(OpenGL Utility Library) 1.3 GLX(OpenGL Extension to the X Window System) 1.3 2 C, (,,,, ).,.,. Computer Graphics : Principles and Practices, James D. Foley, Andries van Dam, Steven K. Feiner, John F. Hughes (Reading, MA: Addison-Wesley, 1990) -.,. 3D Computer Graphics : A User's Guide f or Artists and Designers, Andrew S. Glassner (New York: Design Press, 1989) -
29.,. OpenGL OpenGL., FAQ,. OpenGL. ht t p :/ / www.opengl.org OpenGL OpenGL ARB OpenGL Reference Manual ( Addison-Wesley ). Reference Manual OpenGL., OpenGL (,, ). OpenGL., OpenGL. OpenGL OpenGL. OpenGL. (, )., OpenGL,,,,. OpenGL. Mark Kilgard GLUT(OpenGL Utility Toolkit). GLUT Mark Kilgard OpenGL Programming for the X Window System (Reading, MA: Addison-Wesley Developers Press, 1996). 1 OpenGL D GLUT. GLUT ftp.
30 Ope ngl Progra mming Guide - OpenGL 1.2. ft p :/ / ft p.sgi.com/ opengl / opengl 12.t ar.z ft p :/ / ft p.sgi.com/ opengl / opengl 12. zi p (MS Windows 95/98/NT X Window System ) GLUT GLUT. ht t p :/ / www.opengl.org/ devel oper s/ document at i on/ gl ut / OpenGL. OpenGL OpenGL. OpenGL. Na te Robins Ope ngl OpenGL Nate Robins (OpenGL Tutors).,.,,. GLUT,. ht t p :/ / www. cs.ut ah.edu/ ~nar obi ns/ opengl.ht ml. (errata). ht t p :/ / www.woo. com/ er rat a.ht ml.,.
31. - -,,, -, (brace). glcommand s, i, f, d, GLshort, GLint, GLfloat, GLdouble. glcommand TYPE. void g lco mmand{sifd}(type x1, TYPE y1, TYPE x2, TYPE y2);
1 Ope ngl OpenGL OpenGL OpenGL OpenGL OpenGL
34 Ope ngl Progra mming Guide - OpenGL 1.2 OpenGL 6. OpenGL? OpenGL, OpenGL. OpenGL OpenGL,. OpenGL OpenGL. OpenGL OpenGL. OpenGL. OpenGL OpenGL, GLUT(Graphics Library Utility Toolkit).. Ope ngl? OpenGL 3 250 (200 OpenGL, 50 OpenGL Utility Library ). OpenGL., OpenGL.., OpenGL 3.,,, OpenGL,,. GLU(OpenGL Utility Library), OpenGL. GLU NURBS. GLU OpenGL., (Fahrenheit Scene Graph, FSG) OpenGL
Chapter 1 Ope ngl 35, OpenGL ( OpenGL ). OpenGL., OpenGL.. OpenGL. OpenGL.. 1 (wireframe).,. (, ).,..,.,,,.. 2 (depth-cue).. OpenGL ( (fog) ). 3 (antialias ing). (pixel, picture element ),..
36 Ope ngl Progra mming Guide - OpenGL 1.2 4 (lighting) (flat-s hading).... 5, (smooth-shading). 3. 6 5 (shadow) (texture). OpenGL, 14. 2 3..,,. 7 (motion-blur). ( ). 8. 3. 9 2. 2. 10 DOF(depth-of-field)... OpenGL. OpenGL ( OpenGL ). 1.., (OpenGL,,,, ).
Chapter 1 Ope ngl 37 2. 3,. 3..,,,. 4.. (rasterization)..,,. X Window System OpenGL., OpenGL,. OpenGL ( ) OpenGL. OpenGL,. Ope ngl OpenGL.., OpenGL,. OpenGL,. (rendering). (model) (vertice) (,, ).
38 Ope ngl Progra mming Guide - OpenGL 1.2. (pixel),.. (bitplane),..,., OpenGL. [ 1-1] [ 1-1]. 1-1 1-1 OpenGL #i ncl ude <what everyouneed.h> mai n () { Ini t i al i zeawi ndowpl ease (); gl Cl earcol or (0. 0, 0. 0, 0. 0, 0. 0); gl Cl ear (GL_COLOR_BUFFER_BI T); gl Col or 3f (1. 0, 1. 0, 1. 0); gl Ort ho (0. 0, 1. 0, 0. 0, 1. 0, - 1. 0, 1. 0);
Chapter 1 Ope ngl 39 } glbegin(gl_ POLYGON); gl Vert ex3f (0.25, 0.25, 0. 0); gl Vert ex3f (0.75, 0.25, 0. 0); gl Vert ex3f (0.75, 0.75, 0. 0); gl Vert ex3f (0.25, 0.75, 0. 0); gl End (); gl Fl ush (); Updat ethewi ndowandcheckforevent s (); main() ( ) (window). InitializeAWindowPlease() OpenGL. OpenGL. glclearcolor(), glclear(). glclear()., glcolor3f() ( ).. OpenGL glortho(), (coordinate system) OpenGL., glbegin() glend().. glvertex3f(). (x, y, z), z=0., glflush() (buff er). UpdateTheWindowAndCheckForEvents(). OpenGL.,., InitializeAWindowPlease() UpdateTheWindowAndCheckForEvents() [ 1-1].
40 Ope ngl Progra mming Guide - OpenGL 1.2 Ope ngl glclearcolor() OpenGL gl (prefix). GL_,, _ (, GL_COLOR_BUFFER_BIT)., glcolor3f() glvertex3f() 3f (suffix). glcolor3f() Color OpenGL, OpenGL., 3., Color. f (floating-point). OpenGL. OpenGL 8. [ 1-1] ISO C OpenGL OpenGL. C++ Ada OpenGL. 1-1 C OpenGL b 8 integer signed char GLbyte s 16 integer short GLshort i 32 integer int long GLint, GLsizei f 32 floating-point float GLfloat, GLclampf d 64 floating-point double GLdouble, GLclampd ub 8 unsigned integer unsigned char GLubyte, GLboolean us 16 unsigned integer unsigned short GLushort ui 32 unsigned integer unsigned int unsigned long GLuint, GLenum, GLbitfield
Chapter 1 Ope ngl 41, gl Ver t ex2i (1, 3); gl Ver t ex2f (1. 0, 3. 0); (vertex) 32 integer, (single-precision floating-point). NOTE OpenGL C OpenGL. OpenGL. OpenGL v, ( ).,,.. gl Col or 3f (1. 0, 0. 0, 0. 0); GLfloat col or_array [] = {1. 0, 0. 0, 0. 0}; glcol or3fv (color_array);, OpenGL GLvoid. OpenGL. OpenGL, (*)., glcolor*().., glvertex*v(). Ope ngl OpenGL (state machine)...,
42 Ope ngl Progra mming Guide - OpenGL 1.2. OpenGL,,,,,,,,. glenable() gldisable().,. glgetbooleanv(), glgetdoublev(), glgetfloatv(), glgetintegerv(), glgetpointerv(), glisenabled().. (, glgetlight*(), glgeterror(), glgetpolygonstipple())., glpushattrib(), glpushclientattrib(), glpopattrib() glpopclientattrib().. B OpenGL. glget*(). Ope ngl OpenGL OpenGL (OpenGL Rendering Pipeline). [ 1-2] OpenGL, OpenGL. 3,. OpenGL.,, (evaluator) pre-vertex,,,.
Chapter 1 Ope ngl 43 ( per-fragment, per-fragment ),. 1-2, OpenGL., (display list) (, (immediate mode) ). ( 7 ).. (basis function). (evaluator)
44 Ope ngl Progra mming Guide - OpenGL 1.2. (polynomial mapping),,,, ( 12 ). Per-Vertex, (per-vertex Operation). 4 4. 3D (projection) ( 3 )..,.,,,,.. (clipping),.,,. (perspective division)., (viewport) (depth, z- ). (culling). (2 ).,,,,.
Chapter 1 Ope ngl 45 OpenGL,.,. (scale), (bias)., (clamp), (8 ).,, (mapping), (clamping) (pixel-transfer operation).,..,. OpenGL.. OpenGL. (9 ). (rasterization) (f ragment).,. (filled polygon),,,, (coverage)..
46 Ope ngl Progra mming Guide - OpenGL 1.2,.. (texturing) (texel, texture element)., (scissor),,, ( )..,,,, (6 10 ).,,. Ope ngl OpenGL,., OpenGL.. OpenGL (GLU, OpenGL Utility Library) OpenGL, (tessellation),. OpenGL. GLU OpenGL Ref erence Manual. GLU 11 12 GLU NURBS. GLU glu. OpenGL. X Window System, GLX (OpenGL Extension to the X Window System) OpenGL. GLX glx. MS Windows 95/98/NT, OpenGL WGL. WGL wgl., IBM OS/2 PGL(Presentation Manager to OpenGL
Chapter 1 Ope ngl 47 interface), pgl. Apple, AGL, agl. C. GLX OpenGL Ref erence Manual. OpenGL (GLUT, OpenGL Utility Toolkit) Mark Kilgard API. GLUT, Mark Kilgard OpenGL Programming for the X Window System (ISBN 0-201-48359-9). GLUT glut. GLUT. (FSG, Fahrenheit Scene Graph) OpenGL 3. FSG C++, 3,. FSG OpenGL. include, OpenGL gl.h., OpenGL GLU glu.h., OpenGL. #i ncl ude <GL/ gl.h> #i ncl ude <GL/ gl u.h> MS Windows, MS Windows gl.h glu.h windows.h windows.h gl.h glu.h., GLX, AGL, PGL, WGL., GLX.
48 Ope ngl Progra mming Guide - OpenGL 1.2 #i ncl ude <X11/ Xl i b.h> #i ncl ude <GL/ gl x.h> MS Windows WGL. #i ncl ude <wi ndows.h> GLUT. #i ncl ude <GL/ gl ut.h> NOTE glut.h gl.h glu.h include. glut.h MS Windows,. GLUT glut.h, gl.h glu.h., OpenGL C. #i ncl ude <st dl i b.h> #i ncl ude <st di o.h> GLUT - OpenGL OpenGL., OpenGL.,,, Windows., GLUT. OpenGL GLUT., OpenGL,, GLUT, 3.
Chapter 1 Ope ngl 49 (OpenGL (GLU) GLUT, 3 ). OpenGL GLUT, OpenGL. GLUT ( GLUT D Kilgard OpenGL Programming for the X Window System 4 5 ).. glutinit(int *argc, char **argv) - GLUT (X Window System, -display -geometry ). GLUT glutinit(). glutinitdisplaymode (uns igned int mode) - RGBA,.,, ( glutsetcolor() ).,,., RGBA,, glutinitdisplaymode (GLUT_DOUBLE GLUT_RGB GLUT_DEPTH). glutinitwindowpos ition(int x, int y) -. glutinitwindowsize (int width, int size) -. int glutcreatewindow(char *string) - OpenGL.. glutmainloop().
50 Ope ngl Progra mming Guide - OpenGL 1.2 glutdisplayfunc(void (*f unc)(void)). GLUT.,. glutmainloop() glutpostredisplay(). glutmainloop(void)..,.. [ 1-2] GLUT [ 1-1].. init(). display(), GLUT. 1-2 GLUT OpenGL : hello.c #i ncl ude <GL/ gl ut.h> #i ncl ude <st dl i b.h> voi d di spl ay (voi d ) { / *. */ gl Cl ear (GL_COLOR_BUFFER_BI T) ; / * (0. 25, 0. 25, 0. 0) (0 75, 0.75, 0. 0) * ( ). */ gl Col or 3f (1. 0, 1. 0, 1. 0) ;
Chapter 1 Ope ngl 51 gl Begi n (GL_POLYGON) ; gl Vert ex3f (0.25, 0.25, 0. 0) ; glvert ex3f (0 75, 0.25, 0. 0) ; gl Vert ex3f (0.75, 0.75, 0. 0) ; gl vert ex3f (0.25, 0.75, 0. 0) ; gl End () ; / *, * OpenGL. */ gl Fl ush (); } voi d i ni t (voi d ) { / *. */ gl Cl ear Col or (0. 0, 0. 0, 0. 0, 0. 0) ; / *. */ glmat r i xmode (GL_PROJECTION) ; gl LoadIdent i t y () ; glort ho (0. 0, 1. 0, 0. 0, 1. 0, - 1. 0, 1. 0) ; } / *, ( RGBA ). * "hel l o".. *. *,. */ i nt mai n (i nt argc, char ** argv ) { gl ut Ini t (&argc, argv ) ; glutinitdisplaymode (GLUT_SINGLE GLUT_RGB) ; gl ut I ni t Wi ndowsi ze (250, 250) ; gl ut Ini twi ndowposi t i on (100, 100) ; gl ut Creat ewi ndow("hel l o" ) ; i ni t () ; gl ut Di spl ayfunc (di spl ay ) ; glutmai nloop () ; r et ur n 0; / * I SO C mai n i nt. */ }
52 Ope ngl Progra mming Guide - OpenGL 1.2. glutreshape Func(void (*func)(int w, int h)) -. glutkeyboardfunc (void (*func)(unsigned char key, int x, int y)) -. glutmouse Func (void (*func)(int button, int state, int x, int y)) -. glutmotionfunc(void (*func)(int x, int y)) -., (idle) glutidlefunc(void (*f unc)(void)).. NULL. 3 GLUT 3. (cone) (cube) 12 (dodecahedron) 20 (icosahedron) 8 (octahedron) (sphere) (teapot) (tetrahedron) (torus),.,. void gl utwi recube (GLdouble si ze ); void gl ut Sol i dcube (GLdouble si ze ); void gl utwi resphere (GLdouble radi us, GLint sl i ces, GLint s t acks ); void gl ut Sol i dsphere (GLdouble radi us, GLint sl i ces, GLint s tacks );
Chapter 1 Ope ngl 53 ( D )..,,. 24... 1 24, ( 16 ). 60 76 (refresh), 120. 30 60 60 120. 120... open_wi ndow(); for (i = 0; i < 1000000; i ++) { cl ear_t he_wi ndow(); draw_fr ame (i ); wai t _unt i l_a_24t h_of_a_second_i s_over (); }, 1/24. 1/24,
54 Ope ngl Progra mming Guide - OpenGL 1.2. 1/24.,. OpenGL (double-buff ering)..,,..,.,... open_wi ndow_i n_doubl e_buf fer_mode (); for (i = 0; i < 1000000; i ++) { cl ear_t he_wi ndow(); dr aw_f rame (i ); swap_t he_buf fer s (); } OpenGL, swap_the_buffers().,. 60 60fps(frames per second), 1/60. 1/60,., 1/45, 30fps 1/30-1/45=1/90.
Chapter 1 Ope ngl 55,., 1/60, 60fps, 30fps, 20fps, 15fps, 12fps (60/1, 60/2, 60/3, 60/4, 60/5,...)., 60fps, 1/60 60fps 30fps. 1/30 30 20fps. (1/60, 2/60, 3/60 ),,.,.. = +.,. 3.., (viewpoint),,.. swap_the_buffers(). swap_the_buffers(), OpenGL., X Window System, GLX. voi d gl xswapbuf fers (Di spl ay *dpy, Wi ndow wi ndow);
56 Ope ngl Progra mming Guide - OpenGL 1.2 ( C.) GLUT,. voi d gl ut SwapBuffer s (void ); [ 1-3] [ 1-3] glutswapbuffers()., GLUT idle.. 1-3 1-3 : double.c #i ncl ude <st dl i b.h> #i ncl ude <GL/ gl ut.h> st at i c GLfl oat spi n = 0. 0; voi d i ni t (voi d ) { gl Cl earcol or (0. 0, 0. 0, 0. 0, 0. 0) ; gl ShadeModel (GL_ FLAT) ; } voi d di spl ay (voi d ) { gl Cl ear (GL_COLOR_BUFFER_BI T) ; gl PushMat r i x () ; gl Rot at ef (spi n, 0. 0, 0. 0, 1. 0) ; gl Col or 3f (1. 0, 1. 0, 1. 0) ; } gl Rect f (- 25. 0, - 25. 0, 25. 0, 25. 0) ; gl PopMat r i x () ; gl ut SwapBuf fer s () ;