Вы находитесь на странице: 1из 476

(ahinar@list.

ru)
- http://www.progz.ru/forum/index.php?showforum=91

OpenGL Red Book ( )

1. OpenGL
2.
3.
4.
5.
6. , ,
7.
8. , ,
9.
10.
11.
12. NURBS
13.
14.
A.
B.
C. GLUT
D.
E.
F.
G. OpenGL
H. OpenGL

1. OpenGL
1.1 OpenGL?
OpenGL .
250 ( 200 OpenGL
50 ),
, , ,
.
OpenGL , ,
.
OpenGL
;
, . OpenGL
.
,
, .
OpenGL
, ().
, ,
OpenGL. OpenGL (OpenGL Utility Library -- GLU)
, ,
, NURBS. GLU
OpenGL. ,
, Fahrenheit Scene Graph (FSG), OpenGL
.

,
OpenGL .
1. ,
( OpenGL , , ,
).
2.
.
3. . ,
, ,
.
4.
. (
).
OpenGL , ,
, . ,
, , , ,
, .
(, X Window), OpenGL
, , ,
,
. ,
, , .
, ,
OpenGL, , , ,
. OpenGL (
) ,
, .
, .

1.2 OpenGL
OpenGL , ,
, .
:
, , OpenGL
, ,
.
, , .
(rendering) ,
.
, , ,
(vertices).
.
,
.
(, )
(bitplanes).
, .
, , .
,
,
.

, OpenGL . 1-1
, 1.
1.1.

1-1. OpenGL
#include <__.h>

main()
{
();
glClearColor(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();
();
}
main() .
() ,
, ,
OpenGL. OpenGL,
: glClearColor() ,
, glClear() . ,
,
glClear(). glClearColor().
glColor3f() ,
. ,
,
OpenGL.

OpenGL , , glOrtho(),
, OpenGL
. ,
glBegin() glEnd(), ,
4 .
glVertex3f(). ,
(x, y, z), z=0.
, glFlush() , OpenGL
,
. () - ,
.
.
:
?
? () ()
, , , ,
.

1.3 OpenGL
, ,
OpenGL gl
, (, , glClearColor()).
OpenGL , GL_
(,
GL_COLOR_BUFFER_BIT).
,
(, 3f glColor3f() glVertex3f()).
, Color () glColor3f() ,
.
, .
, 3 glColor3f() ,
, , . f
, .
,
.
. ,

OpenGL ISO - C 1-1.
OpenGL (, C++ Ada)
.
1-1.

,
OpenGL

signed char

GLbyte

16

short

GLshort

32

int long

GLint, GLsizei


32

float

GLfloat, GLclampf


64

double

GLdouble, GLclampd

ud

unsigned char

GLubyte, GLboolean

us

16

unsigned short

GLushort

ui

32

unsigned int unsigned long

GLuint, GLenum, GLbitfield

,
glVertex2i(1,3);
glVertex2f(1.0,3.0);

,
32- ,
.
: OpenGL ,
C ,
OpenGL. ,
OpenGL, C,
OpenGL.
v, ,
( ) ,
. , ,
, ,
,
.

.
glColor3f(1.0,0.0,0.0);
GLfloat color_array[]={1.0,0.0,0.0};
glColor3fv(color_array);

, OpenGL GLvoid,
.

(, glColor*()), ,
.
,
(, glVertex*v()
).

1.4 OpenGL (state machine)


OpenGL . ,
, , , .
, .
, , ,
, .
, OpenGL.
, ,
, ,
, ,
.
OpenGL, glEnable()
glDisable().
,
. ,

, 6 : glGetBooleanv(),
glGetDoublev(), glGetFloatv(), glGetIntegerv(), glGetPointerv(), glIsEnabled().
,
.
( , glGetLight*(), glGetError() glGetPolygonStipple()).
,
glPushAttrib() glPushClientAttrib(),
glPopAttrib() glPopClientAttrib().

,
.

1.5 OpenGL
OpenGL
, OpenGL (OpenGL rendering pipeline).
1-2 ,
, , , OpenGL.
( ),
OpenGL . (,
) , ,
(, )
.
( ) ,
.
1.2.

OpenGL.

1.5.1
, (display
lists) . (
,
.) , ,
.

1.5.2

.

, .
,
, . ,
, ,
.

1.5.3

(per-vertex operations).
.
44.
3D .
OpenGL,
. ,
.
, , ,
, , ,
, ,
.

1.5.4
,
, .
;
(,
).
, ,
, .
(viewport) ( z).
, ,
.
,
.
,
, ,
, .

1.5.5
,
.
, - ,
. ,
.
.
,
(pixel-transfer operations).
.

(pixel copy operations)



.

1.5.6
OpenGL
, .
, ,
.
OpenGL
. ,
. ,
,
.

1.5.7

. .
, , , ,

.
.

1.5.8
, ,
, .
.
, ,

( ). ( )
, (scissor test), -, (stencil test)
( ).
, .
, (dithering),
. ,
, .

1.6 , OpenGL
OpenGL ,
. ,
OpenGL .
, .
:
OpenGL Utility Library (GLU) ,
OpenGL ,
,
.
OpenGL.
,
OpenGL. , X

Window OpenGL (GLX)


glX. Microsoft Windows 95/98/Me/NT/200/XP WGL
Windows OpenGL. wgl.
IBM OS/2 pgl. Apple
AGL, (agl).
OpenGL Utility Toolkit (GLUT) ,
, API
. glut. GLUT
Microsoft Windows 95/98/NT/Me/XP X Window
http://reality.sgi.com/opengl/glut3/glut3.html.
GLUT.
Fahrenheit Scene Graph (FSG) - ,
OpenGL,
. FSG, C++,

,
,
. FSG OpenGL.
OpenGL, Silicon Graphics
(OpenGL Auxiliary Library -- GLAUX).
Microsoft Platform SDK
.

1.7
OpenGL gl.h.
GLU glu.h.
, OpenGL
:
#include <GL/gl.h>
#include <GL/glu.h>

Microsoft Windows windows.h gl.h


glu.h, , ,
windows.h.
OpenGL ,
GLX, AGL, PGL WGL, .
, GLX, :
#include <X11/Xlib.h>
#include <GL/glx.h>

Microsoft Windows WGL :


#include <windows.h>

GLUT ,
, :
#include <GL/glut.h>

: glut.h , gl.h glu.h,


. glut.h
,
, gl.h glu.h.
GLUT-, glut.h
gl.h glu.h.

OpenGL C,

:
#include <stdlib.h>
#include <stdio.h>

1.8

,
. ,
Microsoft Windows OpenGL ( )
opengl32.dll, GLU glu32.dll.
, ,

.
opengl32.lib glu32.lib, , ,
.
, , ,
. (, , GLUT)
,
. , ,
, , .
,
. , ,
, ( )
Microsoft Windows (
,
[ Windows]\System).

1.9 GLUT
, OpenGL ,
. ,
.
, , , ,

.

, GLUT ,
. OpenGL GLUT
, (
).
, OpenGL, ,
GLUT ,
, , () . ( , GLU
, ,
.)
GLUT OpenGL
(,
OpenGL),

OpenGL.
GLUT. , A
.

1.9.1
void glutInit (int argc, char **argv);

glutInit() GLUT ,
GLUT. glutInit()
, .
X Window, iconic, -geometry display. (,
glutInit(), , ,
main()).
void glutInitDisplayMode (unsigned int mode);

(, RGBA ,
) , glutCreateWindow().
,
, . mask ,
OR : GLUT_RGBA
GLUT_INDEX ( ), GLUT_SINGLE GLUT_DOUBLE (
),
GLUT_DEPTH, GLUT_STENCIL, GLUT_ACCUN. ,
, RGBA
, GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH | GLUT_STENCIL.
GLUT_RGBA | GLUT_ SINGLE (
RGBA - ).
void glutInitWindowSize (int width, int height);
void glutInitWindowPosition (int x, int y);


. (x, y) ,
. width height ( ).

.
int glutCreateWindow (char *name);

(
, ). name
, . ,
glutMainLoop(),
- .
.

( OpenGL) .

1.9.2
, , ,
, GLUT.

void glutDisplayFunc (void (*func)(void));

( func), ,
. ,
, , ,
, glutPostRedisplay().
void glutReshapeFunc (void (*func)(int width, int height));

,
. func ,
: width height .
func glViewport()
,
.
glutReshapeFunc() NULL (
),
, glViewport (0,0,width,height).
void glutKeyboardFunc (void (*func)(unsigned int key, int x, int y));

func, , ,
ASCII-. key.
x y ( )
.
void glutMouseFunc (void (*func)(int button, int state, int width, int height));

, .
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));

,
, . x y
( ) .
void glutPostRedisplay (void);

, .
,
glutDisplayFunc().

1.9.3
, ,
OpenGL . ,
. GLUT
RGB
.

void glutSetColor (Glint index, GLfloat red, GLfloat green, GLfloat blue);

index, RGB-, red,


green blue. [0.0, 1.0].

1.9.4

. GLUT
.
. :
,
( ).
, .
, ,
. ,
.
void glutWireSphere (GLdouble radius, GLint slices, GLint stacks);
void glutSolidSphere (GLdouble radius, GLint slices, GLint stacks);

radius,
( ) slices z stacks z.
, , z , ,
.
z . ( ),
( ).
.
stacks, slices.
, , ,
.
void glutWireCube (GLdouble size);
void glutSolidCube (GLdouble size);

size.
void glutWireTorus (GLdouble innerRadius, GLdouble outerRadius, GLint nsides,
GLint rings);
void glutSolidTorus (GLdouble innerRadius, GLdouble outerRadius, GLint nsides,
GLint rings);

() outerRadius
innerRadius. rings
, nsides
.
void glutWireCone (GLdouble radius, GLdouble height, GLint slices, GLint stacks);
void glutSolidCone (GLdouble radius, GLdouble height, GLint slices, GLint
stacks);

radius, height.
slices stacks .
void glutWireIcosahedron (void);
void glutSolidIcosahedron (void);
void glutWireOctahedron (void);

void
void
void
void
void

glutSolidOctahedron (void);
glutWireTetrahedron (void);
glutSolidTetrahedron (void);
glutWireDodecahedron (GLdouble radius);
glutSolidDodecahedron (GLdouble radius);

, ,
(
).
void glutWireTeapot (GLdouble size);
void glutSolidTeapot (GLdouble size);

size.

1.9.5
, ,
, .
.
void glutIdleFunc (void (*func)(void));

, ,
( ).
glutIdleFunc() NULL.

1.9.6
, , GLUT
glutMainLoop().
void glutMainLoop (void);

.
.
1-2 , GLUT ,
1-1. .
,
( ), init().
( ) display(),
.
1-2. OpenGL GLUT: hello.cpp
#include <GL/glut.h>

void init(void)
{
// ()
glClearColor(0.0,0.0,0.0,0.0);
//
glMatrixMode(GL_PROJECTION);
glLoadIdentity();

glOrtho(0.0,1.0,0.0,1.0,-1.0,1.0);
}
void display(void)
{
// glClear(GL_COLOR_BUFFER_BIT);
// () // (0.25, 0.25, 0.0) (0.75,
0.75, 0.0)
glColor3f(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();
// .
// OpenGL
glFlush();
}
// ,
// hello.
//
//
int main(int argc, char **argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
glutInitWindowSize(250,250);
glutInitWindowPosition(100,100);
glutCreateWindow(hello);
init();
glutDisplayFunc(display);
glutMainLoop();
return 0;
}

1.9.7
,
Microsoft Windows,
.
:
.

DOS Windows ( 32-
). ,
C
API . ,
, .
GLUT OpenGL.
, GLUT glutCreateWindow()

. OpenGL
, GLUT, C
(, printf( ) cout<< )
. ,

( ,
OpenGL ).
main(),
( ),
glutInit().
, ,
.
, , GLUT. ,

main() WinMain().
, ,
. glutInit()
main() .
. , (
)
( ).
glutInit() :
char* argv="";
int argc=0;
glutInit(&argc,&argv);

, .

1.10
,
. ,
, ,
,
, .

24 . ,
. ,
, .
, 24 ,
. (
,
16 .)
60 76 (
120 ). , 60
, 30, 120 , 60. ,
120 (
, , ).
,
, . ,
, ,
:

_();
for(i=0;i<1000000;i++)
{
_();
_(i);
____24__();
}

, ,
, , ,
,
1/24 . ,
1/24 .
, , ,
,
, ,
. ,
,
.
OpenGL
,
. , .
, : ,
, .
:
, .
, ,
,
. ,
. .

:
_____();
for(i=0;i<1000000;i++)
{
_();
_(i);
_();
}

1.11
OpenGL, _()
, ,
,
. , 60
. , ,
60 (frames per second -- fps)
1/60 ,
.
, , 1/60 ,
, . ,
, 1/45 , 30 fps
1/30-1/45=1/90 ,
.

, ,
. , 60
, 60 fps, 30, fps, 20 fps, 15 fps, 12 fps
. , ,
, ,
- 60 fps.
, , 1/60
, , , 30 fps,
. ,
, , 1/30
20 fps.
(1/60 , 1/30
, 1/20 ), -
, .
,
. , , ,
, .

, .

1.12 = +
,
.
, .
,
.


, ,
. ,
.
, _()
.
OpenGL _(),
, ,
. , X Window (
) GLX :
void glXSwapBuffers (Display *dpy, Window window);

Microsoft Windows
:
BOOL SwapBuffers (HDC hdc);

GLUT :
void glutSwapBuffers (void);

1-3 glutSwapBuffers()
, 1-3. ,
GLUT /

.
.
1.3.

1.3. , : double.cpp
#include <GL/glut.h>

GLfloat spin=0.0;
void init(void)
{
glClearColor(0.0,0.0,0.0,0.0);
glShadeModel(GL_FLAT);
}
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+1.0;
if(spin>360.0) spin=spin-360.0;
glutPostRedisplay();
}
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();
}
//

// ()
//
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_RIGHT_BUTTON: if (state==GLUT_DOWN) glutIdleFunc(NULL); break;
}
}
//
//
int main(int argc, char **argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB);
glutInitWindowSize(250,250);
glutInitWindowPosition(100,100);
glutCreateWindow(" ");
init();
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutMouseFunc(mouse);
glutMainLoop();
return 0;
}

2.

, OpenGL,
.

.

2.1
, ,
, ,
.
, , ,
.

2.1.1
,
,
. , , ,
,
, , .
.
( )

. ,
, , .
, ,
,
, . :

, ? ,
, . ,
, OpenGL ,
,
. , ,
, ,
.
, ,
. ,
, .
. , ,
(RGBA) ,
, . RGBA
.
, . ,
RGBA :
glClearColor(1.0,1.0,1.0,0.0);
glClear(GL_COLOR_BUFFER_BIT);

,
. glClear() ,
. ,
, (
, ). ,
, - ,
, . OpenGL

., , ,
:
glClearColor(1.0,1.0,1.0,0.0);
glClearDepth(1.0);
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);

glClearColor() , glClearDepth()
, ,
glClear() , ,
, .
glClear() ,
.
void glClearColor (GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha);

RGBA . ,
red, green, blue alpha [0, 1].
, (0.0,0.0,0.0,0.0).
void glClear (GLbitfield mask);

. mask
, 2-1,
.
2-1. ,

GL_COLOR_BUFFER_BIT

GL_DEPTH_BUFFER_BIT

()

GL_ACCUM_BUFFER_BIT

GL_STENCIL_BUFFER_BIT

, ,
, -
RGBA , ,
. glClearColor() glClearDepth()
, glClearIndex(),
glClearAccum() glClearStencil() ,
,
.
OpenGL , ,
, , (
),
. ,
, .
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);

glClear(GL_COLOR_BUFFER_BIT);
glClear(GL_DEPTH_BUFFER_BIT)

, ,

.

2.1.1
OpenGL .
,
. (
) (,
, -
). ,
.
,
. OpenGL
, ,
.
,
__();
_(A);

_(B);
__();
__();
_(C);

A B , C . 4 ,
, (
- ) 5 , ,
.
, glColor3f(). 3 ,
0.0 1.0.
, , , .
,
: 0.0 , , 1.0
. ,
glColor3f(1.0,0.0,0.0);

,
, . ,
; , ,
0.5 ( ).
8 , .
glColor3f(0.0,0.0,0.0);
glColor3f(1.0,0.0,0.0);
glColor3f(0.0,1.0,0.0);
glColor3f(1.0,1.0,0.0);
glColor3f(0.0,0.0,1.0);
glColor3f(1.0,0.0,1.0);
glColor3f(0.0,1.0,1.0);
glColor3f(1.0,1.0,1.0);

2.1.2
OpenGL 1,
.
(Central Processing Unit CPU) . ,
. ,
/ . ,
. high-end
,
, .
CPU ,
. CPU ,
, ,
, . CPU
,
.
, , .
, , -
( ),
( ),
.
,
, .
, ,

. , (
), .
,
, , .
OpenGL glFlush(),
, . ,
, glFlush()
. , ,
,
glFlush() . , glFlush()
,
, , ,
, .

, glFlush() :
,
.
,
.
.
void glFlush(void);

OpenGL, , ,
.
,
glFlush() ( )
, .
glFlush() glFinish().
glFlush(),
, . glFinish() ,
, ,
, Display PostScript .
, , ,
. glFinish()
, ,
. , glFinish()
,
, glFinish()
. glFlush(),
glFinish().
void glFinish(void);

OpenGL.
, .

2.2
, ,

. GLUT,
,

glutReshapeFunc().
:

,
.
,
.

2-1 .
2-1.
void reshape(int w, int h)
{
glViewport(0,0,(GLsizei)w, (GLsizei)h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0,0,(GLdouble)w, (GLdouble)h);
}

GLUT : (
) . glViewport() ,
.
,
(0,0), (w,h) ( 2-1).
. w h
reshape()
. . gluOrtho2D()
,
. , ,
, .
2-1. , w=50 h=50

2.3 ,
, OpenGL.
,
, .
, ,
.

2.3.1 , ?
,
, . OpenGL , .
.
OpenGL ,
, , . ,
, OpenGL .
.
,
1/100 , ,
( )
( ). OpenGL , ,
.
, ( ),
, , , OpenGL
.

2.3.1.1
, .
,
. ,
( x- y-), OpenGL z 0.
: OpenGL
, ,
(x,y,z,w). w 0,
(x/w,y/w,z/w).
w- OpenGL, .
w- , 1.0.

2.3.1.2
OpenGL (),
, .

( 2-2).
.
2-2. (
)

2.3.1.3
( ) , ,
(
). ,
, .
, OpenGL
,
. -, OpenGL (
, , ). , OpenGL . ,
, ( ,
) (
). 2-3
. OpenGL (,
, , ). ,
, ,
. OpenGL
, ,
. ,
( ).
2-3.

, OpenGL , ,

. .
. OpenGL
, .
,
.
, GLU
.
(teselation),
OpenGL ,
.
OpenGL , ,
,
. (, ,
z- 0 .)
,
,
,
. ,

, .
, , ,
( 2-4).

. ,
, .
2-4. ,

2.3.1.4
, OpenGL
, glRect*().
, OpenGL
glRect*() .
void glRect{sifd} (TYPE x1, TYPE y1, TYPE x2, TYPE y2);
void glRect{sifd}v (TYPE *v1, TYPE *v2);

, (x1,y1) (x2,y2).
z=0 .
, ,
(x,y).
,
,
.

2.3.1.5


.
,
, -
( 2-5). ,
, ,
.
2-5.

2.3.2
OpenGL
.
glVertex*().
void glVertex{234}{sifd}(TYPE coords);
void glVertex{234}{sifd}v(const TYPE *coords);
.
2 (x,y) 4 (x,y,z,w),
. ,
z w, z 0, w 1. glVertex*()
glBegin() glEnd().
2-2 glVertex*().
2-2. glVertex*()
glVertex2s(1,5);
glVertex3d(0.7,5.224,3.1415926535898);
glVertex4f(2.1,1.3,-2.0,2.0);
GLdouble dvect[3]={5.0,9.0,1992.0};
glVertex3dv(dvect);


(1,5,0). (, z ,
0.) (0.7,5.224,3.1415926535898)
( ).
(1.05, 0.65, -1.0). (

w=2.0.) dvect
, .
glVertex*() ,
.

. ,
,
.
OpenGL.

2.3.3
, , , ,
OpenGL , .

,
glBegin() glEnd(). , glBegin(), ,
. 2-3
2-6.
2-6. .

2-3
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();

GL_POINTS GL_POLYGON ,
, 2-6. 2-2
glBegin() .
void glBegin(GLenum mode);

, .
mode, ,
2-2.
2-2. mode ( ) glBegin()

GL_POINTS

GL_LINES

GL_LINE_STRIP

()

GL_LINE_LOOP

, , , ,
( )

GL_TRIANGLES

GL_TRIANGLE_STRIP

GL_TRIANGLE_FAN

GL_QUADS

GL_QUAD_STRIP

GL_POLYGON

2-7 ,
2-2. ,
. ,
. ,
.

2-7.

, ,
glBegin() glEnd() n (V[0], V[1], V[2], ..., V[n-1]).
GL_POINTS

GL_LINES

. V[0]
V[1] , V[2] V[3], . n ,
V[n-3] V[n-2], n-1 .

GL_LINE_STRIP

V[0] V[1], V[1] V[2], .

V[n-2] V[n-1]. , n-1 .


n < 2 . ,
( ).
.
GL_LINE_LOOP

, GL_LINE_STRIP, , , V[n-1] V[0],


.

GL_TRIANGLES

( ) V[0],
V[1] V[2], V[3], V[4] V[5], . n 3, 1 2
.

GL_TRIANGLE_STRIP

, V[0], V[1] V[2], V[2], V[1]


V[3] ( ), V[2], V[3], V[4], .
, ,
, .
(,
). ,
n 3.

GL_TRIANGLE_FAN

, GL_TRIANGLE_STRIP, : V[0], V[1], V[2],


V[0], V[2], V[3], V[0], V[3], V[4], .

GL_QUADS

( ),
V[0], V[1], V[2], V[3], V[4], V[5], V[6], V[7], . n
4, 1, 2 3 .

GL_QUAD_STRIP

, : V[0], V[1],
V[3], V[2], V[2], V[3], V[5], V[4], V[4], V[5], V[7], V[6] . n
4, . n ,
.

GL_POLYGON

, V[0], V[1], V[2], ..., V[n-1] . n


3 . ,
.
, .

2.3.3.1 glBegin() glEnd()


,
glVertex*().
, , ,
, . ,
glBegin() glEnd(). 2-3
.
2-3. , glBegin() glEnd().

glVertex*()

glColor*()

glIndex*()

glNormal*()

glTexCoord*()

glMultiTexCoord*ARB()

glEdgeFlag*()

glMaterial*()

glArrayElement()

glEvalCoords*(),
glEvalPoint*()

glCallList(), glCallLists()

glBegin() glEnd(),
OpenGL . ,
, glEnableClientState() glVertexPointer()
glBegin() glEnd() ,
. (, , OpenGL,
glX*() glBegin()

glEnd().) , ,
.
, ,
OpenGL , .
glBegin() glEnd(). 2-4, ,
.
2-4. glBegin() 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;
glVertex2f(cos(angle),sin(angle));
}
glEnd();

:
, , .
,
, sin() cos().
, .
,
.
glVertex*() ,
glBegin() glEnd(),
glVertex*() . glVertex*()
, :
glVertex*() ,
(, glCallList()).
, glBegin() glEnd() ,
glVertex*().
glVertex*() OpenGL ,
, . ,
. ,
, .
glBegin(GL_POINTS);
glColor3f(0.0,1.0,0.0); //
glColor3f(1.0,0.0,0.0); //
glVertex(...);
glColor3f(1.0,1.0,0.0); //
glColor3f(0.0,0.0,1.0); //
glVertex(...);
glVertex(...);
glEnd();

24 glVertex*()
glBegin() glEnd(),
, .

(, glColor*, glVertex*, glColor*, glVertex*
),
.

2.4

RGBA
, . OpenGL
. ,
, , ,
(states), ,
, , .
, OpenGL ,
. ,
.
, .
2 :
void glEnable (GLenum cap);
void glDisable (GLenum cap);

glEnable() , glDisable() . 40
, glEnable()
glDisable(). : GL_BLEND ( RGBA
), GL_DEPTH_TEST (
), GL_LINE_STIPPLE ( ) GL_LIGHTING
().
:
GLboolean glIsEnabled (GLenum capability);

GL_TRUE GL_FALSE
.
, , :
. OpenGL
. , glColor3f() 3
, GL_CURRENT_COLOR. 5
,
:
void
void
void
void
void

glGetBooleanv (GLenum pname, GLboolean *params);


glGetIntegerv (GLenum pname, GLint *params);
glGetFloatv (GLenum pname, GLfloat *params);
glGetDoublev (GLenum pname, GLdouble *params);
glGetPointerv (GLenum pname, GLvoid *params);

, ,
. pname
, ,
params ,
. , RGBA
glGetIntegerv(GL_CURRENT_COLOR, params) glGetFloatv(GL_CURRENT_COLOR,
params). ( )
, .
( ) .

2.5 ,

, ,
, , .
, .

2.5.1
glPointSize()
( ) .
void glPointSize (GLfloat size);

( ) , size
0.0 , , 1.0.
,
, . (
.) (
),
.
, 1.0, 1 x 1
, 2.0 2 x 2
.
, ,

.
( 2-8).
2-8.

OpenGL .
,
GL_ALIASED_POINT_SIZE_RANGE glGetFloatv().

, GL_SMOOTH_POINT_SIZE_RANGE.

. glGetFloatv()
GL_SMOOTH_POINT_SIZE_GRANULARITY, ,
,
,
( ). , glPointSize(2.34),
0.1, 2.4.

:
,
,
OpenGL. , ,
GL_POINTS_SIZE_RANGE ( GL_SMOOTH_POINT_SIZE_RANGE)
GL_POINT_SIZE_GRANULARITY ( GL_SMOOTH_POINT_SIZE_GRANULARITY).
(
). ,
GL_LINE_WIDTH_RANGE (
GL_SMOOTH_LINE_WIDTH_RANGE) GL_LINE_WIDTH_GRANULARITY (
GL_SMOOTH_LINE_WIDTH_GRANULARITY).
- , ,
. , .

2.5.2
OpenGL , ,
, , .

2.5.2.1

void glLineWidth (GLfloat width);

, width 0.0
1.0.

. 1, 2 3
1, 2 3 .

. , OpenGL
,
, .

glGetFloatv() GL_ALIASED_LINE_WIDTH_RANGE.

, OpenGL,
GL_SMOOTH_LINE_WIDTH_RANGE
GL_SMOOTH_LINE_WIDTH_GRANULARITY .
: , 1 ,

. , , ,
OpenGL , ,
, 1
.
,
.
: ,
.
, |y2-y1|<|x2-x1|( (x1,y1) (x2,y2) ) .

,
.

2.5.2.2

(,
) glLineStipple()
glEnable().
glLineStipple(1,0x3F07);
glEnable(GL_LINE_STIPPLE);
void glLineStipple (Glint factor, GLushort pattern);

. pattern 16-
, , .
. ,
, ,
( ). ,
pattern.
factor.
factor , . ,
, factor 3,
9 6 .
factor 1 256.
GL_LINE_STIPPLE glEnable().
glDisable().
, 0x3F07 (
0011111100000111) ,
( ) 3 , 5 , 6
2 ( , -
, , ).
16 , 17-,
. factor 2, ,
: 6 , 10
, 12 4 . 2-9
,
. ,
, 0xFFFF, 1.
,
.
2-9.

( GL_LINE_STRIP GL_LINE_LOOP)
, ,
. (
GL_LINES) ,
glBegin() glEnd().

2-5
.
. 210.
2-10.

2-5. . lines.cpp
#include
#define drawOneLine(x1,y1,x2,y2)
glBegin(GL_LINES);glVertex2f((x1),(y1));glVertex2f((x2),(y2));glEnd();
void init(void)
{
glClearColor(1.0,1.0,1.0,0.0);
glShadeModel(GL_FLAT);
}
void display(void)
{
int i;
glClear(GL_COLOR_BUFFER_BIT);
//
glColor3f(0.0,0.0,0.0);
glEnable(GL_LINE_STIPPLE);
//
glLineWidth(1.0);
glLineStipple(1,0x0101); //
drawOneLine(50.0,125.0,150.0,125.0);
glLineStipple(1,0x00FF); //
drawOneLine(150.0,125.0,250.0,125.0);
glLineStipple(1,0x1C47); //-
drawOneLine(250.0,125.0,350.0,125.0);
//
glLineWidth(5.0);
glLineStipple(1,0x0101); //
drawOneLine(50.0,100.0,150.0,100.0);
glLineStipple(1,0x00FF); //
drawOneLine(150.0,100.0,250.0,100.0);
glLineStipple(1,0x1C47); //-
drawOneLine(250.0,100.0,350.0,100.0);
// - ,
glLineWidth(1.0);
glLineStipple(1,0x1C47); //-
glBegin(GL_LINE_STRIP);
for (i=0;i<7;i++)

glVertex2f(50.0+((GLfloat)i*50.0),75.0);
glEnd();
//
for (i=0;i<6;i++)
{
drawOneLine(50.0+((GLfloat)i*50.0),50.0,50.0+((GLfloat)(i+1)*50.0),50.0);
}
// 1 - =5
glLineStipple(5,0x1c47);
drawOneLine(50.0,25.0,350.0,25.0);
glDisable(GL_LINE_STIPPLE);
glFlush();
}
void reshape(int w,int h)
{
glViewport(0,0,(GLsizei) w, (GLsizei) h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0.0,400.0,0.0,150.0);
}
int main(int argc, char **argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
glutInitWindowSize(400,150);
glutInitWindowPosition(100,100);
glutCreateWindow("Line Stipple Patterns");
init();
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutMainLoop();
return 0;
}

2.5.3
,
, ()
, . ,
.
, ,
, .
,
, (
). , ,
.
, .

2.5.3.1 ,
,
- ,
. ,
(, , ).
, .
, . ,
, ,
glPolygonMode().

void glPolygonMode (GLenum face, GLenum mode);

.
face ,
GL_FRONT_AND_BACK (
), GL_FRONT ( ), GL_BACK ( ).
mode GL_POINT, GL_LINE GL_FILL
: , .
(
, ,
, :
glPolygonMode(GL_FRONT,GL_FILL);
glPolygonMode(GL_BACK,GL_LINE);

2.5.3.2
, ( ) ,
, , .
(
, , , , ,
) . ,
,
, (,
, ).
,
,
( ,
). OpenGL,
glFrontFace().
void glFrontFace (GLenum mode);

, OpenGL . mode
GL_CCW,
. mode
GL_CW, ,
.
,
, , ,

. ,
() , , OpenGL
, . ,
, ,
OpenGL . OpenGL
, glCullFace()
glEnable().
void glCullFace (GLenum mode);

,
. mode GL_FRONT, GL_BACK

GL_FRONT_AND_BACK, ,
. , ,
GL_CULL_FACE
glEnable().
glDisable().
: ,
.

i-

. , GL_CCW, a>0,
,
. GL_CW, , a<0,
( ).

2.5.3.3
, ,
, . ,
32 x 32
glPolygonStipple().
void glPolygonStipple (const GLubyte *mask);

. mask
32 x 32 ,
, ( ).
, 1 , ,
0 . 2-12 ,
mask.
GL_POLYGON_STIPPLE
glEnable() glDisable(). mask GL_UNPACK*
glPixelStore*().
, :
glEnable(GL_POLYGON_STIPPLE);

glDisable() .
2-11 :
, .
2-6. ( 2-11)
( 2-12) ,
( ,
, , ).
2-11.

2-12.

2-6. . polys.cpp
#include

void init(void)
{
glClearColor(0.0,0.0,0.0,0.0);
glShadeModel(GL_FLAT);
}
void display(void)
{
GLubyte fly[]= {
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x03,0x80,0x01,0xC0,0x06,0xC0,0x03,0x60,
0x04,0x60,0x06,0x20,0x04,0x30,0x0C,0x20,
0x04,0x18,0x18,0x20,0x04,0x0C,0x30,0x20,
0x04,0x06,0x60,0x20,0x44,0x03,0xC0,0x22,
0x44,0x01,0x80,0x22,0x44,0x01,0x80,0x22,
0x44,0x01,0x80,0x22,0x44,0x01,0x80,0x22,
0x44,0x01,0x80,0x22,0x44,0x01,0x80,0x22,
0x66,0x01,0x80,0x66,0x33,0x01,0x80,0xCC,
0x19,0x81,0x81,0x98,0x0C,0xC1,0x83,0x30,
0x07,0xE1,0x87,0xE0,0x03,0x3F,0xFC,0xC0,
0x03,0x31,0x8C,0xC0,0x03,0x33,0xCC,0xC0,
0x06,0x64,0x26,0x60,0x0C,0xCC,0x33,0x30,
0x18,0xCC,0x33,0x18,0x10,0xC4,0x23,0x08,
0x10,0x63,0xC6,0x08,0x10,0x30,0x0C,0x08,
0x10,0x18,0x18,0x08,0x10,0x00,0x00,0x08
};
GLubyte halftone[] = {
0xAA,0xAA,0xAA,0xAA,0x55,0x55,0x55,0x55,
0xAA,0xAA,0xAA,0xAA,0x55,0x55,0x55,0x55,
0xAA,0xAA,0xAA,0xAA,0x55,0x55,0x55,0x55,
0xAA,0xAA,0xAA,0xAA,0x55,0x55,0x55,0x55,
0xAA,0xAA,0xAA,0xAA,0x55,0x55,0x55,0x55,
0xAA,0xAA,0xAA,0xAA,0x55,0x55,0x55,0x55,
0xAA,0xAA,0xAA,0xAA,0x55,0x55,0x55,0x55,
0xAA,0xAA,0xAA,0xAA,0x55,0x55,0x55,0x55,
0xAA,0xAA,0xAA,0xAA,0x55,0x55,0x55,0x55,
0xAA,0xAA,0xAA,0xAA,0x55,0x55,0x55,0x55,
0xAA,0xAA,0xAA,0xAA,0x55,0x55,0x55,0x55,
0xAA,0xAA,0xAA,0xAA,0x55,0x55,0x55,0x55,
0xAA,0xAA,0xAA,0xAA,0x55,0x55,0x55,0x55,
0xAA,0xAA,0xAA,0xAA,0x55,0x55,0x55,0x55,
0xAA,0xAA,0xAA,0xAA,0x55,0x55,0x55,0x55,
0xAA,0xAA,0xAA,0xAA,0x55,0x55,0x55,0x55
};
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1.0,1.0,1.0);
//
//
glRectf(25.0,25.0,125.0,125.0);
glEnable(GL_POLYGON_STIPPLE);
glPolygonStipple(fly);
glRectf(125.0,25.0,225.0,125.0);
glPolygonStipple(halftone);
glRectf(225.0,25.0,325.0,125.0);
glDisable(GL_POLYGON_STIPPLE);
glFlush();
}
void reshape(int w, int h)
{
glViewport(0,0,(GLsizei) w, (GLsizei) h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0.0,350.0,0.0,150.0);
}
int main(int argc, char **argv)
{

glutInit(&argc,argv);
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
glutInitWindowSize(350,150);
glutCreateWindow("Polygon Stipple Patterns");
init();
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutMainLoop();
return 0;
}

OpenGL
.

2.5.3.4
: OpenGL ,
, .
,
2-13 . ,
glPolygonMode()
, ,
, .
OpenGL, ,
( , ,
). OpenGL
, ,
, (
). , GL_LINE ,
, . 2-13, ,
, .
2-13.

, ,
glEdgeFlag*().
glBegin() glEnd () ,
glEdgeFlag*().
, ,
,
(GL_TRIANGLE_STRIP, GL_QUAD_STRIP).
void glEdgeFlag (GLboolean flag);

void glEdgeFlagv (const GLboolean *flag);

, (
). flag GL_TRUE,
TRUE ( ) ,
. ,
GL_FALSE. , ,
GL_LINE
.
, 2-7 , 2-14.
2-14. , .

2-7.
glPolygonMode(GL_FRONT_AND_BACK,GL_LINE);
glBegin(GL_POLYGON);
glEdgeFlag(GL_TRUE);
glVertex3fv(V0);
glEdgeFlag(GL_FALSE);
glVertex3fv(V1);
glEdgeFlag(GL_TRUE);
glVertex3fv(V2);
glEnd();

2.6
( ) ,
.
, ,

. OpenGL
.
( ) (
). .
,
. OpenGL
, ( ).
, .
glNormal*(),
, . glVertex*()

. ,
, , 2-8.
2-8.
glBegin(GL_POLYGON);
glNormal3fv(n0);
glVertex3fv(v0);
glNormal3fv(n1);
glVertex3fv(v1);
glNormal3fv(n2);
glVertex3fv(v2);
glNormal3fv(n3);
glVertex3fv(v3);
glEnd();
void glNormal3{bsidf}(TYPE nx, TYPE ny, TYPE nz);
void glNormal3{bsidf}v(const TYPE *v);

, .
( v) , (nx,ny,nz),
.
( v) ,
, .
, b, s i,
[-1.0, 1.0].
, ,
, .
, ,
( ). (
, (x, y, z) (-x, -y, z)).
, ,
.
, , , ,
1. (,
, ). ,
.
:

,
. ,

OpenGL
. ,
glEnable(GL_NORMALIZE).

( ),

glEnable(GL_RESCALE_NORMAL).
OpenGL
, .

,
, .
GL_RESCALE_NORMAL
,
GL_NORMALIZE. (
, ) .

2.7
, OpenGL
. , 20-
22 : glBegin(),
glVertex*() 20- , , glEnd().
(
) .

.
.
,
. , 2-15 6-
8- . ,
, 3 :
, . , 24
, 8-.
2-15. ,

OpenGL
, ,
.
20

. ,
.

.
, . ,
(

OpenGL).
: OpenGL 1.1,
OpenGL 1.0. , 1.0
.


:
1. () ,
: , RGBA
, , , .
2. .
. -
.
3. . OpenGL
,
(, ), . ( .)
:
a. (
,
, )
b. ,

c. .
.

. , ,
,
.

2.7.1 1:
glEnableClientState() ,
. ,

. , , ,
. , ,
GL_COLOR_ARRAY ( RGBA) GL_INDEX_ARRAY (
), ,
, RGBA , ,
.
void glEnableClientState (GLenum array);

.
GL_VERTEX_ARRAY ( ), GL_COLOR_ARRAY (
RGBA), GL_INDEX_ARRAY (
), GL_NORMAL_ARRAY ( ),
GL_TEXTURE_COORD_ARRAY ( ) GL_EDGE_FLAG_ARRAY
( ).
,
.
,
^
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_NORMAL_ARRAY);

, -
. glDisable()
, . , , ,
,
. , :
glDisableClientState(GL_NORMAL_ARRAY);
void glDisableClientState (GLenum array);

, ( ,
).
glEnableClientState().
, , OpenGL
(gl*ClientState()),
glEnable() / glDisable()? ,
glEnable() / glDisable() ,
, .
OpenGL, ,

.

2.7.2 2:

. . 6
6 . ,
,
, .
void glVertexPointer (Glint size, GLenum type, GLsizei stride, const GLvoid
*pointer);

, . pointer
, .
type (GL_SHORT, GL_INT,
GL_FLOAT GL_DOUBLE). size ,
2, 3 4. stride ( )
. stride
0 ( ), , .
, :
void glColorPointer (Glint size, GLenum type, GLsizei stride, const GLvoid
*pointer);
void glIndexPointer (GLenum type, GLsizei stride, const GLvoid *pointer);
void glNormalPointer (GLenum type, GLsizei stride, const GLvoid *pointer);
void glTexCoordPointer (Glint size, GLenum type, GLsizei stride, const GLvoid
*pointer);
void glEdgeFlagPointer (GLsizei stride, const GLvoid *pointer);

, -
,
- . , ,
, .
,

. 2-4
size type ,
, , OpenGL
, , .
2-4. ( )

glVertexPointer

2,3, 4

GL_SHORT, GL_INT, GL_FLOAT, GL_DOUBLE

glNormalPointer

GL_BYTE, GL_SHORT, GL_INT, GL_FLOAT, GL_DOUBLE

glColorPointer

3, 4

GL_BYTE, GL_UNSIGNED_BYTE, GL_SHORT,


GL_UNSIGNED_SHORT, GL_INT, GL_UNSIGNED_INT,
GL_FLOAT, GL_DOUBLE

glIndexPointer

GL_UNSIGNED_BYTE, GL_SHORT, GL_INT, GL_FLOAT,


GL_DOUBLE

glTexCoordPointer

1, 2, 3, 4

GL_SHORT, GL_INT, GL_FLOAT, GL_DOUBLE

glEdgeFlagPointer

OpenGL, ,
glTexCoordPointer()
.
2-9
RGBA. RGB
(x, y)
GL_COLOR_ARRAY ( RGBA) GL_VERTEX_ARRAY (
).
2-9.
GLint vertices[]= {25, 25,
100, 325,
175, 25,
175, 325,
250, 25,
325, 325};
GLfloat colors[]= {1.0, 0.2, 0.2,
0.2, 0.2, 1.0,
0.8, 1.0, 0.2,
0.75, 0.75, 0.75,
0.35, 0.35, 0.35,
0.5, 0.5, 0.5};
glEnableClientState(GL_COLOR_ARRAY);
glEnableClientState(GL_VERTEX_ARRAY);
glColorPointer(3,GL_FLOAT, 0, colors);
glVertexPointer(2,GL_INT, 0, vertices);

2.7.2.1

stride gl*Pointer() OpenGL,


.
, ,
, . ,
0 . , ,
RGB (x, y, z)
:

GLfloat interwined[]={
1.0, 0.2, 1.0, 100.0, 100.0, 0.0,
1.0, 0.2, 0.2, 0.0, 200.0, 0.0,
1.0, 1.0, 0.2, 100.0, 300.0, 0.0,
0.2, 1.0, 0.2, 200.0, 300.0, 0.0,
0.2, 1.0, 1.0, 300.0, 200.0, 0.0,
0.2, 0.2, 1.0, 200.0, 100.0, 0.0};

:
. ,
. ,
GLubyte.
. ,
,
OpenGL ,
, . ,
, ,
. ,
RGB-
GLubyte.
, ,
RGB 3 ,
.
3 . ,

.
. , 2
, OpenGL,
.
interwined,
(
&interwined[0]), 6*sizeof(GLfloat),
. ,
.
glColorPointer(3,GL_FLOAT,6*sizeof(GLfloat),&interwined[0]);

, 4-
interwined (, C 0).
glVertexPointer(3,GL_FLOAT, 6*sizeof(GLfloat),&interwined[3]);

stride 0, ,
( ), ,
, .

2.7.3 3:
, ,
.

.
( ),
(
, )
.

2.7.3.1

void glArrayElement (Glint ith);

ith
.
glVertex[size][type]v(), size 2, 3
4, type s, i, f d ( GLshort, Glint, GLfloat GLdouble ). size,
type glVertexPointer().
glArrayElement() glEdgeFlagv(),
glTexCoord[size][type]v(), glColor[size][type]v(), glIndex[type]v()
glNormal[type]v(). , glVertex*v()
, ,
.
glArrayElement() glBegin() glEnd() (
glArrayElement() ,
,
, , , ;
, ,
). 2-10
, ,
( - , C 0).
2-10. glArrayElement()

glEnableClientState(GL_COLOR_ARRAY);
glEnableClientState(GL_VERTEX_ARRAY);
glColorPointer(3,GL_FLOAT,0,colors);
glVertexPointer(2,GL_INT,0,vertices);
glBegin(GL_TRIANGLES);
glArrayElement(2);
glArrayElement(3);
glArrayElement(5);
glEnd();

,
glBegin(GL_TRIANGLES);
glColor3fv(colors+(2*3));
glVertex2iv(vertices+(2*2));
glColor3fv(colors+(3*3));
glVertex2iv(vertices+(3*2));
glColor3fv(colors+(5*3));
glVertex2iv(vertices+(5*2));
glEnd();

glArrayElement()
,
.
, glBegin()
glEnd(), ,
.
,
.

2.7.3.2

glArrayElement()
. glDrawElements()
glDrawRangeElements()
.
void glDrawElements (GLenum mode, GLsizei count, GLenum type, void *indices);

, count
, indices. type
GL_UNSIGNED_BYTE, GL_UNSIGNED_SHORT
GL_UNSIGNED_INT, indices. mode ,
, ,
glBegin(), GL_POLYGON, GL_LINE_LOOP, GL_LINES,
GL_POINTS .
glDrawElements() ,
:
int i;
glBegin(mode);
for(i=0;i<COUNT;I++)
glArrayElement(indices[i]);
glEnd();

glDrawElements() mode, count type


. , , glDrawElements()
.
glDrawElements() RGB , , ,
( , )
.
glDrawElements()
. 2-11
glDrawElements() . 2-16
, 2-11.
2-16.

2-11. glDrawElements()

GLubyte
GLubyte
GLubyte
GLubyte
GLubyte
GLubyte

frontIndices[] = {4,5,6,7};
rightIndices[] = {1,2,6,5};
bottomIndices[] = {0,1,5,4};
backIndices[] = {0,3,2,1};
leftIndices[] = {0,4,7,3};
topIndices[] = {2,3,7,6};

glDrawElements(GL_QUADS,4,GL_UNSIGNED_BYTE,frontIndices);
glDrawElements(GL_QUADS,4,GL_UNSIGNED_BYTE,rightIndices);
glDrawElements(GL_QUADS,4,GL_UNSIGNED_BYTE,bottomIndices);
glDrawElements(GL_QUADS,4,GL_UNSIGNED_BYTE,backIndices);
glDrawElements(GL_QUADS,4,GL_UNSIGNED_BYTE,leftIndices);
glDrawElements(GL_QUADS,4,GL_UNSIGNED_BYTE,topIndices);

:
GLubyte allIndices[] ={4,5,6,7,1,2,6,5,
0,1,5,4,0,3,2,1,
0,4,7,3,2,3,7,6};
glDrawElements(GL_QUADS,24,GL_UNSIGNED_BYTE,allIndices);

: glDrawElements() glBegin() glEnd() .


glDrawElements(), glDrawRangeElements()
. glDrawRangeElements()
,
. ,
OpenGL
. glDrawRangeElements()
, .
void glDrawRangeElements (GLenum mode, GLuint start, GLuint end, GLsizei count,
GLenum type, void *indices);

,
glDrawElements(),
. glDrawRangeElements(), mode
( ), count ( ), type ( ) indices (
), , glDrawElements().
glDrawRangeElements() : start end,
indices. ,
, indices
start end .
indices [start, end]
. OpenGL
. ,
OpenGL, . ,
.
glGetIntegerv() GL_MAX_ELEMENTS_VERTICES
GL_MAX_ELEMENTS_INDICES , , ,

( , ).
end-start+1 , ,
count , glDrawRangeElements()
- , .

[start, end].

, indices.
, glArrayElements(), glDrawElements()
glDrawRangeElements(), OpenGL
( , ) ,
,
. , 6- ()
8- . 3- . gl*Elements()
6- 24- , ,
16- . OpenGL
, 8 . (
,
glDrawElements() glDrawRangeElements(),
glArrayElement(), ,
glBegin()/glEnd().)

2.7.3.3
glArrayElements(), glDrawElements()
glDrawRangeElements(),
, glDrawArrays()
.
void glDrawArrays (GLenum mode, Glint first, GLsizei count);

,
, first
first+count-1. mode , ,
, glBegin(),
GL_POLYGON, GL_LINE_LOOP, GL_LINES, GL_POINTS .
glDrawArrays()
:
int i;
glBegin(mode);
for(i=0;i<COUNT;I++)
glArrayElement(first+i);
glEnd();

glDrawElements(), glDrawArrays()
RGB-, ,
, ,
.

2.7.4
: .
interwined RGB 3D
. glColorPointer()
glVertexPointer() stride.
GLfloat interwined[]={1.0,
1.0,
1.0,
0.2,

0.2,
0.2,
1.0,
1.0,

1.0,
0.2,
0.2,
0.2,

100.0, 100.0, 0.0,


0.0, 200.0, 0.0,
100.0, 300.0, 0.0,
200.0, 300.0, 0.0,

0.2, 1.0, 1.0, 300.0, 200.0, 0.0,


0.2, 0.2, 1.0, 200.0, 100.0, 0.0};

glInterleavedArrays(),
. , glInterleavedArrays()
, ,
1: 2: .
interwined 14
, glInterleavedArrays(). , ,
interwined RGB- ,
, :
glInterleavedArrays(GL_C3F_V3F, 0, interwined);

glInterleavedArrays() GL_COLOR_ARRAY
GL_VERTEX_ARRAY GL_INDEX_ARRAY,
GL_TEXTURE_COORD_ARRAY, GL_NORMAL_ARRAY GL_EDGE_FLAG_ARRAY.
, , glColorPointer()
glVertexPointer(),
. 3,
glArrayElement(), glDrawElements(), glDrawRangeElements() glDrawArrays()
.
void glInterleavedArrays (GLenum format, GLsizei stride, void *pointer);

,
format. format 14
, 14 . format
2-5. stride
. stride 0, ,
. pointer ,
,
( ).
OpenGL,
glInterleavedArrays() .
, glInterleavedArrays() .
glInterleavedArrays()
2-12 2-5. ,
. et, ec en,

, . st, sc sv
( ) ,
. tc RGBA
, ,
glInterleavedArrays() . pc, pn pv
( )
, , ,
, s --
,
, (
, ).

glInterleavedArrays()
2-12. et, ec,
en, st, sc, sv, tc, pc, pn, pv s format,
2-5.
sizeof(GLubyte) ( 1 ).
2-12. glInterleavedArrays(format, stride, pointer)
int str;
str=stride;
if(str==0)
str=s;
glDisableClientState(GL_EDGE_FLAG_ARRAY);
glDisableClientState(GL_INDEX_ARRAY);
if (et)
{
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glTexCoordPointer(st,GL_FLOAT,str,pointer);
}
else
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
if (ec)
{
glEnableClientState(GL_COLOR_ARRAY);
glColorPointer(sc, tc, str,pointer+pc);
}
else
glDisableClientState(GL_COLOR_ARRAY);
if (en)
{
glEnableClientState(GL_NORMAL_ARRAY);
glNormalPointer(GL_FLOAT,str,pointer+pn);
}
else
glDisableClientState(GL_NORMAL_ARRAY);
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(sv, GL_FLOAT,str,pointer+pv);

2-5, T F True False. f sizeof(GLfloat).


sizeof(GLubyte)*4 ( f, ).
2-5. , glInterleavedArrays()
Format

et

ec

en

st

sc

sv

tc

pc

pv

GL_V2F

GL_V3F

2f

GL_C4UB_V2F

GL_UNSIGNED_BYTE

3f

GL_C4UB_V3F

c+2f

GL_UNSIGNED_BYTE

GL_C3F_V3F

c+3f

GL_FLOAT

3f

GL_N3F_V3F

6f

3f

6f

GL_C4F_N3F_V3F

GL_T2F_V3F

4f

7f

10f

2f

GL_T4F_V4F

4f

5f
8f

GL_T2F_C4UB_V3F

GL_UNSIGNED_BYTE

2f

c+2f

c+5f

GL_T2F_C3F_V3F

GL_FLOAT

2f

5f

8f

GL_T2F_N3F_V3F

2f

5f

8f

GL_T2F_C4F_N3F_V3F

GL_FLOAT

2f

6f

9f

12f

GL_T4F_C4F_N3F_V4F

GL_FLOAT

4f

8f

11f

15f

3
4

GL_FLOAT

pn

, GL_V2F, GL_V3F
GL_C3F_V3F. , C4UB ,
, 4 32-
,
.
OpenGL
.
. ,
, .
,
, , .
: glInterleavedArrays()
.
.
3: glArrayElement(), glDrawElements(),
glDrawRangeElements() glDrawArrays()
.

2.8
,
.
.
OpenGL .
, GL_LINE_BIT 5 :
, GL_LINE_STIPPLE,
,
GL_LINE_SMOOTH. glPushAttrib() glPopAttrib()

.
.
, GL_CULL_FACE
.
OpenGL 1.1 .
(
), ,
glPushClientAttrib() glPopClientAttrib().
, ,
.
,
. , ,

. OpenGL ,
.
20 ,
glPushAttrib() glPopAttrib(). 2
,
glPushClientAttrib() glPopClientAttrib(). ,
,
16 ( OpenGL
GL_MAX_ATTRIB_STACK_DEPTH

GL_MAX_CLIENT_ATTRIB_STACK_DEPTH glGetIntegerv().)
.
void glPushAttrib (GLbitfield mask);
void glPopAttrib (void);

glPushAttrib() , mask,
. glPopAttrib()
, glPushAttrib(). 2-6
mask glPushAttrib().
. (
.) , GL_LIGHTING_BIT
, .
, , ,
, . glPopAttrib()
.
GL_ALL_ATTRIB_BITS
.
2-6.

GL_ACCUM_BUFFER_BIT

GL_ALL_ATTRIB_BITS

---

GL_COLOR_BUFFER_BIT

GL_CURRENT_BIT

GL_DEPTH_BUFFER_BIT

GL_ENABLE_BIT

GL_EVAL_BIT

GL_FOG_BIT

GL_HINT_BIT

GL_LIGHTING_BIT

GL_LINE_BIT

GL_LIST_BIT

GL_PIXEL_MODE_BIT

GL_POINT_BIT

GL_POLYGON_BIT

GL_POLYGON_STIPPLE_BIT

GL_SCISSOR_BIT

GL_STENCIL_BUFFER_BIT

GL_TEXTURE_BIT

GL_TRANSFORM_BIT

GL_VIEWPORT_BIT

void glPushClientAttrib (GLbitfield mask);


void glPopClientAttrib (void);

glPushClientAttrib() , mask,
. glPopClientAttrib()
,
glPushClientAttrib(). 2-7
, mask
glPushClientAttrib() .
GL_ALL_CLIENT_ATTRIB_BITS .
( ),
. 2-7.

GL_CLIENT_PIXEL_STORE_BIT

GL_CLIENT_VERTEX_ARRAY_BIT

2.9

,
.
, , ,

. , ,
,
.
, .
,
.

. ,
,
( ).

.
, , ,
. ( glScale*()
- ,
glFrontFace() .)
.
;
.
, OpenGL
.
,
.
, ,
, ;
, ,
.
,
. ,
,
. ,

.

,
. , ,
, .


, 0.

, 0.
T- ( 2-17).
, AB BC ,

AC. , ,
.
.
2-17. T-

, ,
,
, -
.
:
//
#define PI 3.14159265
// ,
//
#define EDGES 30
glBegin(GL_LINE_STRIP);
for(i=0;i<=EDGES;i++)
glVertex2f(cos((2*PI*i)/EDGES), sin((2*PI*i)/EDGES));
glEnd();

,
0 (2*PI*EDGES/EDGES)
.
, ,
.
.
, i==EDGES,
(2*PI*EDGES/EDGES), 0. (
GL_LINE_LOOP GL_LINE_STRIP
i<EDGES).

2.9.1 :
, ,
. (
, 12 20 ,
). .
2-13 ,
.
2-13.
#define X .525731112119133606

#define Z .850650808352039932
GLfloat vdata[12][3] = {
{-X,0.0,Z},{X,0.0,Z},{-X,0.0,-Z},{X,0.0,-Z},
{0.0,Z,X},{0.0,Z,-X},{0.0,-Z,X},{0.0,-Z,-X},
{Z,X,0.0},{-Z,X,0.0},{Z,-X,0.0},{-Z,-X,0.0}
};
GLuint tindices[20][3] = {
{1,4,0},{4,9,0},{4,5,9},{8,5,4},{1,8,4},
{1,10,8},{10,3,8},{8,3,5},{3,2,5},{3,7,2},
{3,10,7},{10,6,7},{6,11,7},{6,0,11},{6,1,0},
{10,1,6},{11,0,9},{2,11,9},{5,2,9},{11,2,7}
};
int i;
glBegin(GL_TRIANGLES);
for(i=0;i<20;i++)
{
//
glVertex3fv(&vdata[tindices[i][0]][0]);
glVertex3fv(&vdata[tindices[i][1]][0]);
glVertex3fv(&vdata[tindices[i][2]][0]);
}
glEnd();

X Z ,
1.0. 12-
vdata, {-X,0.0,Z},
{X,0.0,Z} . tindices ,
. ,
, vdata.
,
.
,
i- . ,
,
, .
, .
: ,
, ,
,
.
.

2.9.1.1
, ,
. ,
.
( )
. ,
.
2-14.
2-14.
GLfloat d1[3], d2[3], norm[3];
for(j=0;j<3;j++)
{

d1[j]=vdata[tindices[i][0]][j]-vdata[tindices[i][1]][j];
d2[j]=vdata[tindices[i][1]][j]-vdata[tindices[i][2]][j];
}
normcrossprod(d1,d2,norm);
glNormal3fv(norm);

normcrossprod()
, 2-15.
2-15.
void normalize(float v[3])
{
GLfloat d=sqrt(v[0]*v[0]+v[1]*v[1]+v[2]*v[2]);
if(d==0.0)
{
error( 0);
return;
}
v[0]/=d;
v[1]/=d;
v[2]/=d;
}
void normcrossprod(float v1[3], float v2[3], float out[3])
{
out[0]=v1[1]*v2[2]- v1[2]*v2[1];
out[1]=v1[2]*v2[0]- v1[0]*v2[2];
out[2]=v1[0]*v2[1]- v1[1]*v2[0];
normalize(out);
}


, , , ,
, .
,
.
1, .
, ()
( ,
):
glBegin(GL_TRIANGLES);
for(i=0;i<20;i++)
{
glNormal3fv(&vdata[tindices[i][0]][0]);
glVertex3fv(&vdata[tindices[i][0]][0]);
glNormal3fv(&vdata[tindices[i][1]][0]);
glVertex3fv(&vdata[tindices[i][1]][0]);
glNormal3fv(&vdata[tindices[i][2]][0]);
glVertex3fv(&vdata[tindices[i][2]][0]);
}
glEnd();

2.9.1.2
20- ,
,
. , (
)
4, 2-18 (,
AD=DB=AB/2, BE=EC=DC/2 AF=FC=AC/2).

: ,
. , 4 ,
3,
.
,
(
,
1).
.
2-19 20, 80 320 .
2-16 , 80-
.
2-18.

2-19.

2-16.
void drawTriangle(float *v1, float *v2, float *v3)
{
glBegin(GL_TRIANGLES);
glNormal3fv(v1);
glVertex3fv(v1);
glNormal3fv(v2);
glVertex3fv(v2);
glNormal3fv(v3);
glVertex3fv(v3);

glEnd();
}
void subdivine(float *v1, float *v2, float *v3)
{
GLfloat v12[3], v23[3], v31[3];
GLint i;
for (i=0;i<3;i++)
{
v12[i]=(v1[i]+v2[i])/2.0;
v23[i]=(v2[i]+v3[i])/2.0;
v31[i]=(v3[i]+v1[i])/2.0;
}
normalize(v12);
normalize(v23);
normalize(v31);
drawTriangle(v1,v12,v31);
drawTriangle(v2,v23,v12);
drawTriangle(v3,v31,v23);
drawTriangle(v12,v23,v31);
}
for(i=0;i<20;i++)
{
subdivine(&vdata[tindices[i][0]][0],
&vdata[tindices[i][1]][0],
&vdata[tindices[i][2]][0]);
}

2-17 2-16,
. ( depth) 0,
, .
1, 1 .
2-17.
void subdivine(float *v1, float *v2, float *v3, long depth)
{
GLfloat v12[3], v23[3], v31[3];
GLint i;
if(depth==0)
{
drawTriangle(v1,v2,v3);
return;
}
for (i=0;i<3;i++)
{
v12[i]=(v1[i]+v2[i])/2.0;
v23[i]=(v2[i]+v3[i])/2.0;
v31[i]=(v3[i]+v1[i])/2.0;
}
normalize(v12);
normalize(v23);
normalize(v31);
subdivine(v1,v12,v31,depth-1);
subdivine(v2,v23,v12,depth-1);
subdivine(v3,v31,v23,depth-1);
subdivine(v12,v23,v31,depth-1);
}

2.9.1.3
(, , 2-17)
, ,

(
).
, ,
u[0] u[1]. ,
:
void surf(GLfloat u[2],GLfloat vertex[3],GLfloat normal[3]);
float curv(GLfloat u[2]);

u[] surf(),
. u[]
curv() (

).
2-18 ,
,

.
2-18.
void subdivine(float u1[2],float u2[2],float u3[2],float cutoff,long depth)
{
GLfloat v1[3],v2[3],v3[3],n1[3],n2[3],n3[3];
GLfloat u12[2],u23[2],u31[2];
GLint i;
if(depth==maxdepth || (curv(u1)<cutoff))
{
surf(u1,v1,n1);
surf(u2,v2,n2);
surf(u3,v3,n3);
glBegin(GL_POLYGON);
glNormal3fv(n1); glVertex3fv(v1);
glNormal3fv(n2); glVertex3fv(v2);
glNormal3fv(n3); glVertex3fv(v3);
glEnd();
return;
}
for(i=0;i<2;i++)
{
u12[i]=(u1[i]+u2[i])/2.0;
u23[i]=(u2[i]+u3[i])/2.0;
u31[i]=(u3[i]+u1[i])/2.0;
}
subdivine(u1,u12,u31,cutoff,depth+1);
subdivine(u2,u23,u12,cutoff,depth+1);
subdivine(u3,u31,u23,cutoff,depth+1);
subdivine(u12,u23,u31,cutoff,depth+1);
}

3.
, OpenGL ,
, . ,
, .
, .

(, , )
(
, ). ,
, , ,
.
,
. !
. ,
, ,
, , .

.

(), ,
, .
, , , ,
.
.
, ( ),
.

.
,
. ,
.

3.1
, ,
. 3-1
( ) .
1. ( ).
2. (
).
3. ( ).
4.
, (
).
5. ,
.
3-1.

, ,
, ,
.
,

. 3-2 ,
.
3-2.

, ,
M 4x4 .
,
v`=Mv. (, 4 (x, y, z, w),
w=1, z=0.) ,

. (
.) ,
.
, ,
,
.


. OpenGL
.
;
() .
, , x, y, z w,
. ,
.

.
, ,
, x y.
z . ,
z
( ).
. , ,
x y , . OpenGL
,
, , .
, z
x y.
, ,
.
.

3.1.1 :
3-1 , .
, .
.
, 3-1.
.
3-3.

3-1. . cube.cpp
#include <glut.h>
//
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();
// ()
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);
glutWireCube(1.0);
glFlush();
}
//
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);
}
int main(int argc, char** argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
glutInitWindowSize(500,500);
glutInitWindowPosition(100,100);
glutCreateWindow("Transformed Cube");
init();
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutMainLoop();
return 0;
}

3.1.1.1

,
.
,
( 1, 0).
,
() .
, ,
, .
, , .
3-1, ,
gluLookAt(). ,
( ), , .
, , (0, 0, 5),
(0, 0, 0) (0, 1, 0).
.
gluLookAt() ,
. (0, 0, 0),

z,
(0, 1, 0).
gluLookAt() 3-1 z 5 .

3.1.1.2


. , , ,
. 3-1,
glScalef().
. 1.0
. 3-1
y. ,
(3.0, 3.0, 3.0), (3.0, 6.0, 3.0).
3-1 .
, , ,
( ).

. , ,
.
,
.
,
display() glutWireCube(), . ,
display() ,
, , ,
, .
display() ,
,
display().

3.1.1.3

.

, ,
( ).
, .
,
, ,
. 2000 2000
- ,
, .
,
, ( ) .
OpenGL .
,
. ,
.
. , , , , .
, ,
,
glFrustum().


.
( ),
,
, .
,
, .
glFrustum(), ,
. reshape() 3-1,
glMatrixMode() GL_PROJECTION.
,
. ,
glMatrixMode() ,
GL_MODELVIEW. , ,
,
.
, glLoadIdentity()
.
. glFrustum()
, .
,
reshape(), ,
, .
, (
)
, .

3.1.1.4

,
.
, ,
,
. ,
,

(, , ).
glViewport() ( )
( (0, 0)),
.
. reshape():
, . ,
;
,
, .

3.1.1.5

, ,
( ). OpenGL
.

, ,
. , w
.

3.1.2
OpenGL,
. :
glMatrixMode() glLoadIdentity(). ,
glLoadMatrix*() glMultMatrix*()
.
, , gluLookAt() glScale*(),
.
, ,
( )
. glMatrixMode().
,
. ( glMatrixMode()
.)
void glMatrixMode (GLenum mode);

, , , ,
. mode GL_MODELVIEW (
), GL_PROJECTION ( ) GL_TEXTURE (
). .
, .
( )
.
glLoadIdentity()
, .

,
.
void glLoadIdentity (void);

( )
4 x4.

(, - ),
glLoadMatrix*(). glMultMatrix*()
, .
, 16 (
M :

),

.
, ,
( ) , ,
. ( OpenGL


.)
: C m[4][4],
m[i][j] i- j-
OpenGL. C,
m[i][j] i- j-
. C , OpenGL
,
. m[16].
void glLoadMatrix{fd} (const TYPE *m); ,

16 m
.

16 , m.
void glMultMatrix{fd} (const TYPE *m); ,

16 m
.

, 16 m
.
: OpenGL .
C, , glMultMatrix*()
M.
CM.
, .

3.2
OpenGL , ,
. ,
,
. ,

.
,

, .
,
.
, .
.
, . ,
glMatrixMode() GL_MODELVIEW ,
.

3.2.1
:
45 z

x . ,
(
) , .
, , x.
x, ,
y=x, 3-4.
. A,
B,
, , .
3-4.

, .
4x4.
glMultMatrix*()
C ( )
M, CM.
v.
, , ,
: CMv. ,
.
, ,
, .
, .
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glMultMatrixf(N);
// N
glMultMatrixf(M);
// M
glMultMatrixf(L);
// L
glBegin(GL_POINTS);
glVertex3fv(v);
// v
glEnd();

I (), N,
NM NML. NMLv. ,
N(M(Lv)) L
v, M Lv , , N MLv. ,
,
. (
, N, M
L
.)

3.2.1.1

,

,
,
. ,
x , 3-4
( x),
, . , ,
.
( R , T ):
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glMultMatrixf(T);
//
glMultMatrixf(R);
//
_();

3.2.1.2

,
,
,
.
. ,
. (
, , .)
3-4, ,
. x.
.
, .
, , ,
, , ,
. ,
, , ,
.

, .
, , ,
, , (
/).
/ k (a, b, c)
(a*k,b*k,c*k)
.
.
,
.
, .
,
. , ,
, ,
. ,

z.
, .

,
, ,
. ,
.
, ,
.
,
.

3.2.2
OpenGL : glTranslate*(),
glRotate*() glScale*(). ,
( ,
), , , , .
,
glMultMatrix*()
. ,
glMultMatrix*() OpenGL .

, (
) ,
, (
).

3.2.2.1

void glTranslate{fd} (TYPE x, TYPE y, TYPE z);

, ()
x, y, z, ,
( ).
3-5 glTranslate*().
3-5.

, (0.0, 0.0, 0.0)


glTranslate*() ,
.

3.2.2.2

void glRotate{fd} (TYPE angle, TYPE x, TYPE y, TYPE z);

, (
)
, (x, y, z). angle
.
glRotatef(45.0, 0.0,0.0,1.0), 45
z, 3-6.
3-6.

, ,
. , glRotate*()
angle 0 .

3.2.2.3

void glScale{fd} (TYPE x, TYPE y, TYPE z);

, ,
. x -, y- z-
x, y z glScale*().
,
, x, y z,
.
3-7 glScalef(-2.0,0.5,1.0);
3-7.

glScale*() ,
: 1.0
, 1.0 .
-1.0 .
( , ) (1.0, 1.0, 1.0).
glScale*() ,
. glScale*()
,
.
: 0
0. ,
. ,
, ,
. :
.
, ,
, .

3.2.2.4

3-2 , 4 :

.
, x.
, , 1.5
x 1.5 y.
, .

3-2.

glLoadIdentity();
glColor3f(1.0,1.0,1.0);
draw_triangle();
glEnable(GL_LINE_STIPPLE);
glLineStipple(1,0xF0F0);
glLoadIdentity();
glTranslatef(-20.0,0.0,0.0);
draw_triangle();
glLineStipple(1,0xF00F);
glLoadIdentity();
glScalef(1.5,0.5,1.0);
draw_triangle();
glLineStipple(1,0x8888);
glLoadIdentity();
glRotatef(90.0,0.0,0.0,1.0);
draw_triangle();
glDisable(GL_LINE_STIPPLE);

glLoadIdentity()
;
. ,
glLoadIdentity() ,
,
.

.
: , ,

( ). ,
-
(
- ). ,
,
.

3.2.3
.
,
.
.
,
,
. ,
,
, . ,
, ,
,
.
,
.
,
z.


(glTranslate*() glRotate*()).

,
.
gluLookAt()
.
.
() ,
.
,
- . ,
,
.

3.2.3.1

glTranslate*() glRotate*()

,
,
.
, ( 3-8), ,
, , .
, z.
3-8.

, ;
,
. ,
z; ,
. , 5
, ( 3-9),
:
glTranslatef(0.0,0.0,-5.0);

-5 z.
+5 z.
3-9.

, .
?
,
. ,
, . ,

, , ,
, .
.
,
.
, ,
, . ,

:
glTranslatef(0.0,0.0,-5.0);
glRotatef(90.0,0.0,1.0,0.0);

,
,
. ,
,
.
gluLookAt(), .

3.2.3.2

gluLookAt()


,
. ,
gluLookAt() .
, , (,
) , .
, . , ,
- . ( , ,
, .) , ,
.
, y ,
gluLookAt().

,
.
gluLookAt() , ,
. x y (eyex, eyey, eyez)
,
, , .
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
, -
. upz, upy upz ,
( ).
,
z,
y. ,
:
gluLookAt(0.0,0.0,0.0,0.0,0.0,-100.0,0.0,1.0,0.0);

z- -100.0,
,
.
gluLookAt(), ( 3-10). (
, .)
3-10.

, gluLookAt() ,
OpenGL. , gluLookAt() , ,
OpenGL, glTranslate*()
glRotate*(). ,
,
gluLookAt() .
gluLookAt()
z (

).
.
,
z. OpenGL
,
glRotate*().
: .
(
).
, , glLoadIdentity()
.
: (
) (, z)
. ,
,
. .

. ,
0 180 .
,
,
. .

3.2.3.3

:
.
, , , ,
.
.
, ,
.
(x, y, z). ,
roll, pitch heading.
:
void pilotView(GLdouble planex, GLdouble planey, GLdouble planez, GLdouble roll,
GLdouble pitch, GLdouble heading)
{
glRotated(roll,0.0,0.0,1.0);
glRotated(pitch,0.0,1.0,0.0);
glRotated(heading,1.0,0.0,0.0);
glTranslated(-planex,-planey,-planez);
}

,
, . , ,
. ,
distance ,
. ( distance
z.) azimuth
xy, y. ,
elevation yz,
z. , twist
. .

void polarView(GLdouble distance, GLdouble twist, GLdouble elevation, GLdouble


azimuth)
{
glTranslated(0.0,0.0,-distance);
glRotated(-twist,0.0,0.0,1.0);
glRotated(-elevation,1.0,0.0,0.0);
glRotated(azimuth,0.0,0.0,1.0);
}

3.3
,
.
, ,
. ,
, ,
glMatrixMode(GL_PROJECTION);
glLoadIdentity();

,
.
,
.

, . ,
(
), ,
. , ,
.

3.3.1

: ( ),
. ,
(,
, ). ,
,
. ,
.
,
.
, ,
,
, ( ).
glFrustum()
, ,
( ). ,
; ,
(, )
, 3-11.
.
, glFrustum()
.

3-11. ,
glFrustum()

void glFrustum (GLdouble left, GLdouble right, GLdouble bottom, GLdouble top,
GLdouble near, GLdouble far);

.
(left, bottom,-near) (right, top,-near)
(x, y, z)
; near far
(
).
.
,
, .
:
z. ,
glFrustum() ,
, .
.
,
(, ). ,
.
4 ,
. ,
, , , ,
.
3-12. ,
gluPerspective

glFrustum() ,
. gluPerspective()
. ,
glFrustum(), .
, ( )
y (x/y). (
1.0.)
( 3-12).

, , .
, gluPerspective()
x- y-, , .
void gluPerspective (GLdouble fovy, GLdouble aspect, GLdouble near, GLdouble
far);


. fovy yz,
[0.0, 180.0]. aspect
. near far

z.
gluPerspective()
,
. , ,
,
,
. , , .
, 94- 35 20- ,
.

OpenGL. .
. ,
1.0 20.0 , , ,
.

,
.

3.3.2

( 3-13).
,
,
. ,
,
.
3-13.

glOrtho()
. glFrustum()
.
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) ,
. far near ,
, .
,
z, .
,
, gluOrtho2D() .
glOrtho(), , z
1.0 -1.0.
, z ,
, - z .
void gluOrtho2D (GLdouble left, GLdouble right, GLdouble bottom, GLdouble top);


.
(left, bottom) (right, top).

3.3.3
,
, , .
,
.
, . , OpenGL
.

3.4
: , OpenGL (
) .
( )
. ,
(x, y, z, 1)
( z),
.
:

.
z xy.
:

.
, ,

(
,

, ).
:
.
( ,
z ):
.

, , .
, OpenGL
:


OpenGL (
, )
;
OpenGL ( )
, .

, ,
: ?
?
:
1. ,
. 2.
2.
. 3.
3.
2. 4...
, OpenGL
.
:

OpenGL ,
,
. ,
,
.

,
.
(
), , ,
.
,
,
.

,

.

(, ,
). OpenGL
-.
.
.
,
.
, OpenGL (
, /

).
,
.
, .
, /
OpenGL
. , ,
,
. , :
1

1

2
3

2
...

OpenGL ,
,
, , , .
,

. :



: ,
, ,
( ),
. , , :
, ,

. , ,
.
OpenGL , .
,
( )
OpenGL . , OpenGL
.
, (
):

.
(), ,
( ):

.
, , :

.
,
.
:

OpenGL
, .

,
( ,
, ,
).
,
,
( ) .
OpenGL !

3.5
,
, .
,
, . 3-14
, .
,
. ,
, ,
, .

3-14.

3.5.1
void glViewport (GLint x, GLint y, GLint width, GLint height);

,
. (x,y) ,
width height .
,
.
,
.
,
, 3-15. ,
.

.
3-15.

3-15 ,
.
:
gluPerspective(fovy, 1.0, near, far);
glViewport(0,0,400,400);

,
, .
y:
gluPerspective(fovy, 1.0, near, far);
glViewport(0,0,400,200);

,
:
gluPerspective(fovy, 2.0, near, far);
glViewport(0,0,400,200);

:
. (,
), ,
( ) .
, ,
.

3.5.2
(z) (
). glDepthRange()
z ,
. x y , z
OpenGL 0.0 1.0.
void glDepthRange (GLclampd near, GLclampd far);

, z
. near far
,
. 0.0 1.0 ,
. near far
[0.0, 1.0].
( x
- y - ) w.
z ,
( 3-16).
3-16.

,
, ,
.

3.6 ,
,
,
. , -
. ,
(,
,
).
, ,
, .
1. . , . ,
,
. , (

2.

3.
4.
5.

6.

, , )
( , ).
,

( )
z. ,
1.0, 3.0, z
[-1.0, -3.0] , .
, ,
near far
0.001 1000000.0 .
, ,
.
, ,
, . ,
(, ).
, ,
. ,
.
. gluLookAt(),
. ,
glTranslate*() ,
z
. , ,

, .
,
(),
.

,
, .
gluPerspective(), ,
, .
,
:
( 3-17).
,
. 3-3
atan2(),
,
. , , .
3-17.

3-3.
#definePI 3.1415926535>
double calculateAngle(double size, double distance)
{
double radtheta, degtheta;
radtheta = 2.0 * atan2(size/2.0,distance);
degtheta=(180.0*radtheta)/PI;
return degtheta;
}

, ,
.
,
, .
x -, y - z
. ,
. ,
.
, , ( )
:
,

.
(1, 6, 0),
,
(3, 7, 5), :

.
(8, 9, 10),
:

.
5.477 12.570,
0.4357, 23.54 .
.
, . ,
, 179
,
. ,
, .

3.7
, ,
.
( 3-18).
3-18.

,
. , ,
, 4
. , , ,
.
, ,
, , ,
z. , ,
, 4
.
,
.
, ,
.
:

.
, , .
,
.
, , ...

, , , ,
,
, .
,
, .
(glLoadMatrix(), glMultMatrix(),
glLoadIdentity() , )
, .
, : glPushMatrix()
,
glPopMatrix() ( 3-19). (,
). ,
glPushMatrix() , , glPopMatrix()
, .
3-19.

void glPushMatrix (void);

. ,
, glMatrixMode().
, ,
. ,
.
void glPopMatrix (void);

, , .
(, , ) ,
. glMatrixMode().
, glPopMatrix() .
3-4 ,
, .
3-4.
___()
{
long i;
_();
for(i=0;i<5;i++)
{
glPushMatrix();
glRotatef(72.0*i,0.0,0.0,1.0);
glTranslatef(3.0,0.0,0.0);
_();
glPopMatrix();
}
}
____()
{
__();
glPushMatrix();
//
glTranslatef(40,0,30);
___();
glPopMatrix();
glPushMatrix();
//
glTranslatef(40,0,-30);
___();
glPopMatrix();

//
...
}

, z,
72 3
. , 40
30 .
, , ,
. ,
,
,
.
glLoadIdentity().

3.7.1
,
,
.
, . ,
,
. 32
4x4. ( )
. OpenGL 32
. ,
glGetIntegerv (GL_MAX_MODELVIEW_STACK_DEPTH, GLint *params).

3.7.2
,
.
, glLoadIdentity()
.
. OpenGL
4x4.
glGetIntegerv (GL_MAX_PROJECTION_STACK_DEPTH,
GLint *params).
,
, ,
.
,
,
:
glMatrixMode(GL_PROJECTION);
glPushMatrix();//
glLoadIdentity();
glOrtho(...);//
_();
glPopMatrix();

, , ,
.

: ,
,
. , OpenGL
. ,
, , ,
.
3.8
(, , ,
, )
, . ,
, .
: Ax+By+Cz+D=0.

.

. , OpenGL
.
void glClipPlane (GLenum plane, const GLdouble *equation);

. equation 4
, Ax+By+Cz+D=0.
, :

,
M glClipPlane()
.
. plane GL_CLIP_PLANEi, i ,
, . i
0 ,
.
, ,
() :
glEnable(GL_CLIP_PLANEi);

glDisable(GL_CLIP_PLANEi);

OpenGL 6
, .

OpenGL, glGetIntegerv() GL_MAX_CLIP_PLANES.
: , glClipPlane(),
, .
, ( ,
, ).

, ,
, .

3.8.1
3-5 ,
( 3-20).
3-20.

3-5. : clip.cpp
#include <glut.h>
//
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();
gluPerspective(60.0,(GLfloat) w/(GLfloat) h,1.0,20.0);
glMatrixMode(GL_MODELVIEW);
}
//
void display(void)
{
GLdouble eqn[4]={0.0,1.0,0.0,0.0};
GLdouble eqn2[4]={1.0,0.0,0.0,0.0};
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1.0,1.0,1.0);
glPushMatrix();
glTranslatef(0.0,0.0,-5.0);
// (y<0)
glClipPlane(GL_CLIP_PLANE0,eqn);
glEnable(GL_CLIP_PLANE0);
// (x<0)
glClipPlane(GL_CLIP_PLANE1,eqn2);
glEnable(GL_CLIP_PLANE1);
glRotatef(90.0,1.0,0.0,0.0);
glutWireSphere(2.0,20,16);
glPopMatrix();
glFlush();
}

int main(int argc, char **argv)


{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
glutInitWindowSize(500,500);
glutInitWindowPosition(100,100);
glutCreateWindow("Wireframe Sphere with Two Clipping Planes");
init();
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutMainLoop();
return 0;
}

3.9
,
. : ,
,
- , ,
-.

3.9.1
, ,
, . .
glRotate*()
. glTranslate*()
. ,
,
glutWireSphere().
,
. gluPerspective()
gluLookAt().
,
, ,
. ,
. glRotate*(),
. , ,
3-21, .
, ,
.
3-21.

,
. glRotate*()
(
). glTranslate*()
. , ,
. , glRotate*()
, (
).
glRotate*()
, , . ,
, .
, OpenGL
, 3-6.
glPushMatrix();
glutWireSphere(1.0,20,16);
//
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);
//
glPopMatrix();

3-6. : planet.cpp
#include <glut.h>
int year=0, day=0;
//
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();
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);
}

//
void display(void)
{
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1.0,1.0,1.0);
glPushMatrix();
//
glutWireSphere(1.0,20,16);
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);
glPopMatrix();
glutSwapBuffers();
}
//
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;
default:
break;
}
}
int main(int argc, char **argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB);
glutInitWindowSize(500,500);
glutInitWindowPosition(100,100);
glutCreateWindow("Planetary System");
init();
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutKeyboardFunc(keyboard);
glutMainLoop();
return 0;
}

3.9.2
,
. , .
3-22 .
3-22.

,
,
.
, ,
, .
glTranslate*() glRotate*()
, .
. glPushMatrix() glPopMatrix()
glScale*().
( 3-7):
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();

,
.
, x .
, x
. ,
,
.
(, , , ).
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();

3-7. : robot.cpp
#include <glut.h>
static intshoulder=0,elbow=0;

//
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();
gluPerspective(65.0,(GLfloat) w/ (GLfloat) h,6.0,25.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(0.0,0.0,-10.0);
}
//
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 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;
default:
break;
}
}
int main(int argc, char **argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB);
glutInitWindowSize(500,500);

glutInitWindowPosition(100,100);
glutCreateWindow("Robot Arm");
init();
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutKeyboardFunc(keyboard);
glutMainLoop();
return 0;
}

3.10

, ,
. , .
,
.
, .
, ,
.
gluUnProject()
gluUnProject4() .
,
, gluUnProject() .
( [0, 1],
gluUnProject4().)
int gluUnProject (GLdouble winx, GLdouble winy, GLdouble winz, const GLdouble
modelMatrix[16],
const GLdouble projMatrix[16], const GLint viewport[4],
GLdouble *objx, GLdouble *objy, GLdouble *objz);

(winx, winy, winz) ,


, (modelMatrix),
(projMatrix) (viewport).
objx, objy objz.
GL_TRUE, , GL_FALSE
(, ).
,
glDepthRange().
.
.
, gluUnProject()
(winz), ,
glDepthRange().
gluUnProject() winz=0.0
,
winz=1.0 .
3-8 gluUnProject()


. .
3-8. : unproject.cpp
#include <glut.h>

#include <stdlib.h>
#include <stdio.h>
//
void reshape(int w, int h)
{
glViewport(0,0,(GLsizei) w, (GLsizei) h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0,(GLfloat) w/ (GLfloat) h,1.0,100.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
//
void display(void)
{
glClear(GL_COLOR_BUFFER_BIT);
glFlush();
}
//
void mouse(int button,int state,int x, int y)
{
GLint viewport[4];
GLdouble mvmatrix[16], projmatrix[16];
//y OpenGL
GLint realy;
// x, y, z
GLdouble wx,wy,wz;
switch(button)
{
case GLUT_LEFT_BUTTON:
if (state==GLUT_DOWN)
{
glGetIntegerv(GL_VIEWPORT,viewport);
glGetDoublev(GL_MODELVIEW_MATRIX,mvmatrix);
glGetDoublev(GL_PROJECTION_MATRIX,projmatrix);
//viewport[3] -
realy=viewport[3]-(GLint)y-1;
printf(" (%4d,%4d)\n",x,realy);
gluUnProject((GLdouble)x,(GLdouble)realy,0.0,mvmatrix,projmatrix,viewport,&wx,&wy,&wz);
printf(" z=0 (%f,%f,%f)\n",wx,wy,wz);
gluUnProject((GLdouble)x,(GLdouble)realy,1.0,mvmatrix,projmatrix,viewport,&wx,&wy,&wz);
printf(" z=1 (%f,%f,%f)\n",wx,wy,wz);
}
break;
case GLUT_RIGHT_BUTTON:
if (state==GLUT_DOWN)
exit(0);
break;
}
}
int main(int argc, char **argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
glutInitWindowSize(500,500);
glutInitWindowPosition(100,100);
glutCreateWindow("Reversing the Geometric Processing Pipeline");
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutMouseFunc(mouse);
glutMainLoop();
return 0;
}

GLU 1.3 gluUnProject().


gluUnProject4() w
1.
int gluUnProject4 (GLdouble winx, GLdouble winy, GLdouble winz,
GLdouble clipw, const GLdouble modelMatrix[16], const GLdouble
projMatrix[16], const GLint viewport[4],
GLclampd znear, GLclampd zfar, GLdouble *objx, GLdouble *objy,
GLdouble *objz, GLdouble *objw);

, glUnProject().
(winx, winy, winz) ,
, (modelMatrix),
(projMatrix), (viewport) znear zfar.
objx, objy, objz
objw.
, gluUnProject()
gluUnProject4() gluProject(). gluProject()
.
, , gluProject()
.
int gluProject (GLdouble objx, GLdouble objy, GLdouble objz,
const GLdouble modelMatrix[16], const GLdouble projMatrix[16],
const GLint viewport[4],
GLdouble *winx, GLdouble *winy, GLdouble *winz);

(objx, objy, objz)


, (modelMatrix),
(projMatrix) (viewport).
winx, winy winz.
GL_TRUE GL_FALSE .
: , gluUnProject(), gluUnProject4()
gluProject() OpenGL, .
glGetDoublev() glGetIntegerv()
GL_MODELVIEW_MATRIX, GL_PROJECTION_MATRIX GL_VIEWPORT
, ,
gluUnProject(), gluUnProject4()
gluProject().

4.
OpenGL
. ,
. , ,
, OpenGL ,
OpenGL,
,
.

4.1
, ,
(
, : ,
).
, / /.

390 (nm) () 720 nm


() ,
(, , , , , ).
, , ,
, , . ?
.
.
.
, (
). .
,
.
.
, (
) , .
:
, , . (
, , ,
.) ,
.
, ,
.

, , ,
. ,
,
, , .
, ,
.
,
, ,
, , ,
, .
, ,
, , ,
, RGBY (, , , )
. , , ,
.
, ,
(red, green, blue RGB)
.
, ,
, .
: RGB
, HLS, HSV, CMYK .
, ,
RGB RGB .

. , , -
, , ,
, , , .

4.2

, . R
(), G () B () .
(
, A), RGB ( RGBA)
. RGBA
( R, G, B , A),
(
, ).
,
R, G B .
( , ).
.
,
OpenGL.
, GLUT.

, , ,
.
,
.
, , 8- 8
( 256 , )
. .
R, G B 0.0 ( )
1.0 ( ). , R=0.0, G=0.0 B=1.0
. R, G B 0.0,
; 1.0,
, .
. .
.
R, G B , 4.1.
, .
4-1.

, ( ),
:
glColor3f(1.0,0.0,0.0);
// ,
glBegin(GL_POINTS);
glVertex3fv(point_array);
glEnd();

(, ,
),
, ,
. ,
.
RGBA
. , .
( , RGBA - )
.
, , , ,
,
. , ,
, , , .
, ,
. ,
.
, ( ).
,
.
. ,
z () .
;
. ,
, ( )
, . ,
, ,
(dithering )
( - ). ,

( , RGBA - )
.

4.3 RGBA
( RGBA)
.
. 1
. 8 , 8
, ,
, .

R, G B (
, 24 8 ,
), .
, , ,
, glGetIntegerv()
c GL_RED_BITS, GL_GREEN_BITS, GL_BLUE_BITS, GL_ALPHA_BITS
GL_INDEX_BITS .
:
, . ,
,
. 0.0 ( )
1.0 ( ) ,
. : 0.5
( ) 0.0 1.0?
, ,
0.0 1.0,
,
0.5. ,
.
, ,
. ,
, 0.5,
, 0.0 1.0.
,
( -).
,
, .

4.3.1 RGBA
RGBA
R, G, B A (
), 4-2. R, G B
, , ,
. ,
8 ,
0 255. , 0, 1, 2, ..., 255
R 0/255=0.0, 1/255, 2/255, ..., 255/255=1.0.
0.0 , 1.0
.
4-2. RGB

: (A RGBA) ,
. ,
,
R, G B.
,
,
.
, n . ,

24- 16.77
.

4.3.1.1

:
. ,
.
, , ,
1 R, G B, , , 8
: , , , , , , .
, ,
(
,
). ,
,
.
,
.
.
.
,

,
. RGB- ,
,
, .
(, , ,
, .)
4-3
.
4x4 50 , 19
69 .
,
, .
, ,
, , .
4-3.

8 R, G B
. ,
24 , ,
. , ,
2 12 ,
4 R, G B .
4-
.
, GL_DITHER
glEnable() glDisable(). , ,
OpenGL, .

4.3.2
OpenGL ,
, ,
.
,
, ,
, ( 4-4).

4-4.


.
.
: ,
, ,
( 4-5).
4-5.



. .

.
, m
,

RGBA .
(
) .

, ,
, .

4.3.3 RGBA
RGBA -
, , ,
. RGBA
, . ,
, , , , RGBA
, .
:

() ,
, , RGBA.
, RGBA
. ,
8 , RGBA 3
, 3 2 (
). ,
8 ( ) , 8 4 .
.
, ,
, .
, ,

)
256 (
, 4- RGBA . ,
,
, , -
.

, , .

, RGBA , .
, , , , ,
RGBA . ( ,
, , GLUT,

Microsoft Windows XP.)

4.3.4
RGBA
. ,
, ,
RGBA .
, ,
. , ,
) ,
8. 256 (
,
, 16 ( ) . ,
,
( , ,
). ,

, ,
.
,
. , X Windows System X
Visual. X Visual, , .
,
. RGBA
.

.
.

4.4
OpenGL : ( RGBA )
( ).
, , ,
(
). :
_();
_ (A);
_ (B);
_();
_();
_ (C);

A B , C . ,
, (
). , ,
, , ,
, , .

4.4.1 RGBA
RGBA glColor*().
void
void
void
void

glColor3{b
glColor4{b
glColor3{b
glColor4{b

s
s
s
s

i
i
i
i

f
f
f
f

d
d
d
d

ub
ub
ub
ub

us
us
us
us

ui} (TYPE r, TYPE g, TYPE b);


ui} (TYPE r, TYPE g, TYPE b, TYPE a);
ui}v (const TYPE *v);
ui}v (const TYPE *v);

, , .
,
. (3 4) ,
, .
, 1.0.
: (byte b),
(short s), (integer i), (float f),
(double d), (unsigned byte
ub), (unsigned short us)
(unsigned integer ui). (v) ,
.
glColor*(), ,
0.0 1.0

, .
, ,
,
1.0 ( ), 0 0.0
( ).
,

1.0, -1.0 ( 4-1).
, [0, 1]
.
, [0, 1],
, , .
,
.
4-1.

1-byte
integer

-128

-1.0

127

1.0

2-byte
integer

-32,768

-1.0

32,768

1.0

4-byte
integer

-2,147,483,648

-1.0

2,147,483,648

1.0

ub

unsigned
1-byte
integer

0.0

255

1.0

us

unsigned
2-byte
integer

0.0

65,535

1.0

ui

unsigned
4-byte
integer

0.0

4,294,967,295

1.0

4.4.2
glIndex*()
.
void glIndex{s i f d ub} (TYPE c);
void glIndex{s i f d ub}v (const TYPE *c);

c.
: (short s), (integer i),
(float f),
(double d), (unsigned byte ub). (v)
, (
).
2 glClearColor().
glClearIndex().
void glShadeModel (GLenum mode);

. mode GL_SMOOTH
( ) GL_FLAT ( ).

.
.
.
.
4-1 , 4-6.
4-6.

4-1. : smooth.cpp
#include <glut.h>
//
void init(void)
{
glClearColor(0.0,0.0,0.0,0.0);
glShadeModel(GL_SMOOTH);
}
//
void reshape(int w, int h)
{
glViewport(0,0,(GLsizei) w, (GLsizei) h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
if (w<=h)
gluOrtho2D(0.0,30.0,0.0,30.0*(GLfloat)h/(GLfloat)w);
else
gluOrtho2D(0.0,30.0*(GLfloat)w/(GLfloat)h,0.0,30.0);
glMatrixMode(GL_MODELVIEW);
}
//
void triangle(void)
{
glBegin(GL_TRIANGLES);
glColor3f(1.0,0.0,0.0);
glVertex2f(5.0,5.0);
glColor3f(0.0,1.0,0.0);
glVertex2f(25.0,5.0);
glColor3f(0.0,0.0,1.0);
glVertex2f(5.0,25.0);
glEnd();
}

//
void display(void)
{
glClear(GL_COLOR_BUFFER_BIT);
triangle();
glFlush();
}
int main(int argc, char** argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
glutInitWindowSize(500,500);
glutInitWindowPosition(100,100);
glutCreateWindow("Drawing a Smooth-Shaded Triangle");
init();
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutMainLoop();
return 0;
}


. RGBA
, , .

, .
, .
( ) . ,

, OpenGL. GLUT,
glutSetColor()
, .
glutSetColor() , , .
32 , ( 16 47)
, :
for(i=0;i<32;i++)
{
glutSetColor(16+i,1.0*(i/32.0), 1.0*(i/32.0),0.0);
}

, - ,
16 47, .

. ,
() .

4-2. , 1. OpenGL
,
,
( ).
4-2. OpenGL i-

, i-

triangle strip

i+2

triangle fan

i+2

3i

quad strip

2i+2

4i

5.
, OpenGL
, , .
, ,
. , ( ,
, )
. ,
. ,
, . 5-1
,
, .
5-1.

, .
,
.
OpenGL
.

5.1
, .

, , .
, ,
.
. ,
, ,
, .

. ,
:
while(1)
{
_____();
glClear(GL_COLOR_BUFFER_BIT);
___A();
___B();
}

, A B.
.
, B (
A) . , A B
( A B,
B A) .
, ,
. ( ,
, ,
.)
( z-).
( )
( ). ,
glClear() GL_DEPTH_BUFFER_BIT
(
). .
, ,
,
, - . ,
.
, ,
,
. ( ),
. ,
( ) .
, ,
(). .
, , ,
.

:
glutInitDisplayMode(GLUT_DEPTH|...);
glEnable(GL_DEPTH_TEST);
...
while(1)
{
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
_____();
___A();
___B();
}

glClear() , .
.
, ,
.
.
(
) , ,
.

5.2 OpenGL
,
,
. .
, .

,
.
- .
OpenGL ,
, . ,
, , ,
,
, .
OpenGL ,
.
( ) ,
.
, , .
OpenGL ,
. -
, .
, ,
, ,
, , . ,
( ) ,
,
.
, ,
,
, .
OpenGL
. ,
.
(, ),
,
(,
).
OpenGL ,
4 : (ambient), (diffuse), (specular)
( emissive). 4
.

5.2.1 , ,
, (,
), ,
. ,
, ,
. :
, ,
, ,
. ,
.
, , ,
, , ,
. , ,
,
, . ,
, ,
.

.
100
. ,
. ,
.
, ,
, , .
OpenGL ,
,
.
, ,
. ,
, , ,
( , -- ). OpenGL
,
.

5.2.2
OpenGL ,
, , . ,
,
.
( , ),
, . ,
. , , ,
( , ,
).
, , ,
,
.
, ,
. ,
, . .

(
).

5.2.3 RGB
, ,
, .
. R, G B
1.0, . 0.5,
, (
). R=G=1 B=0 ( , , ),
.
. ,
R=1, G=0.5 B=0, ,
. ,
(LR, LG, LB), (MR, MG,
MB) , ,
(LRMR, LGMG, LBMB).
, (R1, G1, B1) (R2, G2,
B2) , OpenGL : (R1+R2, G1+G2, B1+B2).
- 1 ( , ),
1.

5.3 :
, :
1. .
.
2. , .
3. ,
( ,
).
4. .
5-1. ,
, 5-1.
5-1. : light.
#include <glut.h>
//
void init(void)
{
GLfloat mat_specular[]={1.0,1.0,1.0,1.0};
GLfloat mat_shininess[]={50.0};
GLfloat light_position[]={1.0,1.0,1.0,0.0};
GLfloat white_light[]={1.0,1.0,1.0,1.0};
glClearColor(0.0,0.0,0.0,0.0);
glShadeModel(GL_SMOOTH);
glMaterialfv(GL_FRONT,GL_SPECULAR,mat_specular);
glMaterialfv(GL_FRONT,GL_SHININESS,mat_shininess);
glLightfv(GL_LIGHT0,GL_POSITION,light_position);
glLightfv(GL_LIGHT0,GL_DIFFUSE,white_light);
glLightfv(GL_LIGHT0,GL_SPECULAR,white_light);
glEnable(GL_LIGHTING);

glEnable(GL_LIGHT0);
glEnable(GL_DEPTH_TEST);
}
//
void display(void)
{
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glutSolidSphere(1.0,40,16);
glFlush();
}
//
void reshape(int w, int h)
{
glViewport(0,0,(GLsizei) w, (GLsizei) h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
if (w<=h)
glOrtho(-1.5,1.5,-0.5*(GLfloat)h/(GLfloat)w,0.5*(GLfloat)h/(GLfloat)w,10.0,10.0);
else
glOrtho(-1.5*(GLfloat)w/(GLfloat)h,1.5*(GLfloat)w/(GLfloat)h,-1.5,1.5,10.0,10.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
int main(int argc, char **argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB|GLUT_DEPTH);
glutInitWindowSize(500,500);
glutInitWindowPosition(100,100);
glutCreateWindow("Rendering a Lit Sphere");
init();
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutMainLoop();
return 0;
}

, init().
.
, 5-1, ,
, RGBA, . OpenGL -
, , ,
. ,
, RGBA ,
.

5.3.1

.
OpenGL ,
.
glutSolidSphere().
.
,
,
. , ,
, glEnable() GL_NORMALIZE
GL_RESCALE_NORMAL.

GL_RESCALE_NORMAL ,
,
. , ,
.
GL_NORMALIZE , GL_RESCALE_NORMAL.
(GL_NORMALIZE),
, .
, ,
,
.
: OpenGL
GL_RESCALE_NORMAL ,
(GL_NORMALIZE).
, , , .

5.3.2 ,

5-1 .
glLightfv().
(GL_LIGHT0) .
, glLight*().
, 8
. ( OpenGL 8-
.) GL_LIGHT0 .
, , ,
( ) (
). , , ,
. ,
( ) ,
.

glEnable(). , glEnable()
GL_LIGHTING, OpenGL ,
.

5.3.3
,
glLightModel*(). 5-1
.
, :
,
- .
5-1
( )
.
, OpenGL
.
, , ,
. , 5-1
( ),
.

5.3.4
, , ,
( ).

, ,
, . ,
, .
glMaterialfv()
: .

5.3.5
, ,
,
. ,
, , .
, , (
),
.

5.4
, , .
, ,
. ,
glLight*(). : ,
.
void glLight{if} (GLenum light, GLenum pname, TYPE param);
void glLight{if}v (GLenum light, GLenum pname, TYPE *param);

, light (
GL_LIGHT0, GL_LIGHT1, ..., GL_LIGHT7).
pname ( 5-1). param
, pname.
, param
, , param .
,
.
5-1.

GL_AMBIENT

(0.0,0.0,0.0,1.0)

GL_DIFFUSE

(1.0,1.0,1.0,1.0)

(0.0,0.0,0.0,1.0)

(
0- - ,
- )

GL_SPECULAR

(1.0,1.0,1.0,1.0)

(0.0,0.0,0.0,1.0)

(
0- - ,
- )

GL_POSITION

(0.0,0.0,1.0,0.0)

(x,y,z,w)

GL_SPOT_DIRECTION

(0.0,0.0,-1.0)

(x,y,z)

GL_SPOT_EXPONENT

0.0

GL_SPOT_CUTOFF

180.0

GL_CONSTANT_ATTENUATION

1.0

GL_LINEAR_ATTENUATION

0.0

GL_QUADRATIC_ATTENUATION

0.0

: GL_DIFFUSE GL_SPECULAR 5-1


GL_LIGHT0 (GL_LIGHT1, GL_LIGHT2,
...). GL_DIFFUSE GL_SPECULAR GL_LIGHT0
(1.0, 1.0, 1.0, 1.0).
(0.0, 0.0, 0.0, 1.0).
5-2 , glLight*():
5-2.
GLfloat
GLfloat
GLfloat
GLfloat

light_ambient[]={0.0,0.0,0.0,1.0};
light_diffuse[]={1.0,1.0,1.0,1.0};
light_specular[]={1.0,1.0,1.0,1.0};
light_position[]={1.0,1.0,1.0,0.0};

glLightfv(GL_LIGHT0,GL_AMBIENT, light_ambient);
glLightfv(GL_LIGHT0,GL_DIFFUSE, light_diffuse);
glLightfv(GL_LIGHT0,GL_SPECULAR, light_specular);
glLightfv(GL_LIGHT0,GL_POSITION, light_position);

, ,
glLightfv().
glLightfv() ,
GL_AMBIENT, GL_DIFFUSE GL_SPECULAR,
.
: ,
glEnable().
glLight*()
.
.

5.4.1
OpenGL
, : GL_AMBIENT, GL_DIFFUSE GL_SPECULAR.
GL_AMBIENT RGBA ,
. 5-1,
,
GL_AMBIENT (0.0, 0.0, 0.0, 1.0).
5-1. ,
GLfloat light_ambient[]={0.0,0.0,1.0,1.0};
glLightfv(GL_LIGHT0,GL_AMBIENT,light_ambient);

, 5-2.
5-2. , ,

GL_DIFFUSE ,
. RGBA ,
. GL_LIGHT0
GL_DIFFUSE (1.0, 1.0, 1.0, 1.0), .
(GL_LIGHT1, GL_LIGHT2, ...,
GL_LIGHT7) (0.0, 0.0, 0.0, 0.0).
GL_AMBIENT .

( ).
GL_SPECULAR , GL_DIFFUSE. GL_SPECULAR
(1.0, 1.0, 1.0, 1.0) GL_LIGHT0 (0.0, 0.0, 0.0, 0.0) .
: ,
.

5.4.2
, ,
.
(directional):
,
.
.
(positional),
, , .
. ,
5-1, :
GLfloat light_position[]={1.0,1.0,1.0,0.0};
glLightfv(GL_LIGHT0, GL_POSITION, light_position);

, GL_POSITION (x, y, z,
w). w 0,
, (x, y, z) .
. GL_POSITION
(0, 0, 1, 0), ,
z. (,
, (0, 0, 0), ).
w 0, , (x, y, z)
.

.
, ,
, ,
.
: ,
, . , -

. ,
.
, .
.

. ,
,
.
. OpenGL
, :

,
d - ,
- GL_CONSTANT_ATTENUATION ( ),
- GL_LINEAR_ATTENUATION ( ),
- GL_QUADRATIC_ATTENUATION ( ).

1.0,

- 0.0,

glLightf(GL_LIGHT0, GL_CONSTANT_ATTENUATION, 2.0);


glLightf(GL_LIGHT0, GL_LINEAR_ATTENUATION, 1.0);
glLightf(GL_LIGHT0, GL_QUADRATIC_ATTENUATION, 0.5);

, , , .

. ,
( )
,
.

5.4.3
,
,
. ,
. (,
, . ,
,
.)
, , ,
GL_SPOT_CUTOFF. ,
, , 2.

5-3. GL_SPOT_CUTOFF

, . ,
, GL_SPOT_CUTOFF 180.0.
, (
360 , ). GL_SPOT_CUTOFF
[0.0, 90.0] (
180.0).
GL_SPOT_CUTOFF 45 :
glLightf(GL_LIGHT0, GL_SPOT_CUTOFF, 45.0);

,
:
GLfloat spot_direction[] = {-1.0, -1.0, 0.0};
glLightfv(GL_LIGHT0, GL_SPOT_DIRECTION, spot_direction);

.
(0.0, 0.0, -1.0), GL_SPOT_DIRECTION,
z.
, ,
, .
,
. -,
, .
GL_SPOT_EXPONENT (

0), .
.

, GL_SPOT_EXPONENT.
,
(GL_SPOT_EXPONENT) .

5.4.4
,
( , OpenGL). OpenGL
, ,
, .
, 8 GL_LIGHT0,
GL_LIGHT1, GL_LIGHT2, GL_LIGHT3 .
GL_LIGHT0.
, . ,
GL_LIGHT0 .
5-3 :
5-3.
GLfloatlight_ambient[]={0.2,0.2,0.2,1.0};
GLfloat light_diffuse[]={1.0,1.0,1.0,1.0};
GLfloat light_specular[]={1.0,1.0,1.0,1.0};
GLfloat light_position[]={-2.0,2.0,1.0,1.0};
GLfloat spot_direction[]={-1.0,-1.0,0.0};
glLightfv(GL_LIGHT1,GL_AMBIENT, light_ambient);
glLightfv(GL_LIGHT1,GL_DIFFUSE, light_diffuse);
glLightfv(GL_LIGHT1,GL_SPECULAR, light_specular);
glLightfv(GL_LIGHT1,GL_POSITION, light_position);
glLightf(GL_LIGHT1,GL_CONSTANT_ATTENUATION, 1.5);
glLightf(GL_LIGHT1,GL_LINEAR_ATTENUATION, 0.5);
glLightf(GL_LIGHT1,GL_QUADRATIC_ATTENUATION, 0.2);
glLightf(GL_LIGHT1,GL_SPOT_CUTOFF, 45.0);
glLightfv(GL_LIGHT1,GL_SPOT_DIRECTION, spot_direction);
glLightf(GL_LIGHT1,GL_SPOT_EXPONENT, 2.0);
glEnable(GL_LIGHT1);

5-1, :
.

5.4.5
OpenGL ,
. ,
, .
, glLight*()
,
. ,
,
. (
.) ,
, (
), :

5.4.5.1

, 5-1, .
,
/ . 5-4
, init()
reshape().
5-4.
glViewport(0,0,(GLsizei) w, (GLsizei) h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
if (w<=h)
glOrtho(-1.5,1.5,-0.5*(GLfloat)h/(GLfloat)w,0.5*(GLfloat)h/(GLfloat)w,10.0,10.0);
else
glOrtho(-1.5*(GLfloat)w/(GLfloat)h,1.5*(GLfloat)w/(GLfloat)h,-1.5,1.5,10.0,10.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
// init()
GLfloat light_position[]={1.0,1.0,1.0,0.0};
glLightfv(GL_LIGHT0,GL_POSITION,light_position);

, .
,
. ,
(1.0, 1.0, 1.0)
. , ,
, (1.0, 1.0,
1.0).

5.4.5.2

,
.

, .
init() .
( )
(, display()). 5-5
display().
5-5.
GLdouble spin;
void display()
{
GLfloat light_position[]={0.0,0.0,1.5,1.0};
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glPushMatrix();
gluLookAt(0.0,0.0,5.0,0.0,0.0,0.0,0.0,1.0,0.0);
glPushMatrix();
glRotated(spin,1.0,0.0,0.0);
glLightfv(GL_LIGHT0,GL_POSITION,light_position);
glPopMatrix();
glutSolidTorus(0.275,0.85,8,15);
glPopMatrix();
glFlush();
}

spin , , ,
. display()
spin. ,
glPushMatrix() glPopMatrix()
. 5-5 ,

gluLookAt().
glRotate().
, ,

. (,
, .)
, . 5-6
, .
30
.
.
5-6. :
movelight.cpp
#include <glut.h>
int spin=0;
//
void init(void)
{
glClearColor(0.0,0.0,0.0,0.0);
glShadeModel(GL_SMOOTH);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glEnable(GL_DEPTH_TEST);
}
void display(void)
{
GLfloat position[]={0.0,0.0,1.5,1.0};
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glTranslatef(0.0,0.0,-5.0);
glPushMatrix();
glRotated((GLdouble)spin,1.0,0.0,0.0);
glLightfv(GL_LIGHT0,GL_POSITION,position);
glTranslated(0.0,0.0,1.5);
glDisable(GL_LIGHTING);
glColor3f(0.0,1.0,1.0);
glutWireCube(0.1);
glEnable(GL_LIGHTING);
glPopMatrix();
glutSolidTorus(0.275,0.85,40,40);
glPopMatrix();
glutSwapBuffers();
}
//
void reshape(int w, int h)
{
glViewport(0,0,(GLsizei) w, (GLsizei) h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(40.0,(GLfloat)w/(GLfloat)h,1.0,20.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
void light_moving(void)
{

spin=(spin+1)%360;
glutPostRedisplay();
}
void mouse(int button,int state,int x, int y)
{
switch(button)
{
case GLUT_LEFT_BUTTON:
if(state==GLUT_DOWN)
glutIdleFunc(light_moving);
else
glutIdleFunc(NULL);
break;
}
}
int main(int argc, char **argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB|GLUT_DEPTH);
glutInitWindowSize(500,500);
glutInitWindowPosition(100,100);
glutCreateWindow("Moving a Light with Modeling Transformations");
init();
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutMouseFunc(mouse);
glutMainLoop();
return 0;
}

5.4.5.3

, ,
.

. ,
,
. 5-7 init()
(0, 0, 0). ,
.
5-7. ,
GLfloat light_position[]={0.0, 0.0, 0.0, 1.0};
glViewport(0,0,(GLsizei) w, (GLsizei) h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(40.0, (GLfloat)w/(GLfloat)h,1.0,100.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glLightfv(GL_LIGHT0,GL_POSITION,light_position);

, ,
, (0, 0, 0) . 5-7,
, (ex, ey, ez)
, (upx, upy, upz) .
display(), ,
:
GLdlouble ex, ey, ez, upx, upy, upz;

void display()
{
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glPushMatrix();
gluLookAt(ex, ey, ez, 0.0, 0.0, 0.0, upx, upy, upz);
glutSolidTorus(0.275, 0.85, 8, 15);
glPopMatrix();
glFlush();
}

, ,
. ,
gluLookAt() ( ), ,
.
, ,
.
.
, .
, glLightfv(GL_LIGHTi, GL_POSITION, position),
x, y z.
,
.

5.5
OpenGL 4 :

.

.
-
.

.

, . ,
, OpenGL,
.
glLightModel*() ,
. glLightModel*() :
.
void glLightModel{if} (GLenum pname, TYPE param);
void glLightModel{if}v (GLenum pname, TYPE *param);

.
pname ( 5-2). param ,
pname; ,
, param
.
, (
GL_LIGHT_MODEL_AMBIENT).
5-2. pname

GL_LIGHT_MODEL_AMBIENT

(0.2,0.2,0.2,1.0)

RGBA

GL_LIGHT_MODEL_LOCAL_VIEWER

0.0 GL_FALSE

GL_LIGHT_MODEL_TWO_SIDE

0.0 GL_FALSE

GL_LIGHT_MODEL_COLOR_CONTROL

GL_SINGLE_COLOR

5.5.1
,
. , ,
. RGBA
, GL_LIGHT_MODEL_AMBIENT
:
GLfloat lmodel_ambient[]={0.2,0.2,0.2,1.0};
glLightModelfv(GL_LIGHT_MODEL_AMBIENT, lmodel_ambient);

lmodel_ambient
GL_LIGHT_MODEL_AMBIENT.
, ,
- . 5-4
,
( ).
5-4. ,

5.5.2
,
. ,
,
. ,
, ,

.
, ,
.
, ,
,
.
. :

glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, GL_TRUE);

(0, 0, 0) .

GL_TRUE GL_FALSE.

5.5.3
,
. ,
, . 5-1,
, ,
. , ,
. ,
, ,
;
,
. :
glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE);

OpenGL ,
. ,
( ) ,
. .

, .
, GL_TRUE
GL_FALSE. , OpenGL
glFrontFace().

5.5.4
, , ,

.
,
, .
:
glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL, GL_SEPARATE_SPECULAR_COLOR);

OpenGL .
: ,
, ,
.
.

. ,
, , .
, :
glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL, GL_SINGLE_COLOR);


: , ,
.
.
,
.

5.5.5
OpenGL ( )
. ,
, ,
, , .
:
glEnable(GL_LIGHTING);

:
glDisable(GL_LIGHTING);

, , ,
. 5-1
GL_LIGHT0:
glEnable(GL_LIGHT0);

5.6
,
. ,
: , ,
( ) .
,
.
,
glMaterial*().
void glMaterial{if}(GLenum face, GLenum pname, TYPE param);
void glMaterial{if}v(GLenum face, GLenum pname, TYPE *param);

.
face GL_FRONT, GL_BACK GL_FRONT_AND_BACK,
.
pname,
param (
).
GL_SHININESS.
pname 5-3. ,
GL_AMBIENT_AND_DIFFUSE
RGBA.
5-3. pname

GL_AMBIENT

(0.2,0.2,0.2,1.0)

GL_DIFFUSE

(0.8,0.8,0.8,1.0)

GL_AMBIENT_AND_DIFFUSE

GL_SPECULAR

(0.0,0.0,0.0,1.0)

GL_SHININESS

0.0

GL_EMISSION

(0.0,0.0,0.0,1.0)

GL_COLOR_INDEXES

(0,1,1)

,
.
, -
, face glMaterial*().
5-5 ,
.
5-5.

5-8 , 5-5.
5-8.
: two_side_lighting.cpp
#include <glut.h>
//
void init(void)
{
glClearColor(0.0,0.0,0.0,0.0);
glShadeModel(GL_SMOOTH);
//
GLfloat light_position[]={1.0,1.0,1.0,0.0};
GLfloat white_light[]={1.0,1.0,1.0,1.0};
glLightfv(GL_LIGHT0,GL_POSITION,light_position);
glLightfv(GL_LIGHT0,GL_DIFFUSE,white_light);
glLightfv(GL_LIGHT0,GL_SPECULAR,white_light);
//...

GLfloat lmodel_ambient[]={1.0,1.0,1.0,1.0};
glLightModelfv(GL_LIGHT_MODEL_AMBIENT,lmodel_ambient);
glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE);
//
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glEnable(GL_DEPTH_TEST);
//
GLfloat mat_specular_front[]={0.0,0.3,0.9,1.0};
GLfloat mat_ambient_front[]={0.0,0.1,0.3,1.0};
glMaterialfv(GL_FRONT,GL_SPECULAR,mat_specular_front);
glMaterialfv(GL_FRONT,GL_AMBIENT,mat_ambient_front);
//...
GLfloat mat_specular_back[]={1.0,0.0,0.0,1.0};
GLfloat mat_ambient_back[]={0.5,0.1,0.1,1.0};
glMaterialfv(GL_BACK,GL_SPECULAR,mat_specular_back);
glMaterialfv(GL_BACK,GL_AMBIENT,mat_ambient_back);
//GL_SHININESS
GLfloat mat_shininess[]={50.0};
glMaterialfv(GL_FRONT_AND_BACK,GL_SHININESS,mat_shininess);
//
GLdouble equation[]={0.4,0.5,-0.5,0.6};
glClipPlane(GL_CLIP_PLANE1, equation);
glEnable(GL_CLIP_PLANE1);
//
glFrontFace(GL_CW);
}
//
void display(void)
{
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glutSolidTeapot(0.9);
glFlush();
}
//
void reshape(int w, int h)
{
glViewport(0,0,(GLsizei) w, (GLsizei) h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
if (w<=h)
glOrtho(-1.5,1.5,-1.5*(GLfloat)h/(GLfloat)w, 1.5*(GLfloat)h/(GLfloat)w,10.0,10.0);
else
glOrtho(-1.5*(GLfloat)w/(GLfloat)h, 1.5*(GLfloat)w/(GLfloat)h,-1.5,1.5,10.0,10.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
//
int main(int argc, char **argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB|GLUT_DEPTH);
glutInitWindowSize(310,310);
glutInitWindowPosition(100,100);
glutCreateWindow("Two-sided lighting");
init();
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutMainLoop();
return 0;
}

,
, 5-6.
,
.
. ,
.
5-6.

, ,
glMaterial*() RGBA . ,
,
, ,
GL_DIFFUSE. , RGBA
.

5.6.1
GL_DIFFUSE GL_AMBIENT, glMaterial*()
, .
,
.
. (
,

.)
.
.
,
,
.
, .
, .
, ,
, . OpenGL
glMaterial*():
GLfloat mat_amb_diff[]={0.1,0.5,0.8,1.0};
glMaterialfv(GL_FRONT_AND_BACK,GL_AMBIENT_AND_DIFFUSE);

RGBA (0.1, 0.5, 0.8, 1.0)



.

5.6.2
.
, , ,
. , ,
. , ,

. , ,
.
OpenGL ,
( GL_SPECULAR),
( GL_SHININESS). GL_SHININESS
[0.0, 128.0]: , (
GL_SHININESS
).

5.6.3 ()
RGBA GL_EMISSION, ,
.
( ) , , ,
.
,
, ,
. ,
,
, .

5.6.4
5-1
().
.

, . ,
5-9.
5-9.
GLfloat no_mat[]={0.0,0.0,0.0,1.0};
GLfloat mat_ambient[]={0.7,0.7,0.7,1.0};
GLfloat mat_ambient_color[]={0.8,0.8,0.2,1.0};
GLfloat mat_diffuse[]={0.1,0.5,0.8,1.0};
GLfloat mat_specular[]={1.0,1.0,1.0,1.0};
GLfloat no_shininess[]={0.0};
GLfloat low_shininess[]={5.0};
GLfloat high_shininess[]={100.0};
GLfloat mat_emission[]={0.3,0.2,0.2,0.0};
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
//
glPushMatrix();
glTranslate(-3.75,0.0,0.0);
glMaterialfv(GL_FRONT, GL_AMBIENT, no_mat);
glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse);
glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
glMaterialfv(GL_FRONT, GL_SHININESS, no_shininess);
glMaterialfv(GL_FRONT, GL_EMISSION, no_mat);
glutSolidSphere(1.0,16,16);
glPopMatrix();
//
glPushMatrix();
glTranslate(-1.25,0.0,0.0);
glMaterialfv(GL_FRONT, GL_AMBIENT, no_mat);
glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse);
glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
glMaterialfv(GL_FRONT, GL_SHININESS, low_shininess);
glMaterialfv(GL_FRONT, GL_EMISSION, no_mat);
glutSolidSphere(1.0,16,16);
glPopMatrix();
//
glPushMatrix();
glTranslate(1.25,0.0,0.0);
glMaterialfv(GL_FRONT, GL_AMBIENT, no_mat);
glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse);
glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
glMaterialfv(GL_FRONT, GL_SHININESS, high_shininess);
glMaterialfv(GL_FRONT, GL_EMISSION, no_mat);
glutSolidSphere(1.0,16,16);
glPopMatrix();
//
glPushMatrix();
glTranslate(3.75,0.0,0.0);
glMaterialfv(GL_FRONT, GL_AMBIENT, no_mat);
glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse);
glMaterialfv(GL_FRONT, GL_SPECULAR, no_mat);
glMaterialfv(GL_FRONT, GL_SHININESS, no_shininess);
glMaterialfv(GL_FRONT, GL_EMISSION, no_mat);
glutSolidSphere(1.0,16,16);
glPopMatrix();

, glMaterial*()
. ,
, . ,

, .
glMaterial*(), 5-9
(
).

5.6.5

glColorMaterial().
void glColorMaterial (GLenum face, GLenum mode);

, face, ( ) ,
mode, .
( glColor*())
. face GL_FRONT,
GL_BACK GL_FRONT_AND_BACK ( ).
mode GL_AMBIENT, GL_DIFFUSE, GL_SPECULAR,
GL_AMBIENT_AND_DIFFUSE ( ) GL_EMISSION.
. glColorMaterial()
.
, glColorMaterial() :
,
, .
OpenGL mode
!
glColorMaterial() glEnable()
GL_COLOR_MATERIAL.
glColor*() (
glMaterial*()).
glEnable(GL_COLOR_MATERIAL);
glColorMaterial(GL_FRONT, GL_DIFFUSE);
// glColor*()
glColor3f(0.2,0.5,0.8);
//
glColorMaterial(GL_FRONT, GL_SPECULAR);
// glColor*() ,
//
glColor3f(0.9,0.0,0.2);
//
glDisable(GL_COLOR_MATERIAL);

glColorMaterial() ,
.
glMaterial*().
glColorMaterial() ,
, glDisable().
, ,
.
glColorMaterial() OpenGL.

.
5-10 ,
glColorMaterial() .
.
5-10. glColorMaterial(): colormat.cpp

#include <glut.h>
GLfloat diffuseMaterial[4]={0.0,0.0,0.0,1.0};
//
void init(void)
{
GLfloat mat_specular[4]={1.0,1.0,1.0,1.0};
GLfloat light_position[4]={1.0,1.0,1.0,0.0};
glClearColor(0.0,0.0,0.0,0.0);
glShadeModel(GL_SMOOTH);
glEnable(GL_DEPTH_TEST);
glMaterialfv(GL_FRONT,GL_DIFFUSE,diffuseMaterial);
glMaterialfv(GL_FRONT,GL_SPECULAR,mat_specular);
glMaterialf(GL_FRONT,GL_SHININESS,25.0);
glLightfv(GL_LIGHT0,GL_POSITION,light_position);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glColorMaterial(GL_FRONT,GL_DIFFUSE);
glEnable(GL_COLOR_MATERIAL);
}
//
void display(void)
{
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glutSolidSphere(1.0,20,16);
glutWireCube(1.0);
glFlush();
}
//
void reshape(int w, int h)
{
glViewport(0,0,(GLsizei) w, (GLsizei) h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
if (w<=h)
glOrtho(-1.5,1.5,-1.5*(GLfloat)h/(GLfloat)w,1.5*(GLfloat)h/(GLfloat)w,10.0,10.0);
else
glOrtho(-1.5*(GLfloat)w/(GLfloat)h,1.5*(GLfloat)w/(GLfloat)h,-1.5,1.5,10.0,10.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
//
void mouse(int button,int state, int x, int y)
{
switch(button)
{
case GLUT_LEFT_BUTTON:
if (state==GLUT_DOWN) //
{
diffuseMaterial[0]+=0.1;
if (diffuseMaterial[0] > 1.0)
diffuseMaterial[0]=0.0;
glColor4fv(diffuseMaterial);
glutPostRedisplay();
}
break;
case GLUT_MIDDLE_BUTTON:
if (state==GLUT_DOWN) //
{
diffuseMaterial[1]+=0.1;
if (diffuseMaterial[1] > 1.0)
diffuseMaterial[1]=0.0;
glColor4fv(diffuseMaterial);
glutPostRedisplay();
}
break;
case GLUT_RIGHT_BUTTON:
if (state==GLUT_DOWN) //

{
diffuseMaterial[2]+=0.1;
if (diffuseMaterial[2] > 1.0)
diffuseMaterial[2]=0.0;
glColor4fv(diffuseMaterial);
glutPostRedisplay();
}
break;
default:
break;
}
}
int main(int argc, char **argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB|GLUT_DEPTH);
glutInitWindowSize(500,500);
glutInitWindowPosition(100,100);
glutCreateWindow("Using glColorMaterial()");
init();
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutMouseFunc(mouse);
glutMainLoop();
return 0;
}

5.7
: , OpenGL
, RGBA .
,
. ,
, ,
. ,
, ,
, , , .
R, G B
. , ,
, R , G B ,
RGB

. (, A

.)
:
= +
,
+
, ,
.
[0, 1] (
RGBA).
, OpenGL
, ,

. , ,
, .

5.7.1
.
GL_EMISSION .

5.7.2

( GL_LIGHT_MODEL_AMBIENT)
GL_AMBIENT, glMaterial*():

R, G B ,
RGB

5.7.3
,
. ,
:
= * * ( +
+ )

5.7.3.1

,
d - ,
- GL_CONSTANT_ATTENUATION ( ),
- GL_LINEAR_ATTENUATION ( ),
- GL_QUADRATIC_ATTENUATION ( ).
, 1.

5.7.3.2


, ,
:

1, ( GL_SPOT_CUTOFF
180.0);
0, ,
;

--

;
--
(GL_SPOT_DIRECTION), ,
.
v d
; ,
,
.
, OpenGL

.
(GLL_SPOT_CUTOFF)
, .

5.7.3.3

,
:

5.7.3.4

,
. :
,
-- ,
(GL_POSITION).
-- .

5.7.3.5

, .
0, .
( 0,
.) , :


.
:
( )
(
GL_LIGHT_MODEL_LOCAL_VIEWER, ,
(0, 0, 1)). (
).

.
(GL_SHININESS).

).

).

OpenGL
( ):

.
,

, 0.

5.7.4
, ,
, OpenGL :

5.7.5

GL_SEPARATE_SPECULAR_COLOR,
( ) :
= +
,
+
,
.
= ,
.
OpenGL
:

,
.
.

5.8
, RGBA,
, .
, ,
RGBA , . ,
RGBA. ,
GL_DIFFUSE GL_SPECULAR,
GL_SHININESS. GL_DIFFUSE GL_SPECULAR (
,
)
(

) :

,
R(x), G(x) B(x) ,
x. 0.30, 0.59 0.11

.
, glMaterial*()
GL_COLOR_INDEXES:
GLufloat mat_colormap[]={16.0,47.0,79.0};
glMaterialfv(GL_FRONT, GL_COLOR_INDEXES, mat_colormap);

GL_COLOR_INDEXES
, . OpenGL
, ( 16.0)
, , (47.0)
, , (79.0)
. ( 0.0,
1.0. , glColorMaterial()
.)
OpenGL ,
. ,
( 16 47
47 79). ,
.
, ,
:
for (i=0;i<32;i++)

{
glutSetColor(16+i,1.0*(i/32.0),0.0,1.0*(i/32.0));
glutSetColor(48+i,1.0,1.0*(i/32.0),1.0);
}

glutSetColor() GLUT 4 .
, RGB, ,
. i=0 16
RGB (0, 0, 0).
47 ( i=31), RGB (1.0, 0.0, 1.0).

(1.0, 1.0, 1.0) 79.

5.8.1
: ,
, RGBA,
. ,
,
. .
RGBA.

,
. , ,

. (,

RGBA.) d s . ,

.
,
,

, ,
glMaterial*() GL_COLOR_INDEXES.

, ,
(
). ( )

, n .

6. , ,

4 ,
.
, ,
.

6.1
RGBA,
.
glColor*(), glClearColor(),
, ,
. ,
, ,
. ,
?

,

, .
, , ,
. , ,

.

, .
( )

. ,
,
.
.

6.1
RGBA,
.
glColor*(), glClearColor(),
, ,
. ,
, ,
. ,
?
,

, .
, , ,
. , ,

.

, .
( )

. ,
,
.
.
: ,
, .

, RGB , ,
( ).
, ,
, . ,
, ( )
. ,
. 80%
( 20%), ,
, 20% 80% .

.
, ,
,
.

6.1.1
()
,
() . ,
.
RGBA, R, G, B A
. RGBA
.
,

,
s d .
:
.
[0,1].

. , OpenGL
,
.
, .
glBlendFunc(), :
, .
,
:
glEnable(GL_BLEND);

glDisable()
GL_BLEND. , GL_ONE (
) GL_ZERO ( ) ,
( ).
void glBlendFunc (GLenum sfactor, GLenum dfactor);

, ()
, ().
sfactor ; dfactor - .
6-1.
[0,1]; ,
, [0,1].
: 6-1 RGBA ,
s, d c .
, .

, :
.
6-1.

GL_ZERO

(0,0,0,0)

GL_ONE

(1,1,1,1)

GL_DST_COLOR

GL_SRC_COLOR

GL_ONE_MINUS_DST_COLOR

GL_ONE_MINUS_SRC_COLOR

GL_SRC_ALPHA

GL_ONE_MINUS_SRC_ALPHA

GL_DST_ALPHA

GL_ONE_MINUS_DSR_ALPHA

GL_SRC_ALPHA_SATURATE

GL_CONSTANT_COLOR

GL_ONE_MINUS_CONSTANT_COLOR

GL_CONSTANT_ALPHA

GL_ONE_MINUS_CONSTANT_ALPHA

: GL_CONSTANT_COLOR, GL_ONE_MINUS_CONSTANT_COLOR, GL_CONSTANT_ALPHA


GL_ONE_MINUS_CONSTANT_ALPHA ,
OpenGL .

6.1.2
.
.

.
, , ,
. ,
.

,
, ,
GL_ONE, GL_ZERO
.
GL_SRC_ALPHA, GL_MINUS_SRC_ALPHA
0.5. , ,
.
75% 25% ,
,
0.25.
,
GL_ONE, GL_SRC_ALPHA.
0.3333333.

,
, .
, ,
, ,
,
(, 10% 90%
). ,
10- , GL_SRC_ALPHA
GL_ONE_MINUS_SRC_ALPHA . ,
(,
, ). ,
.
,
GL_DST_COLOR GL_ONE_MINUS_DST_COLOR
GL_SRC_COLOR GL_ONE_MINUS_SRC_COLOR
.
, ,
0.80, 0.40, 0.72
, 20% , 60%
28% .
,
. .
, 80% ,
40% , 90%. ,
,
GL_SRC_ALPHA ( ) GL_ONE_MINUS_SRC_ALPHA (
). , 0.2,
0.6, 0.1.
,
( - ),

. , ,
,
OpenGL,
, , ,
, .
,
.
0
1.0 . ,

;
, ,
0. , billboarding (billboard
), ,
. , 6-1
90 .
,
GL_SRC_ALPHA ( )
GL_ONE_MINUS_SRC_ALPHA ( ).

,
.

6-1. billboarding:
billboarding.cpp

6.1.3
6-1 ,
, 0.75. ,
GL_SRC_ALPHA
GL_ONE_MINUS_SRC_ALPHA .
, ,
. , , ,
( 6-2). ,
t.
6-2.

6-1. : alpha.cpp

#include <GL/glut.h>
int leftFirst=GL_TRUE;
//
void init(void)
{
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
glShadeModel(GL_FLAT);
glClearColor(0.0,0.0,0.0,0.0);
}
void drawLeftTriangle(void)
{
//
glBegin(GL_TRIANGLES);
glColor4f(1.0,1.0,0.0,0.75);
glVertex3f(0.1,0.9,0.0);
glVertex3f(0.1,0.1,0.0);
glVertex3f(0.7,0.5,0.0);
glEnd();
}
void drawRightTriangle(void)
{
//
glBegin(GL_TRIANGLES);
glColor4f(0.0,1.0,1.0,0.75);
glVertex3f(0.9,0.9,0.0);
glVertex3f(0.3,0.5,0.0);
glVertex3f(0.9,0.1,0.0);
glEnd();
}
void display(void)
{
glClear(GL_COLOR_BUFFER_BIT);
if(leftFirst)
{
drawLeftTriangle();
drawRightTriangle();
}
else
{
drawRightTriangle();
drawLeftTriangle();
}
glFlush();
}
void reshape(int w, int h)
{
glViewport(0,0,(GLsizei) w, (GLsizei) h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
if (w<=h)
gluOrtho2D(0.0,1.0,0.0,1.0*(GLfloat)h/(GLfloat)w);
else
gluOrtho2D(0.0,1.0*(GLfloat)w/(GLfloat)h,0.0,1.0);
}
void keyboard(unsigned char key,int x,int y)
{
switch(key)
{
case 't':
case 'T':
leftFirst=!leftFirst;
glutPostRedisplay();
break;
case 27:
exit(0);
break;

}
}
int main(int argc, char** argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
glutInitWindowSize(200,200);
glutCreateWindow("Blending Example");
init();
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutKeyboardFunc(keyboard);
glutMainLoop();
return 0;
}

, , .
, ()
,
(). ,
. 0.75,
0.75 1-0.75=0.25 .
,
, .

6.1.4
, , ,
.

, .
.
,
;
,
.
( )
, ,
.
,

, .
,
. ,
,
.
, ,
, .
, ,

. (
).
, .
-
, , ,
, .
, ,
.

. ,
, glDepthMask();
GL_FALSE,
, GL_TRUE
.
6-2
. , a
,
( 6-3). r
. ,
.
6-3.

6-2. : alpha3D.cpp
#include <GL/glut.h>
#define MAXZ 8.0
#define MINZ -8.0
#define ZINC 0.02
float solidZ=MAXZ;
float transparentZ=MINZ;
GLuint sphereList,cubeList;
void init(void)
{
GLfloat mat_specular[]={1.0,1.0,1.0,0.15};
GLfloat mat_shininess[]={100.0};
GLfloat position[]={0.5,0.5,1.0,0.0};
glMaterialfv(GL_FRONT,GL_SPECULAR,mat_specular);
glMaterialfv(GL_FRONT,GL_SHININESS,mat_shininess);
glLightfv(GL_LIGHT0,GL_POSITION,position);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glEnable(GL_DEPTH_TEST);
sphereList=glGenLists(1);
glNewList(sphereList,GL_COMPILE);
glutSolidSphere(0.4,16,16);
glEndList();
cubeList=glGenLists(1);
glNewList(cubeList,GL_COMPILE);
glutSolidCube(0.6);
glEndList();
}

void display(void)
{
GLfloat mat_solid[]={0.75,0.75,0.0,1.0};
GLfloat mat_zero[]={0.0,0.0,0.0,1.0};
GLfloat mat_transparent[]={0.0,0.8,0.8,0.6};
GLfloat mat_emission[]={0.0,0.3,0.3,0.6};
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glTranslatef(-0.15,-0.15,solidZ);
glMaterialfv(GL_FRONT,GL_EMISSION,mat_zero);
glMaterialfv(GL_FRONT,GL_DIFFUSE,mat_solid);
glCallList(sphereList);
glPopMatrix();
glPushMatrix();
glTranslatef(0.15,0.15,transparentZ);
glRotatef(15.0,1.0,1.0,0.0);
glRotatef(30.0,0.0,1.0,0.0);
glMaterialfv(GL_FRONT,GL_EMISSION,mat_emission);
glMaterialfv(GL_FRONT,GL_DIFFUSE,mat_transparent);
glEnable(GL_BLEND);
glDepthMask(GL_FALSE);
glBlendFunc(GL_SRC_ALPHA,GL_ONE);
glCallList(cubeList);
glDepthMask(GL_TRUE);
glDisable(GL_BLEND);
glPopMatrix();
glutSwapBuffers();
}
void reshape(int w, int h)
{
glViewport(0,0,(GLsizei) w, (GLsizei) h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
if (w<=h)
glOrtho(-1.5,1.5,-0.5*(GLfloat)h/(GLfloat)w,1.5*(GLfloat)h/(GLfloat)w,10.0,10.0);
else
glOrtho(-1.5*(GLfloat)w/(GLfloat)h,1.5*(GLfloat)w/(GLfloat)h,-1.5,1.5,10.0,10.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
void animate()
{
if(solidZ<=MINZ || transparentZ >=MAXZ)
glutIdleFunc(NULL);
else
{
solidZ-=ZINC;
transparentZ+=ZINC;
glutPostRedisplay();
}
}
void keyboard(unsigned char key,int x, int y)
{
switch (key)
{
case 'a':
case 'A':
solidZ=MAXZ;
transparentZ=MINZ;
glutIdleFunc(animate);
break;
case 'r':
case 'R':
solidZ=MAXZ;
transparentZ=MINZ;
glutPostRedisplay();
break;

case 27:
exit(0);
}
}
int main(int argc, char** argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB|GLUT_DEPTH);
glutInitWindowSize(500,500);
glutCreateWindow("Three-Dimensional Blending");
init();
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutKeyboardFunc(keyboard);
glutMainLoop();
return 0;
}

6.2
, OpenGL ,
,
. ,
.
(aliasing),
, . 6-4
: ,
. .
6-4.

6-5 , 1
, . ,
, OpenGL
, . 65 . RGBA OpenGL
.
,
. , OpenGL 4

(0000 1111
).
.

6-5.

,
,
OpenGL. glHint()
,
OpenGL .
void glHint (GLenum target, GLenum hint);

OpenGL. target ,
,
6-2. hint GL_FASTEST (
), GL_NICEST( )
GL_DONT_CARE( ).
, OpenGL
.
GL_PERSPECTIVE_CORRECTION_HINT ,
:
( )
( ).
,
, ;
,
. , OpenGL
,
.
6-2. , glHint()

GL_POINT_SMOOTH_HINT
GL_LINE_SMOOTH_HINT
GL_POLYGON_SMOOTH_HINT

GL_FOG_SMOOTH_HINT

,
(GL_NICEST) (GL_FASTEST)

GL_PERSPECTIVE_CORRECTION_HINT

6.2.1


glEnable(), GL_POINT_SMOOTH GL_LINE_SMOOTH
. glHint().
(, .)
, ,
RGBA .

6.2.1.1

RGBA

RGBA . ,
, , GL_SRC_ALPHA ( )
GL_ONE_MINUS_SRC_ALPHA ( ).
GL_ONE( ),
.
.
. ,
, , , . ,
,
. 6-3 ,
.
r ,
, . ,
.
6-3. : aargb.cpp
#include <GL/glut.h>
float rotAngle=0;
void init(void)
{
glEnable(GL_LINE_SMOOTH);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
glHint(GL_LINE_SMOOTH_HINT,GL_NICEST);
glLineWidth(1.5);
glClearColor(0.0,0.0,0.0,0.0);
}
void display(void)
{
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(0.0,1.0,0.0);
glPushMatrix();
glRotatef(-rotAngle,0.0,0.0,0.1);
glBegin(GL_LINES);
glVertex2f(-0.5,0.5);
glVertex2f(0.5,-0.5);
glEnd();
glPopMatrix();
glColor3f(0.0,0.0,1.0);
glPushMatrix();
glRotatef(rotAngle,0.0,0.0,0.1);
glBegin(GL_LINES);
glVertex2f(0.5,0.5);
glVertex2f(-0.5,-0.5);
glEnd();
glPopMatrix();
glFlush();
}
void reshape(int w, int h)
{
glViewport(0,0,(GLsizei) w, (GLsizei) h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();

if (w<=h)
gluOrtho2D(-1.0,1.0,-1.0*(GLfloat)h/(GLfloat)w,1.0*(GLfloat)h/(GLfloat)w);
else
gluOrtho2D(-1.0*(GLfloat)w/(GLfloat)h,1.0*(GLfloat)w/(GLfloat)h,-1.0,1.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
void keyboard(unsigned char key, int x, int y)
{
switch(key)
{
case 'r':
case 'R':
rotAngle+=10;
if (rotAngle>=360)
rotAngle=0;
glutPostRedisplay();
break;
case 27:
exit(0);
break;
}
}
int main(int argc, char** argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
glutInitWindowSize(200,200);
glutCreateWindow("Antialiased Lines");
init();
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutKeyboardFunc(keyboard);
glutMainLoop();
return 0;
}

6.2.1.2


. 4
, 16
. (
16.)

. 6-4 ,
.
: , .
6-4. : aaindex.cpp
#include <GL/glut.h>
#define RAMPSIZE 16
#define RAMP1START 32
#define RAMP2START 48
float rotAngle=0;
void init(void)
{
int i;
for (i=0;i<RAMPSIZE;i++)
{
GLfloat shade;
shade=(GLfloat)i/(GLfloat)RAMPSIZE;

glutSetColor(RAMP1START+(GLint)i,0.,shade,0.);
glutSetColor(RAMP2START+(GLint)i,0.,0.,shade);
}
glEnable(GL_LINE_SMOOTH);
glHint(GL_LINE_SMOOTH_HINT,GL_NICEST);
glLineWidth(1.5);
glClearIndex((GLfloat)RAMP1START);
}
void display(void)
{
glClear(GL_COLOR_BUFFER_BIT);
glIndexi(RAMP1START);
glPushMatrix();
glRotatef(-rotAngle,0.0,0.0,0.1);
glBegin(GL_LINES);
glVertex2f(-0.5,0.5);
glVertex2f(0.5,-0.5);
glEnd();
glPopMatrix();
glIndexi(RAMP2START);
glPushMatrix();
glRotatef(rotAngle,0.0,0.0,0.1);
glBegin(GL_LINES);
glVertex2f(0.5,0.5);
glVertex2f(-0.5,-0.5);
glEnd();
glPopMatrix();
glFlush();
}
void reshape(int w, int h)
{
glViewport(0,0,(GLsizei) w, (GLsizei) h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
if (w<=h)
gluOrtho2D(-1.0,1.0,-1.0*(GLfloat)h/(GLfloat)w,1.0*(GLfloat)h/(GLfloat)w);
else
gluOrtho2D(-1.0*(GLfloat)w/(GLfloat)h,1.0*(GLfloat)w/(GLfloat)h,-1.0,1.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
void keyboard(unsigned char key,int x,int y)
{
switch(key)
{
case 'r':
case 'R':
rotAngle+=10;
if (rotAngle>=360) rotAngle=0;
glutPostRedisplay();
break;
case 27:
exit(0);
break;
}
}
int main(int argc, char** argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_SINGLE|GLUT_INDEX);
glutInitWindowSize(200,200);
glutCreateWindow("Antialiasing in Color-Index mode");
init();
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutKeyboardFunc(keyboard);
glutMainLoop();
return 0;
}

,
, .
, . ,
,
( ) ( ).
, ,
. ,
RGBA, ,
.

. ,
z.
, ,
.
,

. ,
,
. ,
.

6.2.2
.
,
. ,
( ).
,
, , . ,
, , , .
:
, GL_POINT GL_LINE glPolygonMode()
, (
).
GL_FILL.
, RGBA, .

, , , ,
.
,
,
glBlendFunc() GL_SRC_ALPHA_SATURATE ( )
GL_ONE ( ). ,
.
RGBA,
.
GL_POLYGON_SMOOTH glEnable().
,
,
. , ,
GL_POLYGON_SMOOTH_HINT.
. -, ,
, .
GL_SRC_ALPHA_SATURATE ( ) GL_ONE

( ).

.
. ,

,
.
, . ,
,
.

6.3
.
.
, , ,
.
-- ,
( , , , ).
,
.
.
, ,
. ,
.
RGBA, , , ,
.
, ,
, . ,
,
,
.
, , .
depth cuing (

)
.

6.3.1
. ,
GL_FOG, glEnable(). ,
, glFog*(). ,
GL_FOG_HINT
glHint(). 6-5 5 ,
. f .
.
6-6.

6-5. RGBA : fog.cpp


#include <windows.h>
#include <GL/glut.h>
GLint fogMode;
void init(void)
{
GLfloat position[]={0.5,0.5,3.0,0.0};
glEnable(GL_DEPTH_TEST);
glLightfv(GL_LIGHT0,GL_POSITION,position);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
{
GLfloat mat[3]={0.1745,0.01175,0.01175};
glMaterialfv(GL_FRONT,GL_AMBIENT,mat);
mat[0]=0.61424;mat[1]=0.04135;mat[2]=0.04136;
glMaterialfv(GL_FRONT,GL_DIFFUSE,mat);
mat[0]=0.727811;mat[1]=0.626959;mat[2]=0.626959;
glMaterialfv(GL_FRONT,GL_SPECULAR,mat);
glMaterialf(GL_FRONT,GL_SHININESS,0.6*128.0);
}
glEnable(GL_FOG);
{
GLfloat fogColor[4]={0.5,0.5,0.5,1.0};
fogMode=GL_EXP;
glFogi(GL_FOG_MODE,fogMode);
glFogfv(GL_FOG_COLOR,fogColor);
glFogf(GL_FOG_DENSITY,0.35);
glHint(GL_FOG_HINT,GL_NICEST);
glFogf(GL_FOG_START,1.0);
glFogf(GL_FOG_END,5.0);
}
glClearColor(0.5,0.5,0.5,1.0);
}
void renderSphere(GLfloat x ,GLfloat y, GLfloat z)
{
glPushMatrix();
glTranslatef(x,y,z);
glutSolidSphere(0.4,16,16);
glPopMatrix();
}
void display(void)
{
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);

renderSphere(-2.,-0.5,-1.0);
renderSphere(-1.,-0.5,-2.0);
renderSphere(0.,-0.5,-3.0);
renderSphere(1.,-0.5,-4.0);
renderSphere(2.,-0.5,-5.0);
glFlush();
}
void reshape(int w, int h)
{
glViewport(0,0,(GLsizei) w, (GLsizei) h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
if (w<=h)
glOrtho(-2.5,2.5,-2.5*(GLfloat)h/(GLfloat)w,2.5*(GLfloat)h/(GLfloat)w,10.0,10.0);
else
glOrtho(-2.5*(GLfloat)w/(GLfloat)h,2.5*(GLfloat)w/(GLfloat)h,-2.5,2.5,10.0,10.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
void keyboard(unsigned char key,int x, int y)
{
switch (key)
{
case 'f':
case 'F':
if(fogMode==GL_EXP)
{
fogMode=GL_EXP2;
MessageBox(NULL,"Fog mode is GL_EXP2","Five Fogged Spheres in RGBA
mode",MB_OK);
}
else
if(fogMode==GL_EXP2)
{
fogMode=GL_LINEAR;
MessageBox(NULL,"Fog mode is GL_LINEAR","Five Fogged Spheres in
RGBA mode",MB_OK);
}
else
if(fogMode==GL_LINEAR)
{
fogMode=GL_EXP;
MessageBox(NULL,"Fog mode is GL_EXP","Five Fogged Spheres in
RGBA mode",MB_OK);
}
glFogi(GL_FOG_MODE,fogMode);
glutPostRedisplay();
break;
case 27:
exit(0);
break;
}
}
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR
lpCmdLine, int nCmdShow)
{
char* argv="";
int argc=0;
glutInit(&argc,&argv);
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB|GLUT_DEPTH);
glutInitWindowSize(500,500);
glutCreateWindow("Five Fogged Spheres in RGBA mode");
init();
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutKeyboardFunc(keyboard);
glutMainLoop();
return 0;
}

6.3.2

. f,
[0, 1].

z
. density, start end glFog*().
f - , RGBA
.
void glFog{if} (GLenum pname, TYPE param);
void glFog{if}v (GLenum pname, TYPE *params);

. pname
GL_FOG_MODE, param GL_EXP ( ),
GL_EXP2 GL_LINEAR . pname
GL_FOG_DENSITY, GL_FOG_START GL_FOG_END, param (
) density, start end
. ( 1, 0 1 .)
RGBA pname GL_FOG_COLOR,
params , RGBA .
pname GL_FOG_INDEX,
param ,
.
6-7 ,
.
6-7.

6.3.2.1

RGBA

RGBA
:
,

RGBA ,
GL_FOG_COLOR.

6.3.2.2

-- ,


:
,

,
, GL_FOG_INDEX.

--

,
.
, .
, glClearIndex(),
; ,
. , ,
, glIndex*()
( ). ,
,
glIndex*()

. 6-6
.
6-6. : fogindex.cpp
#include <windows.h>
#include <GL/glut.h>
#define NUM_COLORS 32
#define RAMPSTART 16
void init(void)
{
int i;
glEnable(GL_DEPTH_TEST);
for(i=0;i<NUM_COLORS;i++)
{
GLfloat shade;
shade=(GLfloat)(NUM_COLORS-i)/(GLfloat)NUM_COLORS;
glutSetColor(RAMPSTART+i,shade,shade,shade);
}
glEnable(GL_FOG);
glFogi(GL_FOG_MODE,GL_LINEAR);
glFogi(GL_FOG_INDEX,NUM_COLORS);
glFogf(GL_FOG_DENSITY,0.35);
glFogf(GL_FOG_START,1.0);
glFogf(GL_FOG_END,6.0);
glHint(GL_FOG_HINT,GL_NICEST);
glClearIndex((GLfloat)(NUM_COLORS+RAMPSTART-1));
}
void renderSphere(GLfloat x ,GLfloat y, GLfloat z)
{
glPushMatrix();
glTranslatef(x,y,z);
glutWireSphere(0.4,16,16);
glPopMatrix();
}
void display(void)
{
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glIndexi(RAMPSTART);
renderSphere(-2.,-0.5,-1.0);
renderSphere(-1.,-0.5,-2.0);
renderSphere(0.,-0.5,-3.0);
renderSphere(1.,-0.5,-4.0);
renderSphere(2.,-0.5,-5.0);
glFlush();
}
void reshape(int w, int h)
{
glViewport(0,0,(GLsizei) w, (GLsizei) h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
if (w<=h)
glOrtho(-2.5,2.5,-2.5*(GLfloat)h/(GLfloat)w,2.5*(GLfloat)h/(GLfloat)w,10.0,10.0);
else
glOrtho(-2.5*(GLfloat)w/(GLfloat)h,2.5*(GLfloat)w/(GLfloat)h,-2.5,2.5,10.0,10.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR
lpCmdLine, int nCmdShow)
{
char* argv="";
int argc=0;
glutInit(&argc,&argv);

glutInitDisplayMode(GLUT_SINGLE|GLUT_INDEX|GLUT_DEPTH);
glutInitWindowSize(500,500);
glutCreateWindow("Fog in Color-Index Mode");
init();
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutMainLoop();
return 0;
}

6.4
,
GL_FILL, ,
GL_LINE.
, ,
, ,
. ,

(stiching).

, ,
. (
, , , .)

, .
.
6-8 ,
, ,
, .
6-8. ()
()

,
: GL_FILL, GL_LINE, GL_POINT.
, glEnable()
GL_POLYGON_OFFSET_FILL, GL_POLYGON_OFFSET_LINE

GL_POLYGON_OFFSET_POINT. glPolygonMode(),
.
void glPolygonOffset (GLfloat factor, GLfloat units);

,
. ,
,
. :
,
m , r ,
. r
, .
,
(
), ( ).
,
? , ,
.
OpenGL , ,
, ,
factor.
, x y ,
. ,
[0, 1]. ,

.
6-9.

, ,
0. ,
, . ,
, glPolygonOffset() factor=0.0
units=1.0.
,
, . ,
factor, 0.75 1.0

,
.
6-7 (
). ,
GL_FILL factor=1.0 units=1.0.
, ,
. (
, - ,
, - .) , ,
.
6-7.

glEnable(GL_LIGHTING); glEnable(GL_LIGHT0);
glEnable(GL_POLYGON_OFFSET_FILL);
glPolygonOffset(1.0,1.0);
glCallList(list);
glDisable(GL_POLYGON_OFFSET_FILL);
glDisable(GL_LIGHTING);
glDisable(GL_LIGHT0);
glColor3f(1.0,1.0,1.0);
glPolygonMode(GL_FRONT_AND_BACK,GL_LINE);
glCallList(list);
glPolygonMode(GL_FRONT_AND_BACK,GL_FILL);

factor units (1.0,


1.0) . , ,
1, factor. ,

, ,
,
. ,
factor.

7.
( ) OpenGL,
. , ,
, , .
OpenGL ,
, .

.
.
, .

7.1
,
OpenGL .
, -

. ,

, .

,
. ,
. ,
.
,
.

.
OpenGL ,
. ,
.
, , ,
,
.
,
.

,
.

7.2

OpenGL. , ,
.
, . ,
, ,
.
7-1. : torus.cpp
#include <glut.h>
#include <math.h>
GLuint theTorus;
//
void torus(int numc,int numt)
{
int i,j,k;
double s,t,x,y,z,twopi;
twopi=2*(double) 3.1415;
for(i=0;i<numc;i++)
{
glBegin(GL_QUAD_STRIP);
for(j=0;j<=numt;j++)
{
for(k=1;k>=0;k--)
{
s=(i+k)%numc+0.5;
t=j%numt;
x=(1+.1*cos(s*twopi/numc))*cos(t*twopi/numt);
y=(1+.1*cos(s*twopi/numc))*sin(t*twopi/numt);
z=.1*sin(s*twopi/numc);
glVertex3f(x,y,z);
}
}
glEnd();
}
}
void init(void)

{
theTorus=glGenLists(1);
glNewList(theTorus,GL_COMPILE);
torus(8,25);
glEndList();
glShadeModel(GL_FLAT);
glClearColor(0.0,0.0,0.0,0.0);
}
void display()
{
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1.0,1.0,1.0);
glCallList(theTorus);
glFlush();
}
void reshape(int w,int h)
{
glViewport(0,0,(GLsizei)w,(GLsizei)h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(30,(GLfloat)w/(GLfloat)h,1.0,100.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(0,0,10,0,0,0,0,1,0);
}
//"x" -- x -;"y" -- y -;"i"--

void keyboard(unsigned char key,int x,int y)
{
switch(key)
{
case 'X':
case 'x':
glRotatef(30.,1.0,0.0,0.0);
glutPostRedisplay();
break;
case 'Y':
case 'y':
glRotatef(30.,0.0,1.0,0.0);
glutPostRedisplay();
break;
case 'I':
case 'i':
glLoadIdentity();
gluLookAt(0,0,10,0,0,0,0,1,0);
glutPostRedisplay();
break;
case 27:
exit(0);
}
}
int main(int argc, char** argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
glutInitWindowSize(200,200);
glutCreateWindow("Creating a Display List");
init();
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutKeyboardFunc(keyboard);
glutMainLoop();
return 0;
}

init().
OpenGL. ,
(torus()) glNewList() glEndList(),
. listName glNewList()

, glGenLists()
.
x y, x y,
. , ,
keyboard(),
.
glutPostRedisplay(), glutMainLoop() display()
, .
i, keyboard()
.
display() .
glCallList() .
, display()
.
OpenGL. 7-1
glBegin(), glEnd() glVertex().

.
, .
,
, .
,
. ,
.
:
GLU,
OpenGL .
GLU
NURBS.

7.3
,
, . ,
, . ,

. - ,
, .
, ,
OpenGL . , ,
,
- .
, ,
. glRotate()
,
, ,
(
).
,
,
glMultMatrix*(). OpenGL
.

, OpenGL
- ,
,
, . , ,
.
, .
,
.

. OpenGL
.
OpenGL.
. , ,
, .
, OpenGL ,
.
,
.
, .
,
.
, .
,
,
;
.
.
,
.
,
. ,
OpenGL,
, . OpenGL 1.0
.
OpenGL 1.1 ,
. ( 1.0
.
,
.)
.

, , ,
-,
. ,
(GL_COLOR_MATERIAL),
. glMaterial*()
.

. , ,
.
:
glNewList(1, GL_COMPILE);
__();
glEndList();
glLoadMatrix(M);
glCallList(1);

,
, . ,
, OpenGL
, :
glNewList(1, GL_COMPILE);
glLoadMatrix(M);
__();
glEndList();
glCallList(1);

.
, ,
. ,
, ,
OpenGL
.
, .
,
.
.
OpenGL .
(,
), .

7.4
,
glNewList() glEndList().
glCallList(). 7-2 init().
OpenGL .
display() 10 . ,
. ,
, .
7-2. : list.cpp
#include <glut.h>
GLuint listName;
void init(void)
{
listName=glGenLists(1);
glNewList(listName,GL_COMPILE);
glColor3f(1.0,0.0,0.0);
glBegin(GL_TRIANGLES);
glVertex2f(0.0,0.0);
glVertex2f(1.0,0.0);
glVertex2f(0.0,1.0);
glEnd();
glTranslatef(1.5,0.0,0.0);
glEndList();
glShadeModel(GL_FLAT);
}
void drawLine()
{
glBegin(GL_LINES);
glVertex2f(0.0,0.5);
glVertex2f(15.0,0.5);
glEnd();

}
void display(void)
{
GLuint i;
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(0.0,1.0,0.0);
for(i=0;i<=10;i++)
glCallList(listName);
// ,
drawLine();
glFlush();
}
void reshape(int w, int h)
{
glViewport(0,0,w,h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
if (w<=h)
gluOrtho2D(0.0,2.0,-0.5*(GLfloat)h/(GLfloat)w,1.5*(GLfloat)h/(GLfloat)w);
else
gluOrtho2D(0.0,2.0*(GLfloat)w/(GLfloat)h,-0.5,1.5);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
int main(int argc, char** argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
glutInitWindowSize(650,50);
glutCreateWindow("Using a Display List");
init();
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutMainLoop();
return 0;
}

glTranslatef()
.
. drawLine(),
10-
glTranslate(). ,
,
.
.
, glNewList() glEndList(),
,
. , glEndList()
glNewList() GL_INVALID_OPERATION.

7.4.1
.
, ,
.
glGenLists()
.
GLuint glGenLists (GLsizei range);

, range.
.
,
glGenLists() ,
. range 0
, glGenLists() 0.
, , ,
.
listIndex=glGenLists(1);
if (listIndex!=0)
{
glNewList(listIndex, GL_COMPILE);
...
glEndList();
}

: 0 .
void glNewList (GLuint list, GLenum mode);

. ( glEndList())
OpenGL ( , )
. ( ,
, .)
list ,
. mode GL_COMPILE
GL_COMPILE_AND_EXECUTE. GL_COMPILE, ,
OpenGL . ,
, ,
GL_COMPILE_AND_EXECUTE.
void glEndList (void);

.
,
OpenGL. , .
.
, .

7.4.2
, .

.
RGBA (0.0, 0.0, 0.0).
color_vector (1.0, 0.0, 0.0)
, ,
.
GLfloat color_vector[3]={0.0, 0.0, 0.0};
glNewList(1, GL_COMPILE);
glColor3f(color_vector);
glEndList();
color_vector[0]=1.0;

OpenGL .
, , , ,
,
. (
,
.)
, .
OpenGL, .
( , glNewList() ,
.)
glColorPointer()

glFlush()

glNormalPointer()

glDeleteLists()

glGenLists()

glPixelStore()

glDisableClientState()

glGet*()

glReadPixels()

glEdgeFlagPointer()

glIndexPointer()

glRenderMode()

glEnableClientState()

glInterleavedArrays()

glSelectBuffer()

glFeedbackBuffer()

glIsEnabled()

glTexCoordPointer()

glFinish()

glIsList()

glVertexPointer()

, , ,
OpenGL ,
. , ,
,
. , glGet*() glIs*()
, ,
. ,
, . ,
, , .
, , ,
glPixelStore() glSelectBuffer(), ,
.
OpenGL . ,
( glVertexPointer(), glColorPointer()
glInterleavedArrays())
. glArrayElement(), glDrawArrays()
glDrawElements()
,
. ,
, .
,
.
, ,
, ,
. ,
glFinish() glFlush() ,
.

7.4.3
, , ,
glCallList(). ,
, , ,
.

void glCallList (GLuint list);

, list.
, , ,
. list ,
.
glCallList() ,
OpenGL,
( , ,
, ).
, ,
.
,
. ,
.

7.4.4
, ,
, glCallList()
glNewList() glEndList().
, ,
. ,
:
glNewList(listIndex, GL_COMPILE);
glCallList(handlebars);
glCallList(frame);
glTranslatef(1.0,0.0,0.0);
glCallList(wheel);
glTranslatef(3.0,0.0,0.0);
glCallList(wheel);
glEndList();


; 64,
.
OpenGL, :
glGetIntegerv(GL_MAX_LIST_NESTING, GLint *data);

OpenGL , ,
. , ,
.

,
. ,
, 7-3.
7-3.
glNewList(1, GL_COMPILE);
glVertex3fv(v1);
glEndList();
glNewList(2, GL_COMPILE);

glVertex3fv(v2);
glEndList();
glNewList(3, GL_COMPILE);
glVertex3fv(v3);
glEndList();
glNewList(4, GL_COMPILE);
glBegin(GL_POLYGON);
glCallList(1);
glCallList(2);
glCallList(3);
glEnd();
glEndList();

, 4.
,
. ,
, .
,
, .

7.4.5
glGenLists()
. glGenLists(),
glIsList() ,
.
GLboolean glIsList (GLuint list);

GL_TRUE list
GL_FALSE .

glDeleteLists(). glDeleteLists(),
.
void glDeleteLists (GLuint list, GLsizei range);

( ) range,
list.
.

7.5
OpenGL
. ,
glCallLists().
, . ,
, ASCII
. ,

. , glListBase()
glCallLists().
void glListBase (GLuint base);

, glCallLists()
. 0.
glNewList(), glCallList(),
.
void glCallLists (GLsizei n, GLenum type, const GLvoid *lists);

n .
(
glListBase()) , lists.
type lists GL_BYTE,
GL_UNSIGNED_BYTE, GL_SHORT, GL_UNSIGNED_SHORT, GL_INT, GL_UNSIGNED_INT
GL_FLOAT, , lists
, , , , ,
, . Type
GL_2_BYTES, GL_3_BYTES GL_4_BYTES;
2, 3 4 , ,
, . (byte[0]
):
/* b=2, 3 4; 0, 1, 2, 3 */
offset=0;
for(i=0;i<b;i++)
{
offset=offset << 8;
offset+=byte[i];
}
index=offset+listbase;

, , .
,
7-4, - 7-5.
( ).
initStrokedFont() ,
ASCII- .
7-4.
void initStrokedFont(void)
{
GLuint base;
base=glGenLists(128);
glListBase(base);
glNewList(base+A,GL_COMPILE);
drawLetter(Adata);
glEndList();
glNewList(base+E,GL_COMPILE);
drawLetter(Edata);
glEndList();
glNewList(base+P,GL_COMPILE);
drawLetter(Pdata);
glEndList();
glNewList(base+R,GL_COMPILE);
drawLetter(Rdata);
glEndList();
glNewList(base+S,GL_COMPILE);

drawLetter(Sdata);
glEndList();
//
glNewList(base+ ,GL_COMPILE);
glTranslatef(8.0,0.0,0.0);
glEndList();
}

glGenLists() 128 .
.
; ASCII- .
.
, glCallLists() .
, printStrokedString():
void printStrokedString(GLbyte *s)
{
GLint len=strlen(s);
glCallLists(len, GL_BYTE, s);
}

ASCII
.
ASCII- . ,
7-5, 7-1.
7-1. A, E, P, R S

7-5. , :
stroke.cpp
#include <glut.h>
#include <string.h>
#define PT 1
#define STROKE 2
#define END 3
typedef struct charpoint
{
GLfloat x,y;
int type;
} CP;
CP
Adata[]={{0,0,PT},{0,9,PT},{1,10,PT},{4,10,PT},{5,9,PT},{5,0,STROKE},{0,5,PT},{5,5,END}};
CP Edata[]={{5,0,PT},{0,0,PT},{0,10,PT},{5,10,STROKE},{0,5,PT},{4,5,END}};
CP Pdata[]={{0,0,PT},{0,10,PT},{4,10,PT},{5,9,PT},{5,6,PT},{4,5,PT},{0,5,END}};
CP Rdata[]={{0,0,PT},{0,10,PT},{4,10,PT},{5,9,PT},{5,6,PT},{4,5,PT},{0,5,STROKE},{3,5,PT},
{5,0,END}};
CP
Sdata[]={{0,1,PT},{1,0,PT},{4,0,PT},{5,1,PT},{5,4,PT},{4,5,PT},{1,5,PT},{0,6,PT},{0,9,PT},{
1,10,PT},{4,10,PT},{5,9,END}};
//
//
void drawLetter(CP *l)

{
glBegin(GL_LINE_STRIP);
while(1)
{
switch(l->type)
{
case PT:
glVertex2fv(&l->x);
break;
case STROKE:
glVertex2fv(&l->x);
glEnd();
glBegin(GL_LINE_STRIP);
break;
case END:
glVertex2fv(&l->x);
glEnd();
glTranslatef(8.0,0.0,0.0);
return;
}
l++;
}
}
// 6 (5 + )
void init()
{
glLineWidth(2.0);
base=glGenLists(128);
glListBase(base);
glNewList(base+'A',GL_COMPILE); drawLetter(Adata); glEndList();
glNewList(base+'E',GL_COMPILE); drawLetter(Edata); glEndList();
glNewList(base+'P',GL_COMPILE); drawLetter(Pdata); glEndList();
glNewList(base+'R',GL_COMPILE); drawLetter(Rdata); glEndList();
glNewList(base+'S',GL_COMPILE); drawLetter(Sdata); glEndList();
glNewList(base+' ',GL_COMPILE); glTranslatef(8.0,0.0,0.0); glEndList();
}
char *test1="A SPARE SERAPE APPEARS AS";
char *test2="APES PREPARE RARE PEPPERS";
void printStrokedString(char *s)
{
GLsizei len=strlen(s);
glCallLists(len,GL_BYTE,(GLbyte *) s);
}
void display()
{
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(0.0,1.0,0.0);
glPushMatrix();
glScalef(2.0,2.0,2.0);
glTranslatef(10.0,30.0,0.0);
printStrokedString(test1);
glPopMatrix();
glPushMatrix();
glScalef(2.0,2.0,2.0);
glTranslatef(10.0,13.0,0.0);
printStrokedString(test2);
glPopMatrix();
glFlush();
}
void reshape(int w,int h)
{
glViewport(0,0,w,h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0.0,440,0.0,120);
}
void keyboard(unsigned char key,int x,int y)
{

switch(key)
{
case ' ':
glutPostRedisplay();
break;
case 27:
exit(0);
break;
}
}
int main(int argc, char** argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
glutInitWindowSize(440,120);
glutCreateWindow("Multiple Display Lists to Define a Stroked Font");
init();
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutKeyboardFunc(keyboard);
glutMainLoop();
return 0;
}

7.6

,
OpenGL. ,
.
. 7-2
7-6, ,
, ,
.
7-6.
glNewList(listIndex, GL_COMPILE);
glColor3f(1.0,0.0,0.0);
glBegin(GL_POLYGON);
glVertex2f(0.0,0.0);
glVertex2f(1.0,0.0);
glVertex2f(0.0,1.0);
glEnd();
glTranslatef(1.5,0.0,0.0);
glEndList();

, , ,
,
(1.5, 0.0, 0.0), :
glCallList(listIndex);
glBegin(GL_LINES);
glVertex2f(2.0,-1.0);
glVertex2f(1.0,0.0);
glEnd();

, ,

. ,
glGet*(),
.

glPushAttrib()
glPopAttrib() .
, glPushMatrix() glPopMatrix().
.
7-6,
7-7.
7-7.
glNewList(listIndex, GL_COMPILE);
glPushMatrix();
glPushAttrib(GL_CURRENT_BIT);
glColor3f(1.0,0.0,0.0);
glBegin(GL_POLYGON);
glVertex2f(0.0,0.0);
glVertex2f(1.0,0.0);
glVertex2f(0.0,1.0);
glEnd();
glTranslatef(1.5,0.0,0.0);
glPopAttrib();
glPopMatrix();
glEndList();

7-7, 7-8
, .
7-6 ( ),
10 (1.5, 0.0, 0.0).
7-8. drawLine()
void display(void)
{
GLint i;
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(0.0,1.0,0.0);
//
for(i=0;i<10;i++)
glCallList(listIndex); // 10
drawLine();
glFlush();
}

7.6.1

, .
,
,
,
.
, ,
,
. ,
. ,
, , ,
, ,
.
7-9 ,
. glGenLists(),

, .
glCallList().
7-9. ,
GLuint offset;
offset=glGenLists(3);
glNewList(offset,GL_COMPILE);
glDisable(GL_LINE_STIPPLE);
glEndList();
glNewList(offset+1,GL_COMPILE);
glEnable(GL_LINE_STIPPLE);
glLineStipple(1,0x0F0F);
glEndList();
glNewList(offset+2,GL_COMPILE);
glEnable(GL_LINE_STIPPLE);
glLineStipple(1,0x1111);
glEndList();
#define drawOneLine(x1, y1, x2, y2) glBegin(GL_LINES); glVertex2f((x1),(y1));
glVertex2f((x2),(y2)); glEnd();
glCallList(offset);
drawOneLine(50.0,125.0,350.0,125.0);
glCallList(offset+1);
drawOneLine(50.0,100.0,350.0,100.0);
glCallList(offset+2);
drawOneLine(50.0,75.0,350.0,75.0);

8. , ,


, .
, OpenGL :

,
,
.

.
, , ,
, ,
, , (,
, , ). ,
, ,
.
, (
) .
, ,
, .
: OpenGL
, .

8.1

,
. ,
. , 1,
(
, ). ,
0, .
.
OpenGL
. glRasterPos*() glBitmap()
. ,

,
. ,
, .
8-1, F. 8-1
F .
8-1. F

8-1. : drawf.cpp
#include <glut.h>
GLubyte rasters[24]= { 0xC0,0x00,0xC0,0x00,0xC0,0x00,0xC0,0x00,
0xC0,0x00,0xFF,0x00,0xFF,0x00,0xC0,0x00,
0xC0,0x00,0xC0,0x00,0xFF,0xC0,0xFF,0xC0 };
void init(void)
{
glPixelStorei(GL_UNPACK_ALIGNMENT,1);
glClearColor(0.0,0.0,0.0,0.0);
}
void display(void)
{
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1.0,1.0,1.0);

glRasterPos2i(20,20);
glBitmap(10,12,0.0,0.0,11.0,0.0,rasters);
glBitmap(10,12,0.0,0.0,11.0,0.0,rasters);
glBitmap(10,12,0.0,0.0,11.0,0.0,rasters);
glFlush();
}
void reshape(int w, int h)
{
glViewport(0,0,(GLsizei) w, (GLsizei) h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0,w,0,h,-1.0,1.0);
glMatrixMode(GL_MODELVIEW);
}
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(300,100);
glutCreateWindow("Drawing a Bitmapped Character");
init();
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutKeyboardFunc(keyboard);
glutMainLoop();
return 0;
}

8-1 , F 10
. , 8,
8. ,
, , : ,
. ,
0xc0, 0x00, 0xc0, 0x00,
F 0xff, 0xc0, 0xff, 0xc0,
.
glRasterPos2i()
glBitmap(); .
glPixelStorei(); ,
.

8.1.1
,
( ). F
glRasterPos*() (20, 20)
. , F:
glRasterPos2i(20, 20);
void glRasterPos[234]{sifd} (TYPE x, TYPE y, TYPE z, TYPE w);
void glRasterPos[234]{sifd}v (TYPE *coords);

. x, y, z w
. , coords
. glRasterPos2*(),
z 0, w 1; ,
glRasterPos3*(), w 1.

, , glVertex*() (
).
,
, , .
, .
: ,
,
2D .
(width height ):
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0.0, (GLfloat) width, 0.0, (GLfloat) height);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

,
glGetFloatv() GL_CURRENT_RASTER_POSITION .
, (x, y, z, w)
. ,
(), glGetBooleanv()
GL_CURRENT_RASTER_POSITION_VALID .

8.1.2
,
glBitmap(), .
void glBitmap (GLsizei width,GLsizei height,GLfloat
,GLfloat

,GLfloat

,GLfloat

,GLubyte *bitmap);

, bitmap,
.
. , ,
. width height
. 8-,
8 . ( F
, -
, glBitmap() width 10 ,

,
, 10 .)
,
(

, ).
x y,
( 8-2).
8-2.


( ,
, , g, j y) (, ,
, ).
, ,

x y . ( ,
, glBitmap() bitmap
NULL width height 0.)
0,

-- ,

. , ,
. ,
,
0,

0. 8-2, F
11 , 1 .

,
,

,
.
,
, ,
. , F

11.5 12, ,
1, 2 , 1.5 .
: , ,
x y
. , .

8.1.3
glColor*() glIndex*(),
.
:
GL_CURRENT_RASTER_COLOR GL_CURRENT_RASTER_INDEX,
. ,
glRasterPos*(). .
, ?

glColor3f(1.0,1.0,1.0);
/**/
glRasterPos3fv(position);
glColor3f(1.0,0.0,0.0);
/**/
glBitmap(...);

, ?
GL_CURRENT_RASTER_COLOR
glRasterPos3fv(). glColor3f()
GL_CURRENT_COLOR , ,
, .
,
glGetFloatv() glGetIntegerv()
GL_CURRENT_RASTER_COLOR GL_CURRENT_RASTER_INDEX
.

8.1.4
. ,
.
, , ,
, , ,
(, ).
,
( , ASCII ) .
ASCII A ( ) 65, B
66 . DAB 68, 65 66.
65 A, 66 B .
, 68, 65, 66
.
glCallLists() :
void glCallLists(GLsizei n, GLenum type, const GLvoid *lists);

, n, , type
GL_BYTE, lists .

, .
65 A ,
. 1 A, B C 1065, 1066 1067,
2 2065, 2066 2067, 256
8- . ,
,
. A, B C
1065, 1066 1067 1, 2
2065, 2066 2067. ,
1, 1000
65, 66 67. 2,
2000 .
, , glListBase().
1000 2000
. ,
,
glGenLists():

GLuint glGenLists (GLsizei range);

, range
.
, , glGenLists()
( ).
, 4 glGenLists() 81,
81, 82, 83 84
. glGenLists()
, 0. (, glDeleteLists()
, , .)

( 256),
, . (
) ,
. OpenGL ,
1-, 2-, 3- 4- type
glCallLists(). :
GL_BYTE

GL_UNSIGNED_BYTE

GL_SHORT

GL_UNSIGNED_SHORT

GL_INT

GL_UNSIGNED_INT

GL_FLOAT

GL_2_BYTES

GL_3_BYTES

GL_4_BYTES

8.1.5
glBitmap() ,
, . 8-2
ASCII.
, . ,
THEQUICKBROWNFOXJUMPSOVERALAZYDOG. (
8-3).
8-2 F ,
.
,
glGenLists() ASCII .
8-3. ,

8-2. : font.cpp
#include <glut.h>
#include <string.h>
GLubyte space[]=
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
GLubyte letters[][13]={
{0x00,0x00,0xc3,0xc3,0xc3,0xc3,0xff,0xc3,0xc3,0xc3,0x66,0x3c,0x18},
{0x00,0x00,0xfe,0xc7,0xc3,0xc3,0xc7,0xfe,0xc7,0xc3,0xc3,0xc7,0xfe},
{0x00,0x00,0x7e,0x7e,0xc0,0xc0,0xc0,0xc0,0xc0,0xc0,0xc0,0xe7,0x7e},

{0x00,0x00,0xfc,0xce,0xc7,0xc3,0xc3,0xc3,0xc3,0xc3,0xc7,0xce,0xfc},
{0x00,0x00,0xff,0xc0,0xc0,0xc0,0xc0,0xfc,0xc0,0xc0,0xc0,0xc0,0xff},
{0x00,0x00,0xc0,0xc0,0xc0,0xc0,0xc0,0xc0,0xfc,0xc0,0xc0,0xc0,0xff},
{0x00,0x00,0x7e,0x7e,0xc3,0xc3,0xcf,0xc0,0xc0,0xc0,0xc0,0xe7,0x7e},
{0x00,0x00,0xc3,0xc3,0xc3,0xc3,0xc3,0xff,0xc3,0xc3,0xc3,0xc3,0xc3},
{0x00,0x00,0x7e,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x7e},
{0x00,0x00,0x7c,0xee,0xc6,0x06,0x06,0x06,0x06,0x06,0x06,0x06,0x06},
{0x00,0x00,0xc3,0xc6,0xcc,0xd8,0xf0,0xe0,0xf0,0xd8,0xcc,0xc6,0xc3},
{0x00,0x00,0xff,0xc0,0xc0,0xc0,0xc0,0xc0,0xc0,0xc0,0xc0,0xc0,0xc0},
{0x00,0x00,0xc3,0xc3,0xc3,0xc3,0xc3,0xc3,0xdb,0xff,0xff,0xe7,0xc3},
{0x00,0x00,0xc7,0xc7,0xcf,0xcf,0xdf,0xdb,0xfb,0xf3,0xf3,0xe3,0xe3},
{0x00,0x00,0x7e,0xe7,0xc3,0xc3,0xc3,0xc3,0xc3,0xc3,0xc3,0xe7,0x7e},
{0x00,0x00,0xc0,0xc0,0xc0,0xc0,0xc0,0xfe,0xc7,0xc3,0xc3,0xc7,0xfe},
{0x00,0x00,0x3f,0x6e,0xdf,0xdb,0xc3,0xc3,0xc3,0xc3,0xc3,0x66,0x3c},
{0x00,0x00,0xc3,0xc6,0xcc,0xd8,0xf0,0xfe,0xc7,0xc3,0xc3,0xc7,0xfe},
{0x00,0x00,0x7e,0xe7,0x03,0x03,0x07,0x7e,0xe0,0xc0,0xc0,0xe7,0x7e},
{0x00,0x00,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0xff},
{0x00,0x00,0x7e,0xe7,0xc3,0xc3,0xc3,0xc3,0xc3,0xc3,0xc3,0xc3,0xc3},
{0x00,0x00,0x18,0x3c,0x3c,0x66,0x66,0xc3,0xc3,0xc3,0xc3,0xc3,0xc3},
{0x00,0x00,0xc3,0xe7,0xff,0xff,0xdb,0xdb,0xc3,0xc3,0xc3,0xc3,0xc3},
{0x00,0x00,0xc3,0x66,0x66,0x3c,0x3c,0x18,0x3c,0x3c,0x66,0x66,0xc3},
{0x00,0x00,0x18,0x18,0x18,0x18,0x18,0x18,0x3c,0x3c,0x66,0x66,0xc3},
{0x00,0x00,0xff,0xc0,0xc0,0x60,0x30,0x7e,0x0c,0x06,0x03,0x03,0xff}
};
GLuint fontOffset;
void makeRasterFont()
{
GLuint i,j;
glPixelStorei(GL_UNPACK_ALIGNMENT,1);
fontOffset=glGenLists(128);
for(i=0,j='A';i<26;i++,j++)
{
glNewList(fontOffset+j,GL_COMPILE);
glBitmap(8,13,0.0,2.0,10.0,0.0,letters[i]);
glEndList();
}
glNewList(fontOffset+' ',GL_COMPILE);
glBitmap(8,13,0.0,2.0,10.0,0.0,space);
glEndList();
}
void init(void)
{
glShadeModel(GL_FLAT);
makeRasterFont();
}
void printString(char *s)
{
glPushAttrib(GL_LIST_BIT);
glListBase(fontOffset);
glCallLists(strlen(s),GL_UNSIGNED_BYTE,(GLubyte*)s);
glPopAttrib();
}
void display(void)
{
GLfloat white[3]={1.0,1.0,1.0};
glClear(GL_COLOR_BUFFER_BIT);
glColor3fv(white);
glRasterPos2i(20,60);
printString("THE QUICK BROWN FOX JUMPS");
glRasterPos2i(20,40);
printString("OVER A LAZY DOG");
glFlush();
}
void reshape(int w, int h)
{
glViewport(0,0,(GLsizei) 300, (GLsizei) 100);
glMatrixMode(GL_PROJECTION);

glLoadIdentity();
glOrtho(0,w,0,h,-1.0,1.0);
glMatrixMode(GL_MODELVIEW);
}
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(300,100);
glutCreateWindow("Drawing a Complete Font");
init();
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutKeyboardFunc(keyboard);
glutMainLoop();
return 0;
}

8.2
,
,
. , (R,
G, B, A) .
, :


,
,

, .
, ,
.
.

, ,
.
, .

8.2.1 ,
OpenGL :

glReadPixels()
.
glDrawPixels() ,
, ,
glRasterPos*().
glCopyPixels()
.
glReadPixels() glDrawPixels(),
.


8-4.
8-4.

8-4 .
glRasterPos*(),
glDrawPixels() glCopyPixels(), .
glDrawPixels()
glCopyPixels(). (, ,
, .)
- ,
,
,
, .
. ,

, ,
. ,
, ,
, ,


.
.
,
: ,
.

8.2.1.1

void glReadPixels (GLint x, GLint y, GLsizei width, GLsizei height, GLenum


format, GLenum type, GLvoid *pixels);

,
(x, y),
width height, , pixels.
format ,
( R, G, B A 8-1),
type ( 8-2).
glReadPixels(), RGBA
, , , ,
. ,
,
. ,
, glReadBuffer().
8-1. glReadPixels() glDrawPixels()

GL_COLOR_INDEX

GL_RGB

GL_RGBA

, ,

GL_BGR

GL_BGRA

, ,

GL_RED

GL_GREEN

GL_BLUE

GL_ALPHA

GL_LUMINANCE

GL_LUMINANCE_ALPHA

GL_STENCIL_INDEX

GL_DEPTH_COMPONENT

: GL_BGR GL_BGRA OpenGL 1.2.


8-2. glReadPixels() glDrawPixels()

GL_UNSIGNED_BYTE

8-

GL_BYTE

8-

GL_BITMAP

, 8- (
, glBitmap())

GL_UNSIGNED_SHORT

16-

GL_SHORT

16-

GL_UNSIGNED_INT

32-

GL_INT

32-

GL_FLOAT

GL_UNSIGNED_BYTE_3_3_2

8-

GL_UNSIGNED_BYTE_2_3_3_REV

8-

GL_UNSIGNED_SHORT_5_6_5

16-

GL_UNSIGNED_SHORT_5_6_5_REV

16-

GL_UNSIGNED_SHORT_4_4_4_4

16-

GL_UNSIGNED_SHORT_4_4_4_4_REV

16-

GL_UNSIGNED_SHORT_5_5_5_1

16-

GL_UNSIGNED_SHORT_1_5_5_5_REV

16-

GL_UNSIGNED_INT_8_8_8_8

32-

GL_UNSIGNED_INT_8_8_8_8_REV

32-

GL_UNSIGNED_INT_10_10_10_2

32-

GL_UNSIGNED_INT_2_10_10_10_REV

32-

: GL_*_REV
MicrosoftWindows.
, ,
. , GL_RGBA,
32- ( type GL_UNSIGNED_INT
GL_INT), 16
(4 * 4 ).
, 8-2.
() ,
, ,
. , ,
0.0 1.0.
, 8 ,
.
GL_UNSIGNED_SHORT GL_UNSIGNED_INT 16 32
. GL_BYTE, GL_SHORT GL_INT 7, 15 31
, , , .
(
, ) GL_FLOAT,
. GL_BYTE, GL_SHORT GL_INT
1 . ,
8- , 0x7f. GL_FLOAT,

(, 17 17.0).
( ,
GL_UNSIGNED_BYTE_*, GL_UNSIGNED_SHORT_* GL_UNSIGNED_INT_*),
,
: , , .
, 8-3.
,
GL_INVALID_OPERATION.
: OpenGL 1.2.
8-3.

GL_UNSIGNED_BYTE_3_3_2

GL_RGB

GL_UNSIGNED_BYTE_2_3_3_REV

GL_RGB

GL_UNSIGNED_SHORT_5_6_5

GL_RGB

GL_UNSIGNED_SHORT_5_6_5_REV

GL_RGB

GL_UNSIGNED_SHORT_4_4_4_4

GL_RGBA, GL_BGRA

GL_UNSIGNED_SHORT_4_4_4_4_REV

GL_RGBA, GL_BGRA

GL_UNSIGNED_SHORT_5_5_5_1

GL_RGBA, GL_BGRA

GL_UNSIGNED_SHORT_1_5_5_5_REV

GL_RGBA, GL_BGRA

GL_UNSIGNED_INT_8_8_8_8

GL_RGBA, GL_BGRA

GL_UNSIGNED_INT_8_8_8_8_REV

GL_RGBA, GL_BGRA

GL_UNSIGNED_INT_10_10_10_2

GL_RGBA, GL_BGRA

GL_UNSIGNED_INT_2_10_10_10_REV

GL_RGBA, GL_BGRA


,
_REV. _REV ,
. _REV
,
.
, 8-5,
GL_UNSIGNED_BYTE_3_3_2, GL_UNSIGNED_BYTE_2_3_3_REV
4 GL_UNSIGNED_SHORT_4_4_4_4 ( REV)
RGBA/BGRA. 14-

.
8-5.


.
, .

8.2.1.2

void glDrawPixels (GLsizei width, GLsizei height, GLenum format, GLenum type,
const GLvoid *pixels);

width height.
,
. format type ,
glReadPixels(). ( 8-1 8-2.) ,
pixels, .
, , .
8-3 , glDrawPixels()
. makeCheckImage()
RGB 64x64, .
glRasterPos2i(0,0) .
glPixelStorei().
8-3. glDrawPixels(): image.cpp
#define checkImageWidth 64
#define checkImageHeight 64
GLubyte checkImage[checkImageHeight][checkImageWidth][3];
void makeCheckImage()
{
int i,j,c;
for (i=0;i<checkImageHeight;i++)
{
for (j=0;j<checkImageWidth;j++)
{
c=(((i&0x08)==0)^((j&0x8)==0))*255;
checkImage[i][j][0]=(GLubyte)c;
checkImage[i][j][1]=(GLubyte)c;
checkImage[i][j][2]=(GLubyte)c;
}
}
}
void init(void)
{
glClearColor(0.0,0.0,0.0,0.0);
glShadeModel(GL_FLAT);
makeCheckImage();
glPixelStorei(GL_UNPACK_ALIGNMENT,1);
}
void display(void)
{
glClear(GL_COLOR_BUFFER_BIT);
glRasterPos2i(0,0);
glDrawPixels(checkImageWidth,checkImageHeight,GL_RGB,GL_UNSIGNED_BYTE,checkImage);
glFlush();
}

glDrawPixels() RGBA -
, ,
glDrawBuffer().

8.2.1.3

void glCopyPixels (GLint x, GLint y, GLsizei width, GLsizei height, GLenum


buffer);

,
(x, y), width height.

,
. buffer GL_COLOR, GL_STENCIL
GL_DEPTH, . glCopyPixels()
glReadPixels() glDrawPixels()
buffer format:

buffer GL_DEPTH GL_STENCIL, format


GL_DEPTH_COMPONENT GL_STENCIL_INDEX, .
GL_COLOR, GL_RGBA GL_COLOR_INDEX
, RGBA .

, glCopyPixels() format type,


.
glCopyPixels() glReadBuffer()
glDrawBuffer() .

, .

8.2.2
:
,
.
, glPixelZoom().
8-6.
8-6.

glDrawPixels()

, .
.
. ,
.
glReadPixels(), ,
,
.
glCopyPixels() ,
glReadPixels().
glDrawPixels(), .
8-7 glCopyPixels()
( ).
8-7. glCopyPixels()

8-8, ,
, , ,
, .
8-8. glBitmap()

,
, ,
. 8-9
glTexImage*(), glTexSubImage*() glGenTexImage*().
8-9. glTexImage*(), glTexSubImage*()
glGenTexImage*()

8-10,
( glCopyTexImage*() glCopyTexSubImage()),
.
8-10. glCopyTexImage*()
glCopyTexSubImage*()

8.2.2.1


.
, , (
) . .
(
, ),
, , .
, ,
.
( )
, ( , , )
, 0.0 1.0.
,
( , ,
8- ). , ,
. ,
32- , ,
.
8-
32- . OpenGL

. ,
, ,
.

8.2.2.2

-
.
, . , ,
, ,
. , ,
,
2-, 4- 8- .
. ,
, .
, glPixelStore*(),
.
, OpenGL,
glPixelStore*().
.

void glPixelStore{if} (GLenum pname, TYPE param);

,
glDrawPixels()), glReadPixels(), glBitmap(), glPolygonStipple(), glTexImage1D(),
glTexImage2D(), glTexImage3D(), glTexSubImage1D(), glTexSubImage2D(),
glTexSubImage3D(), glGetTexImage(), ,
glGetColorTable(), glGetConvolutionFilter(),
glGetSeparableFilter(), glGetHistogram(), glGetMinmax().
pname 8-4. GL_UNPACK_*
, glDrawPixels(),
glBitmap(), glPolygonStipple(), glTexImage1D(), glTexImage2D(),
glTexImage3D(), glTexSubImage1D(), glTexSubImage2D()
glTexSubImage3D(). GL_PACK_* ,
glReadPixels(), glGenTexImage(), ,
glGetColorTable(),
glGetConvolutionFilter(), glGetSeparableFilter(), glGetHistogram(),
glGetMinmax(). GL_UNPACK_IMAGE_HEIGHT, GL_PACK_IMAGE_HEIGHT,
GL_UNPACK_SKIP_IMAGES, GL_PACK_SKIP_IMAGES 3D
(glTexImage3D(), glTexSubImage3D(),
glGenTexImage(GL_TEXTURE_3D,...)).
8-4. glPixelStore()

GL_UNPACK_SWAP_BYTES,
GL_PACK_SWAP_BYTES

GLboolean

FALSE

TRUE / FALSE

GL_UNPACK_LSB_FIRST, GL_PACK_ LSB_FIRST

GLboolean

FALSE

TRUE / FALSE

GL_UNPACK_ROW_LENGTH,
GL_PACK_ROW_LENGTH

GLint

GL_UNPACK_SKIP_ROWS,
GL_PACK_SKIP_ROWS

GLint

GL_UNPACK_SKIP_PIXELS,
GL_PACK_SKIP_PIXELS

GLint

GL_UNPACK_ALIGNMENT, GL_PACK_ALIGNMENT

GLint

1, 2, 4, 8

GL_UNPACK_IMAGE_HEIGHT,
GL_PACK_IMAGE_HEIGHT

GLint

GL_UNPACK_SKIP_IMAGES,
GL_PACK_SKIP_IMAGES

GLint


,
GL_PACK GL_UNPACK. , *SWAP_BYTES
GL_UNPACK_SWAP_BYTES, GL_PACK_SWAP_BYTES.
*SWAP_BYTES FALSE ( ),
, OpenGL;
TRUE .
, ,
.
OpenGL.
8-10
, GLubyte 8 , GLushort 16, GLuint 32.
, .
8-11. Byte, Short Integer

: OpenGL
, , .
OpenGL,
,
*SWAP_BYTES. *SWAP_BYTES
(,
).
*LSB_FIRST
,
. *LSB_FIRST
FALSE ( ) ,
. , *LSB_FIRST FALSE,
0x31, {0, 0, 1, 1, 0, 0, 0, 1}.
*LSB_FIRST TRUE {1, 0, 0, 0, 1, 1, 0, 0}.

( ), .
, , ,
( )
*ROW_LENGTH. *ROW_LENGTH 0 ( )
, , glReadPixels(),
glDrawPixels() glCopyPixels().
,
. *SKIP_ROWS
*SKIP_PIXELS, 8-12. 0,
.
8-12. *SKIP_ROWS, *SKIP_PIXELS *ROW_LENGTH


, . ,
32- ,
, 32-,
4. , 64- ,
8 .
, , ,
4- .
, ,
4- . 5 ,
1 , 1 1 ,
5x3=15 .
, 4-
, 1 .
,
*ALIGNMENT ( 4).
*ALIGNMENT 1, . 2,
,
2-.
( 1- ),
, , .
, , 75
, 4, 75/8 9 3/8 .
12 4 9 3/8,
12 . 1,
10 , 9 3/8 .

: *ALIGNMENT 4.
, ( *ALIGNMENT
1) .
*IMAGE_HEIGHT *SKIP_IMAGES
.

8.2.2.3

,
, OpenGL .
,
0.0 1.0,
- ; , ,
.

. ,
,
. glPixelTransfer*() glPixelMap*().
, ,
, ,
.
, .

glPixelTransfer*().
glPixelMap*(), .
void glPixelTransfer{if} (GLenum pname, TYPE param);

,
glDrawPixels()), glReadPixels(), glCopyPixels(), glTexImage1D(),
glTexImage2D(), glTexImage3D(), glCopyTexImage1D(), glCopyTexImage2D(),
glTexSubImage1D(), glTexSubImage2D(), glTexSubImage3D(),
glCopyTexSubImage1D(), glCopyTexSubImage2D(), glCopyTexSubImage3D(),
glGetTexImage(). pname ,
8-5, param
.
8-5. glPixelTransfer*()

GL_MAP_COLOR

GLboolean

FALSE

TRUE/FALSE

GL_MAP_STENCIL

GLboolean

FALSE

TRUE/FALSE

GL_INDEX_SHIFT

GLint

GL_INDEX_OFFSET

GLint

GL_RED_SCALE

GLfloat

1.0

GL_GREEN_SCALE

GLfloat

1.0

GL_BLUE_SCALE

GLfloat

1.0

GL_ALPHA_SCALE

GLfloat

1.0

GL_DEPTH_SCALE

GLfloat

1.0

GL_RED_BIAS

GLfloat

0.0

GL_GREEN_BIAS

GLfloat

0.0

GL_BLUE_BIAS

GLfloat

0.0

GL_ALPHA_BIAS

GLfloat

0.0

GL_DEPTH_BIAS

GLfloat

0.0

GL_POST_CONVOLUTION_RED_SCALE

GLfloat

1.0

GL_POST_CONVOLUTION_GREEN_SCALE

GLfloat

1.0

GL_POST_CONVOLUTION_BLUE_SCALE

GLfloat

1.0

GL_POST_CONVOLUTION_ALPHA_SCALE

GLfloat

1.0

GL_POST_CONVOLUTION_RED_BIAS

GLfloat

0.0

GL_POST_CONVOLUTION_GREEN_BIAS

GLfloat

0.0

GL_POST_CONVOLUTION_BLUE_BIAS

GLfloat

0.0

GL_POST_CONVOLUTION_ALPHA_BIAS

GLfloat

0.0

GL_POST_COLOR_MATRIX_RED_SCALE

GLfloat

1.0

GL_POST_COLOR_MATRIX_GREEN_SCALE

GLfloat

1.0

GL_POST_COLOR_MATRIX_BLUE_SCALE

GLfloat

1.0

GL_POST_COLOR_MATRIX_ALPHA_SCALE

GLfloat

1.0

GL_POST_COLOR_MATRIX_RED_BIAS

GLfloat

0.0

GL_POST_COLOR_MATRIX_GREEN_BIAS

GLfloat

0.0

GL_POST_COLOR_MATRIX_BLUE_BIAS

GLfloat

0.0

: GL_POST_CONVOLUTION_* GL_POST_COLOR_MATRIX_*
, OpenGL
.
GL_MAP_COLOR GL_MAP_STENCIL TRUE,
(mapping) .
.
(scale) (bias) , , ,
. , ,
, ,
. (luminance)
, ,
GL_RED_SCALE, GL_GREEN_SCALE GL_BLUE_SCALE,

. RGB
NTSC, GL_RED_SCALE 0.30, GL_GREEN_SCALE 0.59, GL_BLUE_SCALE
0.11.
( ) .
(shift) . ,
, .

8.2.2.4

,
.
glPixelMap*().
void glPixelMap{ui us f}v (GLenum map, GLint mapsize, const TYPE *values);

, map, mapsize,
values. 8-6

; 1, 0.
2.
8-6. glPixelMap*()

GL_PIXEL_MAP_I_I

GL_PIXEL_MAP_S_S

GL_PIXEL_MAP_I_R

GL_PIXEL_MAP_I_G

GL_PIXEL_MAP_I_B

GL_PIXEL_MAP_I_A

GL_PIXEL_MAP_R_R

GL_PIXEL_MAP_G_G

GL_PIXEL_MAP_B_B

GL_PIXEL_MAP_A_A

-.
glGetIntegerv().

GL_MAX_PIXEL_MAP_TABLE,
GL_PIXEL_MAP_*_TO_*. 6 ,
, 2, RGBA
1 GL_MAX_PIXEL_MAP_TABLE.
, , . ,
256 ,
(GL_PIXEL_MAP_I_TO_I).
0 255
glPixelMap*(). , ,
101 ( 0 100 ) 0,
( 101 255 ) 255.
101 155 255.
GL_MAP_COLOR TRUE glPixelTransfer*().

101 0, 101 255.
255, 255 (
) .
(,
88.14585), ( 88)
( 0).

RGB.

8.2.2.5


, .
. ,
glPixelZoom().

void glPixelZoom (GLfloat

, GLfloat

);


(glDrawPixels() glCopyPixels()) x y.

1.0. 2.0,
4- . ,
.

.

, ,
. ,
(
,
). (
) n- m- ,
,

, (
)
.
. OpenGL
. ,
, , ,
glPixelZoom(1.0,-1.0); OpenGL. ,
.
8-4 glPixelZoom().
.
, glCopyPixels(),
. ( ,
.) ,
(1.0),
. z Z
0.5. , .
r .
8-4. , :
image.cpp
#include <glut.h>
#include <windows.h>
#include <stdio.h>
#define checkImageWidth 64
#define checkImageHeight 64
GLubyte checkImage[checkImageHeight][checkImageWidth][3];
GLdouble zoomFactor=1.0;
GLuint height;
void makeCheckImage()
{
int i,j,c;
for (i=0;i<checkImageHeight;i++)
{
for (j=0;j<checkImageWidth;j++)
{

c=(((i&0x08)==0)^((j&0x8)==0))*255;
checkImage[i][j][0]=(GLubyte)c;
checkImage[i][j][1]=(GLubyte)c;
checkImage[i][j][2]=(GLubyte)c;
}
}
}
void init(void)
{
glClearColor(0.0,0.0,0.0,0.0);
glShadeModel(GL_FLAT);
makeCheckImage();
glPixelStorei(GL_UNPACK_ALIGNMENT,1);
}
void display(void)
{
glClear(GL_COLOR_BUFFER_BIT);
glRasterPos2i(0,0);
glDrawPixels(checkImageWidth,checkImageHeight,
GL_RGB,GL_UNSIGNED_BYTE,checkImage);
glFlush();
}
void reshape(int w, int h)
{
glViewport(0,0,(GLsizei) w, (GLsizei) h);
height=(GLint)h;
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0.0,(GLdouble)w,0.0,(GLdouble)h);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
void motion(int x,int y)
{
static GLint screeny;
screeny=height-(GLint)y;
glRasterPos2i(x,screeny);
glPixelZoom(zoomFactor,zoomFactor);
glCopyPixels(0,0,checkImageWidth,checkImageHeight,GL_COLOR);
glPixelZoom(1.0,1.0);
glFlush();
}
void outMsg(bool reset=false)
{
char buffer[100];
if (reset)
sprintf(buffer,"zoomFactor is now %4.1f\n",zoomFactor);
else
sprintf(buffer,"zoomFactor reset to 1.0\n");
MessageBox(NULL,buffer,"Drawing, Copying and Zooming Pixel
Data",MB_OK);
return;
}
void keyboard(unsigned char key,int x,int y)
{

switch(key)
{
case 'r':
case 'R':
zoomFactor=1.0;
outMsg();
glutPostRedisplay();
break;
case 'z':
zoomFactor+=0.5;
if (zoomFactor>=3.0)
zoomFactor=3.0;
outMsg(true);
break;
case 'Z':
zoomFactor-=0.5;
if (zoomFactor<=0.5)
zoomFactor=0.5;
outMsg(true);
break;
case 27:
exit(0);
break;
}
}
int main(int argc, char **argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
glutInitWindowSize(250,250);
glutInitWindowPosition(100,100);
glutCreateWindow("Drawing, Copying and Zooming Pixel Data");
init();
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutKeyboardFunc(keyboard);
glutMotionFunc(motion);
glutMainLoop();
return 0;
}

8.2.3
.
() ,
,
(). ,
.

8.2.3.1

8-13
.
8-13. glDrawPixels()

1. (
GL_COLOR_INDEX GL_STENCIL_INDEX),
,
.
2. GL_LUMINANCE GL_LUMINANCE_ALPHA,
R, G B
R, G B . GL_LUMINANCE_ALPHA
A. GL_LUMINANCE
1.0.
3. (R, G, B , A )
, . ,
R GL_RED_SCALE
GL_RED_BIAS.
4. GL_MAP_COLOR TRUE, R, G, B
[0.0, 1.0],
,
.
5. R, G, B A [0.0, 1.0] (
)

(
).
6. (
),
( ). ,
, ,
0.

GL_INDEX_SHIFT. , GL_INDEX_SHIFT > 0
, GL_INDEX_SHIFT < 0. ,
GL_INDEX_OFFSET.
7. ,
RGBA . RGBA
RGBA GL_PIXEL_MAP_I_TO_R,
GL_PIXEL_MAP_I_TO_G, GL_PIXEL_MAP_I_TO_B GL_PIXEL_MAP_I_TO_A. ,
GL_MAP_COLOR GL_TRUE,
GL_PIXEL_MAP_I_TO_I ( GL_MAP_COLOR GL_FALSE
). ,
, GL_MAP_STENCIL GL_TRUE,
GL_PIXEL_MAP_S_TO_S. GL_MAP_STENCIL FALSE
.
8. , RGBA,
.

8.2.3.2

,
, .
8-14
.
8-14. glReadPixels()

1. (
GL_COLOR_INDEX GL_STENCIL_INDEX),
[0.0, 1.0].
2. , . GL_MAP_COLOR
GL_TRUE,
[0.0, 1.0].
, (L=R+G+B).
3. ( ),
, , GL_MAP_COLOR TRUE,
.
4. GL_COLOR_INDEX GL_STENCIL_INDEX,
(1, 8, 16 32)
.
5. (
RGB), -RGBA. , RGBA
( ).
6. , ,
GL_PACK* glPixelStore*().
, , ,
, ,
.
, ,
, .
: ,
, . , R, G B
, 8-13 8-14.
, , R, G B 30, 59
11 , GL_RED_SCALE .30, GL_GREEN_SCALE .59,
GL_BLUE_SCALE .11. L .30R+.59G+.11B.

8.2.4

, OpenGL ,
. ,
, .
.
, ,
,
(1.0, 1.0).

.
.
,
,
.
,
, ,
OpenGL. , ,
RGB 8 , glDrawPixels()
format, GL_RGB, type, GL_UNSIGNED_BYTE.

.
,
,
.

, ,
. ,
( GL_UNSIGNED_BYTE) (
, GL_LUMINANCE_ALPHA).
, ,
, , , ,
, .

8.2.5
,
, ,
:





,

,
,

.

,
, ,
glPixelTransfer*() glPixelMap*().
(ImagingSubset)
OpenGL. GL_ARB_imaging,
, ,
. ,
.
, OpenGL ,
. ,
, :

, : glReadPixels(), glDrawPixels(),
glCopyPixels()
, : glTexImage1D(),glTexImage2D(),
glCopyTextureImage*D(), glSubTexImage1D(), glSubTexImage2D(),
glCopySubTexImage().

8-15 ,
, , OpenGL .

( , ).
8-15.

: , OpenGL
gl.h,
, ,
OpenGL.
,
glext.h (
http://www.opengl.org/).
.
Windows, , wglGetProcAddress().
.

8.2.5.1

.
,
.
.
. 8-7 ,
.
8-7.

GL_COLOR_TABLE

GL_POST_CONVOLUTION_COLOR_TABLE

GL_POST_COLOR_MATRIX_COLOR_TABLE

glEnable()
8-7.

8.2.5.1.1

, .
8-15, 3
, glColorTable().
void glColorTable (GLenum target, GLenum internalFormat, GLsizei width, GLenum
format, GLenum type, const GLvoid *data);

target GL_COLOR_TABLE, GL_POST_CONVOLUTION_COLOR_TABLE


GL_POST_COLOR_MATRIX_COLOR_TABLE,
, GL_PROXY_COLOR_TABLE,
GL_PROXY_POST_CONVOLUTION_COLOR_TABLE GL_
PROXY_POST_COLOR_MATRIX_COLOR_TABLE ,
. internalFormat
, OpenGL.
GL_ALPHA, GL_ALPHA4, GL_ALPHA8,
GL_ALPHA12, GL_ALPHA16, GL_LUMINANCE, GL_LUMINANCE4, GL_LUMINANCE8,
GL_LUMINANCE12, GL_LUMINANCE16, GL_LUMINANCE_ALPHA, GL_LUMINANCE4_ALPHA4,
GL_LUMINANCE6_ALPHA2, GL_LUMINANCE_8ALPHA8, GL_LUMINANCE12_ALPHA4,
GL_LUMINANCE12_ALPHA12, GL_LUMINANCE16_ALPHA16, GL_INTENSITY,
GL_INTENSITY4, GL_INTENSITY8, GL_INTENSITY12, GL_INTENSITY16, GL_RGB,
GL_R3_G3_B2, GL_RGB4, GL_RGB5, GL_RGB8, GL_RGB10, GL_RGB12, GL_RGB16,
GL_RGBA, GL_RGBA2, GL_RGBA4, GL_RGB5_A1, GL_RGBA8, GL_RGB10_A2, GL_RGBA12,
GL_RGBA16. width, 2,
. format type
. ,
glDrawPixels().
,
. , GL_RGB , ,

. 8-8
,
.
8-8

GL_ALPHA

GL_LUMINANCE

GL_LUMINANCE_ALPHA
GL_INTENSITY
GL_RGB

GL_RGBA

8-8

, .

, , ,
.
,
, , [0; 1].

GL_COLOR_TABLE_SCALE GL_COLOR_TABLE_BIAS
glColorTableParameter*().
void glColorTableParameter{if}v (GLenum target, GLenum pname, TYPE *param);

GL_COLOR_TABLE_SCALE GL_COLOR_TABLE_BIAS
. target GL_COLOR_TABLE,
GL_POST_CONVOLUTION_COLOR_TABLE GL_POST_COLOR_MATRIX_COLOR_TABLE
, .
pnamee GL_COLOR_TABLE_SCALE GL_COLOR_TABLE_BIAS.
param 4- , ,
, , , .
8-5 ,
. ,
.
8-16.
8-16. () ,
())

8-5. : colortable.cpp
#include <glut.h>
#include <GL/glaux.h>
#include "glext.h"
//
AUX_RGBImageRec *image;
// (EXTENSION)
typedef void (APIENTRY * GLCOLORTABLE)
(GLenum target,GLenum internalFormat,GLsizei width,
GLenum format, GLenum type, const GLvoid *data);
GLCOLORTABLE glColorTable=NULL;
void init()
{
int i;
GLubyte colorTable[256][3];
// 24- BMP

//( GLAUX)
image=auxDIBImageLoad("peak.bmp");
//
// OpenGL
Windows
glColorTable=(GLCOLORTABLE)wglGetProcAddress("glColorTable");
if (glColorTable==NULL)
{
MessageBox(NULL, "Function [glColorTable] from
[GL_ARB_imaging] extension not supported!",
"Pixel Replacement Using Color Tables",
MB_OK|MB_ICONSTOP);
exit(1);
}
glPixelStorei(GL_UNPACK_ALIGNMENT,1);
glClearColor(0,0,0,0);
//
for(i=0;i<256;++i)
{
colorTable[i][0]=255-i;
colorTable[i][1]=255-i;
colorTable[i][2]=255-i;
}
glColorTable(GL_COLOR_TABLE,GL_RGB,256,
GL_RGB,GL_UNSIGNED_BYTE,colorTable);
glEnable(GL_COLOR_TABLE);
}
void deinit()
{
//
delete image;
}
void reshape(int w, int h)
{
glViewport(0,0,(GLsizei) w, (GLsizei) h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0,500,0,500);
}
void display()
{
glClear(GL_COLOR_BUFFER_BIT);
glRasterPos2i(1,1);
glDrawPixels(image->sizeX, image->sizeY,
GL_RGB,GL_UNSIGNED_BYTE,image->data);
glFlush();
}
int APIENTRY WinMain(HINSTANCE
HINSTANCE
LPSTR
int
{
char* argv="";
int argc=0;

hInstance,
hPrevInstance,
lpCmdLine,
nCmdShow)

glutInit(&argc,&argv);
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
glutInitWindowSize(540,405);
glutCreateWindow("Pixel Replacement Using Color Tables");
init();
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutMainLoop();
deinit();
return 0;
}
: ,
, , GLUT
, auxDIBImageLoad()
GLAUX Windows.
,
, ,
. glCopyColorTable()
,
.
void glCopyColorTable (GLenum target, GLenum internalFormat, GLint x, GLint y,
GLsizei width);

,
.
(GL_READ_BUFFER) glCopyPixels(),
. , ,
glPixelTransfer*(). target internalFormat ,
glColorTable(). width ,
(x, y) .

8.2.5.1.2

,
glColorSubTable() glCopyColorSubTable().
void glColorSubTable (GLenum target, GLsizei start, GLsizei count, GLenum format,
GLenum type, const GLvoid *data);

[start;start+count-1] ,
data. target GL_COLOR_TABLE,
GL_POST_CONVOLUTION_COLOR_TABLE, GL_POST_COLOR_MATRIX_COLOR_TABLE.
format type glColorTable().
void glCopyColorSubTable (GLenum target, GLsizei start, GLint x, GLint y, GLsizei
count);

[start;start+count-1] count
, (x; y).
internalFormat .

8.2.5.1.3

, ,
glGetColorTable().

8.2.5.1.4

OpenGL ,
. glColorTable()
:

GL_PROXY_COLOR_TABLE
GL_PROXY_POST_CONVOLUTION_COLOR_TABLE
GL_PROXY_POST_COLOR_MATRIX_COLOR_TABLE

OpenGL , .
, width, format type 0.
, . ,
:
glColorTable(GL_PROXY_COLOR_TABLE, GL_RGB, 1024,
GL_RGB, GL_UNSIGNED_BYTE, NULL);
glGetColorTableParameteriv(GL_PROXY_COLOR_TABLE,
GL_COLOR_TABLE_WIDTH, &width);
if(width==0)
/* */

8.2.5.2

(convolutions) ,

. ,
.
8-18 ,

3x3
8-17.

, RGBA
. , kernel,
.

. , 8-17

9- 9
.
void glConvolutionFilter2D (GLenum target,GLenum internalFormat,GLsizei
width,GLsizei height,
GLenum format,GLenum type,const GLvoid *image);

. filter GL_CONVOLUTION_3D.
internalFormat ,
38 ,
internalFormat glColorTable(). width height

.
glGetConvolutionParameter*().
glDrawPixels(), format type ,
, image.
, ,
. 8-9 ,
.
.
GL_LUMINANCE,
,


-- GL_INTENSITY. ,

, , .

8-9. RGBA

GL_ALPHA

GL_LUMINANCE

GL_LUMINANCE_ALPHA
GL_INTENSITY
GL_RGB

GL_RGBA

2D , glEnable
(GL_CONVOLUTION_2D).
8-6 2D GL_LUMINANCE
3x3 RGB. h, v l
.
8-18 (
).
, , ,
, ,
, .
8-18.

8-6. : convolution.cpp
#include
#include
#include
#include

<windows.h>
<glut.h>
<GL/glaux.h>
"glext.h"

// ,
AUX_RGBImageRec *image;
//
GLfloat horizontal[3][3]={{0,-1,0},{0,1,0},{0,0,0}};
GLfloat vertical[3][3]= {{0,0,0},{-1,1,0},{0,0,0}};
GLfloat laplacian[3][3]= {{-0.125,-0.125,-0.125},
{-0.125,1,-0.125},
{-0.125,-0.125,-0.125}};
// (
)
typedef void (APIENTRY * GLCONVOLUTIONFILTER2D)
(GLenum target,GLenum internalFormat,GLsizei width,
GLsizei height,GLenum format, GLenum type, const GLvoid
*data);
GLCONVOLUTIONFILTER2D glConvolutionFilter2D=NULL;
void init()
{
//, GL_ARB_imaging (imaging
subset)
if (glutExtensionSupported("GL_ARB_imaging")==0)

{
MessageBox(NULL,"ARB_imaging extension not supported",
"Using Two-Dimensional Convolution
Filters",MB_OK|MB_ICONHAND);
exit(1);
}
//
glConvolutionFilter2D=(GLCONVOLUTIONFILTER2D)
wglGetProcAddress("glConvolutionFilter2D");
// BMP
image=auxDIBImageLoad("peak.bmp");
glPixelStorei(GL_UNPACK_ALIGNMENT,1);
glClearColor(0,0,0,0);
}
void deinit()
{
//
delete image;
}
void keyboard(unsigned char key, int x, int y)
{
switch(key)
{
case 'h':
MessageBox(NULL,"Using horizontal filter",
"Using Two-Dimensional Convolution
Filters",MB_OK);
glConvolutionFilter2D(GL_CONVOLUTION_2D,GL_LUMINANCE,3,3,
GL_LUMINANCE,GL_FLOAT,horizontal);
glEnable(GL_CONVOLUTION_2D);
break;
case 'v':
MessageBox(NULL,"Using vertical filter",
"Using Two-Dimensional Convolution
Filters",MB_OK);
glConvolutionFilter2D(GL_CONVOLUTION_2D,GL_LUMINANCE,3,3,
GL_LUMINANCE,GL_FLOAT,vertical);
glEnable(GL_CONVOLUTION_2D);
break;
case 'l':
MessageBox(NULL,"Using laplacian filter",
"Using Two-Dimensional Convolution
Filters",MB_OK);
glConvolutionFilter2D(GL_CONVOLUTION_2D,GL_LUMINANCE,3,3,
GL_LUMINANCE,GL_FLOAT,laplacian);
glEnable(GL_CONVOLUTION_2D);
break;
case 'r':
MessageBox(NULL,"No filter used",
"Using Two-Dimensional Convolution
Filters",MB_OK);
glDisable(GL_CONVOLUTION_2D);

break;
case 27:
exit(0);
}
glutPostRedisplay();
}
void reshape(int w, int h)
{
glViewport(0,0,(GLsizei) w, (GLsizei) h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0,540,0,405);
}
void display()
{
glClear(GL_COLOR_BUFFER_BIT);
glRasterPos2i(1,1);
glDrawPixels(image->sizeX,image->sizeY,GL_RGB,
GL_UNSIGNED_BYTE,image->data);
glFlush();
}
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR
lpCmdLine,
int
nCmdShow)
{
char* argv="";
int argc=0;
glutInit(&argc,&argv);
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
glutInitWindowSize(540,405);
glutCreateWindow("Using Two-Dimensional Convolution Filters");
init();
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutKeyboardFunc(keyboard);
glutMainLoop();
deinit();
return 0;
}
,
, . glCopyConvolutionFilter2D()
(GL_READ_BUFFER)
.
GL_LUMINANCE GL_INTENSITY,
.
void glCopyConvolutionFilter2D (GLenum target, GLenum internalFormat, GLint x,
GLint y, GLsizei width, GLsizei height);

, .
target GL_CONVOLUTION_2D, internalFormat
, glConvolutionFilter2D().
(x; y) width
height internalFormat.

8.2.5.2.1

,
.
,
, glSeparableFilter2D().
glConvolutionFilter2D() ,
.
void glSeparableFilter2D (GLenum target, GLenum internalFormat, GLsizei width,
GLsizei height,
GLenum format, GLenum type, const GLvoid *row, const
GLvoid *column);

. target
GL_SEPARABLE_2D. internalFormat ,
glConvolutionFilter2D(). width
row. height column. type
format glConvolutionFilter2D()
row column.
,
glEnable(GL_SEPARABLE_2D). ,
:
GL_CONVOLUTION_2D GL_SEPARABLE_2D.
, 3x3, [-1/2, 1, -1/2]
row, column GL_LUMINANCE. OpenGL
,
,
:

.

, .

8.2.5.2.2

,
1.
.
void glConvolutionFilter1D (GLenum target, GLenum internalFormat, GLsizei width,
GLenum format, GLenum type, const GLvoid *image);

. target
GL_CONVOLUTION_1D. width .
internalFormat, type format ,
glConvolutionFilter2D(). image ,
.

glEnablee(GL_CONVOLUTION_1D).

, ,
. glCopyConvolutionFilterr1D()
(GL_READ_BUFFER),
.
void glCopyConvolutionFilter1D (GLenum target, GLenum internalFormat, GLint x,
GLint y, GLsizei width);

.
glCopyConvolutionFilter1D() width , (x, y)
internalFormat.
, .
glConvolutionParameter*().
- .
void glConvolutionParameter{if} (GLenum target, GLenum pname, TYPE param);
void glConvolutionParameter{if}v (GLenum target, GLenum pname, TYPE *params);

, , .
target GL_CONVOLUTION_1D, GL_CONVOLUTION_2D
GL_SEPARABLE_2D. pname
GL_CONVOLUTION_BORDER_MODE, GL_CONVOLUTION_FILTER_SCALE
GL_CONVOLUTION_FILTER_BIAS. pname
GL_CONVOLUTION_BORDER_MODE .
params GL_REDUCE, GL_CONSTANT_BORDER
GL_REPLICATE_BORDER. pname GL_CONVOLUTION_FILTER_SCALE
GL_CONVOLUTION_FILTER_BIAS, params 4-
, , , .

8.2.5.2.3

, ,
, .
.
:

GL_REDUCE ,
. (width-1).
(height-1).
, ,
, .
GL_CONSTANT_BORDER

.
glConvolutionParameter*().
.
GL_REPLICATE_BORDER
GL_CONSTANT_BORDER ,
, .
.

8.2.5.2.4

, ,
. [0; 1].
glPixelTransfer*(),

GL_POST_CONVOLUTION_*_SCALE GL_POST_CONVOLUTION_*_BIAS.
glColorTable()
GL_POST_CONVOLUTION_COLOR_TABLE,
.

8.2.5.3


, 4x4,
glMatrixMode(GL_COLOR). ,
RGB CMY (cyan , magenta
, yellow ) :
GLfloat rgb2cmy[16]= {-1,0,0,0,
0,-1,0,0,
0,0,-1,0,
1,1,1,1};
glMatrixMode(GL_COLOR);
glLoadMatrixf(rgb2cmy);
glMatrixMode(GL_MODELVIEW);

//
//

: , OpenGL .

.

.
8-7
.
8-19. ,
.
8-19. ,
R G

8-7. :
colormatrix.cpp
#include <windows.h>
#include <glut.h>

#include <glaux.h>
#include "glext.h"
// ,
AUX_RGBImageRec *image;
//
// RGB GBR
GLfloat m[16]={
0.0,1.0,0.0,0.0,
0.0,0.0,1.0,0.0,
1.0,0.0,0.0,0.0,
0.0,0.0,0.0,1.0
};
// ,
bool reversing;
void init()
{
//, GL_ARB_imaging (imaging
subset)
if (glutExtensionSupported("GL_ARB_imaging")==0)
{
MessageBox(NULL,"ARB_imaging extension not supported",
"Using Color Matrix",MB_OK|MB_ICONHAND);
exit(1);
}
// BMP
image=auxDIBImageLoad("tree.bmp");
glPixelStorei(GL_UNPACK_ALIGNMENT,1);
glClearColor(0,0,0,0);
reversing=false;
}
void deinit()
{
//
delete image;
}
void reshape(int w, int h)
{
glViewport(0,0,(GLsizei) w, (GLsizei) h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0,542,0,407);
}
void keyboard(unsigned char key,int x,int y)
{
switch(key)
{
case 'r':
if (!reversing)
{
//
// GL_COLOR
//
//
glMatrixMode(GL_COLOR);

glLoadMatrixf(m);
glMatrixMode(GL_MODELVIEW);
}
else
{
glMatrixMode(GL_COLOR);
glLoadIdentity();
glMatrixMode(GL_MODELVIEW);
}
reversing=!reversing;
glutPostRedisplay();
break;
case 27:
exit(0);
break;
}
}
void display()
{
glClear(GL_COLOR_BUFFER_BIT);
glRasterPos2i(1,1);
glDrawPixels(image->sizeX,image->sizeY,GL_RGB,
GL_UNSIGNED_BYTE,image->data);
glFlush();
}
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR
lpCmdLine,
int
nCmdShow)
{
char* argv="";
int argc=0;
glutInit(&argc,&argv);
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
glutInitWindowSize(542,407);
glutCreateWindow("Exchanging Color Components Using the Color
Matrix");
init();
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutKeyboardFunc(keyboard);
glutMainLoop();
deinit();
return 0;
}

8.2.5.3.1

,
.
glPixelTransfer*() GL_POST_COLOR_MATRIX_*_SCALE
GL_POST_COLOR_MATRIX_*_BIAS
.
[0; 1].

8.2.5.4

,
.

, , ,
.
glHistogram() ,
, ,
.
, glEnable(GL_HISTOGRAMM).
, ,
,
. , ,
0. ,
glHistogramParameter().
void glHistogram (GLenum target, GLsizei width, GLenum internalFormat, GLboolean
sink);

, . target
GL_HISTOGRAM
GL_PROXY_HISTOGRAM. width
. 2. internalFormat
, .
: GL_ALPHA, GL_ALPHA4, GL_ALPHA8, GL_ALPHA12, GL_ALPHA16,
GL_LUMINANCE, GL_LUMINANCE4, GL_LUMINANCE8, GL_LUMINANCE12,
GL_LUMINANCE16, GL_LUMINANCE_ALPHA, GL_LUMINANCE4_ALPHA4,
GL_LUMINANCE6_ALPHA2, GL_LUMINANCE_8ALPHA8, GL_LUMINANCE12_ALPHA4,
GL_LUMINANCE12_ALPHA12, GL_LUMINANCE16_ALPHA16, GL_RGB, GL_RGB2, GL_RGB4,
GL_RGB5, GL_RGB8, GL_RGB10, GL_RGB12, GL_RGB16, GL_RGBA, GL_RGBA2, GL_RGBA4,
GL_RGB5_A1, GL_RGBA8, GL_RGB10_A2, GL_RGBA12, GL_RGBA16.
GL_INTENSITY*.
glColorTable(). sink ,
/ ..
, glDrawPixels(),
, glGetHistogram().
, glGetHistogram()
.
glResetHistogram().
void glGetHistogram (GLenum target, GLboolean reset, GLenum format, GLenum type,
GLvoid *values);

. target
GL_HISTOGRAM. reset,
. format type
values ,
. ,
glDrawPixels().
8-8
. s
sink,
. 8-20
(),
().
8-20.

8-8. : histogram.cpp
#include
#include
#include
#include

<windows.h>
<glut.h>
<glaux.h>
"glext.h"

#define HISTOGRAM_SIZE 256


GLboolean sink=GL_FALSE;
// ,
AUX_RGBImageRec *image;
//

typedef void (APIENTRY * GLHISTOGRAM)
(GLenum target,GLsizei width,
GLenum internalFormat, GLboolean sink);
GLHISTOGRAM glHistogram=NULL;
//
typedef void (APIENTRY * GLGETHISTOGRAM)
(GLenum target,GLboolean reset, GLenum format,
GLenum type, const GLvoid *values);
GLGETHISTOGRAM glGetHistogram=NULL;
void init()
{
//, GL_ARB_imaging (imaging
subset)
if (glutExtensionSupported("GL_ARB_imaging")==0)
{
MessageBox(NULL,"ARB_imaging extension not supported",
" Compute and Diagram an Image's Histogram ",
MB_OK|MB_ICONHAND);
exit(1);
}
//
glHistogram=(GLHISTOGRAM)wglGetProcAddress("glHistogram");
glGetHistogram=(GLGETHISTOGRAM)wglGetProcAddress("glGetHistogram");
// BMP
image=auxDIBImageLoad("pyr.bmp");

glPixelStorei(GL_UNPACK_ALIGNMENT,1);
glClearColor(0,0,0,0);
glHistogram(GL_HISTOGRAM,HISTOGRAM_SIZE,GL_RGB,sink);
glEnable(GL_HISTOGRAM);
}
void deinit()
{
//
delete image;
}
void keyboard(unsigned char key, int x, int y)
{
switch(key)
{
case 's':
sink=!sink;
glHistogram(GL_HISTOGRAM,HISTOGRAM_SIZE,GL_RGB,sink);
glutPostRedisplay();
break;
case 27:
deinit();
exit(0);
break;
}
}
void reshape(int w, int h)
{
glViewport(0,0,(GLsizei) w, (GLsizei) h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0,540,0,405);
}
void display()
{
int i;
GLushort values[HISTOGRAM_SIZE][3];
glClear(GL_COLOR_BUFFER_BIT);
glRasterPos2i(1,1);
glDrawPixels(image->sizeX,image->sizeY,GL_RGB,
GL_UNSIGNED_BYTE,image->data);
glGetHistogram(GL_HISTOGRAM,GL_TRUE,GL_RGB,GL_UNSIGNED_SHORT,values);
//Plot histogram
glBegin(GL_LINE_STRIP);
glColor3f(1.0,0.0,0.0);
for(i=0;i<HISTOGRAM_SIZE;i++)
glVertex2s(i,values[i][0]);
glEnd();
glBegin(GL_LINE_STRIP);
glColor3f(0.0,1.0,0.0);
for(i=0;i<HISTOGRAM_SIZE;i++)
glVertex2s(i,values[i][1]);
glEnd();
glBegin(GL_LINE_STRIP);
glColor3f(0.0,0.0,1.0);

for(i=0;i<HISTOGRAM_SIZE;i++)
glVertex2s(i,values[i][2]);
glEnd();
glFlush();
}

int APIENTRY WinMain(HINSTANCE hInstance,


HINSTANCE hPrevInstance,
LPSTR
lpCmdLine,
int
nCmdShow)
{
char* argv="";
int argc=0;
glutInit(&argc,&argv);
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
glutInitWindowSize(540,405);
glutCreateWindow("Compute and Diagram an Image's Histogram");
init();
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutKeyboardFunc(keyboard);
glutMainLoop();
deinit();
return 0;
}
glResetHistogram() .
void glResetHistogram (GLenum target);

0. target
GL_HISTOGRAM.

8.2.5.5

glMinmax()
. glHistogram()

, .
void glMinmax (GLenum target, GLenum internalFormat, GLboolean sink);

.
target GL_MINMAX. internalFormat
.
internalFormat glMinmax() ,
glHistogram(). sink GL_TRUE,
,
.
glGetMinmax().
glGetHistogram()
.
void glGetMinmax (GLenum target, GLboolean reset, GLenum format, GLenum type,
GLvoid *values);

. target
GL_MINMAX. reset GL_TRUE,
. format
type values
, glDrawPixels().
8-9 glMinMax()
GL_RGB.

8-21.
glEnable(GL_MINMAX).
, glGetMinmax()
,
.
8-21.

8-9. :
minmax.cpp
#include
#include
#include
#include
#include

<windows.h>
<glut.h>
<glaux.h>
<stdio.h>
"glext.h"

// ,
AUX_RGBImageRec *image;

typedef void (APIENTRY * GLMINMAX) GLenum target, GLenum


internalFormat, GLboolean sink);
GLMINMAX glMinmax=NULL;
typedef void (APIENTRY * GLGETMINMAX) GLenum target,GLboolean reset,
GLenum format,GLenum type, const GLvoid *values);
GLGETMINMAX glGetMinmax=NULL;
void init()
{
//, GL_ARB_imaging (imaging
subset)
if (glutExtensionSupported("GL_ARB_imaging")==0)
exit(1);
glMinmax=(GLMINMAX)wglGetProcAddress("glMinmax");
glGetMinmax=(GLGETMINMAX)wglGetProcAddress("glGetMinmax");
// BMP
image=auxDIBImageLoad("tree.bmp");
glPixelStorei(GL_UNPACK_ALIGNMENT,1);
glClearColor(0,0,0,0);
glMinmax(GL_MINMAX,GL_RGB,GL_FALSE);
glEnable(GL_MINMAX);
}
void deinit()
{
//
delete image;
}
void reshape(int w, int h)
{
glViewport(0,0,(GLsizei) w, (GLsizei) h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0,540,0,405);
}
void display()
{
GLubyte values[6];
glClear(GL_COLOR_BUFFER_BIT);
glRasterPos2i(1,1);
glDrawPixels(image->sizeX,image->sizeY,
GL_RGB,GL_UNSIGNED_BYTE,image->data);
glGetMinmax(GL_MINMAX,GL_TRUE,GL_RGB,GL_UNSIGNED_BYTE,values);
glFlush();
printf("Red : min = %d max = %d\n",values[0],values[3]);
printf("Green: min = %d max = %d\n",values[1],values[4]);
printf("Blue : min = %d max = %d\n",values[3],values[5]);
}
int main(int argc,char* argv[])
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
glutInitWindowSize(540,405);
glutCreateWindow("Computing Minimum and Maximum Pixel Values");
init();
glutDisplayFunc(display);
glutReshapeFunc(reshape);

glutMainLoop();
deinit();
return 0;
}
, glGetMinmax()
,
glResetMinmax().
void glResetMinmax (GLenum target);

.
target GL_MINMAX.

8.2.5.6


, .
,
. glBlendEquation()
, ,
.
void glBlendEquation (GLenum mode);

.
mode GL_FUNC_ADD, GL_FUNC_SUBTRACT,
GL_FUNC_REVERSE, GL_MIN GL_MAX. mode
GL_FUNC_ADD (), , ,
.
8-10.
8-10

, S
D ,
glBlendFunc().
8-10. ,

GL_FUNC_ADD
GL_FUNC_SUBTRACT
GL_FUNC_REVERSE_SUBTRACT
GL_MIN
GL_MAX

8-10 .
a, s, r, m, x.
, .
GL_ONE glBlendFunc().
8-22.

8-22.

8-10. : blendeqn.cpp
/*
*
*
*
*
*/

'a'
's'
'r'
'm'
'x'

->
->
->
->
->

GL_FUNC_ADD
GL_FUNC_SUBTRACT
GL_FUNC_REVERSE_SUBTRACT
GL_MIN
GL_MAX

#include <glut.h>
#include "glext.h"
//
typedef void (APIENTRY * GLBLENDEQUATION) (GLenum mode);
GLBLENDEQUATION glBlendEquation=NULL;
void init()
{
//, GL_ARB_imaging (imaging
subset)
if (glutExtensionSupported("GL_ARB_imaging")==0)
{
exit(1);
}
//
glBlendEquation=(GLBLENDEQUATION)wglGetProcAddress("glBlendEquation");
glClearColor(1.0,1.0,0.0,0.0);
glBlendFunc(GL_ONE,GL_ONE);
glEnable(GL_BLEND);
}
void keyboard(unsigned char key, int x, int y)
{
switch(key)
{
case 'a': case 'A':
glBlendEquation(GL_FUNC_ADD);
break;
case 's': case 'S':
glBlendEquation(GL_FUNC_SUBTRACT);
break;
case 'r': case 'R':
glBlendEquation(GL_FUNC_REVERSE_SUBTRACT);
break;
case 'm': case 'M':
glBlendEquation(GL_MIN);
break;
case 'x': case 'X':

glBlendEquation(GL_MAX);
break;
case 27:
exit(0);
}
glutPostRedisplay();
}
void reshape(int w, int h)
{
glViewport(0,0,(GLsizei) w, (GLsizei) h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(-1,1,-1,1);
}
void display()
{
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(0.0,0.0,1.0);
glRectf(-0.5,-0.5,0.5,0.5);
glFlush();
}
int main (int argc, char **argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
glutInitWindowSize(500,500);
glutCreateWindow("Demonstrating The Blend Equation Modes");
init();
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutKeyboardFunc(keyboard);
glutMainLoop();
return 0;
}

8.2.5.7


, glBlendFunc().
8-11.
8-11. ,

GL_CONSTANT_COLOR

GL_ONE_MINUS_CONSTANT_COLOR

GL_CONSTANT_ALPHA

GL_ONE_MINUS_CONSTANT_ALPHA

9.
,
(
) .
,
.
, ,
,
.
( )
(, , )
.
,
. ,
, , ,
, .
, ;
, , ,
.
, , , ,
.
,
,
. ,
,
. ,
, ,
, (
).
, .
,
.
, .
,
.
, , ,
. ()
(texels). , ,
,
- .
9-1 .
, ,
.
, ,
, . ,
. (,

OpenGL.)
9-1.

, ,
. x
y. ,
.
,
. (
256x256),
. ,
, , ,
,
. - --
,
.
,
(, , (mipmaps)).
OpenGL (workingset) ,
, . ,
(resident) /
. OpenGL ,
, .
OpenGL 1.1:

.
, ,
.
(subtextures),
.
.
( )
, .

1.2 , :

3D .
GL_CLAMP_TO_EDGE,
, .
,
(levels-of-details -- LOD).
( ) .

1.2 (
ARB) , :

,
.


, OpenGL, ,
.

9.1
,
. ,
.

9.1.1

, :
1.
2.
3.
4.


,

,

, RGBA .
.

9.1.1.1

, , ,
, . ,
, ,
, (R, G, B, A).
9-1 ,
. ,
. ,
(
). ,
, .

9.1.1.2 ,

4 RGBA
.
(
replace; )
( 9-1.)
(modulate)
;
. ,
.

9.1.1.3

, , .
glEnable()
glDisable() GL_TEXTURE_1D, GL_TEXTURE_2D
GL_TEXTURE_3D ,
. (
, .
.)

9.1.1.4 , ,

,
, .
, ,
. , ,
[0; 1] ,
. , ,
,
. , ,
(0,0) (1, 0) (1, 1) (1, 1) .
, , , .
, ,
,
.
,
[0; 1]. , ,
.

9.1.2

, , ,
, , . ,
,
. 9-1 ,
, , .
, ,
, 45
, 9-2.
.
9-2.

9-1. : checker.cpp
#include <glut.h>
//
#define checkImageWidth 64
#define checkImageHeight 64
GLubyte checkImage[checkImageHeight][checkImageWidth][4];
GLuint texName;
void makeCheckImage()
{
int i,j,c;
for (i=0;i<checkImageHeight;i++)
{
for (j=0;j<checkImageWidth;j++)
{
c=(((i&0x8)==0)^((j&0x8)==0))*255;
checkImage[i][j][0]=(GLubyte)c;
checkImage[i][j][1]=(GLubyte)c;
checkImage[i][j][2]=(GLubyte)c;
checkImage[i][j][3]=(GLubyte)255;
}
}
}
void init(void)
{
glClearColor(0.0,0.0,0.0,0.0);
glShadeModel(GL_FLAT);
glEnable(GL_DEPTH_TEST);
makeCheckImage();
glPixelStorei(GL_UNPACK_ALIGNMENT,1);
glGenTextures(1,&texName);
glBindTexture(GL_TEXTURE_2D,texName);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST);
glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA,checkImageWidth,checkImageHeight,
0,GL_RGBA,GL_UNSIGNED_BYTE,checkImage);
}
void display(void)
{
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glEnable(GL_TEXTURE_2D);
glTexEnvf(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_REPLACE);
glBindTexture(GL_TEXTURE_2D,texName);
glBegin(GL_QUADS);
glTexCoord2f(0.0,0.0);
glTexCoord2f(0.0,1.0);
glTexCoord2f(1.0,1.0);
glTexCoord2f(1.0,0.0);

glVertex3f(-2.0,-1.0,0.0);
glVertex3f(-2.0,1.0,0.0);
glVertex3f(0.0,1.0,0.0);
glVertex3f(0.0,-1.0,0.0);

glTexCoord2f(0.0,0.0); glVertex3f(1.0,-1.0,0.0);
glTexCoord2f(0.0,1.0); glVertex3f(1.0,1.0,0.0);

glTexCoord2f(1.0,1.0); glVertex3f(2.41421,1.0,-1.41421);
glTexCoord2f(1.0,0.0); glVertex3f(2.41421,-1.0,-1.41421);
glEnd();
glFlush();
glDisable(GL_TEXTURE_2D);
}
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,30.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(0.0,0.0,-3.6);
}
int main(int argc, char ** argv)
{
glutInit(&argc,&argv);
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB|GLUT_DEPTH);
glutInitWindowSize(250,250);
glutCreateWindow("Texture-Mapped Checkerboard");
init();
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutMainLoop();
return 0;
}
makeCheckImage(),
init().
glGenTextures() glBindTexture()
.
glTexImage2D(), , ,
.
glTexParameter*() ,
, ,
.
display() glEnable() .
glTexEnv*() GL_REPLACE,
(
, ).
. ,
. glTexCoord*() glNormal*().
glTexCoord*() ;
glVertex*() glTexCoord*()
.
: ,
. ,
4
. , glHint()
GL_PERSPECTIVE_CORRECTION_HINT GL_NICEST.

9.2
glTexImage2D() .
,
.
glTexImage1D() glTexImage3D() .
void glTexImage2D (GLenum target, GLint level, GLint internalFormat, GLsizei
width, GLsizei height,
GLint border, GLenum format, GLenum type, const GLvoid
*texels);

. target
GL_TEXTURE_2D GL_PROXY_TEXTURE_2D. level
, ,
, level 0. internalFormat
, R, G, B, A,
. internalFormat
1 4 38 . 38
: GL_ALPHA, GL_ALPHA4, GL_ALPHA8, GL_ALPHA12, GL_ALPHA16,
GL_LUMINANCE, GL_LUMINANCE4, GL_LUMINANCE8, GL_LUMINANCE12,
GL_LUMINANCE16, GL_LUMINANCE_ALPHA, GL_LUMINANCE4_ALPHA4,
GL_LUMINANCE6_ALPHA2, GL_LUMINANCE8_ALPHA8, GL_LUMINANCE12_ALPHA4,
GL_LUMINANCE12_ALPHA12, GL_LUMINANCE16_ALPHA16, GL_INTENSITY,
GL_INTENSITY4, GL_INTENSITY8, GL_INTENSITY12, GL_INTENSITY16, GL_RGB,
GL_R3_G3_B2, GL_RGB4, GL_RGB5, GL_RGB8, GL_RGB10, GL_RGB12, GL_RGB16,
GL_RGBA, GL_RGBA2, GL_RGBA4, GL_RGB5_A1, GL_RGBA8, GL_RGB10_A2, GL_RGBA12,
GL_RGBA16. internalFormat 38 ,
, , ,
. , internalFormat GL_R3_G3_B2, ,
3 , 3 2
, OpenGL , . ,
OpenGL ,
, . .
GL_LUMINANCE, GL_LUMINANCE_ALPHA, GL_RGB GL_RGBA
,
. (- OpenGL 1.0
internalFormat 1, 2, 3 4
GL_LUMINANCE, GL_LUMINANCE_ALPHA, GL_RGB GL_RGBA
.) width height ;
border 0 ( ),
, m
1. width, height
( width height), b
border. OpenGL,
64x64 ( 66x66 ). format type
. ,
glDrawPixels(). ,
, , glDrawPixels(), ,
glPixelStore*() glPixelTransfer*(). ( 9-1
glPixelsStorei(GL_UNPACK_ALIGNMENT,1);

,
.) format GL_COLOR_INDEX,
GL_RGB, GL_RGBA, GL_RED, GL_GREEN, GL_BLUE, GL_ALPHA, GL_LUMINANCE,
GL_LUMINANCE_ALPHA ,
glDrawPixels() GL_STENCIL_INDEX GLL_DEPTH_COMPONENT.
type GL_BYTE,

GL_UNSIGNED_BYTE, GL_SHORT, GL_UNSIGNED_SHORT, GL_INT, GL_UNSIGNED_INT,


GL_FLOAT, GL_BITMAP , .
, texels .
.

. , GL_RGBA
, GL_RGB,
.
, .
,
. , GL_RGB8
32 , GL_R3_G3_B2
8 . ,
.
, ,
- GL_COLOR_INDEX.

RGBA .
OpenGL
- ,
. ,
, (
/ ).

2.
, gluScaleImage()
GLU, .
int gluScaleImage (GLenum format, GLint widthin, GLint heightin, GLenum typein,
const *datain,
GLint widthout, GLint heightout, GLenum typeout, void
*dataout);

,
datain. format, typein typeout
, glDrawPixels().
widthin x heightin widthout x heightout
.
dataout
GL_PACK*.
.
0, GLU.
: GLU 1.3 gluScaleImage()
( ), OpenGL
1.2.

. glCopyTexImage2D()
.
void glCopyTexImage2D (GLenum target, GLint level, GLint internalFormat, GLint x,
GLint y, GLsizei width, GLsizei height, GLint border);

, .
(GL_READ_BUFFER)
, glCopyPixels(),
, .
glPixelTransfer*()
. target
GL_TEXTURE_2D. level, internalFormat border ,
glTexImage2D().
(x, y). width
height . width, height
, m (
width height), b border.
,
target, border level, . target
(
glTexImage*D()), ,
OpenGL.
.
. level
, ,
.

9.2.1
OpenGL, ,
. ,
. ,
, OpenGL
.
glGetIntegerv(GL_MAX_TEXTURE_SIZE, ...);
( ) ( ).
.
GL_MAX_3D_TEXTURE_SIZE
3D (, , ).
GL_MAX_TEXTURE_SIZE, GL_MAX_3D_TEXTURE_SIZE
, .
, GL_RGB16 64
, GL_LUMINANCE4 16 .
( , , ,
.)

OpenGL .
glTexImage2D()
target, GL_PROXY_TEXTURE_2D
level, internalFormat, width, height, border, format type. (
1D 2D .)
texels NULL.
,
,
glGetTexLevelParameter*(). ,
,
0.

void glGetTexLevelParameter{if}v (GLenum target, GLint level, GLenum pname, TYPE


*params);

params
level . target
GL_TEXTURE_1D, GL_TEXTURE_2D, GL_TEXTURE_3D,
GL_PROXY_TEXTURE_1D, GL_PROXY_TEXTURE_2D, GL_PROXY_TEXTURE_3D.
pname : GL_TEXTURE_WIDTH,
GL_TEXTURE_HEIGHT, GL_TEXTURE_DEPTH, GL_TEXTURE_BORDER,
GL_TEXTURE_INTERNAL_FORMAT, GL_TEXTURE_RED_SIZE, GL_TEXTURE_GREEN_SIZE,
GL_TEXTURE_BLUE_SIZE, GL_TEXTURE_ALPHA_SIZE, GL_TEXTURE_LUMANANCE_SIZE,
GL_TEXTURE_INTENSITY_SIZE. pname
GL_TEXTURE_COMPONENTS, -
OpenGL 1.0.
GL_TEXTURE_INTERNAL_FORMAT.
9-2 ,
64 x 64
RGBA 8 . ,
glGetTexLevelParameteriv() (
GL_RGBA8) format.
9-2.
GLint width;
glTexImage2D(GL_PROXY_TEXTURE_2D, 0, GL_RGBA8, 64, 64, 0, GL_RGBA,
GL_UNSIGNED_BYTE, NULL);
glGetTexLevelParameteriv(GL_PROXY_TEXTURE_2D, 0, GL_TEXTURE_WIDTH,
&width);
: :
,
. ,
.
, ,
,
( ,
). , ,
,
.

9.2.2
,
. OpenGL 1.1,

. ,
, , ,
.
glTexSubImage2D()
. ,
glTexSubImage2D()
2. ( ,
2.
, ,
,

.)

void glTexSubImage2D (GLenum target, GLint level, GLint xoffset, GLint yoffset,
GLsizei width, GLsizei height,
GLenum format, GLenum type, const GLvoid *texels);

,
( 2D ) .
target GL_TEXTURE_2D. level,
format type ,
glTexImage2D(). level . width
height 0 ,
. format type .
glPixelStore*(),
glPixelTransfer*() . texels
. width height ,
. xoffset yoffset
x y , ,
.
.
9-3 9-1. s
. (
9-3.) r
. 9-3 makeCheckImages()
keyboard()).
9-3.

9-3. : texsub.cpp
//
#define checkImageWidth 64
#define checkImageHeight 64
#define subImageWidth 16
#define subImageHeight 16
GLubyte checkImage[checkImageHeight][checkImageWidth][4];
GLubyte subImage[subImageHeight][subImageWidth][4];
void makeCheckImages()
{
int i,j,c;
for (i=0;i<checkImageHeight;i++)
{
for (j=0;j<checkImageWidth;j++)
{
c=(((i&0x8)==0)^((j&0x8)==0))*255;
checkImage[i][j][0]=(GLubyte)c;

checkImage[i][j][1]=(GLubyte)c;
checkImage[i][j][2]=(GLubyte)c;
checkImage[i][j][3]=(GLubyte)255;
}
}
for (i=0;i<subImageHeight;i++)
{
for (j=0;j<subImageWidth;j++)
{
c=(((i&0x4)==0)^((j&0x4)==0))*255;
subImage[i][j][0]=(GLubyte)c;
subImage[i][j][1]=(GLubyte)0;
subImage[i][j][2]=(GLubyte)0;
subImage[i][j][3]=(GLubyte)255;
}
}
}
void keyboard(unsigned char key, int x, int y)
{
switch (key)
{
case 's':
case 'S':
glBindTexture(GL_TEXTURE_2D,texName);
glTexSubImage2D(GL_TEXTURE_2D,0,12,44,subImageWidth,subImageHeight,GL_RGBA,GL
_UNSIGNED_BYTE,subImage);
glutPostRedisplay();
break;
case 'r':
case 'R':
glBindTexture(GL_TEXTURE_2D,texName);
glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA,checkImageWidth,checkImageHeight,0,GL_RG
BA,GL_UNSIGNED_BYTE,checkImage);
glutPostRedisplay();
break;
}
}

.
glCopyTexSubImage2D()
. (glCopyTexSubImage2D()
- glCopyTexImage2D() glTexSubImage2D().)
void glCopyTexSubImage2D (GLenum target, GLint level, GLine xoffset, GLint
yoffset, GLint x, GLint y, GLsizei width, GLsizei height);


.
(GL_READ_BUFFER)
glCopyPixels(), ,
.
glPixelStore*(), glPixelTransfer*() .
target GL_TEXTURE_2D. level
. xoffset yoffset
,
, .

(x, y). width height .

9.2.3
,
,
.
1 .
.
, glTexImage1D().
void glTexImage1D (GLenum target, GLint level, GLint internalFormat, GLsizei
width, GLint border,
GLenum format, GLenum type, const GLvoid *texels);

. ,
glTexImage2D() , texels
. width
(
, ), m

. (
target, GL_PROXY_TEXTURE_1D),
.
, ,
9-8.
OpenGL
(GL_CONVOLUTION_1D),
. ( .)
.
,
glTexSubImage1D().
void glTexSubImage1D (GLenum target, GLint level, GLint xoffset, GLsizei width,
GLenum format, GLenum type, const GLvoid *texels);

, (
1D ) .
target GL_TEXTURE_1D. level,
format type , glTexImage1D(). level
. format type
. ,
glPixelsStore*(), glPixelsTransfer*()
. texels
. width ,
. xoffset
, ,
.

,
, glCopyTexImage1D()
glCopyTexSubImage1D() .
void glCopyTexImage1D (GLenum target, GLint level, GLint internalFormat, GLint x,
GLint y, GLsizei width, GLint border);

, .
(GL_READ_BUFFER)
, glCopyPixels(),
, .
glPixelTransfer*()
. target
GL_TEXTURE_1D. level, internalFormat border ,
glCopyTexImage2D().
(x, y). width
(

, ), m .

void glCopyTexSubImage1D (GLenum target, GLint level, GLint xoffset, GLint x,


GLint y, GLsizei width, GLint border);


.
(GL_READ_BUFFER)
glCopyPixels(), ,
.
glPixelStore*(), glPixelTransfer*() .
target GL_TEXTURE_1D. level
. xoffset
, ,
.
(x, y). width .

9.2.4


.
.
, ,
. (
,
volume rendering applications.
voxels, ,
.)
-
. 16
32 , .
1.2
OpenGL. 1.2
OpenGL.
.

.
.
glTexImage3D ().
void glTexImage3D (GLenum target, GLint level, GLint internalFormat, GLsizei
width, GLsizei height,
GLsizei depth, GLint border, GLenum format, GLenum type, const
GLvoid *texels);

. ,
glTexImage2D(), , texels
. , depth. depth

(
, ), m
. (
target, GL_PROXY_TEXTURE_3D),
.
:
,
.
9-4 , .
9-4. : texture3d.cpp
#define iwidth 16
#define iheight 16
#define idepth 16
GLubyte image [idepth][iheight][iwidth][3];
GLuint texName;
// 16x16x16x3,

// [r, g, b] .

// 0 255
void makeImage(void)
{
int s, t, r;
for(s=0;s<16;s++)
for(t=0;t<16;t++)
for(r=0;r<16;r++)
{
image[r][t][s][0]=s*17;
image[r][t][s][1]=t*17;
image[r][t][s][2]=r*17;
}
}
// : 3D
void init(void)
{
glClearColor(0.0,0.0,0.0,0.0);
glShadeModel(GL_FLAT);
glEnable(GL_DEPTH_TEST);
makeImage();
glPixelStorei(GL_UNPACK_ALIGNMENT,1);
glGenTextures(1, &texName);
glBindTexture(GL_TEXTURE_3D,texName);
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_T, GL_CLAMP);
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_R, GL_CLAMP);
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);

glTexImage3D(GL_TEXTURE_3D,0,GL_RGB,iWidth,iHeight,iDepth,
0,GL_RGB,GL_UNSIGNED_BYTE,image);
}
,
glTexSubImage3D().
void glTexSubImage3D (GLenum target, GLint level, GLint xoffset, GLint yoffset,
GLint zoffset,
GLsizei width, GLsizei height, GLsizei depth, GLenum
format,
GLenum type, const GLvoid *texels);

,
. target
GL_TEXTURE_3D. level, format type
, glTexImage3D(). level
. format type .
,
glPixelsStore*(), glPixelsTransfer*() .
texels . width, height
depth . xoffset, yoffset zoffset
,
, , .

, ,
glCopyTexSubImage3D().
void glCopyTexSubImage3D (GLenum target, GLint level, GLint xoffset, GLint
yoffset, GLint zoffset,
GLint x, GLint y, GLsizei width, GLint border);


.
(GL_READ_BUFFER)
glCopyPixels(), ,
.
glPixelStore*(), glPixelTransfer*() .
target GL_TEXTURE_3D. level
.
(x, y). width
height . xoffset, yoffset zoffset
, ,
. ,
(
zoffset).

9.2.4.1


( , ). glPixelStore*()
, *ROW_LENGTH,
*ALIGNMENT, *SKIP_PIXELS *SKIP_ROWS ( * GL_PACK
GL_UNPACK), (
) .


,
.
*IMAGE_HEIGHT *SKIP_IMAGES glTexImage3D(),
glTexSubImage3D() glGetTexImage()
.
, ,

*IMAGE_HEIGHT. , ,
*SKIP_IMAGES.
*IMAGE_HEIGHT ,
( ) .
*IMAGE_HEIGHT 0 ( ),
height,
glTexImage3D() glTexSubImage3D(). (
, *IMAGE_HEIGHT
0.) *IMAGE_HEIGHT.
9-4 , *IMAGE_HEIGHT (
height ).
.
9-4. *IMAGE_HEIGHT

*SKIP_IMAGES , ,
. *SKIP_IMAGES
( n),
( n*
). n
, depth,

glTexImage3D() glTexSubImage3D(). *SKIP_IMAGES 0


( ), ,
.
9-5 , *SKIP_IMAGES ,
, .
*SKIP_IMAGES 3, 3.
9-5. *SKIP_IMAGES

9.2.5

: ,
OpenGL, ,
. ,
, ,
4- ,
, ,
( 4- ).
,
,
. ,
, - ,
, -, .
,
,
.
, , 8
, ,
.

, .
, ,
.
glTexSubImage2D().
,
, .

9.2.6

: , ,
.


. OpenGL
, ,
, . ,
,
( 128x128 ), .
,
,
, .
,
(128x128, 64x64, 32x32
). 9-6.
(mipmap) (Lance Williams),
(Pyramidal Parametrics)
(SIGGRAPH1983). Mip multum in parvo,
.
.
9-6.

: ,
.
, OpenGL ,
( )
.
, ,
, .
;
, , ,
.

, 2, 1x1. ,
64x16,
32x8, 16x4, 8x2, 4x1, 2x1 1x1.
.
4 .
( OpenGL
,

.
, 9-7.)
, glTexImage2D()
,
level, width, height image. 0, level ,
.
64x16,
level=0, 32x8 level=1, . ,
, .
: OpenGL
(
).
, GL_TEXTURE_MIN_LOD,
GL_TEXTURE_MAX_LOD, GL_TEXTURE_BASE_LEVEL GL_TEXTURE_MAX_LEVEL
. ( 4 OpenGL 1.2.)

9-5 6 ,
32x32 1x1. ,
,
, 9-7. ,
0.0 8.0, ,
64 ( 8 ).
, ,
.
9-7.

9-5. : mipmap.cpp
#include <glut.h>
GLubyte
GLubyte
GLubyte
GLubyte
GLubyte
GLubyte

mipmapImage32[32][32][4];
mipmapImage16[16][16][4];
mipmapImage8[8][8][4];
mipmapImage4[4][4][4];
mipmapImage2[2][2][4];
mipmapImage1[1][1][4];

GLuint texName;
void makeImages()
{
int i,j;
for (i=0;i<32;i++)
{
for (j=0;j<32;j++)
{
mipmapImage32[i][j][0]=255;
mipmapImage32[i][j][1]=255;
mipmapImage32[i][j][2]=0;
mipmapImage32[i][j][3]=255;
}
}
for (i=0;i<16;i++)
{
for (j=0;j<16;j++)
{
mipmapImage16[i][j][0]=255;
mipmapImage16[i][j][1]=0;
mipmapImage16[i][j][2]=255;
mipmapImage16[i][j][3]=255;
}
}
for (i=0;i<8;i++)
{
for (j=0;j<8;j++)
{
mipmapImage8[i][j][0]=255;
mipmapImage8[i][j][1]=0;
mipmapImage8[i][j][2]=0;
mipmapImage8[i][j][3]=255;
}
}
for (i=0;i<4;i++)
{
for (j=0;j<4;j++)
{
mipmapImage4[i][j][0]=0;
mipmapImage4[i][j][1]=255;
mipmapImage4[i][j][2]=0;
mipmapImage4[i][j][3]=255;
}
}
for (i=0;i<2;i++)
{
for (j=0;j<2;j++)
{
mipmapImage2[i][j][0]=0;
mipmapImage2[i][j][1]=0;
mipmapImage2[i][j][2]=255;
mipmapImage2[i][j][3]=255;
}
}
mipmapImage1[i][j][0]=255;
mipmapImage1[i][j][1]=255;
mipmapImage1[i][j][2]=255;
mipmapImage1[i][j][3]=255;
}

void init()
{
glEnable(GL_DEPTH_TEST);
glShadeModel(GL_FLAT);
glTranslatef(0.0,0.0,-3.6);
makeImages();
glPixelStorei(GL_UNPACK_ALIGNMENT,1);
glGenTextures(1,&texName);
glBindTexture(GL_TEXTURE_2D,texName);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,
GL_NEAREST_MIPMAP_NEAREST);
glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA,32,32,0,
GL_RGBA,GL_UNSIGNED_BYTE,mipmapImage32);
glTexImage2D(GL_TEXTURE_2D,1,GL_RGBA,16,16,0,
GL_RGBA,GL_UNSIGNED_BYTE,mipmapImage16);
glTexImage2D(GL_TEXTURE_2D,2,GL_RGBA,8,8,0,
GL_RGBA,GL_UNSIGNED_BYTE,mipmapImage8);
glTexImage2D(GL_TEXTURE_2D,3,GL_RGBA,4,4,0,
GL_RGBA,GL_UNSIGNED_BYTE,mipmapImage4);
glTexImage2D(GL_TEXTURE_2D,4,GL_RGBA,2,2,0,
GL_RGBA,GL_UNSIGNED_BYTE,mipmapImage2);
glTexImage2D(GL_TEXTURE_2D,5,GL_RGBA,1,1,0,
GL_RGBA,GL_UNSIGNED_BYTE,mipmapImage1);
glTexEnvf(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_REPLACE);
glEnable(GL_TEXTURE_2D);
}
void display()
{
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glBindTexture(GL_TEXTURE_2D,texName);
glBegin(GL_QUADS);
glTexCoord2f(0.0,0.0);
glTexCoord2f(0.0,8.0);
glTexCoord2f(8.0,8.0);
glTexCoord2f(8.0,0.0);
glEnd();
glFlush();
}

glVertex3f(-2.0,-1.0,0.0);
glVertex3f(-2.0,1.0,0.0);
glVertex3f(2000.0,1.0,-6000.0);
glVertex3f(2000.0,-1.0,-6000.0);

void reshape(int w,int h)


{
glViewport(0,0,w,h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(60.0,w/h,1.0,30000);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
int main(int argc, char **argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB|GLUT_DEPTH);
glutInitWindowSize(500,500);

glutInitWindowPosition(100,100);
glutCreateWindow("Mipmap Textures");
init();
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutMainLoop();
return 0;
}
9-5 .
, , , .
,
, . ,

.
, , OpenGL. ,
, GLU
, ,
.

9.2.6.1

,
0, gluBuild1DMipmaps(), gluBuild2DMipmaps() gluBuild3DMipmaps()
1x1 ( 1
, 1x1x1 ).
2, gluBuild*DMipmaps()
2. , , gluBuild*DMipmaps()
( ).
int gluBuild1DMipmaps (GLenum target, GLint internalFormat, GLint width, GLenum
format, GLenum type, void *texels);
int gluBuild2DMipmaps (GLenum target, GLint internalFormat, GLint width, GLint
height, GLenum format, GLenum type, void *texels);
int gluBuild3DMipmaps (GLenum target, GLint internalFormat, GLint width, GLint
height,
GLint depth, GLenum format, GLenum type, void *texels);

glTexImage*D()
. target, internalFormat, width, height, depth,
format, type texels , glTexImage1D(),
glTexImage2D() glTexImage3D(). ,
0. GLU.

9.2.6.2


( ).
--

. (

, ,
.)

--

, , .
,
.
,

, 64x64 , -32x32 ,

( 4.0)

. 64x32

, -- 8x16 ,
y 2.0)

( x 8.0,

:

, .
GL_LINEAR,
GL_NEAREST_MIPMAP_NEAREST GL_NEAREST_MIPMAP_LINEAR,

. ,
, .
OpenGL 1.2
. ,
, . ,
,
, .

, .
. ,
,
. 9-8,
, .
,
. ,
, .
9-8.

, ,
. OpenGL
1.2 .
OpenGL 1.2 :
GL_TEXTURE_MIN_LOD, GL_TEXTURE_MAX_LOD, GL_TEXTURE_BASE_LEVEL
GL_TEXTURE_MAX_LEVEL. (
BASE_LEVEL MAX_LEVEL) , ,
, , .
(MIN_LOD MAX_LOD)

BASE_LEVEL MAX_LEVEL ,
. BASE_LEVEL
. BASE_LEVEL 0. ,
,
. MAX_LEVEL
,
MAX_LEVEL ( , ).
, ,
BASEE_LEVEL MAX_LEVEL.
: MAX_LEVEL ,
1 . MAX_LEVEL 1000,
, 1 .
: ,
.
, ,
.
,
glTexParameter*() , GL_TEXTURE_1D,
GL_TEXTURE_2D GL_TEXTURE_3D, .
, 9-1.
.
9-1.

GL_TEXTURE_BASE_LEVEL


( )

GL_TEXTURE_MAX_LEVEL


( )

9-6 2 5
. ( 2)
64x32 , 3, 4 5
.
9-6.
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_BASE_LEVEL,2);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAX_LEVEL,5);
glTexImage2D(GL_TEXTURE_2D,2,GL_RGBA, 64,32,0,
GL_RGBA, GL_UNSIGNED_BYTE, image1);
glTexImage2D(GL_TEXTURE_2D,3,GL_RGBA, 32,16,0,
GL_RGBA, GL_UNSIGNED_BYTE, image2);
glTexImage2D(GL_TEXTURE_2D,4,GL_RGBA, 16,8,0,
GL_RGBA, GL_UNSIGNED_BYTE, image3);
glTexImage2D(GL_TEXTURE_2D,5,GL_RGBA, 8,4,0,
GL_RGBA, GL_UNSIGNED_BYTE, image4);

. ,
128x64 1.
BASE_LEVEL.

9.2.6.3
MIN_LOD MAX_LOD
( )
, .
64xx64 , MIN_LOD
, 0.0, 0 64x64
( BASE_LEVEL=0; ,
BASE_LEVEL <= MIN_LOD). , MIN_LOD 2.0,
, 16x16
,

MAX_LOD ,
( MAX_LEVEL, , 1
). 64x64 ,

1x1 . MAX_LOD 4.0,


4x4 .
MIN_LOD
, MAX_LOD
. , MIN_LOD
BASE_LEVEL MAX_LOD MAX_LEVEL
,
.
BASE_LEVEL MAX_LEVEL, MAX_LOD
MIN_LOD glTexParameter*().
9-2.
9-2.

GL_TEXTURE_MIN_LOD

GL_TEXTURE_MAX_LOD


.
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_LOD,2.5);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAX_LOD,4.5);

9.2.6.4
,
. (,
4x4 ,
1x1).
,
gluBuild*DMipmapLevels().
int gluBuild1DMipmapLevels (GLenum target, GLint internalFormat, GLint width,
GLenum format,

GLenum
*texels);
int gluBuild2DMipmapLevels (GLenum
GLenum height, GLenum format,
GLenum
*texels);
int gluBuild3DMipmapLevels (GLenum
GLenum height, GLenum depth,
GLenum
GLint max, void *texels);

type, GLint level, GLint base, GLint max, void


target, GLint internalFormat, GLint width,
type, GLint level, GLint base, GLint max, void
target, GLint internalFormat, GLint width,
format, GLenum type, GLint level, GLint base,

glTexImage*D()
. level ,
texels. base max
, , texels.
target, internalFormat, width, height, depth, format type
, glTexImage1D(), glTexImage2D()
glTexImage3D(). , 0.
GLU .
: GLU 1.3 gluBuild*DMipmaps()
gluBuild*DMipmapLevels() (
), OpenGL 1.2.

9.3
,
,
.

()
(), 9-9.
,
. OpenGL
, .
/ .
.
9-9.

, :
, .
(x y),

.
, OpenGL ,
.
, ,
.
,
glTexParameter*() :
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);

GL_TEXTURE_1D, GL_TEXTURE_2D
GL_TEXTURE_3D .
GL_TEXTURE_MAG_FILTER,
GL_TEXTURE_MIN_FILTER, ,
. .
9-3.
9-3.

GL_TEXTURE_MAG_FILTER

GL_NEAREST, GL_LINEAR

GL_TEXTURE_MIN_FILTER

GL_NEAREST, GL_LINEAR, GL_NEAREST_MIPMAP_NEAREST,


GL_NEAREST_MIPMAP_LINEAR,
GL_LINEAR_MIPMAP_NEAREST, GL_LINEAR_MIPMAP_LINEAR

GL_NEAREST,
.
( ).
GL_LINEAR,
2x2, . (
2x2x2,
.)
, ,
.
, GL_REPEAT, GL_CLAMP GL_CLAMP_TO_EDGE
, , .
GL_NEAREST , GL_LINEAR , ,
, GL_LINEAR .
, , ,
.
, ,
. ( GL_NEAREST
GL_LINEAR, .)
9-3, 4
.
(GL_NEAREST_MIPMAP_NEAREST)
(GL_LINEAR_MIPMAP_NEAREST).
, . ,
,
; ,
. ,
GL_NEAREST_MIPMAP_LINEAR GL_LINEAR_MIPMAP_LINEAR
.
GL_NEAREST_MIPMAP_LINEAR ,

. GL_LINEAR_MIPMAP_LINEAR
,
. ,
GL_LINEAR_MIPMAP_LINEAR ,
.
: , ,
, OpenGL
, . ,
, .
.
GL_NEAREST (point sampling). GL_LINEAR
(bilinear sampling),
2x2. GL_LINEAR_MIPMAP_LINEAR
(trilinear sampling),
.

9.4
.
,
.
,
, (
) ,
glTexImage*D().
,
.
.

.

.
(
).

, ,
. ,
,
.
( ) ,
.

: OpenGL 1.1.

9.4.1

. ,
glGenTextures() .
void glGenTextures (GLsizei n, GLuint *textureNmes);

n textureNames.
, textureNames,
. ,
, (1D, 2D
3D) .
, glGenTextures().
glIsTexture() ,
. glGenTextures(),
(
glBindTexture()), glIsTexture() GL_FALSE.
void glIsTexture (GLuint textureName);

GL_TRUE, textureName ,
. GL_FALSE ,
textureName 0, 0,
.

9.4.2

glBindTexture() ,
. (
glBindTexture())
.
glTexImage*(), glTexSubImage*(), glCopyTexImage*(), glCopyTexSubImage*(),
glTexParameter*() glPrioritizeTextures()
.
( ), ,
, , , ,
.
, ,
.
, , ,
, .
void glBindTexture (GLenum target, GLuint textureName);

glBindTexture() . textureName
0 , ,
.
, .
textureName 0, OpenGL
.
( )
, GL_TEXTURE_1D, GL_TEXTURE_2D
GL_TEXTURE_3D, target.
GL_TEXTURE_1D,
GL_TEXTURE_2D GL_TEXTURE_3D ( )
OpenGL. ,
, ,
.
9-7 init() 2 . display()

. 9-10.

9-10.
#include <glut.h>
#define checkImageWidth 64
#define checkImageHeight 64
GLubyte checkImage[checkImageHeight][checkImageWidth][4];
GLubyte otherImage[checkImageHeight][checkImageWidth][4];
GLuint texName[2];
//
void makeCheckImage()
{
int i,j,c;
for(i=0;i<checkImageHeight;i++)
{
for(j=0;j<checkImageWidth;j++)
{
c=(((i&0x8)==0)^((j&0x8)==0))*255;
checkImage[i][j][0]=(GLubyte)c;
checkImage[i][j][1]=(GLubyte)0;
checkImage[i][j][2]=(GLubyte)0;
checkImage[i][j][3]=(GLubyte)1.0;
c=(((i&0x10)==0)^((j&0x10)==0))*255;
otherImage[i][j][0]=(GLubyte)0;
otherImage[i][j][1]=(GLubyte)c;
otherImage[i][j][2]=(GLubyte)0;
otherImage[i][j][3]=(GLubyte)1.0;
}
}
}
void init(void)
{
glClearColor(1.0,1.0,1.0,0.0);
glShadeModel(GL_FLAT);
glEnable(GL_DEPTH_TEST);
makeCheckImage();
glPixelStorei(GL_UNPACK_ALIGNMENT,1);
glGenTextures(2,texName);
glBindTexture(GL_TEXTURE_2D,texName[0]);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T, GL_CLAMP);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA,checkImageWidth,checkImageHeight,
0,GL_RGBA,GL_UNSIGNED_BYTE,checkImage);
glBindTexture(GL_TEXTURE_2D,texName[1]);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T, GL_CLAMP);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexEnvf(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_REPLACE);
glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA,checkImageWidth,checkImageHeight,
0,GL_RGBA,GL_UNSIGNED_BYTE,otherImage);

glEnable(GL_TEXTURE_2D);
}
void display(void)
{
glClear (GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glBindTexture(GL_TEXTURE_2D,texName[0]);
glBegin(GL_QUADS);
glTexCoord2f(0.0,0.0); glVertex3f(-2.0,-1.0,0.0);
glTexCoord2f(0.0,1.0); glVertex3f(-2.0,1.0,0.0);
glTexCoord2f(1.0,1.0); glVertex3f(0.0,1.0,0.0);
glTexCoord2f(1.0,0.0); glVertex3f(0.0,-1.0,0.0);
glEnd();
glBindTexture(GL_TEXTURE_2D,texName[1]);
glBegin(GL_QUADS);
glTexCoord2f(0.0,0.0); glVertex3f(1.0,-1.0,0.0);
glTexCoord2f(0.0,1.0); glVertex3f(1.0,1.0,0.0);
glTexCoord2f(1.0,1.0); glVertex3f(2.41421,1.0,-1.41421);
glTexCoord2f(1.0,0.0); glVertex3f(2.41421,-1.0,-1.41421);
glEnd();
glFlush();
}
void reshape(int w, int h)
{
glViewport(0,0,(GLsizei) w, (GLsizei) h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
if (w<=h)
glOrtho(-3.0,3.0,-3.0*(GLfloat)h/(GLfloat)w,
3.0*(GLfloat)h/(GLfloat)w,-10.0,10.0);
else
glOrtho(-3.0*(GLfloat)w/(GLfloat)h,
3.0*(GLfloat)w/(GLfloat)h,-3.0,3.0,-10.0,10.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
int main(int argc, char **argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB|GLUT_DEPTH);
glutInitWindowSize(620,620);
glutInitWindowPosition(100,100);
glutCreateWindow("Binding Texture Objects");
init();
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutMainLoop();
return 0;
}
( ),
. ,
,
.
9-7 display()
texName[1]. : -
, ,
.

, ,
, . 9-5
0-5 texName.

9.4.3


, - - .
,
.
void glDeleteTextures (GLsizei n, const GLuint *textureNames);

n , textureNames.
(,
glGenTextures()). ,
, glBindTextures()
textureName 0.
- .

9.4.4

OpenGL
, , . ,

.
,
.
, , ,
. ,
, ,
glGetTexParameter*v(), ,
GL_TEXTURE_RESIDENT.
, glAreTexturesResident().
GLboolean glAreTexturesResident (GLsizei n, const GLuint *textureNames, GLboolean
*residences);

n ,
textureNames. residences ,

textureNames. , textureNames,
, GL_TRUE,
residences . textureNames
, GL_FALSE, residences,
textureNames,
GL_FALSE.
, glAreTexturesResident()
. ,
.
. ,
, .

OpenGL ,
.
glAreTexturesResident() GL_TRUE.

9.4.4.1


,
. ,
,
.
.
. ,
, ,
glTexSubImage*()
.
: ,
, glTexSubImage*()
.
, .
, ,
. ,
, ,
.
. ,

.
glPrioritizeTextures().
void glPrioritizeTextures (GLsizei n, const GLuint *textureNames, const GLclampf
*priorities);

n priorities n
textureNames.
[0; 1]. 0 (
), 1 . glPrioritizeTextures()
, - textureNames
. ,
.

glTexParameter*(), , .
, glTexParameter*()
.
, OpenGL
,
, (least
recently used -- LRU). ,
, ,
LRU .
OpenGL LRU
( , ),
LRU,
. (

), ,
.
.
: ,
. ,
,
,
.

9.4.55


,
. ,

. 4
, glTexEnv*().
void glTexEnv{if} (GLenum target, GLenum pname, TYPE param);
void glTexEnv{if}v (GLenum target, GLenum pname, TYPE *params);

. target
GL_TEXTURE_1D, GL_TEXTURE_2D GL_TEXTURE_3D.
pname GL_TEXTURE_ENV_MODE, param GL_DECAL,
GL_REPLACE, GL_MODULATE GL_BLEND, ,
. pname
GL_TEXTURE_ENV_COLOR, param 4
, R, G, B A.
GL_BLEND.
,
.
,
. (,
.) ,
glTexImage*D(),
.
9-4 9-5 ,
. 6 (
, ): GL_ALPHA (A), GL_LUMINANCE
(L), GL_LUMINANCE_ALPHA (L A), GL_INTENSITY (I), GL_RGB (C) GL_RGBA (C A).
,
.
: 9-4 t , f
, c ,
GL_TEXTURE_ENV_COLOR,
.
R, G B ;
( )
( ) .
9-4. GL_REPLACE GL_MODULATE

GL_REPLA

GL_MODULA

GL_DECAL

GL_BLEND

CE

TE

GL_ALPHA

GL_LUMINANCE

GL_LUMINANCE_ALP
HA

GL_INTENSITY

GL_RGB

GL_RGBA

: (GL_REPLACE) ,
( ),
.
, .
GL_DECAL ( ) ,
RGB RGBA
. RGBA
,
,
. ,
( , ,
).
(GL_MODULATE)
. GL_LUMINANCE, GL_LUMINANCE_ALPHA
GL_INTENSITY, ,
( 1)
( 0). RGB RGBA
(, ,
) . ,
. ,

.
, .
, ,
GL_TEXTURE_ENV_COLOR. ,
-
GL_TEXTURE_ENV_COLOR .

9.4.5.1

,
.
.
,
. ,
: ,
, ,
.
. ()
, .

.

9.4.6

,
, .
, .
, .

, . (,
.)
1, 2, 3 4 .
s, t, r q, (x, y,
z, w) (u, v).
s; s t; s, t r.
q, w, 1.
.
glTexCoord*() glVertex*(), glColor*() glNormal*()
glBegin()
glEnd(). 0 1,
.
void glTexCoord{1234}{sifd} (TYPE coords);
void glTexCoord{1234}{sifd}v (TYPE *coords);

(s, t, r, q).
glVertex*()
. glTexCoord1*() s
, t r 0, q 1.
glTexCoord3*() q 1, s, t r . 4
glTexCoord4*().
(s, i, f d) TYPE (GLshort, GLint,
GLfloat GLdouble), .
,
, . ,
,
4x4. ,
, [-1; 1]
.
, .
, , OpenGL
.

9.4.7

,
, .

,
, ,
. ,
, .
(0,0), (1,0), (1,1), (1,0). ,
,
.
, 2/3 , -
. ,
, . ,
2/3 .
(0,0),
(1, 0), (1, 2/3), (0, 2/3).
, ,
.
, , .
, 4 12 ,
3 1.
1,
, , ,
() () 4
. , .
, 30 4
( ) 12/30 ( 1/30
).
:
1:

(0,0)

(1/30,0)

(1/30,2/3)

(0,2/3)

2:

(1/30,0)

(2/30,0)

(2/30,2/3)

(1/30,2/3)

3:

(2/30,0)

(3/30,0)

(3/30,2/3)

(2/30,2/3)

(29/30,0)

(1,0)

(1,2/3)

(29/30, 2/3)

...
30:

,
(
). . ,
, .
,
. , ,
,


,
.
, .
, ()
,
,
. 9-11 , (,
, ),
( ).
9-11.

, ,
u v
. , ,

.

9.4.8
[0,1],
. ,
, 0.0
10.0 , 100 ,
( ).
,
. , ,
,
.
:
1.0 1.0, 0.0
0.0. , ,
.
0.0 10.0 ,
.
,
, ,
, , .
GL_NEAREST, , (
) .
GL_LINEAR ,
2x2 (
). ,
:
GL_REPEAT .
2x2 .
, , .
.

GL_CLAMP (
GL_TEXTURE_BORDER_COLOR) 2x2.
GL_CLAMP_TO_EDGE .
( ) ,
. ( GL_CLAMP_TO_EDGE OpenGL 1.2.)
, ,
. , 0
( ). GL_DECAL
.
, , , .
,
[0.0, 1.0].
9-1, ,
0.0 3.0.
glBegin (GL_QUADS);
glTexCoord2f (0.0,0.0);
glTexCoord2f (0.0,3.0);
glTexCoord2f (3.0,3.0);
glTexCoord2f (3.0,0.0);
glTexCoord2f
glTexCoord2f
glTexCoord2f
glTexCoord2f
glEnd();

(0.0,0.0);
(0.0,3.0);
(3.0,3.0);
(3.0,0.0);

glVertex3f(-2.0,-1.0,0.0);
glVertex3f(-2.0,1.0,0.0);
glVertex3f(0.0,1.0,0.0);
glVertex3f(0.0,-1.0,0.0);
glVertex3f(1.0,-1.0,0.0);
glVertex3f(1.0,1.0,0.0);
glVertex3f(2.41421,1.0, -1.41421);
glVertex3f(2.41421,-1.0, 2.41421);

GL_REPEAT 912.
9-12.

s, t,
:
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_REPEAT);

GL_CLAMP GL_REPEAT,
9-13.
9-13.

,
9-14.
9-14.

glTexParameter*().
.
void glTexParameter{if} (GLenum target, GLenum pname, TYPE param);
void glTexParameter{if}v (GLenum target, GLenum pname, TYPE *param);

, ,
.
target GL_TEXTURE_1D, GL_TEXTURE_2D
GL_TEXTURE_3D, , .
pname param 9-5.

GL_TEXTURE_BORDER_COLOR
. ,
4-1;
[0, 1].
9-5. , glTexParameter*()

GL_TEXTURE_WRAP_S

GL_CLAMP, GL_REPEAT, GL_CLAMP_TO_EDGE

GL_TEXTURE_WRAP_T

GL_CLAMP, GL_REPEAT, GL_CLAMP_TO_EDGE

GL_TEXTURE_WRAP_R

GL_CLAMP, GL_REPEAT, GL_CLAMP_TO_EDGE

GL_TEXTURE_MAG_FILTER

GL_NEAREST, GL_LINEAR

GL_TEXTURE_MIN_FILTER

GL_NEAREST, GL_LINEAR, GL_NEAREST_MIPMAP_NEAREST,


GL_NEAREST_MIPMAP_LINEAR,GL_LINEAR_MIPMAP_NEAREST,
GL_LINEAR_MIPMAP_LINEAR

GL_TEXTURE_BORDER_COLOR

4 [0.0, 1,0]

GL_TEXTURE_PRIORITY

[0.0, 1.0]

GL_TEXTURE_MIN_LOD

GL_TEXTURE_MAX_LOD

GL_TEXTURE_BASE_LEVEL

GL_TEXTURE_MAX_LEVEL

9.5

.
, OpenGL
,
glTexCoord*().
glTexGen*().
void glTexGen{ifd} (GLenum coord, GLenum pname, TYPE param);
void glTexGen{ifd}v (GLenum coord, GLenum pname, TYPE *param);

.
coord GL_S, GL_T, GL_R GL_Q, ,
: s, t, r q . pname
GL_TEXTURE_GEN_MODE, GL_OBJECT_PLANE, GL_EYE_PLANE,
GL_SPHERE_MAP. GL_TEXTURE_GEN_MODE, param
( ,
), GL_OBJECT_LINEAR, GL_EYE_LINEAR GL_SPHERE_MAP.
,
.
pname, param (
), .
.
,
.
, GL_OBJECT_LINEAR
.
(GL_EYE_LINEAR)
. GL_EYE_LINEAR
, .
, ,
. GL_SPHERE_MAP
(environmental
mapping).

9.5.1
GL_TEXTURE_GEN_MODE GL_OBJECT_LINEAR,

:
=

param glTexGen*v() pname,

GL_OBJECT_PLANE.

. ,

, x=0.
, 0,
.
9-8
; x=0.
x=0 :
GLfloat xequalzero[]={1.0,0.0,0.0,0.0};

1 ( ),
. , ,
.
xy, .
9-15.
9-15. x=0

s :
GLfloat stanted[]={1.0,1.0,1.0,0.0};

x+y+z=0.
9-16. ,
x=0, x.
9-16. x+y+z=0

9-8. : texgen.cpp
#include <glut.h>
#define stripeImageWidth 32
GLubyte stripeImage[4*stripeImageWidth];
GLuint texName;
void makeStripeImage()
{
int j;
for(j=0;j<stripeImageWidth;j++)
{
stripeImage[4*j]=(GLubyte) ((j<=4) ? 255 : 0);
stripeImage[4*j+1]=(GLubyte) ((j>4) ? 255 : 0);
stripeImage[4*j+2]=(GLubyte) 0;
stripeImage[4*j+3]=(GLubyte) 255;
}
}
GLfloat xequalzero[]={1.0,0.0,0.0,0.0};
GLfloat slanted[]={1.0,1.0,1.0,0.0};
GLfloat *currentCoeff;
GLenum currentPlane;
GLint currentGenMode;
void init()
{
glClearColor(0.0,0.0,0.0,0.0);
glEnable(GL_DEPTH_TEST);
glShadeModel(GL_SMOOTH);
makeStripeImage();
glPixelStorei(GL_UNPACK_ALIGNMENT,1);
glGenTextures(1,&texName);
glBindTexture(GL_TEXTURE_1D,texName);

glTexParameteri(GL_TEXTURE_1D,GL_TEXTURE_WRAP_S,GL_REPEAT);
glTexParameteri(GL_TEXTURE_1D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_1D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
glTexImage1D(GL_TEXTURE_1D,0,GL_RGBA,stripeImageWidth,0,
GL_RGBA,GL_UNSIGNED_BYTE,stripeImage);
glTexEnvf(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_MODULATE);
currentCoeff=xequalzero;
currentGenMode=GL_OBJECT_LINEAR;
currentPlane=GL_OBJECT_PLANE;
glTexGeni(GL_S,GL_TEXTURE_GEN_MODE,currentGenMode);
glTexGenfv(GL_S,currentPlane,currentCoeff);
glEnable(GL_TEXTURE_GEN_S);
glEnable(GL_TEXTURE_1D);
glEnable(GL_CULL_FACE);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glEnable(GL_AUTO_NORMAL);
glEnable(GL_NORMALIZE);
glFrontFace(GL_CW);
glCullFace(GL_BACK);
glMaterialf(GL_FRONT,GL_SHININESS,64.0);
}
void display()
{
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glRotatef(45.0,0.0,0.0,1.0);
glBindTexture(GL_TEXTURE_1D,texName);
glutSolidTeapot(2.0);
glPopMatrix();
glFlush();
}
void reshape(int w, int h)
{
glViewport(0,0,(GLsizei) w, (GLsizei) h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
if (w<=h)
glOrtho(-3.5,3.5,-3.5*(GLfloat)h/(GLfloat)w,
3.5*(GLfloat)h/(GLfloat)w,-3.5,3.5);
else
glOrtho(-3.5*(GLfloat)w/(GLfloat)h,
3.5*(GLfloat)w/(GLfloat)h,-3.5,3.5,-3.5,3.5);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
void keyboard(unsigned char key,int x, int y)
{
switch(key)
{
case 'e':
case 'E':
currentGenMode=GL_EYE_LINEAR;
currentPlane=GL_EYE_PLANE;
glTexGeni(GL_S,GL_TEXTURE_GEN_MODE,currentGenMode);

glTexGenfv(GL_S,currentPlane,currentCoeff);
glutPostRedisplay();
break;
case 'o':
case 'O':
currentGenMode=GL_OBJECT_LINEAR;
currentPlane=GL_OBJECT_PLANE;
glTexGeni(GL_S,GL_TEXTURE_GEN_MODE,currentGenMode);
glTexGenfv(GL_S,currentPlane,currentCoeff);
glutPostRedisplay();
break;
case 's':
case 'S':
currentCoeff=slanted;
glTexGenfv(GL_S,currentPlane,currentCoeff);
glutPostRedisplay();
break;
case 'x':
case 'X':
currentCoeff=xequalzero;
glTexGenfv(GL_S,currentPlane,currentCoeff);
glutPostRedisplay();
break;
}
}
int main(int argc, char **argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB|GLUT_DEPTH);
glutInitWindowSize(350,350);
glutInitWindowPosition(100,100);
glutCreateWindow("Automatic Texture-Coordinate Generation");
init();
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutKeyboardFunc(keyboard);
glutMainLoop();
return 0;
}
s- ,
GL_TEXTURE_GEN_S glEnable(). t, r
q GL_TEXTURE_GEN_T,
GL_TEXTURE_GEN_R GL_TEXTURE_GEN_Q .
glDisable() .
GL_OBJECT_LINEAR
. 9-8 GL_OBJECT_LINEAR,
,
, . ,
e GL_OBJECT_LINEAR
GL_EYE_LINEAR,
. ( o
GL_OBJECT_LINEAR.) x=0,
yz ,

9-17. ,
,
.
:

,
.

-- ,

param glTexGen*v() pname,


GL_EYE_PLANE.

glTexGen*v(),
, .
9-17. yz


. s, t ( ) r
, ,
.
, .

. , s GL_OBJECT_LINEAR,
t GL_EYE_LINEAR.

9.5.2
,
,
, . ,
, ,
, . (
T1000 2.)
, ,
.
, , ,
OpenGL .

(environmental mapping) ,
,

.
,
.
, .

,
.
, ,
. ,
, , ,
. ,
( ).
,
,
,
, .

, ,
( ).
, ,
, OpenGL.
, ,

, .

, :
glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);
glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);
glEnable(GL_TEXTURE_GEN_S);
glEnable(GL_TEXTURE_GEN_T);
GL_SPHERE_MAP
. ,
(s t).
, .
GL_SPHERE_MAP :
1. u
( ).
2. n
.
3. r

4.
.
5. , s t :

,
, , .
. 9-18
,
,
. 9-19
.
9-18. ,

9-19.

9.6
: ,
( q), .
.

9.6.1

, 4x4
.

, ,
. ,
, ,
,
. ,
4x4, .
,
, , 2 .
glPushMatrix(), glPopMatrix(), glMultMatrix(),
glRotate*() .
, GL_TEXTURE
:
glMatrixMode(GL_TEXTURE); /* */
glRotated(...);
/*... ...*/
glMatrixMode(GL_MODELVIEW);

9.6.1.1 q
q w
(x, y, z, w) . (s,
t, r, q) , (s, t, r, q)
.
s/q, t/q r/q.
q ,
. , ,
,
- .
, ,
,
.
),
(
, .
, (
) .
,
, .
,
.

9.6.2

. OpenGL 1.2 ,

.
. ,
, OpenGL Architecture Review Board (ARB
OpenGL),
, OpenGL, OpenGL 1.2
.

,
(texture units),

. ,
. 9-20 , 4
.
9-20.

,
, .

9.6.2.1
, ,
:
1. , .
, ,
.
,
glGetIntegerv(GL_MAX_TEXTURE_UNITS_ARB, ...).
1,
.
: , ,
(feedback)
.
2. , ,
, , ,
.
glActiveTextureARB().
3. , glMultiTexCoord*ARB()
.
.
(
).

.

9.6.2.2
,
.
, :






( ).


.
, .
glActiveTextureARB() ,
.
glTexImage*(), glTexParameter*(), glTexEnv*(), glTexGen*() glBindTexture()
.
,

.
void glActiveTextureARB (GLenum texUnit);

, .
texUnit GL_TEXTUREi_ARB, i
0 k-1, k .
,
. ,
( ).
9-9 .
( , texelss0 texels1
).
.
9-9.
/* */
GLuint texNames[2];
glGenTextures(2, texNames);
glBindTexture(GL_TEXTURE_2D,texNames[0]);
glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA,32,32,0,
GL_RGBA,GL_UNSIGNED_BYTE,texels0);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAX_FILTER,GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_REPEAT);
glBindTexture(GL_TEXTURE_2D,texNames[1]);
glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA,16,16,0,
GL_RGBA,GL_UNSIGNED_BYTE,texels1);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAX_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_CLAMP_TO_EDGE);
/* 2 2
, */
/* */
glActiveTextureARB(GL_TEXTURE0_ARB);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D,texNames[0]);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
glMatrixMode(GL_TEXTURE);
glLoadIdentity();
glTranslatef(0.5,0.5,0.0);
glRotatef(45.0,0.0,0.0,1.0);
glTranslatef(-0.5,-0.5,0.0);
glMatrixMode(GL_MODELVIEW);
glActiveTextureARB(GL_TEXTURE1_ARB);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D,texNames[1]);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
,
2 .
texels0, GL_NEAREST,
GL_REPEAT, GL_REPLACE .
,
(GL_TEXTURE1_ARB),
texels1, GL_LINEAR,
GL_CLAMP_TO_EDGE, GL_MODULATE
.

: (
glPushAttrib(), glPushClientAttrib(), glPopAttrib() glPopClientAttrib())

( ).

9.6.2.3
.
.
glTexCoord*()
glMultiTexCoord*ARB(),
, .
void glMultiTexCoord{1234}{sifd}ARB (GLenum texUnit, TYPE coords);
void glMultiTexCoord{1234}{sifd}vARB (GLenum texUnit, TYPE *coords);

(s, t, r, q) ,
coords. texUnit.
texUnit ,
glActiveTextureARB().
9-10 ,
.
9-10.
glBegin(GL_TRIANGLES);
glMultiTexCoord2fARB(GL_TEXTURE0_ARB,0.0,0.0);
glMultiTexCoord2fARB(GL_TEXTURE1_ARB,1.0,0.0);
glVertex2f(0.0,0.0);
glMultiTexCoord2fARB(GL_TEXTURE0_ARB,0.5,1.0);
glMultiTexCoord2fARB(GL_TEXTURE1_ARB,0.5,0.0);
glVertex2f(50.0,100.0);
glMultiTexCoord2fARB(GL_TEXTURE0_ARB,1.0,0.0);
glMultiTexCoord2fARB(GL_TEXTURE1_ARB,1.0,1.0);
glVertex2f(100.0,0.0);
glEnd();
:
glTexCoord*(),
. , glTexCoord*()
glMultiTexCoord*ARB(GL_TEXTURE0_ARB, ...).
,
,
. , glMultiTexCoord*ARB()
,
glRasterPos*(). (
,
, .)

, glActiveTextureARB() ,
:

glTexGen*(...);
glEnable(GL_TEXTURE_GEN_*);
glDisable(GL_TEXTURE_GEN_*);


, glClientActiveTextureARB(),
, glTexCoordPointer()
.
void glCLientActiveTextureARB (GLenum texUnit);

,
. texUnit GL_TEXTUREi_ARB,
, glActiveTextureARB().

10.

. ,
,
. (
) .
, ,
. .
, .
, .
. ,
.
,
. ,
,
.
10-1, OpenGL (0, 0),
1x1,
. (x, y) ,
x, x+1, y, y+1.
10-1. ,

,
, .
, 1280 , 1024 24

( 16,777,216) ,
. 24 ( 8 1 ),
, , 3
1,310,720 (1280*1024) .
,
.
.
,
. ,
. .
(framebuffer) ( ) .
( )
; ,
, , ,
.
, OpenGL
. ,
, - . ,
, ,
, .

10.1
OpenGL :

: , , ,
, .


, ,
OpenGL. ,
, .
glGetIntegerv(), OpenGL
10-1.
: XWindow, ,
, RGBA,
, ,
. ,
Pseudo-Color

. , ,
, glXGetConfig().
10-1.

GL_RED_BITS, GL_GREEN_BITS, GL_BLUE_BITS,


GL_ALPHA_BITS

R, G, B A

GL_INDEX_BITS

GL_DEPTH_BITS

GL_STENCIL_BITS

GL_ACCUM_RED_BITS, GL_ACCUM_GREEN_BITS,
GL_ACCUM_BLUE_BITS,
GL_ACCUM_ALPHA_BITS

R, G, B A

10.1.1
10.1.1.1
, .
, RGB , .
OpenGL, ,
.
, . ,
,
. OpenGL
.
,
. OpenGL ,
,
. ,
. , ,
.
, ( ,
) ( ,
),
glGetBooleanv() GL_STEREO GL_DOUBLEBUFFER .
,
( ), glGetIntegerv() GL_AUX_BUFFERS.

10.1.1.2
.
, ,
. ,
,
. z (z
, x y
, z ).

10.1.1.3
,
( ).
, ,
,
. ,
, . ,
,
, , , ,
, .

10.1.1.4

RGBA
RGBA (
).
.
, .
( )
.
.
; ,
,
.

10.1.2
( )
1280x1024
.
, .
, , ,
.
,
. OpenGL
.
, .
, ,
. ,
;
.
.
void
void
void
void
void

glClearColor (GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha);


glClearIndex (GLfloat index);
glClearDepth (GLclampd depth);
glClearStencil (GLint s);
glClearAccum (GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha);

( RGBA ),
( ), ,
. GLclampf GLclampd (
)
[0.0, 1.0] ( ).
1.0; 0.0.
,
.

glClear().
void glClear (GLbitfield mask);

. mask
GL_COLOR_BUFFER_BIT, GL_DEPTH_BUFFER_BIT,
GL_STENCIL_BUFFER_BIT GL_ACCUM_BUFFER_BIT, .
GL_COLOR_BUFFER_BIT RGBA,
, .
,

. ,
, ,
. , glColorMask()
glIndexMask() . ,
glClear().

10.1.3

: , , , ,
, .
,
.
.
glDrawBuffer() ,
glReadBuffer() ,
glReadPixels(), glCopyPixels(), glCopyTexImage*()
glCopyTexSubImage*().
,
( ).
,
.
glDrawBuffer(), .
glDrawBuffer() (GL*LEFT
GL*RIGHT) (GL_AUXi).
void glDrawBuffer (GLenum mode);


, .
.
mode :
GL_FRONT

GL_FRONT_LEFT

GL_AUXi

GL_BACK

GL_FRONT_RIGHT

GL_FRONT_AND_BACK

GL_LEFT

GL_BACK_LEFT

GL_NONE

GL_RIGHT

GL_BACK_RIGHT

, LEFT RIGHT,
. , FRONT BACK, ,
. i GL_AUXi .
mode GL_FRONT
GL_BACK .
: ,
glDrawBuffer()
. mode ,
.
void glReadBuffer (GLenum mode);

,
glReadPixels(), glCopyPixels(),

glCopyTexImage*(), glCopyTexSubImage*() glCopyConvolutionFilter*()


, .
mode :
GL_FRONT

GL_FRONT_LEFT

GL_BACK

GL_FRONT_RIGHT

GL_LEFT

GL_BACK_LEFT

GL_RIGHT

GL_BACK_RIGHT

GL_AUXi

glReadBuffers() , glDrawBuffers().
mode GL_FRONT GL_BACK
.
: .
.

10.1.4
, OpenGL ,
, ,
.
.
void glIndexMask (GLuint mask);
void glColorMask (GLboolean red, GLboolean green, GLboolean blue, GLboolean
alpha);
void glDepthMask (GLboolean flag);
void glStencilMask (GLuint mask);

, . ,
glIndexMask() .
1,
; 0 . glColorMask()
RGBA. red, green, blue alpha ,
(GL_TRUE ,
). flag glDepthMask() GL_TRUE,
; . glStencilMask()
, .
GL_TRUE,
.

. , ,

. ,
. RGBA
,
, , .
,
,
, .
, , ,
, , .
, , ,

. , ,

, . ,
.
. ,
,
, .

( )..
: , glStencilMask() ,
.
, glStencilFunc().
,
.

10.2
, ,
OpenGL , ,
, ,
, . ,
OpenGL, ,
, , ,
,
. ,
, ,
, .
, .
, ,
, ,
.
; ,
.
1.
2.
3.
4.
5.
6.
7.

(scissor test)
(alpha test)
(stencil test)
(depth test)
(blending)
(dithering)
(logical operations)

10.2.1
glScissor()
. ,
.
void glScissor (GLint x, GLint y, GLsizei width, GLsizei height);

(
scissorbox). (x, y)
(width, height). ( .)
, .

GL_SCISSOR_TEST glEnable()
glDisable(). ,
.
,
.
,
, .
:
. ,
,
.
.
, , ,
, GL_SCISSOR_TEST glIsEnabled()
GL_SCISSOR_BOX glGetIntegerv() .

10.2.2
RGBA
.
GL_ALPHA_TEST glEnable() glDisable().
, , GL_ALPHA_TEST
glIsEnabled().
,
.
. ,
glAlphaFunc().
0, GL_ALWAYS, .
,
GL_ALPHA_FUNC GL_ALPHA_TEST_REF glGetIntegerv().
void glAlphaFunc (GLenum func, GLclampf ref);

.
ref [0; 1].
func 10-2.
10-2. glAlphaFunc()

GL_NEVER

GL_ALWAYS

GL_LESS

, <

GL_LEQUAL

, <=

GL_EQUAL

, =

GL_GEQUAL

, >=

GL_GREATER

, >

GL_NOTEQUAL

, ! =

.
,
1, 1.

,
.
, , ,
.

10.2.3
, . (
, .)
,
.
. ,
glStencilFunc() glStencilOp().
void glStencilFunc (GLenum func, GLint ref, GLuint mask);

(func), (ref) (mask)


. ref
,
, mask.
GL_NEVER, GL_ALWAYS, GL_LESS, GL_LEQUAL,
GL_GEQUAL, GL_GREATER, GL_EQUAL GL_NOTEQUAL. ,
GL_LESS, , ref ,
. s ,
ref
s mask. .
.

GL_STENCIL_TEST glEnable() glDisable(). ,
func GL_ALWAYS, mask , ref -- 0.
void glStencilOp (GLenum fail, GLenum zfail, GLenum zpass);

,
. fail, zfail zpass
GL_KEEP, GL_ZERO, GL_REPLACE, GL_INCR, GL_DECR GL_INVERT.
( ) , 0,
, 1,
1 .
0
, (
). fail ,
s ,
, zfail
, , zpass
, ( ).

10.2.3.1
6 , ,
glGetIntegerv() , 103. , ,
GL_STENCIL_TEST glIsEnabled().
10-3.

b>

GL_STENCIL_FUNC

GL_STENCIL_REF

GL_STENCIL_VALUE_MASK

GL_STENCIL_FAIL

GL_STENCIL_PASS_DEPTH_FAIL

GL_STENCIL_PASS_DEPTH_PASS

10.2.3.2
,
.
, ,
.
, ,
zpass (, GL_REPLACE). (
, ,
glDrawPixels().) (
) .
,
0 ( GL_FALSE). ,
.
, ,
1, GL_EQUAL.
.
10-1 .
. .
,
.
10-1. : stencil.cpp
#include <glut.h>
#define YELLOWMAT 1
#define BLUEMAT 2
void init()
{
GLfloat yellow_diffuse[]={0.7,0.7,0.0,1.0};
GLfloat yellow_specular[]={1.0,1.0,1.0,1.0};
GLfloat blue_diffuse[]={0.1,0.1,0.7,1.0};
GLfloat blue_specular[]={0.1,1.0,1.0,1.0};
GLfloat position_one[]={1.0,1.0,1.0,0.0};
glNewList(YELLOWMAT,GL_COMPILE);
glMaterialfv(GL_FRONT,GL_DIFFUSE,yellow_diffuse);
glMaterialfv(GL_FRONT,GL_SPECULAR,yellow_specular);
glMaterialf(GL_FRONT,GL_SHININESS,64.0);
glEndList();
glNewList(BLUEMAT,GL_COMPILE);
glMaterialfv(GL_FRONT,GL_DIFFUSE,blue_diffuse);
glMaterialfv(GL_FRONT,GL_SPECULAR,blue_specular);
glMaterialf(GL_FRONT,GL_SHININESS,45.0);

glEndList();
glLightfv(GL_LIGHT0,GL_POSITION,position_one);
glEnable(GL_LIGHT0);
glEnable(GL_LIGHTING);
glEnable(GL_DEPTH_TEST);
glClearStencil(0x0);
glEnable(GL_STENCIL_TEST);
}
void display()
{
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
// , =1
glStencilFunc(GL_EQUAL,0x1,0x1);
glStencilOp(GL_KEEP,GL_KEEP,GL_KEEP);
glCallList(BLUEMAT);
glutSolidSphere(0.5,15,15);
// , <>1
glStencilFunc(GL_NOTEQUAL,0x1,0x1);
glPushMatrix();
glRotatef(45,0.0,0.0,1.0);
glRotatef(45,0.0,1.0,0.0);
glCallList(YELLOWMAT);
glutSolidTorus(0.275,0.85,15,15);
glPushMatrix();
glRotatef(90.0,1.0,0.0,0.0);
glutSolidTorus(0.275,0.85,15,15);
glPopMatrix();
glPopMatrix();
}
void reshape(int w,int h)
{
glViewport(0,0,(GLsizei)w,(GLsizei)h);
//
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
if (w<=h)
gluOrtho2D(-3.0,3.0,-3.0*(GLfloat)h/(GLfloat)w,
3.0*(GLfloat)h/(GLfloat)w);
else
gluOrtho2D(-3.0*(GLfloat)w/(GLfloat)h,
3.0*(GLfloat)w/(GLfloat)h,-3.0,3.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glClear(GL_STENCIL_BUFFER_BIT);
glStencilFunc(GL_ALWAYS,0x1,0x1);
glStencilOp(GL_REPLACE,GL_REPLACE,GL_REPLACE);
glBegin(GL_QUADS);
glVertex2f(-1.0,0.0);
glVertex2f(0.0,1.0);
glVertex2f(1.0,0.0);
glVertex2f(0.0,-1.0);
glEnd();

glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0,(GLfloat)w/(GLfloat)h,3.0,7.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(0.0,0.0,-5.0);
}
int main(int argc, char **argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB|GLUT_DEPTH|GLUT_STENCIL);
glutInitWindowSize(400,400);
glutCreateWindow("Using the Stencil Test");
init();
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutMainLoop();
return 0;
}
.
, (
, , ),
, ,
. , ,
, ,
. ,
,
GL_ALWAYS.
, . ,
, , ,
0, , 1.
, ,
0
.
, , ,
. ,

, .
, .
, , 0,
.
, .
, ,
. , ,
.

10.2.4
,
, . , ,
, .

.
, ,
, . ,
.
, ,
, , .
, , ,
glEnable() GL_DEPTH_TEST
.
.
void glDepthFunc (GLenum func);

.
func GL_NEVER, GL_ALWAYS, GL_LESS, GL_LEQUAL, GL_EQUAL, GL_GEQUAL,
GL_GREATER GL_NOTEQUAL. ,
z , ,
. GL_LESS,
, .
z ,
, .

10.2.5 ,

,
.
. ,
RGBA , ,
, (
).

, .

, .

10.2.5.1
R, G, B A
, .
,
.

10.2.5.2
,
,
. .
, 2
, ,
.
( ) ( )
.

,
.

; ,
OpenGL .
, , , ,
.
GL_DITHER tglEnable() glDisable()
. .
RGBA, .
- -
. , , ,
, 4.4, 60% 4, 40% - 5. ( ,

(x, y).) RGBA
( ). ,
, , (
),
.

10.2.5.3
, ,
OR, XOR INVERT,
() / ,
(). ,

,
. ,
,
;
.
,
. ,
XOR
XOR ,
. ,
.
,

.

GL_INDEX_LOGIC GL_COLOR_LOGIC glEnable() glDisable()
RGBA .
glLogicOp().
GL_COPY. ( OpenGL
1.0, glEnable(GL_LOGIC_OP)
.)
void glLogicOp (GLenum opcode);

,
() , ().
opcode 10-4.
s (source), d (destination).
GL_COPY.

10-4.

10.3

GL_CLEAR

GL_AND

GL_COPY

GL_OR

GL_NOOP

GL_NAND

GL_SET

GL_NOR

GL_COPY_INVERTED

GL_XOR

GL_INVERT

GL_EQUIV

GL_AND_REVERSE

GL_AND_INVERTED

GL_OR_REVERSE

GL_OR_INVERTED

: ,
, ,
, .
,
.
OpenGL .
,
.
,
.
( ), .
, , ,
. , ,
.
,
. -
. ,
,
. ,
, .
void glAccum (GLenum op, GLfloat value);

. op , value ,
.
GL_ACCUM, GL_LOAD, GL_RETURN, GL_ADD GL_MULT.
GL_ACCUM
glReadBuffer(), R, G, B A value
.
GL_LOAD GL_ACCUM ,
, .
GL_RETURN , value
, .

GL_ADD GL_MULT
value. GL_MULT value
[-1.0, 1.0]. GL_ADD .

10.3.1
,
. ( n)
, (jittering
) ,
glAccum(GL_ACCUM,1.0/n);


glAccum(GL_RETURN,1.0);

, ,
GL_ACCUM GL_LOAD, .
n,
. ,
, ,
( ,
).
, ,

, , .
, , ,
glAccum() GL_RETURN, 16.0/1.0, 16.0/2.0,
16.0/3.0, ... 1/16
, 2/16 . GL_RETURN
, .
,
.
, n, (
,
) ( ,
). 10-2
, 16 ,
.
10-2.

10-2.
#include <math.h>
#define PI_20 3.14159265358979323846
void accFrustum(GLdouble left,GLdouble right,
GLdouble bottom,GLdouble top,
GLdouble zNear,GLdouble zFar,
GLdouble pixdx,GLdouble pixdy,
GLdouble eyedx, GLdouble eyedy,
GLdouble focus)
{
GLdouble xwsize, ywsize;
GLdouble dx, dy;
GLint viewport[4];
glGetIntegerv(GL_VIEWPORT,viewport);
xwsize=right-left;
ywsize=top-bottom;

dx=-(pixdx*xwsize/(GLdouble)viewport[2] + eyedx*zNear/focus);
dy=-(pixdy*ywsize/(GLdouble)viewport[3] + eyedy*zNear/focus);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glFrustum(left+dx,right+dx,bottom+dy,top+dy,zNear,zFar);
glMatrixMode(GL_MODELVIEW);
glTranslatef(-eyedx,-eyedy,0.0);
}
void accPerspective(GLdouble fovy,GLdouble aspect,
GLdouble zNear,GLdouble zFar,
GLdouble pixdx,GLdouble pixdy,
GLdouble eyedx,GLdouble eyedy,
GLdouble focus)
{
GLdouble fov2,left,right,bottom,top;
fov2=((fovy*PI_20)/180.0)/2.0;
top=zNear/(cos(fov2)/sin(fov2));
bottom=-top;
right=top*aspect;
left=-right;
accFrustum(left,right,bottom,top,zNear,zFar,
pixdx,pixdy,eyedx,eyedy,focus);
}
10-3 10-2
.
10-3. : accpersp.cpp
#include <glut.h>
#include "jitter.h"
#define ACSIZE 16
#define SPHERE_FACES 32
#define JIT j16
void init()
{
GLfloat
GLfloat
GLfloat
GLfloat

mat_ambient[]={1.0,1.0,1.0,1.0};
mat_specular[]={1.0,1.0,1.0,1.0};
light_position[]={0.0,0.0,10.0,1.0};
lm_ambient[]={0.2,0.2,0.2,1.0};

glMaterialfv(GL_FRONT,GL_AMBIENT,mat_ambient);
glMaterialfv(GL_FRONT,GL_SPECULAR,mat_specular);
glMaterialf(GL_FRONT,GL_SHININESS,50.0);
glLightfv(GL_LIGHT0,GL_POSITION,light_position);
glLightModelfv(GL_LIGHT_MODEL_AMBIENT,lm_ambient);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glEnable(GL_DEPTH_TEST);
glShadeModel(GL_FLAT);
glClearColor(0.0,0.0,0.0,0.0);
glClearAccum(0.0,0.0,0.0,0.0);
}

void displayObjects()
{
GLfloat torus_diffuse[]={0.7,0.7,0.0,1.0};
GLfloat cube_diffuse[]={0.0,0.7,0.7,1.0};
GLfloat sphere_diffuse[]={0.7,0.0,0.7,1.0};
GLfloat octa_diffuse[]={0.7,0.4,0.4,1.0};
glPushMatrix();
glTranslatef(0.0,0.0,-5.0);
glRotatef(30.0,1.0,0.0,0.0);
glPushMatrix();
glTranslatef(-0.80,0.35,0.0);
glRotatef(100.0,1.0,0.0,0.0);
glMaterialfv(GL_FRONT,GL_DIFFUSE,torus_diffuse);
glutSolidTorus(0.275,0.85,SPHERE_FACES,SPHERE_FACES);
glPopMatrix();
glPushMatrix();
glTranslatef(-0.75,-0.50,0.0);
glRotatef(45.0,0.0,0.0,1.0);
glRotatef(45.0,1.0,0.0,0.0);
glMaterialfv(GL_FRONT,GL_DIFFUSE,cube_diffuse);
glutSolidCube(1.5);
glPopMatrix();
glPushMatrix();
glTranslatef(0.75,0.60,0.0);
glRotatef(30.0,1.0,0.0,0.0);
glMaterialfv(GL_FRONT,GL_DIFFUSE,sphere_diffuse);
glutSolidSphere(1.0,SPHERE_FACES,SPHERE_FACES);
glPopMatrix();
glPushMatrix();
glTranslatef(0.70,-0.90,0.25);
glMaterialfv(GL_FRONT,GL_DIFFUSE,octa_diffuse);
glutSolidCube(1.5);
glPopMatrix();
glPopMatrix();
}
void display()
{
GLint viewport[4];
int jitter;
glGetIntegerv(GL_VIEWPORT,viewport);
glClear(GL_ACCUM_BUFFER_BIT);
for (jitter=0;jitter<ACSIZE;jitter++)
{
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
accPerspective(50.0,(GLdouble)viewport[2]/(GLdouble)viewport[3],
1.0,15.0,JIT[jitter].x,JIT[jitter].y,
0.0,0.0,1.0);
displayObjects();
glAccum(GL_ACCUM,1.0/ACSIZE);
}
glAccum(GL_RETURN,1.0);
glFlush();
}

void reshape(int w,int h)


{
glViewport(0,0,(GLsizei)w,(GLsizei)h);
}
int main (int argc, char **argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB|GLUT_DEPTH|GLUT_ACCUM);
glutInitWindowSize(310,310);
glutInitWindowPosition(100,100);
glutCreateWindow("Scene Antialiasing");
init();
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutMainLoop();
return 0;
}
, ,
.
, glTranslate*().
, glTranslate*() ,
1 . ,
,
,
.
, , ,
,
1 . 10-4 , display()
reshape(), 4.5.
10-4. : accanti.cpp
void display()
{
GLint viewport[4];
int jitter;
glGetIntegerv(GL_VIEWPORT,viewport);
glClear(GL_ACCUM_BUFFER_BIT);
for (jitter=0;jitter<ACSIZE;jitter++)
{
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glPushMatrix();
// , 4.5 -

.
.

// ,
//
glTranslatef(JIT[jitter].x*4.5/viewport[2],
JIT[jitter].y*4.5/viewport[3],0.0);
displayObjects();
glPopMatrix();
glAccum(GL_ACCUM,1.0/ACSIZE);

glAccum(GL_RETURN,1.0);
glFlush();
}
void reshape(int w,int h)
{
glViewport(0,0,(GLsizei)w,(GLsizei)h);
glMatrixMode(GL_PROJECTION);
if(w<=h)
glOrtho(-2.25,2.25,-2.25*h/w,2.25*h/w,-10.0,10.0);
else
glOrtho(-2.25*w/h,2.25*w/h,-2.25,2.25,-10.0,10.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}

10.3.2
,
10-3. ,
,
. , ,
, .
,

glAccum(GL_MULT, decayFactor);

decayFactor 0.0 1.0. decayFactor


.

,
glAccum(GL_RETURN,1.0);


. ,
( ) ,
. ,
, .
,
,
.

, , . ,

( ) (
). , , :
glAccum(GL_LOAD, 0.9);
glAccum(GL_RETURN, 1.0);

,
, , .
10-5, 10-3.

,
. , ,
,
( ).
( 1.0),
, ,
, .
10-3.

10-5. : motiblur.cpp
#include <glut.h>
#define SPHERE_FACES 64
//
#define PROJ_SIZE 8
// /
#define TIME_JITTER_STEPS 10
//
//
#define FULL_ROT 0
//
#define SCALE_FACTOR 1.0
void init()
{
GLfloat
GLfloat
GLfloat
GLfloat

mat_ambient[]={0.8,0.8,0.8,1.0};
mat_specular[]={1.0,1.0,1.0,1.0};
light_position[]={0.0,0.0,10.0,1.0};
lm_ambient[]={0.2,0.2,0.2,1.0};

glMaterialfv(GL_FRONT,GL_AMBIENT,mat_ambient);
glMaterialfv(GL_FRONT,GL_SPECULAR,mat_specular);
glMaterialf(GL_FRONT,GL_SHININESS,50.0);
glLightfv(GL_LIGHT0,GL_POSITION,light_position);
glLightModelfv(GL_LIGHT_MODEL_AMBIENT,lm_ambient);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);

glEnable(GL_RESCALE_NORMAL);
glEnable(GL_DEPTH_TEST);
glShadeModel(GL_SMOOTH);
glClearColor(0.0,0.0,0.0,0.0);
glClearAccum(0.0,0.0,0.0,0.0);
}
void displayObjects(GLfloat xoffset,GLfloat yrot)
{
GLfloat torus1_diffuse[]={1.0,0.0,0.0,1.0};
GLfloat torus2_diffuse[]={1.0,0.7,0.7,1.0};
GLfloat sphere_diffuse[]={1.0,1.0,1.0,1.0};
glLoadIdentity();
glTranslatef(xoffset,0.0,0.0);
glRotatef(yrot,0.0,1.0,0.0);
glScalef(SCALE_FACTOR,SCALE_FACTOR,SCALE_FACTOR);
glMaterialfv(GL_FRONT,GL_DIFFUSE,torus1_diffuse);
glutSolidTorus(0.3,0.55,SPHERE_FACES,SPHERE_FACES);
glMaterialfv(GL_FRONT,GL_DIFFUSE,torus2_diffuse);
glutSolidTorus(0.35,0.45,SPHERE_FACES,SPHERE_FACES);
glMaterialfv(GL_FRONT,GL_DIFFUSE,sphere_diffuse);
glutSolidSphere(0.4,SPHERE_FACES,SPHERE_FACES);
}
void display()
{
GLfloat correctedProjSize=PROJ_SIZE-3;
int step;
GLfloat oneStepTrans=correctedProjSize/TIME_JITTER_STEPS;
GLfloat oneStepRot=FULL_ROT/TIME_JITTER_STEPS;
glClear(GL_COLOR_BUFFER_BIT|GL_ACCUM_BUFFER_BIT);
for(step=0;step<=TIME_JITTER_STEPS;step++)
{
glClear(GL_DEPTH_BUFFER_BIT);
displayObjects(-correctedProjSize/2+oneStepTrans*step,
oneStepRot*step);
if(step!=TIME_JITTER_STEPS)
glAccum(GL_LOAD,0.9);
else
glAccum(GL_LOAD,1.0);
glAccum(GL_RETURN,1.0);
}
glAccum(GL_RETURN,1.0);
glFlush();
}
void reshape(int w,int h)
{
glViewport(0,0,(GLsizei)w,(GLsizei)h);
glMatrixMode(GL_PROJECTION);
if(w<=h)
glOrtho(-PROJ_SIZE/2,PROJ_SIZE/2,
-(PROJ_SIZE/2)*h/w,(PROJ_SIZE/2)*h/w,-10.0,10.0);
else
glOrtho(-PROJ_SIZE/2*w/h,(PROJ_SIZE/2)*w/h,
-(PROJ_SIZE/2),PROJ_SIZE/2,-10.0,10.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}

int main (int argc, char **argv)


{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB|GLUT_DEPTH|GLUT_ACCUM);
glutInitWindowSize(620,620);
glutInitWindowPosition(100,100);
glutCreateWindow("Motion blur with Accumulator");
init();
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutMainLoop();
return 0;
}

10.3.3
, ,
,
. , .
,
.
, , OpenGL,
(
).
,
. ( )
, , ,
.
, ,
glFrustum() . ,
( )
, , , ,
( 10-4).

.
10-4.

10-5 5 ,
. ( ) ,

( ). , ,
10-6. 8 ,
( accPerspective()).
, , 5- 6-
x y .
,
. , 9- ()
accPerspective() ( z=5.0).
x y(7- 8- ) .
,
, . (
, 10-6 4- 5- accPerspective() 0.0.
, .)
10-5.

10-6. : dof.cpp
#include <glut.h>
#include "jitter.h"
#define ACSIZE 8
#define JIT j8
GLint teapotList;
void init()
{
GLfloat
GLfloat
GLfloat
GLfloat

ambient[]={0.0,0.0,0.0,1.0};
diffuse[]={1.0,1.0,1.0,1.0};
specular[]={1.0,1.0,1.0,1.0};
position[]={0.0,3.0,3.0,0.0};

GLfloat lmodel_ambient[]={0.2,0.2,0.2,1.0};
GLfloat local_view[]={0.0};
glLightfv(GL_LIGHT0,GL_AMBIENT,ambient);
glLightfv(GL_LIGHT0,GL_DIFFUSE,diffuse);
glLightfv(GL_LIGHT0,GL_POSITION,position);
glLightModelfv(GL_LIGHT_MODEL_AMBIENT,lmodel_ambient);
glLightModelfv(GL_LIGHT_MODEL_LOCAL_VIEWER,local_view);
glFrontFace(GL_CW);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);

glEnable(GL_AUTO_NORMAL);
glEnable(GL_NORMALIZE);
glEnable(GL_DEPTH_TEST);
glClearColor(0.0,0.0,0.0,0.0);
glClearAccum(0.0,0.0,0.0,0.0);
teapotList=glGenLists(1);
glNewList(teapotList,GL_COMPILE);
glutSolidTeapot(0.5);
glEndList();
}
void renderTeapot(GLfloat
GLfloat
GLfloat
GLfloat
GLfloat
{
GLfloat mat[4];

x,GLfloat y,GLfloat z,
ambr,GLfloat ambg,GLfloat ambb,
difr,GLfloat difg,GLfloat difb,
specr,GLfloat specg,GLfloat specb,
shine)

glPushMatrix();
glTranslatef(x,y,z);
mat[0]=ambr;mat[1]=ambg;mat[2]=ambb;mat[3]=1.0;
glMaterialfv(GL_FRONT,GL_AMBIENT,mat);
mat[0]=difr;mat[1]=difg;mat[2]=difb;
glMaterialfv(GL_FRONT,GL_DIFFUSE,mat);
mat[0]=specr;mat[1]=specg;mat[2]=specb;
glMaterialfv(GL_FRONT,GL_SPECULAR,mat);
glMaterialf(GL_FRONT,GL_SHININESS,shine);
glCallList(teapotList);
glPopMatrix();
}
void display()
{
GLint viewport[4];
int jitter;
glGetIntegerv(GL_VIEWPORT,viewport);
glClear(GL_ACCUM_BUFFER_BIT);
for (jitter=0;jitter<ACSIZE;jitter++)
{
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glPushMatrix();
accPerspective(45.0,(GLdouble)viewport[2]/(GLdouble)viewport[3],
1.0,15.0,0.0,0.0,
0.33*JIT[jitter].x,0.33*JIT[jitter].y,5.0);

//, , ,
renderTeapot(-1.1,-0.5,-4.5,
0.1745,0.01175,0.01175,
0.61424,0.04136,0.04136,
0.727811,0.626959,0.626959,
0.6);
renderTeapot(-0.5,-0.5,-5.0,
0.24725,0.1995,0.0745,
0.75164,0.60648,0.22648,
0.628281,0.555802,0.366065,

0.4);
renderTeapot(0.2,-0.5,-5.5,
0.19225,0.19225,0.19225,
0.50754,0.50754,0.50754,
0.508273,0.508273,0.508273,
0.4);
renderTeapot(1.0,-0.5,-6.0,
0.0215,0.1745,0.0215,
0.07568,0.61424,0.07568,
0.633,0.727811,0.633,
0.6);
renderTeapot(1.8,-0.5,-6.5,
0.0,1.0,0.06,
0.0,0.50980392,0.50980392,
0.50196078,0.50196078,0.50196078,
0.25);
glAccum(GL_ACCUM,0.125);
glPopMatrix();
}
glAccum(GL_RETURN,1.0);
glFlush();
}
void reshape(int w,int h)
{
glViewport(0,0,(GLsizei)w,(GLsizei)h);
}
int main(int argc, char **argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB|GLUT_DEPTH|GLUT_ACCUM);
glutInitWindowSize(620,620);
glutInitWindowPosition(100,100);
glutCreateWindow("Depth-of-Field Effect");
init();
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutMainLoop();
return 0;
}

10.3.4
, ,
.

.

10.3.5
9 16 ,
, ,
. , . ,
.
, ,
. , 10-5
, .
,
.

10-5.

[0.25,0.75],[0.75,0.25]

[0.5033922635,0.8317967229],[0.7806016275,0.2504380877], [0.2261828938,0.4131553612]

[0.375,0.25],[0.125,0.75],[0.875,0.25],[0.625,0.75]

[0.5,0.5],[0.3,0.1],[0.7,0.9],[0.9,0.3],[0.1,0.7]

[0.4646464646,0.4646464646],[0.1313131313,0.7979797979], [0.5353535353,0.8686868686],
[0.8686868686,0.5353535353], [0.7979797979,0.1313131313],[0.2020202020,0.2020202020]

[0.5625,0.4375],[0.0625,0.9375],[0.3125,0.6875],[0.6875,0.8125], [0.8125,0.1875],
[0.9375,0.5625],[0.4275,0.0625],[0.1875,0.3125]

[0.5,0.5],[0.1666666666,0.9444444444], [0.5,0.1666666666],[0.5,0.8333333333],
[0.1666666666,0.2777777777],[0.8333333333,0.3888888888], [0.1666666666,0.6111111111],
[0.8333333333,0.7222222222], [0.8333333333,0.0555555555]

12

[0.4166666666,0.625],[0.9166666666,0.875],[0.25,0.375], [0.4166666666,0.125],[0.75,0.125],
[0.0833333333,0.125], [0.75,0.625],[0.25,0.875],[0.5833333333,0.375], [0.9166666666,0.375],
[0.0833333333,0.625],[0.5833333333,0.875]

16

[0.375,0.4375],[0.625,0.0625],[0.875,0.1875],[0.125,0.0625], [0.375,0.6875],[0.875,0.4375],
[0.625,0.5625],[0.375,0.9375], [0.625,0.3125],[0.125,0.5625],[0.125,0.8125],[0.375,0.1875],
[0.875,0.9375],[0.875,0.6875],[0.125,0.3125],[0.625,0.8125]

11.
OpenGL (GL) ,
.
OpenGL (GLU) OpenGL, .
GLU ( gluBuild*DMipmaps(),
gluScaleImage(),
gluOrtho2D(), gluPerspective(), gluLookAt(),
gluProject(), gluUnProject() gluUnProject4()) .
.
, OpenGL
, GLU ()
, OpenGL. , OpenGL
, , ,
GLU , , ,
.

11.1
OpenGL .
, ,
,
. ,
,
,

. , GLU
.
, ,
, ,
.
11-1 , :
,
.
11-1. ,

, , :
1. gluNewTess().
2. gluTessCallback()
, .
- ,
,
GLU_TESS_COMBINE.
3. gluTessProperty().
,
, .
4. ,
. ,
. (
,
.)
5. - ,
. ,
gluDeleteTess().
: , , GLU 1.2.
GLU, ,
GLU. GLU,
gluGetString(GLU_VERSION),
GLU. GLU gluGetString(),
GLU 1.0 .

11.1.1

, , , .
,
gluNewTess().

GLUtesselator* gluNewTess (void);

.
, .
.
,
, ,
- , .
,
.
. ,
-, , .
, .

11.1.2 -
, ,
- ,
. ,
GLU.
, .
-
, ,
. gluTessCallback().
void gluTessCallback (GLUtesselator *tessobj, GLenum type, void (*fn)());

- fn tessobj.
type,
GLU_TESS_BEGIN, GLU_TESS_BEGIN_DATA, GLU_TESS_EDGE_FLAG,
GLU_TESS_EDGE_FLAG_DATA, GLU_TESS_VERTEX, GLU_TESS_VERTEX_DATA,
GLU_TESS_END, GLU_TESS_END_DATA, GLU_TESS_COMBINE,
GLU_TESS_COMBINE_DATA, GLU_TESS_ERROR GLU_TESS_ERROR_DATA. 12
- :
GLU_TESS_BEGIN

void begin (GLenum type);

GLU_TESS_BEGIN_DATA

void begin (GLenum type, void* user_data);

GLU_TESS_EDGE_FLAG

void edgeFlag (GLboolean flag);

GLU_TESS_EDGE_FLAG_DATA

void edgeFlag (GLboolean flag, void* user_data);

GLU_TESS_VERTEX

void vertex (void* vertex_data);

GLU_TESS_VERTEX_DATA

void vertex (void* vertex_data, void* user_data);

GLU_TESS_END

void end (void);

GLU_TESS_END_DATA

void end (void* user_data);

GLU_TESS_COMBINE

void combine (GLdouble coords[3], void* vertex_data[4], GLfloat


weight[4], void** outData);

GLU_TESS_COMBINE_DATA

void combine (GLdouble coords[3], void* vertex_data[4], GLfloat weight[4],


void** outData, void* user_data);

GLU_TESS_ERROR

void error (GLenum errno);

GLU_TESS_ERROR_DATA

void error (GLenum errno, void* user_data);

- , gluTessCallback()
.
, gluTessCallback()
.

, , ,
OpenGL glBegin(), glEdgeFlag*(), glVertex*()
glEnd(). (combine)
. (error)
, - , .
GLU_TESS_BEGIN
4 : GL_TRIANGLE_FAN, GL_TRIANGLE_STRIP,
GL_TRIANGLES GL_LINE_LOOP. ()
, ,
. (
GLU_TESS_BOUNDARY_ONLY, GL_LINE_LOOP.)
GL_TRIANGLE_FAN
GL_TRIANGLE_STRIP, ,
GLU_TESS_EDGE_FLAG, , GLU_TESS_BEGIN
GL_TRIANGLES. GLU_TESS_EDGE_FLAG
OpenGL glEdgeFlag*().
, GLU_TESS_BEGIN ,
GLU_TESS_END,
GLU_TESS_VERTEX GLU_TESS_EDGE_FLAG ( -
gluTessVertex()).
, OpenGL glBegin()
glEnd().
- , GLU.
, ,
gluErrorString().
11-1 tess.cpp,
.
11-1. : tess.cpp
#ifndef CALLBACK
#define CALLBACK
#endif
/* init() */
tobj=gluNewTess();
gluTessCallback(tobj,GLU_TESS_VERTEX,glVertex3dv);
gluTessCallback(tobj,GLU_TESS_BEGIN,beginCallback);
gluTessCallback(tobj,GLU_TESS_END,endCallback);
gluTessCallback(tobj,GLU_TESS_ERROR,errorCallback);
/* ,
gluTessCallback() */
void CALLBACK beginCallback(GLenum which)
{
glBegin(which);
}
void CALLBACK endCallback(void)
{
glEnd();
}
void CALLBACK errorCallback(GLenum errorCode)

{
const GLubyte *estring;
estring=gluErrorString(errorCode);
fprintf(stderr, "Tesselation error: %s\n",estring);
exit(0);
}
: ,
, ,
Microsoft Windows (95/98/NT) UNIX.
Microsoft Windows, , -
, tess.cpp CALLBACK
. CALLBACK (
) Microsoft Windows, UNIX.
#ifndef CALLBACK
#define CALLBACK
#endif
void CALLBACK callbackFunction(..)
{
}
11-1, GLU_TESS_VERTEX,
glVertex3dv(),
. ,
, , , ,
. 11-2
tess.cpp.
vertexCallback() ,
6 : x, y z,
, .
11-2. - GLU_TESS_VERTEX
GLU_TESS_COMBINE
/* init() */
gluTessCallback(tobj,GLU_TESS_VERTEX,vertexCallback);
gluTessCallback(tobj,GLU_TESS_BEGIN,beginCallback);
gluTessCallback(tobj,GLU_TESS_END,endCallback);
gluTessCallback(tobj,GLU_TESS_ERROR,errorCallback);
gluTessCallback(tobj,GLU_TESS_COMBINE,combineCallback);
/* - */
void CALLBACK vertexCallback(GLvoid* vertex)
{
const GLdouble* pointer;
pointer=(GLdouble*)vertex;
glColor3dv(pointer+3);
glVertex3dv(vertex);
}
void CALLBACK combineCallback(GLdouble coords[3],
GLdouble* vertex_data[4],
GLfloat weight[4], GLdouble** dataOut)
{
GLdouble *vertex;
int i;

vertex=(GLdouble*) malloc(6*sizeof(GLdouble));
vertex[0]=coords[0];
vertex[1]=coords[1];
vertex[2]=coords[2];
for(i=3;i<6;i++)
vertex[i]=weight[0]*vertex_data[0][i]+
weight[1]*vertex_data[1][i]+
weight[2]*vertex_data[2][i]+
weight[3]*vertex_data[3][i];
*dataOut=vertex;
}
11-2 GLU_TESS_CALLBACK.
, , ,
, ,
GLU_TESS_COMBINE.
,
, .
, 11-2
vertex_data[0..3].
weight[0..3] ( 1.0). coords
.

,
vertex_data weight data_out.
combineCallback() 11-2 .
6- , x, y z ,
RGB .

11.1.2.1 ,
- .
, 12 .
,
, . ,
gluTessBeginPolygon(),
*DATA. GLU_TESS_BEGIN_DATA
,
. -
, user_data.
, , 12 ,
6.
, 11-2 , vertexCallback()
RGB .
,
. , ,
,
. GLU_TESS_BEGIN_DATA
user_data.

11.1.3

gluTessProperty() ,

. ,
, , .
void gluTessProperty (GLUtesselator* tessobj, GLenum property, GLdouble value);

property tessobj
value. property GLU_TESS_BOUNDARY_ONLY,
GLU_TESS_TOLERANCE GLU_TESS_WINDING_RULE. property
GLU_TESS_BOUNDARY_ONLY, value GL_TRUE GL_FALSE.
GL_TRUE
, ,
. GL_FALSE. (
gluTessNormal() ,
.) property GLU_TESS_TOLERANCE, value
, ,
,
GLU_TESS_COMBINE.

, -
.
OpenGL, ()
.
. GLU_TESS_WINDING_RULE ,
, . value
GLU_TESS_WINDING_ODD ( ),
GLU_TESS_WINDING_NONZERO, GLU_TESS_WINDING_POSITIVE,
GLU_TESS_WINDING_NEGATIVE GLU_TESS_WINDING_ABS_GEQ_TWO.

11.1.3.1
,
, ,
( 1 ,
1) . ,
.
. ,
.
11-2
. ,
, .
,
0.
11-2.

, ,
(odd , nonzero , positive
, negative abs
2). GLU_TESS_WINDING_ODD GLU_TESS_WINDING_NONZERO
. ,

CSG (computational solid geometry ).
11-3
. .
11-3.

11.1.3.2 CSG

GLU_TESS_WINDING_ODD GLU_TESS_WINDING_NONZERO
.
.
CSG
, ( ) .
, ,
0, 1. (
.) , ,
, , ,
, . ,

.
,
,
GLU_TESS_BOUNDARY_ONLY. ,
. ,

.
, CSG
:

UNION () ,
.

, .
GLU_TESS_WINDING_NONZERO
GLU_TESS_WINDING_POSITIVE. , ,
, .
INTERSECTION ()
. .
GLU_TESS_WINDING_ABS_GEQ_TWO.
DIFFERENCE () , A diff (B union C
union D). ,
A, B, C D .
GL_TESS_WINDING_POSITIVE.
( B, C D GLU_TESS_BOUNDARY_ONLY,
,
gluTessNormal() .)

11.1.3.3
, gluTessProperty().
gluTessGetProperty() .
,
, gluTessNormal()
.
void gluTessGetProperty (GLUtesselator* tessobj, GLenum property, GLdouble*
value);

property tessobj
value. property value ,
gluTessGetProperty().

void gluTessNormal (GLUtesselator* tessobj, GLdouble x, GLdouble y, GLdouble z);

tessobj.
.
.

. (
.) (0, 0, 0).
,
gluTessNormal() . , ,
xy, gluTessNormal(tessobj,0,0,1).
(0, 0, 0), .
,
,
. ,
(,
). ,
,
.

11.1.4
,
, ,
, .
void gluTessBeginPolygon (GLUtesselator* tessobj, void* user_data);
void gluTessEndPolygon (GLUtesselator* tessobj);

,
tessobj. user_data
,
GLU_TESS_*_DATA.
gluTessBeginPolygon() gluTessEndPolygon()
. gluTessEndPolygon(),
, .

.
void gluTessBeginContour (GLUtesselator* tessobj);
void gluTessEndContour (GLUtesselator* tessobj);

,
.
gluTessVertex(), .
.
3 .
void gluTessVertex (GLUtesselator* tessobj, GLdouble coords[3], void*
vertex_data);

tessobj. coords
, vertex_data ,
GLU_TESS_VERTEX GLU_TESS_VERTEX_DATA. ,
vertex_data , ,
, - , .
tess.cpp, 11-3,
.
,
.
. ,
, () .
star
, vertexCallback() , .
tess.cpp 11-4.
11-4.

, ,
gluTessVertex()
(vertex_data). ,
, .
: , gluTessVertex()
coords vertex_data.
coords , vertex_data
, .
11-3. : tess.cpp
GLdouble rect[4][3]= { 50.0, 50.0, 0.0,
200.0,50.0,0.0,
200.0,200.0,0.0,
50.0,200.0,0.0 };
GLdouble tri[3][3]={ 75.0,75.0,0.0,
125.0,175.0,0.0,
175.0,75.0,0.0 };
GLdouble star[5][6]={ 250.0,50.0,0.0,1.0,0.0,1.0,
325.0,200.0,0.0,1.0,1.0,0.0,
400.0,50.0,0.0,0.0,1.0,1.0,
250.0,150.0,0.0,1.0,0.0,0.0,
400.0,150.0,0.0,0.0,1.0,0.0 };

startList=glGenLists(2);
tobj=gluNewTess();
gluTessCallback(tobj,GLU_TESS_VERTEX,glVertex3dv);
gluTessCallback(tobj,GLU_TESS_BEGIN,beginCallback);
gluTessCallback(tobj,GLU_TESS_END,endCallback);
gluTessCallback(tobj,GLU_TESS_ERROR,errorCallback);
glNewList(startList,GL_COMPILE);
glShadeModel(GL_FLAT);
gluTessBeginPolygon(tobj,NULL);
gluTessBeginContour(tobj);
gluTessVertex(tobj,rect[0],rect[0]);
gluTessVertex(tobj,rect[1],rect[1]);
gluTessVertex(tobj,rect[2],rect[2]);
gluTessVertex(tobj,rect[3],rect[3]);
gluTessEndContour(tobj);
gluTessBeginContour(tobj);
gluTessVertex(tobj,tri[0],tri[0]);
gluTessVertex(tobj,tri[1],tri[1]);
gluTessVertex(tobj,tri[2],tri[2]);
gluTessEndContour(tobj);
gluTessEndPolygon(tobj);
glEndList();
gluTessCallback(tobj,GLU_TESS_VERTEX,vertexCallback);
gluTessCallback(tobj,GLU_TESS_BEGIN,beginCallback);
gluTessCallback(tobj,GLU_TESS_END,endCallback);
gluTessCallback(tobj,GLU_TESS_ERROR,errorCallback);
gluTessCallback(tobj,GLU_TESS_COMBINE,combineCallback);
glNewList(startList+1,GL_COMPILE);
glShadeModel(GL_SMOOTH);
gluTessProperty(tobj,GLU_TESS_WINDING_RULE,
GLU_TESS_WINDING_POSITIVE);
gluTessBeginPolygon(tobj,NULL);
gluTessBeginContour(tobj);
gluTessVertex(tobj,star[0],star[0]);
gluTessVertex(tobj,star[1],star[1]);
gluTessVertex(tobj,star[2],star[2]);
gluTessVertex(tobj,star[3],star[3]);
gluTessVertex(tobj,star[4],star[4]);
gluTessEndContour(tobj);
gluTessEndPolygon(tobj);
glEndList();

11.1.5
,
gluDeleteTess().
void gluDeleteTess (GLUtesselator* tessobj);

tessobj
.

11.1.6
.

1.
.
, , .
2. gluTessNormal(), .
3. ,
. (

.)

11.1.7 GLU
GLU .
,
NURBS ,
GL.

11.1.8
GLU 1.0 1.1,
. 1.0/1.1
.
(
COMBINE) - . 1.0/1.1
GLU 1.2/1.3, .
1.0/1.1 .
gluNewTess() gluDeleteTess() .
, , gluTessVertex(). gluTessCallback(),
5
12.
1.0/1.1:
void gluBeginPolygon (GLUtriangulatorObj* tessobj);
void gluNextContour (GLUtriangulatorObj* tessobj, GLenum type);
void gluEndPolygon (GLUtriangulatorObj* tessobj);

,
gluNextContour().
, gluNextContour() .
( ),
,
gluNextContour(). gluTessVertex()
. type gluNextContour()
GLU_EXTERIOR, GLU_INTERIOR, GLU_CCW, GLU_CW GLU_UNKNOWN.
.
, .
, ,
, - .
(GLU_EXTERIOR), (GLU_INTERIOR).
, GLU_EXTERIOR.
(GLU_CW GLU_CCW)
.
, GLU_CCW GLU_CW .
, , GLU_UNKNOWN.

GLU 1.0/1.1 ,
. , .
1. GLUtriangulatorObj
GLUtesselator. GLU 1.2 .
2. gluBeginPolygon() : gluTessBeginPolygon()
gluTessBeginContour(). ,
.
3. gluTessContour() gluTessEndContour()
gluTessBeginContour(). ,
.
4. gluEndPolygon() gluTessEndContour() gluTessEndPolygon().
.
5. gluTessCallback() . GLU 1.2
GLU_BEGIN, GLU_VERTEX, GLU_END, GLU_ERROR GLU_EDGE_FLAG
GLU_TESS_BEGIN, GLU_TESS_VERTEX, GLU_TESS_END,
GLU_TESS_ERROR GLU_TESS_EDGE_FLAG.

11.2 : ,

OpenGL
, . 3D
, 2D , ,
.
GLU
2D 3D (, ,
),
( ).

.
:


. ,
:
1. ,
gluNewQuadric().
2. (, ,
):
a. gluQuadricOrientation()
.
b. gluQuadricDrawStyle(),
, .
c. ,
gluQuadricNormals(),
.
.
d. ,
gluQuadricTexture(),
.

3. -
gluQuadricCallback(). ,
.
4. :
gluSphere(), gluCylinder(), gluDisk() gluPartialDisk().
,
.
5.
gluDeleteQuadric(). ,
.

11.2.1
, -
, GLUquadricObj.
, , ,
,
.
,
.
GLUquadricObj* gluNewQuadric (void);

.
.
void gluDeleteQuadric (GLUquadricObj* qobj);

gobj , .
void gluQuadricCallback (GLUquadricObj* qobj, GLenum which, void (*fn)());

, fn .
which GLU_ERROR,
fn . fn NULL,
.
GLU_ERROR fn , .
gluErrorString() ASCII .

11.2.2
,
. .
11-4, quadric.cpp
, ,
.
void gluQuadricDrawStyle (GLUquadricObj* qobj, GLenum drawStyle);

drawStyle qobj.
drawStyle GLU_POINT, GLU_LINE, GLU_SILHOUETTE GLU_FILL.

GLU_POINT GLU_LINE ,
.
GLU_SILHOUETTE , ,
, .
.
GLU_FILL ,
.
gluQuadricOrientation().
void gluQuadricOrientation (GLUquadricObj* qobj, GLenum orientation);

qobj orientation GLU_OUTSIDE


(, ) GLU_INSIDE ()
.
.
z .
void gluQuadricNormals (GLUquadricObj* qobj, GLenum normals);

qobj, normals GLU_NONE (


, ), GLU_FLAT (
) GLU_SMOOTH ( ).
gluQuadricNormals() , .
GLU_NONE , ,
. GLU_FLAT ,
,
. GLU_SMOOTH ,
,
.
void gluQuadricNormals (GLUquadricObj* qobj, GLenum normals);

qobj textureCoords GL_TRUE


GL_FALSE ( ) ,
.
.

11.2.3
,
. qobj
, gluNewQuadric().
void gluSphere (GLUquadricObj* qobj, GLdouble radius, GLint slices, GLint
stacks);

radius,
. z , slices (-
), z stacks (-
).

, t 0.0
z=-radius 1.0 z=radius, t
. s 0.0 +y, 0.25 +x,
0.5 y, 0.75 x 1.0 +y.
void gluCylinder (GLUquadricObj* qobj, GLdouble baseRadius, GLdouble
topRadius,GLdouble height, GLint slices, GLint stacks);

, z ,
z=0, z=height. ,
z slices , z stacks . baseRadius
, topRadius (
,
). topRadius 0.0, .
, t
0.0 z=0 1.0 z=height. s
.
: , . ,
, .
void gluDisk (GLUquadricObj* qobj, GLdouble innerRadius, GLdouble outerRadius,
GLint slices, GLint rings);

z=0, outerRadius
innerRadius. innerRadius 0, .
z slices ( ).
, z rings .
+z :
z.
,
. R=outerRadius, s t (R, 0, 0) (1,
0.5), (0, R, 0) (0.5, 1), (-R, 0, 0) (0, 0.5), , , (0, -R,
0) (0.5, 0).
void gluPartialDisk (GLUquadricObj* qobj, GLdouble innerRadius, GLdouble
outerRadius,
GLint slices, GLint rings, GLdouble startAngle, GLdouble
sweepAngle);

z=0. outerRadius, innerRadius, slices rings


. , ,
startAngle startAngle+sweepAngle ( startAngle
sweepAngle , 0
y, 90 x, 180
y, 270 x).

.
:

(*Radius, height ) glScale(),
.
rings stacks 1,

.
, .
11-4 ,
. 11-5.
11-5.

11-4. : quadric.cpp
#include
#include
#include
#ifndef CALLBACK
#define CALLBACK
#endif
GLuint startList;
void CALLBACK errorCallback(GLenum errorCode)
{
printf("Quadric error: %s\n",gluErrorString(errorCode));
exit(0);
}

//
void init(void)
{
GLUquadricObj *qobj;
GLfloat mat_ambient[]={0.5,0.5,0.5,1.0};
GLfloat mat_specular[]={1.0,1.0,1.0,1.0};
GLfloat mat_shininess[]={50.0};
GLfloat light_position[4]={1.0,1.0,1.0,0.0};
GLfloat model_ambient[]={0.5,0.5,0.5,1.0};
glClearColor(0.0,0.0,0.0,0.0);
glMaterialfv(GL_FRONT,GL_AMBIENT,mat_ambient);
glMaterialfv(GL_FRONT,GL_SPECULAR,mat_specular);
glMaterialfv(GL_FRONT,GL_SHININESS,mat_shininess);
glLightfv(GL_LIGHT0,GL_POSITION,light_position);
glLightModelfv(GL_LIGHT_MODEL_AMBIENT,model_ambient);
glEnable(GL_LIGHT0);
glEnable(GL_DEPTH_TEST);
// 4 -.
//
startList=glGenLists(4);
qobj=gluNewQuadric();
gluQuadricCallback(qobj,GLU_ERROR,
(void(__stdcall*)(void))errorCallback);
//
gluQuadricDrawStyle(qobj,GLU_FILL);
gluQuadricNormals(qobj,GLU_SMOOTH);
glNewList(startList,GL_COMPILE);
gluSphere(qobj,0.75,15,10);
glEndList();
//
gluQuadricDrawStyle(qobj,GLU_FILL);
gluQuadricNormals(qobj,GLU_FLAT);
glNewList(startList+1,GL_COMPILE);
gluCylinder(qobj,0.5,0.3,1.0,15,5);
glEndList();
//
gluQuadricDrawStyle(qobj,GLU_LINE);
gluQuadricNormals(qobj,GLU_NONE);
glNewList(startList+2,GL_COMPILE);
gluDisk(qobj,0.25,1.0,20,4);
glEndList();
//
gluQuadricDrawStyle(qobj,GLU_SILHOUETTE);
gluQuadricNormals(qobj,GLU_NONE);
glNewList(startList+3,GL_COMPILE);
gluPartialDisk(qobj,0.0,1.0,20,4,0.0,225.0);
glEndList();
}
//
void display(void)
{
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glPushMatrix();

glEnable(GL_LIGHTING);
glShadeModel(GL_SMOOTH);
glTranslatef(-1.0,-1.0,0.0);
glCallList(startList);
glShadeModel(GL_FLAT);
glTranslatef(0.0,2.0,0.0);
glPushMatrix();
glRotatef(300.0,1.0,0.0,0.0);
glCallList(startList+1);
glPopMatrix();
glDisable(GL_LIGHTING);
glColor3f(0.0,1.0,1.0);
glTranslatef(2.0,-2.0,0.0);
glCallList(startList+2);
glColor3f(1.0,1.0,0.0);
glTranslatef(0.0,2.0,0.0);
glCallList(startList+3);
glPopMatrix();
glFlush();
}
//
void reshape(int w, int h)
{
glViewport(0,0,(GLsizei) w, (GLsizei) h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
if (w<=h)
glOrtho(-2.5,2.5,-2.5*(GLfloat)h/(GLfloat)w,
2.5*(GLfloat)h/(GLfloat)w,-10.0,10.0);
else
glOrtho(-2.5*(GLfloat)w/(GLfloat)h,
2.5*(GLfloat)w/(GLfloat)h,-2.5,2.5,-10.0,10.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
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|GLUT_DEPTH);
glutInitWindowSize(500,500);
glutInitWindowPosition(100,100);
glutCreateWindow("Quadrics Objects");
init();
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutKeyboardFunc(keyboard);

glutMainLoop();
return 0;
}

12. NURBS
: ,
,
.
.

, , .
16
, 1000
. , 1000 ,
.
(evaluators)
( ) .
. ,
. ,
-
,
,
.

.
, : B
, NURBS (Non-UniformRationalB-Spline B - ,
), .

, ,
.
NURBS GLU
.
,
(, ) NURBS
.

12.1
.
,
, .

, , . ,
,
.
( ) .
,
.
, , NURBS.
,
GLU NURBS .

,
.
,
:

Farin, Gerald E., Curves and Surfaces for Computer Aided Geometric Design,
Fourth Edition. San Diego, CA: Academic Press, 1996.
Farin, Gerald E., NURB Curves and Surfaces: from Projective Geometry to
Practical Use. Wellesley, MA: A. K. Peters Ltd., 1995.
Farin, Gerald E., editor, NURBS for Curve and Surface Design. Society for
Industrial and Applied Mathematics, Philadelphia, PA, 1991.
Hoschek, Josef and Dieter Lasserm Fundamentals of Computer Aided Geometric
Design. Wellesley, MA: A. K. Peters Ltd., 1993.
Piegl, Les and Wayne Tiller, The NURBS Book. New York, NY: Springer Verlag,
1995.

: . . , .
. .
-- .: , 1996.
: ,
,
. , OpenGL
. , OpenGL ,
,
.

12.1

,
u ( [0, 1]).

.
u v .
, . ,
,
, RGBA
.
.
u ( u v, ), C() ( S())
( ). ,
C() S(), ,
glEvalCoord1() glEvalCoord2() glVertex*(). ,

, . ,
, , u
( u v). ,
, .

12.1.1

. ,
.

12.1.1.1 :
, 12-1
4 , 12-1.
12-1.

12-1. 4 : bezcurve.cpp
#include
GLfloat ctrlpoints[4][3]={

{-4.0,-4.0,0.0},
{-2.0,4.0,0.0},
{2.0,-4.0,0.0},
{4.0,4.0,0.0}

};
void init()
{
glClearColor(0.0,0.0,0.0,0.0);
glShadeModel(GL_FLAT);
glMap1f(GL_MAP1_VERTEX_3,0.0,1.0,3,4,&ctrlpoints[0][0]);
glEnable(GL_MAP1_VERTEX_3);
}
void display()
{
int i;
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(0.0,1.0,0.0);
glBegin(GL_LINE_STRIP);
for(i=0;i<=30;i++)

glEvalCoord1f((GLfloat)i/30.0);
glEnd();
//
glPointSize(5.0);
glColor3f(1.0,1.0,0.0);
glBegin(GL_POINTS);
for(i=0;i<4;i++)
glVertex3fv(&ctrlpoints[i][0]);
glEnd();
glFlush();
}
void reshape(int w, int h)
{
glViewport(0,0,(GLsizei) w, (GLsizei) h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
if (w<=h)
glOrtho(-5.0,5.0,-5.0*(GLfloat)h/(GLfloat)w,
5.0*(GLfloat)h/(GLfloat)w,-5.0,5.0);
else
glOrtho(-5.0*(GLfloat)w/(GLfloat)h,
5.0*(GLfloat)w/(GLfloat)h,-5.0,5.0,-5.0,5.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
int main(int argc, char** argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
glutInitWindowSize(500,500);
glutInitWindowPosition(100,100);
glutCreateWindow("Bezier Curve with Four Control Points");
init();
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutMainLoop();
return 0;
}
4 ,
ctrlpoints[][].
glMap1f(). :
GL_MAP1_VERTEX3

0.0

1.0

, 1. 3
( )

&ctrlpoints[][]

,
u 0.0 1.0,
. glEnable()
.

display() glBegin() glEnd().


, glEvalCoord1f()
glVertex() ,
u.

12.1.1.2
n( n+1)

(-, -, -
),

u 0.0 1.0.
, u

, 0.0 1.0,

.
glMap1() ,
.
void glMap1{fd} (GLenum target, TYPE u1, TYPE u2, GLint stride, GLint order,
const TYPE *points);

. target ,
( 12-1) , ,
points. ,
RGBA, . ,
target GL_MAP1_COLOR_4,
RGBA . ,
12-1,
.
, glEnable()
glDisable() .
glMap1*() u1 u2
u. stride
,
.
order 1,
. points
.

12-1. glMap1*()

GL_MAP1_VERTEX_3

x, y z

GL_MAP1_VERTEX_4

x, y, z w

GL_MAP1_INDEX

GL_MAP1_COLOR_4

R, G, B, A

GL_MAP1_NORMAL

GL_MAP1_TEXTURE_COORD_1

GL_MAP1_TEXTURE_COORD_2

s t

GL_MAP1_TEXTURE_COORD_3

s, t r

GL_MAP1_TEXTURE_COORD_4

s, t, r q

.
, , GL_MAP1_VERTEX_3 GL_MAP1_COLOR_4,
glEvalCoord1() .
, .
.
, ,
, , .
,
, .

glEvalCoord1*().
void glEvalCoord1{fd} (TYPE u);
void glEvalCoord1{fd}v (TYPE* u);

. u
.
glEvalCoord*() ,
, . glEvalCoord*()
.

12.1.1.3

glEvalCoord1() u,

, 12-1. ,
glMapGrid1*() , glEvalMesh1().
void glMapGrid1{fd} (GLint n, TYPE u1, TYPE u2);

u1 u2 n .
void glEvalMesh1 (GLenum mode, GLint p1, GLint p2);


. mode GL_POINT
GL_LINE ,
.

glEvalCoord1() p1 p2 , 0<=p1,
p2<=n. , :
glBegin(GL_POINTS);
/* glBegin(GL_LINES); */
for(i=p1;i<=p2;i++)
glEvalCoord1(u1+i*(u2-u1)/n);
glEnd();
, i=0 i=n, glEvalCoord1()
u1 u2.

12.1.2
,
2 u v. , ,
, .


m*n , B
, .
, , .
.
1. ( ) glMap2*().
2. , ( )
glEnable().
3. glEvalCoord2()
glBegin() glEnd(),
glMapGrid2() glEvalMesh2().

12.1.2.1
glMap2*() glEvalCoord2*()
.
void glMap2{fd} (GLenum target, TYPE u1, TYPE u2, GLint ustride, GLint uorder,
TYPE v1, TYPE v2,
GLint vstride, GLint vorder, TYPE* points);

target 12-1,
MAP1 MAP2 . ,
glEnable() glDisable()
.
u v, u1, u2, v1 v2, .
ustride vstride
u v,
. ,

GLfloat ctrlpoints[100][100][3];

4x4,
ctrlpoints[20][30], ustride 100*3, vstride 3. points
&ctrlpoints[20][30][0]. , ,
uorder vorder, ,
, ,
.
void glEvalCoord2{fd} (TYPE u, TYPE v);
void glEvalCoord2{fd}v (TYPE* u, TYPE* v);

.
u v (
) (
). (GL_MAP2_VERTEX_3
GL_MAP2_VERTEX_4),
. (
GL_AUTO_NORMAL glEnable()),
. ,
.
, .

12.1.2.2 :
12-2 , 12-2,
. 9
. 30 .
, reshape() main() 12-1.
12-2.

12-2. : bezsurf.cpp
GLfloat ctrlpoints[4][4][3]={
{{-1.5,-1.5,4.0},{-0.5,-1.5,2.0},{0.5,-1.5,-1.0},{1.5,1.5,2.0}},
{{-1.5,-0.5,1.0},{-0.5,-0.5,3.0},{0.5,-0.5,0.0},{1.5,-0.5,1.0}},
{{-1.5,0.5,4.0},{-0.5,0.5,0.0},{0.5,0.5,3.0},{1.5,0.5,4.0}},
{{-1.5,1.5,-2.0},{-0.5,1.5,-2.0},{0.5,1.5,0.0},{1.5,1.5,-1.0}}
};

void display()
{
int i,j;
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glColor3f(0.0,0.0,0.0);
glLoadIdentity();
glRotatef(85.0,1.0,1.0,1.0);
for(j=0;j<=8;j++)
{
glBegin(GL_LINE_STRIP);
for(i=0;i<=30;i++)
glEvalCoord2f((GLfloat)i/30.0,(GLfloat)j/8.0);
glEnd();
glBegin(GL_LINE_STRIP);
for(i=0;i<=30;i++)
glEvalCoord2f((GLfloat)j/8.0,(GLfloat)i/30.0);
glEnd();
}
glFlush();
}
void init()
{
glClearColor(1.0,1.0,1.0,0.0);
glLineWidth(2.0);
glMap2f(GL_MAP2_VERTEX_3,0,1,3,4,0,1,12,4,&ctrlpoints[0][0][0]);
glEnable(GL_MAP2_VERTEX_3);
glMapGrid2f(20,0.0,1.0,20,0.0,1.0);
glEnable(GL_DEPTH_TEST);
glShadeModel(GL_FLAT);
}

12.1.2.3

glMapGrid2*() glEvalMesh2()
, ,
u, v.
void glMapGrid2{fd} (GLint nu, TYPE u1, TYPE u2, GLint vn, TYPE v1, TYPE v2);
void glEvalMesh2 (GLenum mode, GLint i1, GLint i2, GLint j1, GLint j2);

, u1 u2 nu
v1 v2 nv (glMapGrid2*())
(glEvalMesh2()).
,
mode glEvalMesh2() GL_POINT GL_LINE
GL_FILL. GL_FILL
. , glEvalMesh2()
. ( , ,
i=nu j=nv, u2 v2, u1+nu*(u2-u1)/nu
v1+nv*(v2-v1)/nv - .)

glBegin(GL_POINTS);
/* GL_POINT */
for(i=nu1;i<=nu2;i++)
for(j=nv1;j<=nv2;j++)
glEvalCoord2(u1+i*(u2-u1)/nu, v1+j*(v2-v1)/nv);
glEnd();

for(i=nu1;i<=nu2;i++)
/* GL_LINE */
{
glBegin(GL_LINES);
for(j=nv1;j<=nv2;j++)
glEvalCoord2(u1+i*(u2-u1)/nu, v1+j*(v2-v1)/nv);
glEnd();
}
for(j=nv1;j<=nv2;j++)
{
glBegin(GL_LINES);
for(i=nu1;i<=nu2;i++)
glEvalCoord2(u1+i*(u2-u1)/nu, v1+j*(v2-v1)/nv);
glEnd();
}

for(i=nu1;i<=nu2;i++)
/* GL_FILL */
{
glBegin(GL_QUAD_STRIP);
for(j=nv1;j<=nv2;j++)
glEvalCoord2(u1+i*(u2-u1)/nu, v1+j*(v2-v1)/nv);
glEvalCoord2(u1+(i+1)*(u2-u1)/nu, v1+j*(v2-v1)/nv);
glEnd();
}
12-3 , 12-2,
, glMapGrid2() glEvalMesh2()
8x8.
12-3 , 12-3.
12-3. ,

12-3. ,
: bezmesh.cpp
void display()
{
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glRotatef(85.0,1.0,1.0,1.0);
glEvalMesh2(GL_FILL,0,20,0,20);
glFlush();
}
void init()
{
glClearColor(1.0,1.0,1.0,0.0);
glMap2f(GL_MAP2_VERTEX_3,0,1,3,4,0,1,12,4,&ctrlpoints[0][0][0]);
glEnable(GL_MAP2_VERTEX_3);
glMapGrid2f(20,0.0,1.0,20,0.0,1.0);
glEnable(GL_DEPTH_TEST);
glEnable(GL_AUTO_NORMAL);
//
GLfloat ambient[]={0.2,0.2,0.2,1.0};
GLfloat position[]={0.0,0.0,2.0,1.0};
GLfloat mat_diffuse[]={0.6,0.6,0.6,1.0};
GLfloat mat_specular[]={1.0,1.0,1.0,1.0};
GLfloat mat_shininess[]={50.0};
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glLightfv(GL_LIGHT0,GL_AMBIENT,ambient);
glLightfv(GL_LIGHT0,GL_POSITION,position);
glMaterialfv(GL_FRONT,GL_DIFFUSE,mat_diffuse);
glMaterialfv(GL_FRONT,GL_SPECULAR,mat_specular);
glMaterialfv(GL_FRONT,GL_SHININESS,mat_shininess);
}

12.1.3
12-3 2 :
, 12-3,
.
u v, ,
, ,
.
(0,0), (0, 1), (1,0)
(1,1); (0,0) (0,0), (0,1) (0,1) .
2 ( 1),
(u,v) (s,t).
, , ,
, 12-4. ,
3 , 1.0 texpts[ ][ ][ ].
12-4.

12-4. : texturesurf.cpp
#include
#include
GLfloat ctrlpoints[4][4][3]={
{{-1.5,-1.5,4.0},{-0.5,-1.5,2.0},{0.5,-1.5,-1.0},{1.5,1.5,2.0}},
{{-1.5,-0.5,1.0},{-0.5,-0.5,3.0},{0.5,-0.5,0.0},{1.5,-0.5,1.0}},
{{-1.5,0.5,4.0},{-0.5,0.5,0.0},{0.5,0.5,3.0},{1.5,0.5,4.0}},
{{-1.5,1.5,-2.0},{-0.5,1.5,-2.0},{0.5,1.5,0.0},{1.5,1.5,-1.0}}
};
GLfloat
texpts[2][2][2]={{{0.0,0.0},{0.0,1.0}},{{1.0,0.0},{1.0,1.0}}};
void display()
{
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glColor3f(1.0,1.0,1.0);
glEvalMesh2(GL_FILL,0,20,0,20);
glFlush();
}
#define imageWidth 64
#define imageHeight 64
GLubyte image[3*imageWidth*imageHeight];
void makeImage()
{
int i,j;
float ti,tj;
for(i=0;i<="h)" glOrtho(-4.0,4.0,-4.0*(GLfloat)h (GLfloat)w,
4.0*(GLfloat)h (GLfloat)w,-4.0,4.0); else glOrtho(-4.0*(GLfloat)w
(GLfloat)h, 4.0*(GLfloat)w (GLfloat)h,-4.0,4.0,-4.0,4.0);
glMatrixMode(GL_MODELVIEW); glLoadIdentity();
glRotatef(85.0,1.0,1.0,1.0); } int main(int argc, char** argv) {
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB|GLUT_DEPTH);
glutInitWindowSize(500,500); glutInitWindowPosition(100,100);

glutCreateWindow(?Using Evaluators for Textures?); init();


glutDisplayFunc(display); glutReshapeFunc(reshape); glutMainLoop();
return 0; }< pre>

12.2 GLU NURBS


OpenGL
, , ,
,
. GLU
NURBS, OpenGL
.

12.2.1 NURBS
NURBS, NURBS OpenGL
,
. , NURBS
.
1. NURBS,
glEnable() GL_AUTO_NORMAL
(
).
2. gluNewNurbsRenderer()
NURBS .
NURBS.
3. , gluNurbsProperty()
, , ,
. gluNurbsProperty()
,

.
4. ,
gluNurbsCallback(). (
, , , .)
gluNurbsCallback() ,
.
5. , gluBeginCurve()
gluBeginSurface().
6. .
gluNurbsCurve() gluNurbsSurface(),
( ),

NURBS. /
.
7. gluEndCurve() gluEndSurface(),
.
12-5 NURBS
, -3.0 3.0.
B ,
,
. , -
.
12-5.
12-5. NURBS

12-5. NURBS: surface.cpp


#include
#include
#ifndef CALLBACK
#define CALLBACK
#endif
GLfloat ctrlpoints[4][4][3];
int showPoints=0;
GLUnurbsObj *theNurb;
void init_surface()
{
int u,v;
for (u=0;u<4;u++)
{
for(v=0;v<4;v++)
{
ctrlpoints[u][v][0]=2.0*((GLfloat)u-1.5);
ctrlpoints[u][v][1]=2.0*((GLfloat)v-1.5);
if((u==1||u==2)&&(v==1||v==2))
ctrlpoints[u][v][2]=3.0;
else
ctrlpoints[u][v][2]=-3.0;
}
}
}
void CALLBACK nurbsError(GLenum errorCode)
{
char message[100];
sprintf(message,"NURBS error: %s\n",gluErrorString(errorCode));
MessageBox(NULL,message,"NURBS surface",MB_OK);
exit(0);
}
void display()
{
GLfloat knots[8]={0.0,0.0,0.0,0.0,1.0,1.0,1.0,1.0};
int i,j;
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);

glPushMatrix();
glRotatef(330.0,1.0,0.0,0.0);
glScalef(0.5,0.5,0.5);
gluBeginSurface(theNurb);
gluNurbsSurface(theNurb,8,knots,8,knots,4*3,3,
&ctrlpoints[0][0][0],4,4,GL_MAP2_VERTEX_3);
gluEndSurface(theNurb);
if(showPoints)
{
glPointSize(5.0);
glDisable(GL_LIGHTING);
glColor3f(1.0,1.0,0.0);
glBegin(GL_POINTS);
for(i=0;i<4;i++)
for(j=0;j<4;j++)
glVertex3fv(&ctrlpoints[i][j][0]);
glEnd();
glEnable(GL_LIGHTING);
}
glPopMatrix();
glFlush();
}
void init()
{
GLfloat mat_diffuse[]={0.7,0.7,0.7,1.0};
GLfloat mat_specular[]={1.0,1.0,1.0,1.0};
GLfloat mat_shininess[]={100.0};
glClearColor(0.0,0.0,0.0,0.0);
glMaterialfv(GL_FRONT,GL_DIFFUSE,mat_diffuse);
glMaterialfv(GL_FRONT,GL_SPECULAR,mat_specular);
glMaterialfv(GL_FRONT,GL_SHININESS,mat_shininess);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glEnable(GL_DEPTH_TEST);
glEnable(GL_AUTO_NORMAL);
glEnable(GL_NORMALIZE);
init_surface();
theNurb=gluNewNurbsRenderer();
gluNurbsProperty(theNurb,GLU_SAMPLING_TOLERANCE,2.0);
gluNurbsProperty(theNurb,GLU_DISPLAY_MODE,GLU_FILL);
gluNurbsCallback(theNurb,GLU_ERROR,(void(__stdcall
*)(void))nurbsError);
}
void reshape(int w, int h)
{
glViewport(0,0,(GLsizei) w, (GLsizei) h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0,(GLdouble)w/(GLdouble)h,3.0,8.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(0.0,0.0,-5.0);
}
void keyboard(unsigned char key,int x,int y)

{
switch(key)
{
case 'c':
case 'C':
showPoints=!showPoints;
glutPostRedisplay();
break;
}
}
int main(int argc, char** argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB|GLUT_DEPTH);
glutInitWindowSize(500,500);
glutInitWindowPosition(100,100);
glutCreateWindow("NURBS surface");
init();
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutKeyboardFunc(keyboard);
glutMainLoop();
return 0;
}

12.2.2 NURBS
12-5, gluNewNurbsRenderer()
NURBS, GLUnurbsObj.
, NURBS.
NURBS,
gluDeleteNurbsRenderer() .
GLUnurbsObj* gluNewNurbsRenderer (void);

NURBS nobj ,
OpenGL NURBS.
void gluDeleteNurbsRenderer (GLUnurbsObj* nobj);

NURBS nobj.

12.2.2.1 NURBS
, NURBS, ,
. , (,
),
, .
void gluNurbsProperty (GLUnurbsObj* nobj, GLenum property, GLfloat value);

NURBS nobj. property


GLU_DISPLAY_MODE, GLU_NURBS_MODE,
GLU_CULLING, GLU_SAMPLING_METHOD, GLU_SAMPLING_TOLERANCE,
GLU_PARAMETRIC_TOLERANCE, GLU_U_STEP, GLU_V_STEP

GLU_AUTO_LOAD_MATRIX. value ,
.
GLU_DISPLAY_MODE, GLU_FILL,
.
GLU_OUTLINE_POLYGON,
, .
GLU_OUTLINE_PATCH, , ,
.
GLU_NURBS_MODE ,
( , GLU_NURBS_RENDERER)

(
GLU_NURBS_TESSELATOR).
GLU_CULLING ,
GL_TRUE ( GL_FALSE). ,
, .
NURBS ,
(u v)
. property GLU_SAMPLING_METHOD, value
GLU_PATH_LENGTH ( ),
GLU_PARAMETRIC_ERROR, GL_DOMAIN_DISTANCE, GLU_OBJECT_PATH_LENGTH
GLU_OBJECT_PARAMETRIC_ERROR, .
value GLU_PATH_LENGTH,
, ,
, GLU_SAMPLING_TOLERANCE. value
GLU_PARAMETRIC_ERROR, ,
GLU_PARAMETRIC_TOLERANCE
.
value GLU_OBJECT_PATH_LENGTH GLU_PATH_LENGTH
, , GLU_SAMPLING_TOLERANCE
, .
GLU_OBJECT_PARAMETRIC_ERROR GLU_PARAMETRIC_ERROR ,
GLU_SAMPLING_TOLERANCE ,
.
value GLU_DOMAIN_DISTANCE,
,
u v GLU_U_STEP GLU_V_STEP.
property GLU_SAMPLING_TOLERANCE
GLU_PATH_LENGTH GLU_OBJECT_PATH_LENGTH, value
, ,
. , 50.0
50.0 50.0
. property GLU_PARAMETRIC_ERROR
GLU_PARAMETRIC_ERROR
GLU_OBJECT_PARAMETRIC_ERROR, value

. GLU_PARAMETRIC_ERROR
0.5. GLU_PARAMETRIC_ERROR ,
,
, 0.5 . (
GLU_OBJECT_PARAMETRIC_ERROR .)

GLU_DOMAIN_DISTANCE, property
GLU_U_STEP GLU_V_STEP, value ,
u v
. 100.
GLU_AUTO_LOAD_MATRIX ,
, OpenGL (
GL_TRUE )
gluLoadSamplingMatrices() (GL_FALSE).
: NURBS, GLU_NURBS_MODE
GLU_NURBS_TESSELATOR,
GLU_OBJECT_PATH_LENGTH GLU_OBJECT_PARAMETRIC_ERROR GLU
1.3. 1.3
( ).

GLU.
void gluLoadSamplingMatrices (GLUnurbsObj* nobj, const GLfloat modelMatrix[16],
const GLfloat projMatrix[16], const GLint viewport[4]);

GLU_AUTO_LOAD_MATRIX , ,
, gluLoadSamplingMatrices()
NURBS.
NURBS,
gluGetNurbsProperty().
void gluGetNurbsProperty (GLUnurbsObj* nobj, GLenum property, GLfloat* value);

property nobj value.

12.2.2.2 NURBS
37 , NURBS,

. ,
. 12-5

gluNurbsCallback(theNurb, GLU_ERROR, (GLvoid (*)()) nurbsError);
void gluNurbsCallback (GLUnurbsObj* nobj, GLenum which, void (* fn)(GLenum
errorCode));

which , which
GLU_ERROR. NURBS
, fn,
. errorCode 37
, GLU_NURBS_ERROR1
GLU_NURBS_ERROR37.
gluErrorString().
12-5
nurbsErrorr():
void CALLBACK nurbsError(GLenum errorCode)

{
char message[100];
sprintf(message,"NURBS error: %s\n",gluErrorString(errorCode));
MessageBox(NULL,message,"**NURBS surface",MB_OK);
exit(0);
}
GLU 1.3 ,
,
.

12.2.3 NURBS
NURBS, gluNurbsSurface()
gluBeginSurface() gluEndSurface().
.
void gluBeginSurface (GLUnurbsObj* nobj);
void gluEndSurface (GLUnurbsObj* nobj);

gluBeginSurface() gluNurbsSurface()
.
GL_MAP2_VERTEX_3 GL_MAP2_VERTEX_4
. gluEndSurface()
. NURBS
.
void gluNurbsSurface (GLUnurbsObj* nobj, GLint uknot_count, GLfloat* uknot, GLint
vknot_count, GLfloat* vknot,
GLint u_stride, GLint v_stride, GLfloat* ctlarray, GLint
uorder, GLint vorder, GLenum type);

( , ) NURBS nobj.
u v,
, (uknot vknot), (uknot_count
vknot_count) (uorder vorder). ,
.
.
.
ctlarray .
type ,
. GL_MAP2_VERTEX_3 (
) GL_MAP2_VERTEX_4 ( ).
, GL_MAP2_TEXTURE_COORD_*
GL_MAP2_NORMAL
. , ( )
NURBS,
:
gluBeginSurface(nobj);
gluNurbsSurface(nobj, ..., GL_MAP2_TEXTURE_COORD_2);
gluNurbsSurface(nobj, ..., GL_MAP2_NORMAL);
gluNurbsSurface(nobj, ..., GL_MAP2_VERTEX_3);
glEndSurface();

u_stride v_stride
.
u_stride v_stride .
12-5 u_stride 12 (4*3), 3
(GL_MAP2_VERTEX_3) v,
v_stride 3, 3 v
.
NURBS , ,
u, . ,
gluBeginCurve() gluEndCurve().
void gluBeginCurve (GLUnurbsObj* nobj);
void gluEndCurve (GLUnurbsObj* nobj);

gluBeginCurve(), gluNurbsCurve()
.
GL_MAP1_VERTEX_3 GL_MAP1_VERTEX_4
. , gluEndCurve().
void gluNurbsCurve (GLUnurbsObj* nobj, GLint uknot_count, GLfloat* uknot, GLint
u_stride, GLfloat* ctlarray, GLint uorder, GLenum type);

NURBS nobj. ,
gluNurbsSurface(). ,
NURBS.
gluBeginCurve() / gluEndCurve(), type
, (,
GL_MAP1_VERTEX_3 GL_MAP1_VERTEX_4).

12.2.3.1 NURBS
NURBS NURBS
, . GLU 1.3
, ,
.
, gluNurbsProperty()
GLU_NURBS_MODE GLU_NURBS_TESSELATOR.
gluNurbsCallback()
,
NURBS.
void gluNurbsCallback (GLUnurbsObj* nobj, GLenum which, void (*fn)());

nobj NURBS. which


, .
GLU_NURBS_MODE GLU_NURBS_TESSELATOR,
GLU_ERROR 12 . ( ,
GLU_ERROR.) 12
:
GLU_NURBS_BEGINtd>

void begin (GLenum type);

GLU_NURBS_BEGIN_DATA

void begin (GLenum type, void* userData);

GLU_NURBS_TEXTURE_COORD

void texCoord (GLfloat* tCrd);

GLU_NURBS_TEXTURE_COORD_DATA

void texCoord (GLfloat* tCrd, void* userData);

GLU_NURBS_COLOR

void color (GLfloat* color);

GLU_NURBS_COLOR_DATA

void color (GLfloat* color, void* userData);

GLU_NURBS_NORMAL

void normal (GLfloat* nml);

GLU_NURBS_NORMAL_DATA

void normal (GLfloat* nml, void* userData);

GLU_NURBS_VERTEX

void vertex (GLfloat* vertex);

GLU_NURBS_VERTEX_DATA

void vertex (GLfloat* vertex, void* userData);

GLU_NURBS_END

void end (void);

GLU_NURBS_END_DATA

void end (void* userData);

, .
, gluNurbsCallback()
.
6 .
, gluNurbsCallbackData().
void gluNurbsCallbackData (GLUnurbsObj* nobj, void* userData);

nobj NURBS. userData ,


.
,
glBegin(), glTexCoord*(), glColor*(), glNormal*(),
glVertex*() glEnd(). GLU_NURBS_TESSELATOR
, ,
.
, 12-6
12-7. 12-6 init(), NURBS,
GLU_NURBS_TESSELATOR GLU_NURBS_MODE
.
12-6. NURBS: surfpoints.cpp
void init(void)
{
/* init() */
theNurb=gluNewNurbsRenderer();
gluNurbsProperty(theNurb, GLU_NURBS_MODE,
GLU_NURBS_TESSELATOR);
gluNurbsProperty(theNurb,GLU_SAMPLING_TOLERANCE,100.0);
gluNurbsProperty(theNurb,GLU_DISPLAY_MODE,GLU_FILL);
gluNurbsCallback(theNurb,GLU_ERROR,nurbsError);
gluNurbsCallback(theNurb,GLU_NURBS_BEGIN,beginCallback);
gluNurbsCallback(theNurb,GLU_NURBS_VERTEX,vertexCallback);
gluNurbsCallback(theNurb,GLU_NURBS_NORMAL,normalCallback);
gluNurbsCallback(theNurb,GLU_NURBS_END,endCallback);
}
12-7 . printf()
,
, . ,
.
12-7. NURBS: surfpoints.cpp
void CALLBACK beginCallback(GLenum whichType)

{
glBegin(whichType);

//

printf("glBegin(");
switch(whichType)//
{
case GL_LINES:
printf(GL_LINES)\n);
break;
case GL_LINE_LOOP:
printf(GL_LINE_LOOP)\n);
break;
case GL_LINE_STRIP:
printf(GL_LINE_STRIP)\n);
break;
case GL_TRIANGLES:
printf(GL_TRIANGLES)\n);
break;
case GL_TRIANGLE_STRIP:
printf(GL_TRIANGLE_STRIP)\n);
break;
case GL_TRIANGLE_FAN:
printf(GL_TRIANGLE_FUN)\n);
break;
case GL_QUADS:
printf(GL_QUADS)\n);
break;
case GL_QUAD_STRIP:
printf(GL_QUAD_STRIP)\n);
break;
case GL_POLYGON:
printf(GL_POLYGON)\n);
break;
default:
break;
}
}
void CALLBACK endCallback()
{
glEnd();
printf(glEnd()\n);
}
void CALLBACK vertexCallback(GLfloat* vertex)
{
glVertex3fv(vertex);
printf("glVertex3f (%5.3f, %5.3f, %5.3f)\n",
vertex[0],vertex[1],vertex[2]);
}
void CALLBACK normalCallback(GLfloat* normal)
{
glNormal3fv(normal);
printf(glNormal3f (%5.3f, %5.3f, %5.3f)\n,
normal[0], normal[1], normal[2]);
}

12.2.4 NURBS
NURBS OpenGL,
. gluBeginSurface()

gluNurbsSurface(), gluEndSurface()
gluBeginTrim().
void gluBeginTrim (GLUnurbsObj* nobj);
void gluEndTrim (GLUnurbsObj* nobj);

.

( ), NURBS.
:
gluPwlCurve() NURBS gluNurbsCurve().
, ,
. NURBS
(u, v). NURBS
GLU_MAP1_TRIM_2. , GLU_MAP1_TRIM_3,
(u, v, w) (u, v)=(u/w, v/w).
void gluPwlCurve (GLUnurbsObj* nobj, GLint count, GLfloat* array, GLint stride,
GLenum type);

NURBS nobj.
count , array. type
GLU_MAP1_TRIM_2 ( ) GLU_MAP1_TRIM_3 (
(u, v, w)). type stride,
2 3. stride
array.

,
. ,
, , , , , .
, ,
, .
,
, , .
,
2 .
. ,
, , .
, .
.
, .
, ,
. . ,
, ,
, , ,
, ,
. 12-6
.
12-6.

12-7 , 12-5,
, NURBS. ,
12-5 ,
12-8.
12-7. NURBS

12-7. NURBS: trim.cpp


void display()
{
GLfloat knots[8]={0.0,0.0,0.0,0.0,1.0,1.0,1.0,1.0};
GLfloat edgePt[5][2]= /* */
{{0.0,0.0},{1.0,0.0},{1.0,1.0},{0.0,1.0},
{0.0,0.0}};
GLfloat curvePt[4][2]= /* */
{{0.25,0.5}, {0.25,0.75}, {0.75,0.75}, {0.75,0.5}};

GLfloat curveKnots[8]={0.0,0.0,0.0,0.0,1.0,1.0,1.0,1.0};
GLfloat pwlPt[3][2]= /* */
{{0.75,0.5}, {0.5,0.25}, {0.25,0.5}};
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glRotatef(330.0,1.0,0.0,0.0);
glScalef(0.5,0.5,0.5);
gluBeginSurface(theNurb);
gluNurbsSurface(theNurb,8,knots,8,knots,4*3,3,
&ctrlpoints[0][0][0],4,4,GL_MAP2_VERTEX_3);
gluBeginTrim(theNurb);
gluPwlCurve(theNurb,5,&edgePt[0][0],2,GLU_MAP1_TRIM_2);
gluEndTrim(theNurb);
gluBeginTrim(theNurb);
gluNurbsCurve(theNurb,8,curveKnots,2,
&curvePt[0][0],4,GLU_MAP1_TRIM_2);
gluPwlCurve(theNurb,3,&pwlPt[0][0],2,GLU_MAP1_TRIM_2);
gluEndTrim(theNurb);
gluEndSurface(theNurb);
glPopMatrix();
glFlush();
}
12-8 gluBeginTrim() gluEndTrim()
. , edgePt[
][ ],
. ,
(, ,
). NURBS
. NURBS (0.9, 0.5) (0.1,
0.5), , .

13.

.
, , , -
. OpenGL
. ,
, ,
,
. , OpenGL
(selection mechanism), ,
.
,
, (picking) .
OpenGL;
(feedback) .
OpenGL
. ,
, OpenGL .
, , ,

, ,
,
.
,
, , .
, , OpenGL
. ,
, .
.

13.1
, OpenGL,
,
. , ,
, .
, OpenGL ,
(,
, ).
, ,
(hit).
(hitrecords)
. ,
,
. ,
, ,
.
OpenGL ,
,
.
, ,
, . (

. , ,
.) (picking)
, , .

13.1.1
, .
1. glSelectBuffer() ,
.
2. , GL_SELECT
glRenderMode().
3. glInitNames() glPushName().
4. ,
. ,
, , ,

glPushMatrix() glPopMatrix().
5.
, ,
.
6.
( ).

void glSelectBuffer (GLsizei size, GLuint* buffer);

,
. buffer
, , size
, .
glSelectBuffer() .
GLint glRenderMode (GLenummode);

, .
mode GL_RENDER ( ,
), GL_SELECTION ( ) GL_FEEDBACK ( ).
, glRenderMode()
.
glSelectBuffer(). ,
glFeedbackBuffer()
. glRenderMode() ,
( ,
) GL_SELECT GL_FEEDBACK.
,
GL_SELECT GL_FEEDBACK ;
, .
, ,
GL_RENDER_MODE glGetIntegerv().

13.1.2
, ,
. ,
glInitNames(), ,
.
,
, , (glPushName()),
,
(glPopName()) - (glLoadName()).
, , 13-1.
13-1.
glInitStack();
glPushName(0);
glPushMatrix();

/* */

/* */
glLoadName(1);
___();
glLoadName(2);
__();
glLoadName(3);
___();
__();
glPopMatrix();
/*
*/

,
. ,
,
.
, .
void glInitNames (void);

.
void glPushName (GLuint name);

name . ,
GL_STACK_OVERFLOW.
OpenGL, ,
, 64 .
GL_NAME_STACK_DEPTH glGetIntegerv().
void glPopName (void);

.
GL_STACK_UNDERFLOW.
void glLoadName (GLuint name);

name. ,
glInitNames(), glLoadName()
GL_INVALID_OPERATION. ,
- glPushName()
glLoadName().
glPushName(), glPopName() glLoadName() ,
. ,

,
.

13.1.3
, ,
. ,
glRenderMode(), OpenGL ,

glRenderMode(). ,
, ,
. , ,

glRenderMode().
: ,
glRasterPos(). ,
,
.
4 ( ):

.
z () ,
.
, [0, 1]

.
.
.

, OpenGL
. , ,
.
, size
glSelectBuffer(), OpenGL
.
glRenderMode(), ,
( ,
), ,
. , -1.

13.1.4
13-2 drawTriangle() 4
: , , ,
( drawViewVolume()).
, ( selectObjects()).
processHits()
.
, ,
. 13-1.
13-1.

13-2. : select.cpp
#include
#include
#include
void drawTriangle(GLfloat x1,GLfloat y1,GLfloat x2,GLfloat y2,GLfloat

x3,GLfloat y3,GLfloat z)
{
glBegin(GL_TRIANGLES);
glVertex3f(x1,y1,z);
glVertex3f(x2,y2,z);
glVertex3f(x3,y3,z);
glEnd();
}
void drawViewVolume(GLfloat x1,GLfloat x2,GLfloat y1,GLfloat
y2,GLfloat z1,GLfloat z2)
{
glColor3f(1.0,1.0,1.0);
glBegin(GL_LINE_LOOP);
glVertex3f(x1,y1,-z1);
glVertex3f(x2,y1,-z1);
glVertex3f(x2,y2,-z1);
glVertex3f(x1,y2,-z1);
glEnd();
glBegin(GL_LINE_LOOP);
glVertex3f(x1,y1,-z2);
glVertex3f(x2,y1,-z2);
glVertex3f(x2,y2,-z2);
glVertex3f(x1,y2,-z2);
glEnd();
glBegin(GL_LINES);
glVertex3f(x1,y1,-z1);
glVertex3f(x1,y1,-z2);
glVertex3f(x1,y2,-z1);
glVertex3f(x1,y2,-z2);
glVertex3f(x2,y1,-z1);
glVertex3f(x2,y1,-z2);
glVertex3f(x2,y2,-z1);
glVertex3f(x2,y2,-z2);
glEnd();
}
void drawScene()
{
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(40.0,4.0/3.0,1.0,100.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(7.5,7.5,12.5,2.5,2.5,-5.0,0.0,1.0,0.0);
glColor3f(0.0,1.0,0.0);
drawTriangle(2.0,2.0,3.0,2.0,2.5,3.0,-5.0);
glColor3f(1.0,0.0,0.0);
drawTriangle(2.0,7.0,3.0,7.0,2.5,9.0,-5.0);
glColor3f(1.0,1.0,0.0);
drawTriangle(2.0,2.0,3.0,2.0,2.5,3.0,0.0);
drawTriangle(2.0,2.0,3.0,2.0,2.5,3.0,-10.0);
drawViewVolume(0.0,5.0,0.0,5.0,0.0,10.0);
}
void processHits(GLint hits,GLuint buffer[])

{
int i,j;
GLuint names, *ptr;
printf("hits=%d\n",hits);
ptr=(GLuint*)buffer;
for (i=0;i< pre>

:
Green triangle name is 1
Red triangle name is 2
Yellow triangles name are 3
hits=2
number of names for hit=1
z1 is 0.999999; z2 is 0.999999;
the names are 1
number of names for hit=1
z1 is 0; z2 is 2;
the names are 3

13.1.5
, ,
,
. ,
,
, .
- , , ,
.
, .
, ,
.
, ,
:

.
,
.
gluPickMatrix()
.
(,
glOrtho() glFrustum()).
,
:
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
gluPickMatrix(...);
gluPerspective, glOrtho, gluOrtho2D glFrustum
/* ... , ...
*/
glPopMatrix();
void gluPickMatrix (GLdouble x, GLdouble y, GLdouble width, GLdouble height,
GLint viewport[4]);

,
.
(x, y) (
). width height ( )
. (
.) viewport[]
,

glGetIntegerv(GL_VIEWPORT, GLint *viewport);

: , gluPickMatrix()
1<=(x,y,z)<=1 ( -w<=(wx,wy,wz)<=w).
, .
,
,
.
.
13-3 .

, .
33x3, .
board[3][3] .
, pickSquares(),
, .
. ,
, ,
. , , 13-2.
13-2.

13-3. : picksquares.cpp
#include
#include
#include

int board[3][3]; //
void init()
{
int i,j;
for(i=0;i<3;i++)
for(j=0;j<3;j++)
board[i][j]=0;
glClearColor(0.0,0.0,0.0,0.0);
}
void drawSquares(GLenum mode)
{
GLuint i,j;
for (i=0;i<3;i++)
{
if (mode==GL_SELECT)
glLoadName(i);
for(j=0;j<3;j++)
{
if(mode==GL_SELECT)
glPushName(j);
glColor3f((GLfloat)i/3.0,(GLfloat)j/3.0,(GLfloat)board[i][j]/3.0);
glRecti(i,j,i+1,j+1);
if (mode==GL_SELECT)
glPopName();
}
}
}
void processHits(GLint hits,GLuint buffer[])
{
int i,j;
GLuint ii, jj, names, *ptr;
printf("hits=%d\n",hits);
ptr=(GLuint*)buffer;
for (i=0;i< pre this if(j="=0)" ii="*ptr;" else if (j="=1)"
jj="*ptr;" board[ii][jj]="(board[ii][jj]+1)%3;" pickSquares(int
button,int state,int x,int y) viewport[4];
if(button!="GLUT_LEFT_BUTTON" || state!="GLUT_DOWN)" return;
glGetIntegerv(GL_VIEWPORT,viewport); Create 5x5 pixel picking region
near cursor location
gluPickMatrix((GLdouble)x,(GLdouble)(viewport[3]y),5.0,5.0,viewport); drawSquares(GL_SELECT); glutPostRedisplay();
glClear(GL_COLOR_BUFFER_BIT); drawSquares(GL_RENDER); reshape(int w,
h) glViewport(0,0,w,h); gluOrtho2D(0.0,3.0,0.0,3.0);
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
glutInitWindowSize(300,300); glutCreateWindow(?Picking
glutMouseFunc(pickSquares); glutReshapeFunc(reshape);>

13.1.5.1


. , ,
,
.


. ,
,
.
13-4 ,
.
13-4.
___()
{
long i;
_();
for(i=0;i<5;i++)
{
glPushMatrix();
glRotate(72.0*i,0.0,0.0,1.0);
glTranslate(3.0,0.0,0.0);
glPushName(i);
_();
glPopName();
glPopMatrix();
}
}
____()
{
_();
glPushMatrix();
glTranslate(40,0,20);
/* */
glPushName(1);
/* 1 */
___();
glPopName();
glPopMatrix();
glPushMatrix();
glTranslate(40,0,-20); /* */
glPushName(1);
/* 2 */
___();
glPopName();
glPopMatrix();
/* */
}
13-5 13-4
, 1, 2 3.
13-5.
__()
{
glInitNames();
glPushMatrix();
_____();
glPushName(1);
____();
glPopName();
glPopMatrix();

glPushMatrix();
_____();
glPushName(2);
____();
glPopName();
glPopMatrix();
glPushMatrix();
_____();
glPushName(3);
____();
glPopName();
glPopMatrix();
}
, ,
, , .
; d1 d2
.
2

d1

d2

d1

d2

d1

d2

1, 1
3

0 1 1

,
. ,
2 .
, , , , ,
,
. .

13.1.5.2
13-6 ,
.
. ,
pickRects(). ,
,
. ,
. ,
,
. ,
, 13-3.
13-3.

,
z.
, . , ,
,
z.
13-6. : pickdepth.cpp
#include
#include
#include
void init()
{
glClearColor(0.0,0.0,0.0,0.0);
glEnable(GL_DEPTH_TEST);
glShadeModel(GL_FLAT);
glDepthRange(0.0,1.0);
*/
}
void drawRects(GLenum mode)
{
if (mode==GL_SELECT)
glLoadName(1);
glBegin(GL_QUADS);
glColor3f(1.0,1.0,0.0);
glVertex3i(2,0,0);
glVertex3i(2,6,0);
glVertex3i(6,6,0);
glVertex3i(6,0,0);
glEnd();
if (mode==GL_SELECT)
glLoadName(2);
glBegin(GL_QUADS);

/* z

glColor3f(0.0,1.0,1.0);
glVertex3i(3,2,-1);
glVertex3i(3,8,-1);
glVertex3i(8,8,-1);
glVertex3i(8,2,-1);
glEnd();
if (mode==GL_SELECT)
glLoadName(3);
glBegin(GL_QUADS);
glColor3f(1.0,0.0,1.0);
glVertex3i(0,2,-2);
glVertex3i(0,7,-2);
glVertex3i(5,7,-2);
glVertex3i(5,2,-2);
glEnd();
}
void processHits(GLint hits,GLuint buffer[])
{
int i,j;
GLuint names, *ptr;
printf("hits=%d\n",hits);
ptr=(GLuint*)buffer;
for (i=0;i< pre this pickSquares(int button,int state,int x,int
y) viewport[4]; if(button!="GLUT_LEFT_BUTTON" || state!="GLUT_DOWN)"
return; glGetIntegerv(GL_VIEWPORT,viewport); Create 5x5 pixel picking
region near cursor location
gluPickMatrix((GLdouble)x,(GLdouble)(viewport[3]y),5.0,5.0,viewport); reshape(int w, h) glViewport(0,0,w,h);
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB); glutCreateWindow(?Picking
glutMouseFunc(pickSquares); glutReshapeFunc(reshape);
drawRects(GL_SELECT); drawRects(GL_RENDER); glOrtho(0.0,8.0,0.0,8.0,0.5,2.5); glutInitWindowSize(400,400); with Depth Values?);>

13.1.6

,
, ,
.
( )
,
OpenGL. ,

. , OpenGL
, . ,
-
, .
, .
.
, , ,
.
, , .
, , .

, - . ,

, , , -
.
OpenGL,
,
. , , ,
. ,
, .
,
(
).
.
, -
( ). ,
. :

:
1. .
,
.
2.
.
, . (

.)
3. , ,
,
, ,
, , .
.
. ( ,
,
.
.)
4. , ,
Shift, .
, .
5. Shift,
.
6.
. ( )
- , ,
.
.
,
-
(, Alt). ,
: Alt, ,
Alt. Alt ,
.

7. Shift ,
.
8. , , ,
. ( ,
), , ,
,
.
.
.
, , ,
,
. ,
. ,
, .
,
;
.

,
. ,
.

13.2
, , ,
, .
, ,
, .
, .

.
. ,
, ,
(, , , ),
, .
,
.
glRenderMode() GL_FEEDBACK.
.
1. glFeedbackBuffer(), ,
.
, .
2. glRenderMode(), . (
, glRenderMode().)
,
, .
3. .
glPassThrough()
, .
4. , glRenderMode() GL_RENDER,
. ,
glRenderMode(), ,
.
5. .

void glFeedbackBuffer (GLsizei size, GLenum type, GLfloat* buffer);

: buffer ,
. size ,
. type ,
;
13-1. glFeedbackBuffer()
. 13-1 k 1 4 RGBA.
13-1. type glFeedbackBuffer()
type

GL_2D

x, y

GL_3D

x, y, z

GL_3D_COLOR

x, y, z

3+k

GL_3D_COLOR_TEXTURE

x, y, z

7+k

GL_4D_COLOR_TEXTURE

x, y, z, w

8+k

: ,
0.

13.2.1
, (
glBitmap(), glDrawPixels() glCopyPixels()
) ,
.
type glFeedbackBuffer(). ,
, : GL_2D GL_3D
, GL_3D_COLOR ,
GL_3D_COLOR_TEXTURE GL_4D_COLOR_TEXTURE ,
.
,
. ,
.
. ,
, ( ). 132 . , ,
, 13-1. ,
n. x, y z, ,
. w,
.
.
, GL_LINE_RESET_TOKEN ,
.
13-2.

GL_POINT_TOKEN

GL_LINE_TOKEN GL_LINE_RESET_TOKEN

GL_POLYGON_TOKEN

n ...

GL_BITMAP_TOKEN

GL_DRAW_PIXEL_TOKEN
GL_COPY_PIXEL_TOKEN

GL_PASS_THROUGH_TOKEN

13.2.2
, ,
glPolygonMode().
, , ,
( OpenGL ,
). , ,
, , .
,
glPassThrough(). ,
. ,
GL_PASS_THROUGH_TOKEN,
, .
void glPassThrough (GLfloat token);

, ,
. GL_PASS_THROUGH_TOKEN,
token.
, . glPassThrough()
glBegin() glEnd() GL_INVALID_OPERATION.

13.2.3
13-7 .
.
.
, GL_3D_COLOR,
RGBA, 7
: x, y, z, r, g, b a.
,
. (-100.0, -100.0, -100.0),
, ,
. ,
. , ,
13-4.
13-4.

13-7. : feedback.cpp
#include

#include
#include
void init()
{
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
}
void drawGeometry(GLenum mode)
{
glBegin(GL_LINE_STRIP);
glNormal3f(0.0,0.0,1.0);
glVertex3f(30.0,30.0,0.0);
glVertex3f(50.0,60.0,0.0);
glVertex3f(70.0,40.0,0.0);
glEnd();
if(mode==GL_FEEDBACK)
glPassThrough(1.0);
glBegin(GL_POINTS);
glVertex3f(-100.0,-100.0,-100.0); //
glEnd();
if(mode==GL_FEEDBACK)
glPassThrough(2.0);
glBegin(GL_POINTS);
glNormal3f(0.0,0.0,1.0);
glVertex3f(50.0,50.0,0.0);
glEnd();
glFlush();
}
void print3DcolorVertex(GLint size,GLint *count,GLfloat *buffer)
{
int i;
printf("
");
for(i=0;i<7;i++)
{
printf("%4.2f ",buffer[size-(*count)]);
*count=*count-1;
}
printf("\n");
}
void printBuffer(GLint size,GLfloat *buffer)
{
GLint count;
GLfloat token;
count=size;
while(count)
{
token=buffer[size-count];
count--;
if(token==GL_PASS_THROUGH_TOKEN)
{
printf("GL_PASS_THROUGH_TOKEN\n");
printf("
%4.2f\n",buffer[size-count]);

count--;
}
else
if(token==GL_POINT_TOKEN)
{
printf("GL_POINT_TOKEN\n");
print3DcolorVertex(size,&count,buffer);
}
else
if(token==GL_LINE_TOKEN)
{
printf("GL_LINE_TOKEN\n");
print3DcolorVertex(size,&count,buffer);
print3DcolorVertex(size,&count,buffer);
}
else
if(token==GL_LINE_RESET_TOKEN)
{
printf("GL_LINE_RESET_TOKEN\n");
print3DcolorVertex(size,&count,buffer);
print3DcolorVertex(size,&count,buffer);
}
}
}
void display()
{
GLfloat feedBuffer[1024];
GLint size;
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0.0,100.0,0.0,100.0,0.0,1.0);
glClearColor(0.0,0.0,0.0,0.0);
glClear(GL_COLOR_BUFFER_BIT);
drawGeometry(GL_RENDER);
glFeedbackBuffer(1024,GL_3D_COLOR,feedBuffer);
glRenderMode(GL_FEEDBACK);
drawGeometry(GL_FEEDBACK);
size=glRenderMode(GL_RENDER);
printBuffer(size,feedBuffer);
}
int main(int argc, char* argv[])
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
glutInitWindowSize(100,100);
glutInitWindowPosition(100,100);
glutCreateWindow("Feedback Mode");
init();
glutDisplayFunc(display);
glutMainLoop();
return 0;
}
:

GL_LINE_RESET_TOKEN
30.00 30.00 0.00 0.84
50.00 60.00 0.00 0.84
GL_LINE_RESET_TOKEN
50.00 60.00 0.00 0.84
70.00 40.00 0.00 0.84
GL_PASS_THROUGH_TOKEN
1.00
GL_PASS_THROUGH_TOKEN
2.00
GL_POINT_TOKEN
50.00 50.00 0.00 0.84

0.84 0.84 1.0


0.84 0.84 1.0
0.84 0.84 1.0
0.84 0.84 1.0

0.84 0.84 1.0

, , ,
:
glBegin(GL_LINE_STRIP);
glNormal3f(0.0,0.0,1.0);
glVertex3f(30.0,30.0,0.0);
glVertex3f(50.0,60.0,0.0);
glVertex3f(70.0,40.0,0.0);
glEnd();
GL_LINE_RESET_TOKEN. ,
, .
GL_LINE_TOKEN, ,
, , ,
. 7
. , RGBA
(0.84, 0.84, 0.84, 1.0),
.
.

, , ,
glPassThrough() .
, (50.0, 50.0, 0.0),
.
: ,
. , ,
- , ,
, ,
( ).

14.
, OpenGL,
.
,
.

14.1
, .

. (
100 , OpenGL,

?) OpenGL
OpenGL GLU.
OpenGL , . ,
,
OpenGL . (,
GL_OUT_OF_MEMORY,
.) ,
, glGetError(),
. ,
, glGetError()
GL_NO_ERROR.
GLenum glGetError (void);

. GL GLU,
.
GL_NO_ERROR, ,
glGetError() OpenGL.
, glGetError(),
, GL_NO_ERROR.
glGetError()
display() . OpenGL
14-1.
14-1. OpenGL

GL_INVALID_ENUM

GLenum

GL_INVALID_VALUE

GL_INVALID_OPERATION

GL_STACK_OVERFLOW

GL_STACK_UNDERFLOW

GL_OUT_OF_MEMORY

37 GLU NURBS (
GL_NURBS_ERROR1, GLU_NURBS_ERROR2
); 14 (GLU_TESS_MISSING_BEGIN_POLYGON,
GLU_TESS_MISSING_END_POLYGON, GLU_TESS_MISSING_BEGIN_CONTOUR,
GLU_TESS_MISSING_END_CONTOUR, GLU_TESS_COORD_TOO_LARGE,
GLU_TESS_NEED_COMBINE_CALLBACK, 8 ,
GLU_TESS_ERROR*); GLU_INCOMPATIBLE_GL_VERSION. GLU
GLU_INVALID_ENUM, GLU_INVALID_VALUE
GLU_OUT_OF_MEMORY, , OpenGL.
, GL GLU,
GLU gluErrorString().
const GLubyte* gluErrorString (GLenum errorCode);

, GL
GLU, errorCode.
14-1 .

14-1.
GLenum errCode;
const GLubyte *errString;
if ((errCode=glGetError())!=GL_NO_ERROR
{
errString=gluErrorString(errCode);
fsprintf(stderr,OpenGL error: %s\n, errString);
}
: ,
gluErrorString().

14.2
OpenGL
. OpenGL
, , ,

OpenGL. , ,
OpenGL.

. OpenGL
glGetString().
const GLubyte* glGetString (GLenum name);

, OpenGL.
name GL_VENDOR, GL_RENDERER, GL_VERSION
GL_EXTENSIONS. GL_VENDOR ,
OpenGL, :
NVIDIA Corporation

GL_RENDERER ,
, :
Voodoo550/AGP

GeForce4 Ti 4600/AGP/SSE2

GL_EXTENSIONS .
GL_VERSION ,
OpenGL. :
< ><><, >


major_number.minor_number


major_number.minor_number.release_number

. ,
, . , OpenGL
XYZ, :
1.2.4 XYZ-OS 3.2

, OpenGL XYZ,
OpenGL 1.2. ,
- 3.2.
OpenGL
#ifdef
GL_VERSION_1_3, GL_VERSION_1_2 GL_VERSION_1_1.
GL_VERSION_1_3 , GL_VERSION_1_2, GL_VERSION_1_1
GL_VERSION_1_0. GL_VERSION_1_2 ,
GL_VERSION_1_1 GL_VERSION_1_0 .
: ,
OpenGL , (
) . ,
OpenGL 1.3,
Microsoft
, OpenGL
1.1. , glGetString(GL_VERSION)

OpenGL, , #ifndef
,
gl.h.
: (, OpenGL
X Window) .
, ,
, .

14.2.1 GLU
gluGetString() GLU
glGetString().
const GLubyte* gluGetString (GLenum name);

, GLU.
name GLU_VERSION GLU_EXTENSIONS.
, gluGetString() GLU 1.0.
GLU ( ,
)
#ifndef GLU_VERSION_1_3,
GLU_VERSION_1_2, GLU_VERSION_1_1 GLU_VERSION_1_0
GL.
, GLU OpenGL.

14.2.2
, OpenGL,
GLX, WGL, PGL AGL (,
glXQueryExtensionString()), .
( glXQueryExtensionString() GLX 1.1
GLX1.0)

14.3
OpenGL ,
, .

.
,
OpenGL,
OpenGL OpenGL ARB (Architecture Review
Board ).
, ,
( )
(, ). , XYZ
, glCommandXYZ()
GL_DEFINITION_XYZ, . XYZ
(Special Developed)
, glCommandXYZsd() GL_DEFINITION_XYZ_SD.
,
EXT (glCommandEXT()
GL_DEFINITION_EXT).
, OpenGL ARB,
ARB (glCommandARB() GL_DEFINITION_ARB).
,
, glGetString() GL_EXTENSIONS,
gluGetString() GLU_EXTENSIONS.
, .
.
ARB OpenGL 1.2.

(Imaging Subset),
GL_ARB_imaging. GL_ARB_multitexture ,
, ARB.
GLU 1.3 ,
gluCheckExtension() ,
.
GLboolean gluCheckExtension (char* extName, const GLubyte* extString);

GL_TRUE, extName extString, GL_FALSE


.

gluCheckExtension() OpenGL, GLX, GLU.


GLU
, 14-2,
. QueryExtension()
GL_TRUE, GL_FALSE .
14-2. (
GLU 1.0, 1.1 1.2)
GLboolean QueryExtension(char *extName)
{
char *p=(char*)glGetString(GL_EXTENSIONS);
char *end;
if(p==NULL)
return GL_FALSE;
end=p+strlen(p);
while(p<end)
{
int n=strcspn(p," ");
if((strlen(extName)==n) && (strncmp(extName,p,n)==0))
return GL_TRUE;
p+=(n+1);
}
return GL_FALSE;
}

14.3.1 Microsoft Windows (WGL)


Microsoft Windows
, :

, ,

wglProcAddress()
.

14-3
glSpecialEXT(). , (#ifndef)
GL_EXT_special. ,
PFNGLSPECIALEXTPROC. ,
wglGetProcAddress() .
14-3. OpenGL wglGetProcAddress()
#ifdef GL_EXT_special
PFNGLSPECIALEXTPROC glSpecialEXT;
#endif
/* - */
#ifdef GL_EXT_special
glSpecialEXT=(
PFNGLSPECIALEXTPROC)wglGetProcAddress(glSpecialEXT);
assert(glSpecialEXT!=NULL);
#endif

14.4
,
. ,
.
32 32 1024 ,
1023 (
). , , 29 ,
, 29 ( 297 )
0, 1.
, ,
.
, , 0,
.
, ,
, ,
. ,

.
,
.

14.5
, , .
,
(
).
, , .
, , 16
. 16 :
GLubyte stips[16][4*32];

,
1/16 32x32 ,
. :
_();
glColor3f(0.0,0.0,0.0);
/* */
for(i=0;i<16;i++)
{
glPolygonStipple(&stips[i][0]);
_____();
}
OpenGL ,
.
, :
#define STIP_OFFSET 100
for(i=0;i<16;i++)
{
glNewList(i+STIP_OFFSET,GL_COMPILE);
glPolygonStipple(&stips[i][0]);
glEndList();

}

glPolygonStipple(&stips[i][0]);

glCallList(i);

, OpenGL
stips[ ][ ] - ,
.
. ,
, ,
. ,
, , ,
. , -
16 , (
). :
current_stipple=0;
while(1)
/* */
{
__();
glCallList(current_stipple)++;
if(current_stipple==16)
current_stipple=0;
glColor3f(0.0,0.0,0.0);
/*
*/
_____();
}
1/16 . ,
16 , . ,
,

.

14.6
OpenGL ,
. :
, ;
.
,
. ,
,
, .

.
,
, ,
.

, ,
, ,
.
,
( )
.
. RGBA
R, G B.
, ,
. , ,
4- (16 )
, .
, .
, , 4096 ,
12 .
, 4-
, , ,
4- .
, , ,
.
,
. , , 4 ,
15/16 ,
1/16 .
255/256 . ,
, ,
16 256 , .
, ,
,
(, ). ,
RGBA
. , .

14.7
(,
, , ,
), .
, ,
.
, glPixelZoom().
,
.
, ,
, .
,
m n , [0,m-1] [0,n-1].
x(m,n) y(m,n). ,
3.2, x(m,n)=3.2m, y(m,n)=3.2n.
:
glShadeModel(GL_FLAT);
glScale(3.2,3.2,1.0);

for(j=0;j<n;j++)
{
glBegin(GL_QUAD_STRIP);
for(i=0;i<=m;i++)
{
glVertex2i(i,j);
glVertex2i(i,j+1);
set_color(i,j);
}
glEnd();
}
,
3.2. set_color()
, .
,
x(i,j) y(i,j):
glShadeModel(GL_FLAT);
glScale(3.2,3.2,1.0);
for(j=0;j<n;j++)
{
glBegin(GL_QUAD_STRIP);
for(i=0;i<=m;i++)
{
glVertex2i(x(i,j), y(i,j));
glVertex2i(x(i,j+1), y(i,j+1));
set_color(i,j);
}
glEnd();
}

:
glShadeModel(GL_SMOOTH);
glScale(3.2,3.2,1.0);
for(j=0;j<n-1;j++)
{
glBegin(GL_QUAD_STRIP);
for(i=0;i<m;i++)
{
set_color(i,j);
glVertex2i(x(i,j), y(i,j));
set_color(i,j+1);
glVertex2i(x(i,j+1), y(i,j+1));
}
glEnd();
}
. ,
,
. ,

(GL_SRC_ALPHA, GL_ONE),
.

14.8

(, )
,
.
, , ,
.
, 14-2.
14-2.
1

, 8 ,
.
14-2. ,
: 0
, 1 , 2 . ,
0 7 , 4 ,
3, 2 , 2, 1 ,
1.
, 7 ( ), 0.
, 7, n, n
, .
.
, , 7, 0.

14.9

glBitmap() --
, . ,
, , ,
.
( .)
, ,
,
, 14-1 .
14-1.

,
,
,
,
. ,
.
,
, .
RGBA, 32
1 .
8- RGBA
.
,
, 2 3
.
14-1
: 0 , 1
, 2 3 . ,
0 , , 3 ,
1 2 33% 66% , ,
. 0, 1, 2 3
2 , 2 4 .
,
, RGBA
.
RGBA ,
1, 2 3. .
33% (RGB=(0.666, 0.666, 0.666)) ,
1 ( ).
RGB=(0.333, 0.333, 0.333) . ,
.
,
.

,
,
. ,
, , 1 3.
, 2 3.
, 0 , 1 -, 2 -, 3
. 3, 1 .
2 . , 14-1 0,
. , 1, 2 3,
1, 2 3.
4-
. 8 4, RGBA 7
, . 16 15
4.

14.10
,
, (
),
0.5.

14.11
, (
), ,
.
. ,
10 , A
0, B 9.
, i- A (9-i)/9,
B i/9.
,
. A 0.
1 1/9 B 8/9 ,
. 2 1/8 B
7/8 . 3 1/7 B 6/7
. 1/1
B 0/1 ,
B.
, , , i

B/(9-i) (8-i)/(9-i) . :

14.12

,
. , ,
, A B.
B - ,
A.
, , B A,
,
, (GL_GEQUAL).
,
, B
A, . :
1.
2.
3.
4.

A.
B.
A.
.

,
. 1 A , ,
; , 2
B. 3 , A
, , ,
. , 4
( ).
, .
1. , 1
0 . A.
2. ,
, 1.
. B.
-
,
( , A)
A.
, .

14.13

1234567, 14-2. ,
: 123, 134, 145, 156 167.
.
9 A, B, C, ..., I, I
.
14-2.

,
. A, D F ;
, .
( ) .
, , ,
.
.
. ,

GL_INVERT. ( GL_TRIANGLE_FAN.)
, ,
, . ,
, , ,
.
. ,
( ),
, .
: ,
. 1234567 P
, .
P12, P23, P34, P45, P56, P67 P71. ,
, ,
. P ,
.
(,
) .

. , ,
(
). abcd efghi, jkl mnop. z
. :
zab zbc zcd zda zef zfg zgh zhi zie zjk zkl zlj zmn zno zop zpm

, ,
, .

14.14
- ,
, , ,
.
( , ).
,

. , , ,
.
, ,
,
, .

;
.
. ,
,
,
. (
,
.) ,
,
;
.
,
, ,
( ).
,

.
.
, ,
, .
,
;
, ; ,
. ,
, 1-
, 2- 4- .
, 1- ( 1
0), 1- , 1 ,
GL_INVERT.
,
. , 2
1 2, 2 -
,
. , 1,
2 . , 1
2. , , .


, 3 (
1, 2). .

14.15

4x4
. , 3,
.
4x4, 3.
(,
) , ,
,
. ,
, .
, ,
, ax+by+cz+d=0.
S=(sx, sy, sz, 1). , S,
,
-- . ,

, , :

.
, :

I
, ,
.
, S I S, :

,
, .
, , ,
S D=(dx, dy, dz).

, ,
.

,
, ,

.
,
- -.

14.16
,
, ,
,
.
, ,
. ,
;
(
).
,
, . ,
, , , .
, ,
.

14.16.1

,
.
GL_LINE.
GL_FILL , ,
.
.
glEnable(GL_DEPTH_TEST);
glPolygonMode(GL_FRONT_AND_BACK,GL_LINE);
_(_);

_____();
glPolygonMode(GL_FRONT_AND_BACK,GL_FILL);
glEnable(GL_POLYGON_OFFSET_FILL);
glPolygonOffset(1.0,1.0);
_();
_____();
glDisable(GL_POLYGON_OFFSET_FILL);
( ,
).

14.16.2


. ,
, . ,
, ,
- .
, 0 .

.
, ,
.
, ,
.
.

.
glEnable(GL_STENCIL_TEST);
glEnable(GL_DEPTH_TEST);
glClear(GL_STENCIL_BUFFER_BIT);
glStencilFunc(GL_ALWAYS,0,1);
glStencilOp(GL_INVERT,GL_INVERT,GL_INVERT);
_(_);
for(i=0;i<max;i++)
{
__(i);
_();
glStencilFunc(GL_EQUAL,0,1);
glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
__(i);
_(_);
glStencilFunc(GL_ALWAYS,0,1);
glStencilOp(GL_INVERT,GL_INVERT,GL_INVERT);
__(i);
}

14.17
,
.
.



() .
(,
).
, :
.

, ,
.
,
, (
).
.

, .

14.18 ,
,
, ,
, .

, ,
, .
, ,
.
, .
, , ,
(
),
-
OpenGL . ,
, .
,
glDrawPixels().
, 0,
, ,
, .
,
( ) ,
, 1.
,
.
,
;
GL_DEPTH_BIAS glPixelTransfer*().

14.19
S , (
) A S ,
A, S.

. 14-3.

14-3.

S
, S,
.

, .
( )
. ,
, : ,
, .
,
,
.
,
,
. , ,
.

14.20
(Game of Life) ,
, .
,
( 8 ).
n+1, n
. n+1, n
.
n+1.
. 14-4 6 .
14-4. 6

OpenGL
.
. , ( ), ,
( ).
, 0,
, ,
. ,
,
, ,
.
.
, 8 ,
, . ,
,
. ,
, ,
, 3 (
). , ,
. ,
, 3 .
0, 1, 2, 4, 5, 6, 7 8.
0, 1, 4, 5, 6, 7 8 .
,
, 2,

.
. .
, , , ,
, , ,
.

14.21 glDrawPixels()
glCopyPixels()
, glDrawPixels()
. ,
, .
,
,
glDrawPixels() .
, ,
, ,
, 100x100 ( ).

. .
- ,
glDrawPixels().
, . ,
(1-)
. ,

. 1,
.

, ,
OpenGL .
,

.
.

glCopyPixels() XOR.
.
A B 2 , :
a. A=A XOR B
b. B=A XOR B
c. A=A XOR B

A.
OpenGL,
, ,
.

,
( glGetIntegerv() glIsEnabled()),
.
.
,
, .
void glGetClipPlane (GLenum plane, GLdouble *equation);
void glGetColorTable (GLenum target, GLenum pname, GLenum type,
GLvoid *table);
void glGetColorTableParameter{if}v (GLenum target, GLenum pname, TYPE
*params);
void glGetConvolutionFilter (GLenum target, GLenum format, GLenum
type, GLvoid *image);
void glGetConvolutionParameter{if}v (GLenum target, GLenum pname,
TYPE *params);
GLenum glGetError (void);
void glGetHistogram (GLenum target, GLboolean reset, GLenum format,
GLenum type, GLvoid *values);
void glGetHistogramParameter{if}v (GLenum target, GLenum pname, TYPE
*params);
void glGetLight{if}v (GLenum light, GLenum pname, TYPE *params);
void glGetMap{ifd}v (GLenum target, GLenum query, TYPE *v);
void glGetMaterial{if}v (GLenum face, GLenum pname, TYPE *params);
void glGetMinmax (GLenum target, GLboolean reset, GLenum format,
GLenum type, GLvoid *values);
void glGetMinmaxParameter{if}v (GLenum target, GLenum pname, TYPE
**params);
void glGetPixelMap {f ui us}v (GLenum map, TYPE *values);
void glGetPolygonStipple (GLubyte *mask);
void glGetSeparableFilter (GLenum target, GLenum format, GLenum type,
GLvoid *row, GLvoid *column, GLvoid *span);
const GLubyte* glGetString (GLenum name);
void glGetTexEnv{if}v (GLenum target, GLenum pname, TYPE *params);
void glGetTexGen{ifd}v (GLenum coord, GLenum pname, TYPE *params);
void glGetTexImage (GLenum target, GLint level, GLenum format, GLenum
type, GLvoid *pixels);
void glGetTexLevelParameter{if}v (GLenum target, GLint level, GLenum
pname, TYPE *params);
void glGetTexParameter{if}v (GLenum target, GLenum pname, TYPE
*params);
GLboolean glIsList (GLuint list);
GLboolean glIsTexture (GLuint texObject);
void gluGetNurbsProperty (GLUnurbsObj *nobj, GLenum property, GLfloat
*value);
const GLubyte* gluGetString (GLenum name);
void gluGetTessProperty (GLUtesselator *tess, GLenum which, GLdouble
*data);

OpenGL
,
. , ,
, ,
glGet*().
,
glGetBooleanv(), glGetIntegerv(), glGetFloatv() glDoublev()
,
. ( ,
glGetPointerv().)

glIsEnabled().
, glIsEnabled() ,
glBooleanv(), glGetIntegerv(),
glGetFloatv() glDoublev(). ,
,
.
: , ,
GL_TEXTURE_MATRIX, OpenGL,
GL_ARB_multitexture, ,
.
, ,
.
.
,
, glPushAttrib(),
glPopAttrib(), glPushClientAttrib() glPopClientAttrib().
, ,
, , .
A-1.

GL_CURRENT_COLOR

(1,1,1,1)

glGetIntegerv(),
glGetFloatv()

GL_CURRENT_INDEX

glGetIntegerv(),
glGetFloatv()

GL_CURRENT_TEXTURE_COORDS

(0,0,0,1)

glGetFloatv()

GL_CURRENT_NORMAL

(0,0,1)

glGetFloatv()

GL_CURRENT_RASTER_POSITION

(0,0,0,1)

glGetFloatv()

GL_CURRENT_RASTER_DISTANCE

glGetFloatv()

GL_CURRENT_RASTER_COLOR

(1,1,1,1)

glGetIntegerv(),
glGetFloatv()

GL_CURRENT_RASTER_INDEX

glGetIntegerv(),
glGetFloatv()

GL_CURRENT_RASTER_TEXTURE_COORDS

(0,0,0,1)

glGetFloatv()

GL_CURRENT_RASTER_POSITION_VALID

GL_TRUE

glGetBooleanv()

GL_EDGE_FLAG

(
)

GL_TRUE

glGetBooleanv()

A-2.

GL_VERTEX_ARRAY

GL_FALSE

glIsEnabled()

GL_VERTEX_ARRAY_SIZE

glGetIntegerv()

GL_VERTEX_ARRAY_TYPE

GL_FLOAT

glGetIntegerv()

GL_VERTEX_ARRAY_STRIDE

glGetIntegerv()

GL_VERTEX_ARRAY_POINTER

NULL

glGetPointerv()

GL_NORMAL_ARRAY

GL_FALSE

glIsEnabled()

GL_NORMAL_ARRAY_TYPE

GL_FLOAT

glGetIntegerv()

GL_NORMAL_ARRAY_STRIDE

glGetIntegerv()

GL_NORMAL_ARRAY_POINTER

NULL

glGetPointerv()

GL_COLOR_ARRAY


RGBA

GL_FALSE

glIsEnabled()

GL_COLOR_ARRAY_SIZE

glGetIntegerv()

GL_COLOR_ARRAY_TYPE

GL_FLOAT

glGetIntegerv()

GL_COLOR_ARRAY_STRIDE

glGetIntegerv()

GL_COLOR_ARRAY_POINTER

NULL

glGetPointerv()

GL_INDEX_ARRAY

GL_FALSE

glIsEnabled()

GL_INDEX_ARRAY_TYPE

GL_FLOAT

glGetIntegerv()

GL_INDEX_ARRAY_STRIDE

glGetIntegerv()

GL_INDEX_ARRAY_POINTER

NULL

glGetPointerv()

GL_TEXTURE_COORD_ARRAY

GL_FALSE

glIsEnabled()

GL_TEXTURE_COORD_ARRAY_SIZE

glGetIntegerv()

GL_TEXTURE_COORD_ARRAY_TYPE

GL_FLOAT

glGetIntegerv()

GL_TEXTURE_COORD_ARRAY_STRIDE

glGetIntegerv()

GL_TEXTURE_COORD_ARRAY_POINTER

NULL

glGetPointerv()

GL_EDGE_FLAG_ARRAY

GL_FALSE

glIsEnabled()

GL_EDGE_FLAG_ARRAY_STRIDE

glGetIntegerv()

GL_EDGE_FLAG_ARRAY_POINTER

NULL

glGetPointerv()

GL_CLIENT_ACTIVE_TEXTURE_ARB

GL_TEXTURE0_
ARB

glGetIntegerv()

A-3.

GL_COLOR_MATRIX

glGetFloatv()

GL_MODELVIEW_MATRIX

glGetFloatv()

GL_PROJECTION_MATRIX

glGetFloatv()

GL_TEXTURE_MATRIX

glGetFloatv()

GL_VIEWPORT

glGetIntegerv()

GL_DEPTH_RANGE

0, 1

glGetFloatv()

GL_COLOR_STACK_DEPTH

glGetIntegerv()

GL_MODELVIEW_STACK_DEPTH

glGetIntegerv()

GL_PROJECTION_STACK_DEPTH

glGetIntegerv()

GL_TEXTURE_STACK_DEPTH

glGetIntegerv()

GL_MATRIX_MODE

GL_MODELVIEW

glGetIntegerv()

GL_NORMALIZE

GL_FALSE

glIsEnabled()

GL_RESCALE_NORMAL

GL_FALSE

glIsEnabled()

GL_GET_CLIP_PLANEi

i-

(0,0,0,0)

glGetClipPlane()

GL_GET_CLIP_PLANEi

i-

GL_FALSE

glIsEnabled()

A-4.

GL_FOG_COLOR

(0,0,0,0)

glGetFloatv()

GL_FOG_INDEX

glGetFloatv()

GL_FOG_DENSITY

1.0

glGetFloatv()

GL_FOG_START

0.0

glGetFloatv()

GL_FOG_END

1.0

glGetFloatv()

GL_FOG_MODE

GL_EXP

glGetIntegerv()

GL_FOG

GL_FALSE

glIsEnabled()

GL_SHADE_MODEL

GL_SMOOTH

glGetIntegerv()

A-5.

GL_LIGHTING

GL_FALSE

glIsEnabled()

GL_COLOR_MATERIAL

GL_FALSE

glIsEnabled()

GL_COLOR_MATERIAL_PARAMETER

GL_AMBIENT_
AND_DIFFUSE

glGetIntegerv()

GL_COLOR_MATERIAL_FACE

GL_FRONT_
AND_BACK

glGetIntegerv()

GL_AMBIENT

(0.2,0.2,0.2,1.0)

glGetMaterialfv()

GL_DIFFUSE

(0.8,0.8,0.8,1.0)

glGetMaterialfv()

GL_SPECULAR

(0.0,0.0,0.0,1.0)

glGetMaterialfv()

GL_EMISSION

(0.0,0.0,0.0,1.0)

glGetMaterialfv()

GL_SHININESS

0.0

glGetMaterialfv()

GL_LIGHT_MODEL_AMBIENT

(0.2,0.2,0.2,1.0)

glGetFloatv()

GL_LIGHT_MODEL_LOCAL_VIEWER

GL_FALSE

glGetBooleanv()

GL_LIGHT_MODEL_TWO_SIZE

GL_FALSE

glGetBooleanv()

GL_LIGHT_MODEL_COLOR_CONTROL

GL_SINGLE_
COLOR

glGetIntegerv()

GL_AMBIENT

(0.0,0.0,0.0,1.0)

glGetLightfv()

GL_DIFFUSE

glGetLightfv()

GL_SPECULAR

glGetLightfv()

GL_POSITION

(0.0,0.0,1.0,0.0)

glGetLightfv()

GL_CONSTANT_ATTENUATION

1.0

glGetLightfv()

GL_LINEAR_ATTENUATION

0.0

glGetLightfv()

GL_QUDRATIC_ATTENUATION

0.0

glGetLightfv()

GL_SPOT_DIRECTION

(0.0,0.0,-1.0)

glGetLightfv()

GL_SPOT_EXPONENT

0.0

glGetLightfv()

GL_SPOT_CUTOFF

180.0

glGetLightfv()

GL_LIGHTi

GL_FALSE

glIsEnabled()

GL_COLOR_INDEXES

0,1,1

glGetMaterialfv()

A-6.

GL_POINT_SIZE

1.0

glGetFloatv()

GL_POINT_SMOOTH

GL_FALSE

glIsEnabled()

GL_LINE_WIDTH

1.0

glGetFloatv()

GL_LINE_SMOOTH

GL_FALSE

glIsEnabled()


GL_LINE_STIPPLE_PATTERN

glGetIntegerv()

GL_LINE_STIPPLE_REPEAT

glGetIntegerv()

GL_LINE_STIPPLE

GL_FALSE

glIsEnabled()

GL_CULL_FACE

GL_FALSE

glIsEnabled()

GL_CULL_FACE_MODE

GL_BACK

glGetIntegerv()

GL_FRONT_FACE

GL_CCW

glGetIntegerv()

GL_POLYGON_SMOOTH

GL_FALSE

glIsEnabled()

GL_POLYGON_MODE

GL_FILL

glGetIntegerv()

GL_POLYGON_OFFSET_FACTOR

glGetFloatv()

GL_POLYGON_OFFSET_BIAS

glGetFloatv()

GL_POLYGON_OFFSET_POINT

GL_FALSE

glIsEnabled()

GL_POLYGON_OFFSET_LINE

GL_FALSE

glIsEnabled()

GL_POLYGON_OFFSET_FILL

GL_FALSE

glIsEnabled()

GL_POLYGON_STIPPLE

GL_FALSE

glIsEnabled()

glGetPolygonStipple()

A-7.

GL_TEXTURE_x

GL_FALSE

glIsEnabled()

GL_TEXTURE_BINDING_x


GL_TEXTURE_x
( x 1D, 2D
3D)

GL_FALSE

glGetIntegerv()

GL_TEXTURE

x-D
i

glGetTexImage()

GL_TEXTURE_WIDTH

i-

glGetTexLevelParameter
*()

x-D
GL_TEXTURE_HEIGHT

i-

x-D

glGetTexLevelParameter
*()

GL_TEXTURE_DEPTH

i-

x-D

glGetTexLevelParameter
*()

GL_TEXTURE_BORDER

i-

x-D

glGetTexLevelParameter
*()

GL_TEXTURE_INTERNAL_FOR
MAT

i-

x-D

glGetTexLevelParameter
*()

GL_TEXTURE_RED_SIZE

x-D

glGetTexLevelParameter
*()

GL_TEXTURE_GREEN_SIZE

x-D

glGetTexLevelParameter
*()

GL_TEXTURE_BLUE_SIZE

x-D

glGetTexLevelParameter
*()

GL_TEXTURE_ALPHA_SIZE

x-D

glGetTexLevelParameter
*()

GL_TEXTURE_LUMINANCE_SI
ZE

i-

x-D

glGetTexLevelParameter
*()

GL_TEXTURE_INTENSITY_SIZ
E

i-

x-D

glGetTexLevelParameter
*()

GL_TEXTURE_BORDER_COLO
R

(0,0,0,0)

glGetTexParameter*()

GL_TEXTURE_MIN_FILTER

GL_NEAREST
_ MIPMAP_
LINEAR

glGetTexParameter*()

GL_TEXTURE_MAG_FILTER

GL_LINEAR

glGetTexParameter*()

GL_TEXTURE_WRAP_x

(
x S, T R)

GL_REPEAT

glGetTexParameter*()

GL_TEXTURE_PRIORITY

glGetTexParameter*()

GL_TEXTURE_RESIDENT

glGetTexParameterfv()

GL_TEXTURE_MIN_LOD

-1000

glGetTexParameterfv()

GL_TEXTURE_MAX_LOD

1000

glGetTexParameterfv()

GL_TEXTURE_BASE_LEVEL

glGetTexParameterfv()

GL_TEXTURE_MAX_LEVEL

1000

glGetTexParameterfv()

GL_TEXTURE_ENV_MODE

GL_MODULAT
E

glGetTexEnviv()

GL_TEXTURE_ENV_COLOR

(0,0,0,0)

glGetTexEnvfv()

GL_TEXTURE_GEN_x


(
x S, T R)

GL_FALSE

glIsEnabled()

GL_EYE_PLANE

glGetTexGenfv()

GL_OBJECT_PLANE

glGetTexGenfv()

GL_TEXTURE_GEN_MODE

GL_EYE_
LINEAR

glGetTexGeniv()

GL_ACTIVE_TEXTURE_ARB

GL_TEXTURE
0_ ARB

glGetIntegerv()

A-8.

GL_SCISSOR_TEST

GL_FALSE

glIsEnabled()

GL_SCISSOR_BOX

glGetIntegerv()

GL_ALPHA_TEST

GL_FALSE

glIsEnabled()

GL_ALPHA_TEST_FUNC

GL_ALWAYS

glGetIntegerv()

GL_ALPHA_TEST_REF

glGetIntegerv()

GL_STENCIL_TEST

GL_FALSE

glIsEnabled()

GL_STENCIL_FUNC

GL_ALWAYS

glGetIntegerv()

GL_STENCIL_VALUE_MASK

glGetIntegerv()

GL_STENCIL_REF

glGetIntegerv()

GL_STENCIL_FAIL

GL_KEEP

glGetIntegerv()

GL_STENCIL_PASS_DEPTH_FAIL

GL_KEEP

glGetIntegerv()

GL_STENCIL_PASS_DEPTH_PASS

GL_KEEP

glGetIntegerv()

GL_DEPTH_TEST

GL_FALSE

glIsEnabled()

GL_DEPTH_FUNC

GL_LESS

glGetIntegerv()

GL_BLEND

GL_FALSE

glIsEnabled()

GL_BLEND_SRC

GL_ONE

glGetIntegerv()

GL_BLEND_DST

GL_ZERO

glGetIntegerv()

GL_BLEND_EQUATION

GL_FUNC_ADD

glGetIntegerv()

GL_BLEND_COLOR

(0,0,0,0)

glGetFloatv()

GL_DITHER

GL_TRUE

glIsEnabled()

GL_INDEX_LOGIC_OP

GL_FALSE

glIsEnabled()

GL_COLOR_LOGIC_OP


RGBA

GL_FALSE

glIsEnabled()

GL_LOGIC_OP_MODE

GL_COPY

glGetIntegerv()

A-9.

GL_DRAW_BUFFER

glGetIntegerv()

GL_INDEX_WRITEMASK

glGetIntegerv()

GL_COLOR_WRITEMASK

RGBA

GL_TRUE

glGetBooleanv()

GL_DEPTH_WRITEMASK

GL_TRUE

glGetBooleanv()

GL_STENCIL_WRITEMASK

glGetIntegerv()

GL_COLOR_CLEAR_VALUE

(RGBA)

(0,0,0,0)

glGetFloat()

GL_INDEX_CLEAR_VALUE


()

glGetFloat()

GL_DEPTH_CLEAR_VALUE

glGetIntegerv()

GL_STENCIL_CLEAR_VALUE

glGetIntegerv()

GL_ACCUM_CLEAR_VALUE

glGetFloat()

A-10.

GL_UNPACK_SWAP_BYTES


GL_UNPACK_SWAP_BY
TES

GL_FALSE

glGetBooleanv()

GL_UNPACK_LSB_FIRST


GL_UNPACK_LSB_FIRS
T

GL_FALSE

glGetBooleanv()

GL_UNPACK_IMAGE_HEIGHT


GL_UNPACK_IMAGE_H
EIGHT

glGetIntegerv()

GL_UNPACK_SKIP_IMAGES


GL_UNPACK_SKIP_IMA
GES

glGetIntegerv()

GL_UNPACK_ROW_LENGTH


GL_UNPACK_ROW_LEN
GTH

glGetIntegerv()

GL_UNPACK_SKIP_ROWS


GL_UNPACK_SKIP_RO
WS

glGetIntegerv()

GL_UNPACK_SKIP_PIXELS


GL_UNPACK_SKIP_PIX
ELS

glGetIntegerv()

GL_UNPACK_ALIGNMENT


GL_UNPACK_ALIGNME
NT

glGetIntegerv()

GL_PACK_SWAP_BYTES


GL_PACK_SWAP_BYTE
S

GL_FALSE

glGetBooleanv()

GL_PACK_LSB_FIRST


GL_PACK_LSB_FIRST

GL_FALSE

glGetBooleanv()

GL_PACK_IMAGE_HEIGHT


GL_PACK_IMAGE_HEI
GHT

glGetIntegerv()

GL_PACK_SKIP_IMAGES


GL_PACK_SKIP_IMAGE
S

glGetIntegerv()

GL_PACK_ROW_LENGTH


GL_PACK_ROW_LENGT
H

glGetIntegerv()

GL_PACK_SKIP_ROWS


GL_PACK_SKIP_ROWS

glGetIntegerv()

GL_PACK_SKIP_PIXELS


GL_PACK_SKIP_PIXEL
S

glGetIntegerv()

GL_PACK_ALIGNMENT


GL_PACK_ALIGNMENT

glGetIntegerv()

GL_MAP_COLOR

GL_FALSE

glGetBooleanv()

GL_MAP_STENCIL

GL_FALSE

glGetBooleanv()


GL_INDEX_SHIFT


GL_INDEX_SHIFT

glGetIntegerv()

GL_INDEX_OFFSET


GL_INDEX_OFFSET

glGetIntegerv()

GL_x_SCALE


GL_x_SCALE ( x
RED, GREEN, BLUE
ALPHA)

glGetFloatv()

GL_x_BIAS


GL_x_BIAS ( x
RED, GREEN, BLUE
ALPHA)

glGetFloatv()

GL_COLOR_TABLE

GL_FALSE

glIsEnabled()

GL_POST_CONVOLUTION_COLOR
_TABLE

GL_FALSE

glIsEnabled()

GL_POST_COLOR_MATRIX_COLO
R_TABLE

GL_FALSE

glIsEnabled()

GL_COLOR_TABLE

glGetColorTable()

GL_COLOR_TABLE_FORMAT

GL_RGBA

glGetColorTableParamet
eriv()

GL_COLOR_TABLE_WIDTH

glGetColorTableParamet
eriv()

GL_COLOR_TABLE_x_SIZE



( x RED,
GREEN, BLUE, ALPHA,
LUMINANCE
INTENSITY)

glGetColorTableParamet
eriv()

GL_COLOR_TABLE_SCALE

(1,1,1,1)

glGetColorTableParamet
eriv()

GL_COLOR_TABLE_BIAS

(0,0,0,0)

glGetColorTableParamet
eriv()

GL_CONVOLUTION_1D

1D

GL_FALSE

glIsEnabled()

GL_CONVOLUTION_2D

2D

GL_FALSE

glIsEnabled()

GL_SEPARABLE_2D

2D

GL_FALSE

glIsEnabled()

GL_CONVOLUTION_1D

1D

glGetConvolutionFilter()

GL_CONVOLUTION_2D

2D

glGetConvolutionFilter()

GL_SEPARABLE_2D

2D

glGetSeparableFilter()

GL_CONVOLUTION_BORDER_COL
OR

(0,0,0,0)

glGetConvolutionParame
terfv()

GL_CONVOLUTION_BORDER_MO
DE

GL_REDUCE

glGetConvolutionParame
teriv()

GL_CONVOLUTION_FILTER_SCAL
E

(1,1,1,1)

glGetConvolutionParame
terfv()

GL_CONVOLUTION_FILTER_BIAS

(0,0,0,0)

glGetConvolutionParame
terfv()

GL_CONVOLUTION_FORMAT

GL_RGBA

glGetConvolutionParame
teriv()

GL_CONVOLUTION_WIDTH

glGetConvolutionParame
teriv()

GL_CONVOLUTION_HEIGHT

glGetConvolutionParame
teriv()

GL_POST_CONVOLUTION_x_SCA
LE


( x RED,

glGetFloatv()

GREEN, BLUE
ALPHA)
GL_POST_CONVOLUTION_x_BIAS


( x RED,
GREEN, BLUE
ALPHA)

glGetFloatv()

GL_POST_COLOR_MATRIX_x_SC
ALE


( x RED,
GREEN, BLUE
ALPHA)

glGetFloatv()

GL_POST_COLOR_MATRIX_x_BIA
S


( x RED, GREEN,
BLUE ALPHA)

glGetFloatv()

GL_HISTOGRAM

GL_FALSE

glIsEnabled()

GL_HISTOGRAM

glGetHistogram()

GL_HISTOGRAM_WIDTH

glGetHistogramParamete
riv()

GL_HISTOGRAM_FORMAT

GL_RGBA

glGetHistogramParamete
riv()

GL_HISTOGRAM_x_SIZE

( x
RED, GREEN, BLUE,
ALPHA
LUMINANCE)

glGetHistogramParamete
riv()

GL_HISTOGRAM_SINK

GL_FALSE

glGetHistogramParamete
riv()

GL_MINMAX

GL_FALSE

glIsEnabled()

glGetMinmax()

GL_MINMAX

GL_MINMAX_FORMAT

GL_RGBA

glGetMinmaxParameteri
v()

GL_MINMAX_SINK

GL_FALSE

glGetMinmaxParameteri
v()

GL_ZOOM_X

1.0

glGetFloatv()

GL_ZOOM_Y

1.0

glGetFloatv()

GL_PIXEL_MAP_x

glGetPixelMap*()

GL_PIXEL_MAP_x_SIZE

glGetIntegerv()

GL_READ_BUFFER

glGetIntegerv()

A-11.

GL_ORDER

1D

glGetMapiv()

GL_ORDER

2D

1,1

glGetMapiv()


GL_COEFF

1D

glGetMapfv()

GL_COEFF

2D

glGetMapfv()

GL_DOMAIN

1D

glGetMapfv()

GL_DOMAIN

2D

glGetMapfv()

GL_MAP1_x

1D
( x
)

GL_FALSE

glIsEnabled()

GL_MAP2_x

2D
( x
)

GL_FALSE

glIsEnabled()

GL_MAP1_GRID_DOMAIN

1D

0,1

glGetFloatv()

GL_MAP2_GRID_DOMAIN

2D

0,1;0,1

glGetFloatv()

GL_MAP1_GRID_SEGMENTS

1D

glGetFloatv()

GL_MAP2_GRID_ SEGMENTS

2D

1,1

glGetFloatv()

GL_AUTO_NORMAL

GL_FALSE

glIsEnabled()

GL_PERSPECTIVE_CORRECTION_HI
NT

GL_DONT_CAR
E

glGetIntegerv
()

GL_POINT_SMOOTH_HINT

GL_DONT_CAR
E

glGetIntegerv
()

GL_LINE_SMOOTH_HINT

GL_DONT_CAR
E

glGetIntegerv
()

GL_POLYGON_SMOOTH_HINT

GL_DONT_CAR
E

glGetIntegerv
()

GL_FOG_HINT

GL_DONT_CAR
E

glGetIntegerv
()

A-12. ,

GL_MAX_LIGHTS

glGetIntegerv()

GL_MAX_CLIP_PLANES

glGetIntegerv()

GL_MAX_MODELVIEW_STACK_DEP
TH

32

glGetIntegerv()


GL_MAX_PROJECTION_STACK_DEP
TH

glGetIntegerv()

GL_MAX_TEXTURE_STACK_DEPTH

glGetIntegerv()

GL_SUBPIXEL_BITS


x y,

glGetIntegerv()

GL_MAX_3D_TEXTURE_SIZE

16

glGetIntegerv()

GL_MAX_TEXTURE_SIZE

64

glGetIntegerv()

GL_MAX_PIXEL_MAP_TABLE

(glPixelMap())

32

glGetIntegerv()

GL_MAX_NAME_STACK_DEPTH

64

glGetIntegerv()

GL_MAX_LIST_NESTING

64

glGetIntegerv()

GL_MAX_EVAL_ORDER

glGetIntegerv()

GL_MAX_VIEWPORT_DIMS

glGetIntegerv()

GL_MAX_ATTRIB_STACK_DEPTH

16

glGetIntegerv()

GL_MAX_CLIENT_ATTRIB_STACK_D
EPTH

16

glGetIntegerv()

GL_AUX_BUFFERS

glGetBooleanv()

GL_RGBA_MODE


RGBA

glGetBooleanv()

GL_INDEX_MODE

glGetBooleanv()

GL_DOUBLEBUFFER

glGetBooleanv()

GL_STEREO

glGetBooleanv()

GL_ALIASED_POINT_SIZE_RANGE

1,1

glGetFloatv()

GL_SMOOTH_POINT_SIZE_RANGE

1,1

glGetFloatv()

GL_SMOOTH_POINT_SIZE_GRANUL
ARITY

glGetFloatv()

GL_ALIASED_LINE_WIDTH_RANGE

1,1

glGetFloatv()

GL_SMOOTH_LINE_ WIDTH_RANGE

1,1

glGetFloatv()

GL_SMOOTH_LINE_WIDTH_GRANU
LARITY

glGetFloatv()

GL_MAX_CONVOLUTION_WIDTH

glGetConvolutionParamet
eriv()

GL_MAX_CONVOLUTION_HEIGHT

glGetConvolutionParamet
eriv()

GL_MAX_ELEMENTS_INDICES



glDrawRangeElemen
ts()

glGetIntegerv()

GL_MAX_ELEMENTS_VERTICES

glDrawRangeElemen
ts()

glGetIntegerv()

GL_MAX_TEXTURE_UNITS_ARB

glGetIntegerv()

A-13. ,

GL_RED_BITS

glGetIntegerv()

GL_GREEN_BITS

glGetIntegerv()

GL_BLUE_BITS

glGetIntegerv()

GL_ALPHA_BITS

glGetIntegerv()

GL_INDEX_BITS

glGetIntegerv()

GL_DEPTH_BITS

glGetIntegerv()

GL_STENCIL_BITS

glGetIntegerv()

GL_ACCUM_RED_BITS

glGetIntegerv()

GL_ACCUM_GREEN_BITS

glGetIntegerv()

GL_ACCUM_BLUE_BITS

glGetIntegerv()

GL_ACCUM_ALPHA_BITS

glGetIntegerv()

A-14.

GL_LIST_BASE

glListBase()

glGetIntegerv()

GL_LIST_INDEX


, 0

glGetIntegerv()


GL_LIST_MODE


, 0

glGetIntegerv()

GL_ATTRIB_STACK_DEPTH

glGetIntegerv()

GL_CLIENT_ATTRIB_STACK_DEPTH

glGetIntegerv()

GL_NAME_STACK_DEPTH

glGetIntegerv()

GL_RENDER_MODE

(glRenderMode())

GL_RENDER

glGetIntegerv()

GL_SELECTION_BUFFER_POINTER

glGetPointerv()

GL_SELECTION_BUFFER_SIZE

glGetIntegerv()

GL_FEEDBACK_BUFFER_POINTER

glGetPointerv()

GL_FEEDBACK _BUFFER_SIZE

glGetIntegerv()

GL_FEEDBACK _BUFFER_TYPE

GL_2D

glGetIntegerv()


()

glGetError()

B.
,
OpenGL.
,
,
.
. , ,
, .
,
, .
,
. ,
,
,
.
,
.
, B-1.
, ,
.
B-1. () ()


,
( ). ,
,
:
V(s, t) = [X(s, t) Y(s, t) Z(s, t)],
s t , X, Y Z
2- . ,

,
s t.

, , .
2-
. ( , .)

, .
[x y z],

, s=1 t=2,
(1, 8, 1), (-24, 2, 24)
. 34,
,
(-24/34, 2/34, 24/34) = (-0.70588, 0.058823, 0.70588).
,
F(x, y, z)=0
.
, z=G(x, y)

V(s, t) = [s t G(s, t)].
.
, , ,
,

,
(x, y, z). ,
, .

1 :

,
.
z :

.
z,

,
, .
, (2/3, 1/3, 2/3) .
(4/3, 2/3, 4/3).
(2/3, 1/3, 2/3), , ,
.


, ,
, , ,
. (
)
,
. B-2 .
(, ,
.)
, ,
.
B-2.

,
v1, v2 v3, .

. (
.) ,
. , ,
B-2, n1, n2, n4 n5 , P,
n1+n2+n4+n5, . (
, .)
P.
. ,
( Q B-2)
, , .
, , .
, ( R
B-2 ).

,
,
.

C. GLUT
GLUT ,
. (
Xt Toolkit, X Intristics.) ,
.
, .
, .
.


.
void glutInit (int argc, char **argv);

glutInit() GLUT ,
GLUT. glutInit()
, .
X Window, iconic, -geometry display. (,
glutInit(), , ,
main()).
void glutInitDisplayMode (unsigned int mode);

(, RGBA ,
) , glutCreateWindow().
,
, . mask ,
OR : GLUT_RGBA
GLUT_INDEX ( ), GLUT_SINGLE GLUT_DOUBLE (
),
GLUT_DEPTH, GLUT_STENCIL, GLUT_ACCUN. ,
, RGBA
, GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH | GLUT_STENCIL.
GLUT_RGBA | GLUT_ SINGLE (
RGBA - ).
void glutInitWindowSize (int width, int height);

void glutInitWindowPosition (int x, int y);


. (x, y) ,
. width height ( ).

.
int glutCreateWindow (char *name);

(
, ). name
, . ,
glutMainLoop(),
- .
.

( OpenGL) .


, , ,
, GLUT.
void glutDisplayFunc (void (*func)(void));

( func), ,
. ,
, , ,
, glutPostRedisplay().
void glutReshapeFunc (void (*func)(int width, int height));

,
. func ,
: width height .
func glViewport()
,
.
glutReshapeFunc() NULL (
),
, glViewport (0,0,width,height).
void glutKeyboardFunc (void (*func)(unsigned int key, int x, int y));

func, , ,
ASCII-. key.
x y ( )
.
void glutMouseFunc (void (*func)(int button, int state, int width, int height));

, .
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));

,
, . x y
( ) .

void glutPostRedisplay (void);

, .
,
glutDisplayFunc().


, ,
OpenGL . ,
. GLUT
RGB
.
void glutSetColor (Glint index, GLfloat red, GLfloat green, GLfloat blue);

index, RGB-, red,


green blue. [0.0, 1.0].



. GLUT
.
. :
,
( ).
, .
, ,
. ,
.
void glutWireSphere (GLdouble radius, GLint slices, GLint stacks);

void glutSolidSphere (GLdouble radius, GLint slices, GLint stacks);

radius,
( ) slices z stacks z.
, , z , ,
.
z . ( ),
( ).
.
stacks, slices.
, , ,
.
void glutWireCube (GLdouble size);

void glutSolidCube (GLdouble size);

size.
void glutWireTorus (GLdouble innerRadius, GLdouble outerRadius, GLint nsides,
GLint rings);

void glutSolidTorus (GLdouble innerRadius, GLdouble outerRadius, GLint nsides,


GLint rings);

() outerRadius
innerRadius. rings
, nsides
.
void glutWireCone (GLdouble radius, GLdouble height, GLint slices, GLint stacks);

void glutSolidCone (GLdouble radius, GLdouble height, GLint slices, GLint


stacks);

radius, height.
slices stacks .
void glutWireIcosahedron (void);

void glutSolidIcosahedron (void);

void glutWireOctahedron (void);

void glutSolidOctahedron (void);

void glutWireTetrahedron (void);

void glutSolidTetrahedron (void);

void glutWireDodecahedron (GLdouble radius);

void glutSolidDodecahedron (GLdouble radius);

, ,
(
).
void glutWireTeapot (GLdouble size);

void glutSolidTeapot (GLdouble size);

size.


, ,
, .
.
void glutIdleFunc (void (*func)(void));

, ,
( ).
glutIdleFunc() NULL.


, , GLUT
glutMainLoop().
void glutMainLoop (void);

.
.
1-2 , GLUT ,
1-1. .
,
( ), init().
( ) display(),
.

D.
,
.
, , ,
.

,
. OpenGL .
. OpenGL
.

, D-1.
(, )
, ,
(, )
.
, .
D-1.

, ,
.
, ,
.
, , .
, ,
, . ,
.
,
.

, ,
.
, ,
.


, , ,
,
, (, , ).
(x, y, z, w), ,
, RGBA, , .

, , .
glVertex*(), 4 ,
( z=0 w=1),
. .
( , ,
.)



,

, .
,

.
.
, (
). ,
, , , ,
.
,
.


- ,
, . ,
.
,
. (

.)
;
, .
,

.
, , ,
, .
w,

. ,
, (
).
.


.
OpenGL, ,
. ,
(pixel map).

, .
,
( , ).
.

, ,
,
.


OpenGL 1.1 .
,
. .
,
. ,
, , .


, ,
. ,
(),
.
, ( RGBA ),
. RGBA,
.
. .
,
, .
,
,
, .


, ,
. glMultMatrix*(), glLoadMatrix*()
glLoadIdentity() , glTranslate*(),
glRotate*(), glScale*(), glOrtho() glFrustum()
, .

,
.
, ,
, , .
.
glClear()
, .

E.

.
, , ,
, .
,
.


OpenGL ,
,
.

, 0. a
0,

--

, w 0,

,
.


. w=0.0,
,
. ,
, (1, 2, 0, 0)
(1, 2, 0, 1), (1, 2, 0, 0.01) (1, 2, 0, 0.0001),
(1, 2), (100, 200) (10,000, 20,000).
, 2x=y.
, (1, 2, 0, 0) ,
.
: OpenGL
w<0. ,
OpenGL, .


( , ,
) (
)
4x4 , . v

, 4x4, Mv
v M. (
, , ,
. ,
.)
, x, y z
[-w, w] ( , w>0). ,
[-1.0, 1.0].


, .
,
, .
.
((a, b, c, d),
0. q 0, (a, b, c,
d) (qa, qb, qc, qd) .

((a, b, c, d), ax+by+cz+dw=0. ( w=1,


.) (a, b, c, d) ,
a, b c 0.
0, (0, 0, 0, d) ,
.
pp , v , v
p pv=0, pv .
M ( 4x4

), pv=0

, Mv

. ,

M.
,
, , v n , v
n.

. ,

M,
, ,
. ,
-.
,
.


, M
,
. .

glTranslate*(x, y, z) T,

glScale*(x, y, z) S,

x, y z 0.

glRotate*(a, x, y, z) R :

,
m M, 3x3,
. R . x=y=z=0, R
. R,
.

, a a,

glRotate*() .
,
:

.
.


glFrustum(l,r,b,t,n,f) R,

R ,


glOrtho(l,r,b,t,n,f) R,


R ,

F.
,
. ,
OpenGL,
.

. glGetError()
, ,
.
OpenGL
. , OpenGL 1.1
,
glBegin()/glEnd(), .
,
. ,
OpenGL, (
) .
. ,
, glRotate*()
. glLoadIdentity()
, glRotate*()
.
,
,
,
, OpenGL.
, (,
)
.
, OpenGL .
, .


.
glFlush() OpenGL
. , glGet*() glIs*()
.
, ,
.

(, glCopyPixels()).

. ,
4 ,
.
,
,
.
, :
gluOrtho2D(0, width,0,height);

width height .

, . , glRecti(0,0,1,1)
, glRasterPosi(0,0)
.
,
. , , (x1, 0.5)
(x2, 0.5) ,
, (0.5, 0.5), ,
glRecti(0,0,1,1).

,
, , ,
x y 0.375, .

,
.
glViewport(0,0,width,height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0,width,0,height);
gllMatrixMode(GL_MODELVIEW);
glLadIdentity();
glTranslatef(0.375,0.375,0.0);
/* */

w
q . OpenGL
,
.
, OpenGL
. , glRotated(),
,
. ,
glRotated() .

OpenGL


(, ), glColorMaterial().
glMaterial() ,
.
, ,
glLoadIdentity().

, glRotate*(), glTranslate*()
glScale*() , ,
.
,

.
,
glPushAttrib() glPopAttrib().
( )
.
,
.
.
glTexImage*() ( ),
,
glTexParameter*() .
.
, gl*TexSubImage()
, ,
.
OpenGL
,
, , .
,
, .
,
.
.

.
,
GL_NORMALIZE.
glScale*(),
.
, GL_FLAT
glShadeModel().
glClear() .
glClear() ,
.

glBegin(GL_TRIANGLES) ( GL_QUADS GL_LINES),
glBegin(GL_POLYGON).
, GL_TRIANGLES,
GL_POLYGON.
OpenGL
.
.
.
,
,
.
,
.
,
.
, OpenGL
.
,
, .

GLX

glXWaitGL() glFinish(), X
GL.
glXWaitX() glFinish(),
GL X.
glXChooseVisual(),
.

, glXChooseVisual()
, . ,

,
. ,
.

G. OpenGL
OpenGL . ,
,
. OpenGL
, , .
, .
.
OpenGL , ,

. ,
,
. ,

. ,

.
,
. ,
(x, y). OpenGL ,

, , , ,
, ,
, , , , ,
, ,
. , ,
,
, , , ,
, ,
.
OpenGL , ,
, ,
( ), (
), ( ),
( , ),
.
,
,
. ,

,
GL_ONE GL_ZERO , glDisable(GL_BLEND). (
, ,
, .) , ,

.
, OpenGL , ,
, ( )
OpenGL ,
. , OpenGL, ,

, .
.
, , ,
, , ,
.
, OpenGL ,
,
,
.
, ,
.

H. OpenGL
OpenGL
. OpenGL ,
. OpenGL
,
.

, OpenGL,
, , ,
. ,
OpenGL.
,
: X Windows System, Apple Mac OS, IBM OS/2 Warp Microsoft
Windows 95/98/NT.
.

GLX: OpenGL X Window System


X Window OpenGL X
. GLX
X ( API) OpenGL
X.
X.
XX, OpenGL
X
OpenGL.
, OpenGL X OpenGL
X ,
.

GLX 1.3 , ,
GLXFBConfig, GLX (
, , ,
). GLXFBConfig
GLXDrawable. ( X,
Drawable.)
GLX 1.3 3 GLXDrawable: GLXWindow, GLXPixmap
GLXPbuffer. GLXWindow , .
GLXPixmap X, OpenGL X
. GLXPbuffer
OpenGL,
. (
,
.)
X Visual
OpenGL.
XVisualInfo, ( RGBA),
, , ,
. X Visual (, PseudoColor TrueColor)
,
X Visual.
GLX 1.3 GLXWindow X Visual, GLXFBConfig.
GLXPixmap GLXPBuffer , X
Visual. GLX 1.3 ( )
X Visual. ( 1.3 P GLX.)
GLX,
: ftp://sgigate.sgi.com/pub/opengl/doc/opengl1.2.

glXQueryExtension() glXQueryVersion()
, GLX X , , .
glXQueryExtensionString()
. glXGetClientString() ,
. glXGetServerString()
.
glXChooseFBConfig() GLXFBConfig,
GLX, ,
. glXGetFBConfigAttrib()
,
GLX. glXGetVisualFromFBConfig() X Visual,
GLXFBConfig.

. GLXWindow X Window X Visual,
GLXFBConfig. X Window
glXCreateWindow(), GLXWindow. GLXPixmap
X Pixmap , GLXFBConfig.
Pixmap glXCreatePixmap()
GLXPixmap. GLXPbuffer X Window X Pixmap
glxCreatePbuffer() GLXFBConfig.

: GLX 1.2 ,
GLXFBConfig. glXChooseVisual(),
XVisualInfo, X Visual,
, . X Visual
OpenGL glXGetConfig().
,
glXCreateGLXPixmap().


GLX
OpenGL. ,
GLX, X OpenGL,
, X font.

OpenGL
OpenGL glXCreateNewContext().

, X Server, . (
X
OpenGL .)
glXCreateNewContext()
. ,
OpenGL glXIsDirect().
glXMakeContextCurrent()
.

. ,
GLXDrawable. glXGetCurrentContext() .

glXGetCurrentDrawable(),
glXGetCurrentReadDrawable(), X Display
glXGetCurrentDisplay(). glXQueryContext()
.
.
,
OpenGL glXCopyContext().
,
glXDestroyContext().
: GLX 1.2 , glXCreateContext()
glXMakeCurrent()
.
, glXGetCurrentReadDrawable().

GLX
GLX 1.3. X11.
GLX
GLXPbuffer. GLX 1.3
glXSelectEvent() GLX_PBUFFER_CLOBBER_MASK.
X
GLXPbuffer ,
. ( glXGetSelectedEvent() ,
.)


X , OpenGL ,
glXWaitGL(). ,
OpenGL , X,
glXWaitGL().
glFinish(), glXWaitGL() ,
, , OpenGL
.
OpenGL
X, glXWaitX().
, X ,
OpenGL, glXWaitX().



glXSwapBuffer(). glFlush() .

X Font
X Font OpenGL
glXUseXFont().
, glBitmap().


,
glXDestroyWindow(), glXDestroyPixmap()
glXDestroyPbuffer(). ( GLX 1.2 ,
glXDestroyGLXPixmap() glXDestroyPixmap().)

GLX

, GLX X:
bool glXQueryExtension (Display *dpy, int *errorBase, int *eventBase);
:
bool glXQueryVersion (Display *dpy, int *major, int *minor);
const char* glXGetClientString (Display *dpy, int name);
const char* glXQueryServerString (Display *dpy, int screen, int name);
const char* glXQueryExtensionString (Display *dpy, int screen);
:
GLXFBConfig* glXGetFBConfigs (Display *dpy, int screen, int* nelements);

GLXFBConfig* glXChooseFBConfig (Display *dpy, int screen, const int attribList, int
*nelements);
GLX X:
int glXGetFBConfigAttrib (Display *dpy, GLXFBConfig config, int attribute, int *value);
XVisualInfo* glXGetVisualFromFB (Display *dpy, GLXFBConfig config);
( ):
GLXWindow glXCreateWindow (Display *dpy, GLXFBConfig config, Window win,
int* attribList);
GLXPixmap glXCreatePixmap (Display *dpy, GLXFBConfig config, Pixmap pixmap,
int* attribList);

const

const

GLXPbuffer glXCreatePbuffer (Display *dpy, GLXFBConfig config, const int* attribList);


OpenGL:
GLXContext glXCreateNewContext (Display *dpy, GLXBFConfig config, int renderType,
GLXContext shareList, bool direct);
bool glXMakeContextCurrent (Display *dpy, GLXDrawable drawable, GLXDrawable read,
GLXContext context);
void glXCopyContext (Display *dpy, GLXContext source, GLXContext dest, unsigned long
mask);
bool glXIsDirect (Display *dpy, GLXContext context);
GLXContext glXGetCurrentContext (void);
Display * glXGetCurrentDisplay (void);
GLXDrawable glXGetCurrentDrawable (void);
GLXDrawable glXGetCurrentReadDrawable (void);
int glXQueryContext (Display *dpy, GLXContext context, int attribute, int* value);
void glXDestroyContext (Display *dpy, GLXContext context);
GLX:
int glXSelectEvent (Display *dpy, GLXDrawable drawable, unsigned long eventMask);
int glXGetSelectedEvent (Display *dpy, GLXDrawable drawable, unsigned long*
eventMask);
:
void glXWaitGL (void);

void glXWaitX (void);


:
void glXSwapBuffers (Display *dpy, GLXDrawable drawable);
X Font:
void glXUseXFont (Font font, int first, int count, int listBase);
:
void glXDestroyWindow (Display *dpy, GLXWindow win);
void glXDestroyPixmap (Display *dpy, GLXPixmap pixmap);
void glXDestroyPbuffer (Display *dpy, GLXPbuffer pbuffer);


GLX 1.3.
GLX 1.2 ,
.
X Visual:
XVisualInfo* glXChooseVisual (Display *dpy, int screen, int* attribList);
int glXGetConfig (Display *dpy, XVisualInfo* visual, int attrib, int* value);
OpenGL:
GLXContext glXCreateContext (Display *dpy, XVisualInfo *visual, GLXContext shareList,
bool direct);
bool glXMakeCurrent (Display *dpy, GLXDrawable drawable, GLXContext context);
:
GLXPixmap glXCreateGLXPixmap (Display *dpy, XVisualInfo *visual, Pixmap pixmap);
void glXDestroyGLXPixmap (Display *dpy, GLXPixmap pix);

AGL: OpenGL Apple Macintosh


, OpenGL
Apple Macintosh (AGL). , Macintosh
(QuickDraw).
(
Macintosh) Apple:
http://www.apple.com/opengl.
OpenGL Macintosh ,
, ,
. , ,

OpenGL . ,
, OpenGL,
.
AGLPixelFormat ( AGL XVisualInfo)
, ( RGBA),
( ), , ,
.
OpenGL (, X Window System)
.
glFlush(),
OpenGL , .

aglGetVersion() AGL
Macintosh.


aglChoosePixelFormat(). AGLPixelFormat NULL
, .


OpenGL AGL .

.
,
, .
( )
.

OpenGL
OpenGL ( ,
) aglCreateContext().

.
aglSetDrawable()
, , aglSetCurrentContext() , .

. ,
, .

( ).
: aglGetCurrentContext()
aglGetDrawable().
,
OpenGL aglCopyContext().
,
aglDestroyContext().

.

aglSetDrawable().
aglSetInteger(AGL_BUFFER_RECT, ...).



AGL_OFFSCREEN.
aglSetOffScreen().



AGL_FULLSCREEN.
aglSetFullScreen().


(
) aglSwapBuffers()
.
aglSetInteger(AGL_SWAP_RECT, ...). glFlush() .


Apple Macintosh
.
OpenGL ,
, AGL aglUpdateContext().
,
. ,
.

Apple Macintosh
Apple Macintosh
aglUseFont().
, glBitmap().


OpenGL Apple Macintosh
. ,
aglGetError() , .

AGL

:
void aglGetVersion (GLint* major, GLint* minor);

:
AGLPixelFormat aglChoosePixelFormat (const AGLDevice* gdevs, GLint ndev, onst GLint
*attribs);
void aglDestroyPixelFormat (AGLPixelFormat pix);
AGLPixelFormat aglNextPixelFormat (AGLPixelFormat pix);
GLboolean aglDescribePixelFormat (AGLPixelFormat pix, GLint attrib, GLint *value);
AGLDevice* aglDevicesOfPixelFormat (AGLPixelFormat pix, GLint *ndevs);
:
AGLRendererInfo aglQueryRendererInfo (const AGLDevice* gdevs, GLint ndev);
void aglDestroyRendererInfo (AGLRendererInfo rend);
AGLRendererInfo aglNextRendererInfo ((AGLRendererInfo rend);
GLboolean aglDescribeRenderer (AGLRendererInfo rend, GLint prop, GLint *value);


OpenGL:
AGLContext aglCreateContext (AGLPixelFormat pix, AGLContext share);
GLboolean aglDestroyContext (AGLContext ctx);
GLboolean aglCopyContext (AGLContext src, AGLContext dst, GLuint mask);
GLboolean aglUpdateContext (AGLContext ctx);
:
GLboolean aglSetCurrentContext (AGLContext ctx);
AGLContext aglGetCurrentContext (void);
:
GLboolean aglSetDrawable (AGLContext ctx, AGLDrawable draw);
GLboolean aglSetOffScreen (AGLContext ctx, GLsizei width, GLsizei height, GLsizei
rowbytes, GLvoid *baseaddr);
GLboolean aglSetFullScreen (AGLContext ctx, GLsizei width, GLsizei height, GLsizei freq,
GLint device);
AGLDrawable aglGetDrawable (AGLContext ctx);
:

GLboolean aglSetVirtualScreen (AGLContext ctx, GLint screen);


GLint aglGetVirtualScreen (AGLContext ctx);
:
GLboolean aglConfigure (GLenum pname, GLuint param);
:
void aglSwapBuffers (AGLContext ctx);
:
GLboolean aglEnable (AGLContext ctx, GLenum pname);
GLboolean aglDisable (AGLContext ctx, GLenum pname);
GLboolean aglIsEnabled (AGLContext ctx, GLenum pname);
GLboolean aglSetInteger (AGLContext ctx, GLenum pname, contst GLint *params);
GLboolean aglGetInteger (AGLContext ctx, GLenum pname, contst GLint *params);
:
GLboolean aglUseFont (AGLContext ctx, GLint fontID, Style face, GLint size, GLint first,
GLint count, GLint base);
:
GLenum aglGetError (void);
const GLubyte *aglErrorString (GLenum code);
:
void aglResetLibrary (void);

PGL: OpenGL IBM OS/2 Warp


OpenGL IBM OS/2 Warp PGL,
OpenGL Presentation Manager IBM.
OpenGL PGL (
) (
(Graphics Programming Interface -GPI) OpenGL).
VISUALCONFIG ( PGL XVisualInfo)
, ( RGBA),
( ), , ,
.
(
IBM OS/2 Warp, Version 3.0)
IBM: http://www.austin.ibm.com/software/opengl.


pglQueryCapability() pglQueryVersion()
, OpenGL , ,
. pglChooseConfig()
VISUALCONFIG, ,
.
,
pglQueryConfigs().


PGL
OpenGL, ,
Presentation Manager OpenGL, ,
OS/2.

OpenGL
OpenGL pglCreateContext().
,
, GPI, PM,
. ,
pglIsDirect().
, pglMakeCurrent();
pglGetCurrentContext() .
pglGetCurrentWindow().
OpenGL pglCopyContext().
OpenGL, pglDestroyContext().



pglGrabFrontBitmap().
glFlush() ,
. , ,
pglReleaseFrontBitmap()
.


GPI , OpenGL
, pglWaitGL(). ,
OpenGL ,
GPI, pglWaitGL().
OpenGL
GPI, pglWaitPM(). ,
GPI ,
OpenGL, pglWaitPM().
: OpenGL GPI ,
.


pglSwapBuffers(). glFlush() .


8- ( 256 ),
.
pglSelectColorIndexPalette(), OpenGL ,
.
, . RGBA OpenGL
.

OS/2
OS/2
pglUseFont().
, glBitmap().

PGL

, OpenGL , , :
long pglQueryCapability (HAB hab);
void pglQueryVersion (HAB hab, int *major, int *minor);
:
PVISUALCONFIG pglChooseConfig (HAB hab, int *attribList);
PVISUALCONFIG pglQueryConfigs (HAB hab);


:
HGC pglCreateContext (HAB hab, PVISUALCONFIG pVisualConfig, HGC shareList, bool
isDirect);
bool pglDestroyContext (HAB hab, HGC hgc);
bool pglMakeCurrent (HAB hab, HGC hgc, HWND hwnd);
long pglIsDirect (HAB hab, HGC hgc);
HGL pglGetCurrentContext (HAB hab);
HWND pglGetCurrentWindow (HAB hab);
:
bool pglGrabFrontBitmap (HAB hab, HPS *hps, HBITMAP *phbitmap);

bool pglReleaseFrontBitmap (HAB hab);


:
HPS pglWaitGL (HAB hab);
void pglWaitPM (HAB hab);
:
void pglSwapBuffers (HAB hab, HWND hwnd);
:
void pglSelectColorIndexPalette (HAB hab, HPAL hpal, HGC hgc);
OS/2:
bool pglUseFont (HAB hab, HPS hps, FATTRS *fontAttribs, long logicalID, int first, int
count, int listBase);

WGL: OpenGL Microsoft Windows 95/98/NT


OpenGL Microsoft Windows 95, 98 NT.
,
OpenGL Win32.
OpenGL wgl.
OpenGL
Win32/WGL PIXELFORMATDESCRIPTOR.
PIXELFORMATDESCRIPTOR ,
( RGBA), ( ),
, , .
WGL
, Microsoft Developer Network.

GetVersion()
GetVersionEx(). ChoosePixelFormat()
PIXELFORMATDESCRIPTOR . ,
SetPixelFormat() .

wglCreateContext().
,
DecribePixelFormat() , , wglDescribeLayerPlane().


WGL
OpenGL, , ,
.

OpenGL

OpenGL,
wglCreateContext().
(
wglCreateLayerContext().) ,
wglMakeCurrent(); wglGetCurrentContext() .
wglGetCurrentDC().
OpenGL
wglCopyContext()
wglShareLists().
, wglDestroyContext().

OpenGL
OpenGL
wglGetProcAddress(). ,
OpenGL,
glGetString(GL_EXTENSIONS). wglGetProcAddress()
( glMinmax glConvolution2D)
,
NULL, .


Win32
, OpenGL
. CreateDIBBitmap()
(Device Dependent Bitmap DDB) (Device
Independent Bitmap DIB). CreateDibSection()
, .
, DeleteObject().


GDI OpenGL, , Win32
glXWaitGL(), glXWaitX() pglWaitGL().
glXWaitGL() Win32,
glFinish(), ,
OpenGL GdiFlush(), ,
GDI.



SwapBuffers() wglSwapLayerBuffers()
.


( )
GDI .
wglRealizeLayerPalette(),
RGBA
. wglGetLayerPaletteEntries() wglSetLayerPaletteEntries()
.

WGL wglUseFontBitmaps() wglUseFontOutlines(),



OpenGL.
.

WGL

:
BOOL GetVersion (LPOSVERSIONINFO lpVersionInformation);
BOOL GetVersionEx (LPOSVERSIONINFO lpVersionInformation);
:
int ChoosePixelFormat (HDC hdc, CONST PIXELFORMATDESCRIPTOR *ppfd);
BOOL SetPixelFormat (HDC hdc, CONST PIXELFORMATDESCRIPTOR *ppfd);
int DescribePixelFormat (HDC hdc, int iPixelFormat, UINT nBytes,
LPPIXELFORMATDESCRIPTOR ppfd);
BOOL wglDescribeLayerPlane (HDC hdc, int iPixelFormat, int iLayerPlane, UINT
nBytes, LPLAYERPLANEDESCRIPTOR plpd);


OpenGL:
HGLRC wglCreateContext (HDC hdc);
HGLRC wglCreateLayerContext (HDC hdc, int iLayerPlane);
BOOL wglShareLists (HGLRC hglrc1, HGLRC hglrc2);
BOOL wglDeleteContext (HGLRC hglrc);
BOOL wglCopyContext (HGLRC hglrcSrc, HGLRC hglrcDst, UINT mask);
BOOL wglMakeCurrent (HDC hdc, HGLRC hglrc);
HGLRC wglGetCurrentContext (void);
HDC wlgGetCurrentDC (void);
:
PROC wglGetProcAddress (LPCSTR lpszProc);
:
HBITMAP CreateDIBitmap (HDC hdc, CONST BITMAPINFOHEADER *lpbmih, DWORD
fdwInit, CONST VOID *lpbInit, CONST BITMAPINFO *lpbmi, UINT fuUsage);

HBITMAP CreateDIBSection(HDC hdc, CONST BITMAPINFO *pbmi, UINT iUsage, VOID


**ppvBits, HANDLE hSection, DWORD dwOffset);
BOOL DeleteObject (HGDIOBJ hObject);
:
BOOL SwapBuffers (HDC hdc);
BOOL wglSwapLayerBuffers (HDC hdc, UINT fuPlanes);
:
int wglGetLayerPaletteEntries (HDC hdc, int iLayerPlane, int iStart, int cEntries, CONST
COLORREF *pcr);
int wglSetLayerPaletteEntries (HDC hdc, int iLayerPlane, int iStart, int cEntries,
CONST COLORREF *pcr);
BOOL wglRealizeLayerPalette(HDC hdc, int iLayerPlane, BOOL bRealize);
:
BOOL wglUseFontBitmaps (HDC hdc, DWORD first, DWORD count, DWORD listBase);
BOOL wglUseFontOutlines(HDC hdc, DWORD first, DWORD count, DWORD listBase,
FLOAT deviation, FLOAT extrusion, int format,
LPGLYPHMETRICSFLOAT lpgmf);