/docs/MyDocs

To get this branch, use:
bzr branch http://darksoft.org/webbzr/docs/MyDocs

« back to all changes in this revision

Viewing changes to Development/libraries/opengl/api.txt

  • Committer: Suren A. Chilingaryan
  • Date: 2009-04-09 03:21:08 UTC
  • Revision ID: csa@dside.dyndns.org-20090409032108-w4edamdh4adrgdu3
import

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
Basic Definitions
 
2
=================
 
3
 - Front-facing - Polygons whose vertices appear in counterclockwise order on 
 
4
 the screen are called front-facing.
 
5
 
 
6
 - Field of view (angle of view). ���� ����� ����� ������������� ��������� 
 
7
 �������� �����, �������, ������ � ���������� � ���������� x-y, ������ ��� 
 
8
 ������.
 
9
 
 
10
    Functions coding scheme
 
11
    -----------------------
 
12
    - example function prototype: glColor[234][u][dfis][v]()
 
13
        [234] - defines number of properties (2D, 3D, ...)
 
14
        [u][dfis] - defines supported types
 
15
            u[unsigned],d[double],f[float],i[int,s[short],b[byte]
 
16
        [v] - specifies an vector format
 
17
 
 
18
    4D coordinate system
 
19
    ---------------------
 
20
      Coordinates are (x,y,z,w). Where 'w' is some kind of perespective 
 
21
    coefficient (basically dummy) added to simplify matrix transformations.
 
22
    Consider following 2D example: to convert vector (x,y) to (x+a,y+b) the
 
23
    following matrix multiplication may be used.
 
24
            1 0 a     x     x + a
 
25
            0 1 b  *  y  =  y + b
 
26
            0 0 1     1       1
 
27
    this would be not possible with only two dimensions. Therefore 3rd dummy "1"
 
28
    is added to the vector. Exactly, the same is happening with vector.
 
29
    
 
30
Defining Primitives
 
31
===================
 
32
    glBegin(primitive_type);
 
33
        ... code ...
 
34
    glEnd();
 
35
 
 
36
 - Primtives:
 
37
    GL_POINTS
 
38
    GL_LINES (�� ����������) GL_LINE_STRIP (�������), GL_LINE_LOOP (���������)
 
39
    GL_TRIANGLES, GL_QUADS
 
40
    GL_TRIANGLE_STRIP, GL_TRIANGLE_FAN, GL_QUAD_STRIP (���������)
 
41
    GL_POLYGON (convex, without intersections)      
 
42
 
 
43
 - Basic code
 
44
    glColor[234][dfis][v](r,g,b)        - setting local color
 
45
    glVertex[234][dfis][v](x,y,z)       - setting primitive vertex
 
46
    glNormal[234][dfis][v](x,y,z)       - defines a normal vector at next vertex
 
47
 
 
48
  - Various aspects, functions should be stated before 'glBegin'
 
49
    * glPointSize(float)                        - 1.0 is default
 
50
    * glLineWidth(float)                        - 1.0 is default
 
51
    * glPolygonMode(GL_FRONT, GL_FILL)          - Polygon filling mode
 
52
        GL_FRONT, GL_BACK 
 
53
        GL_FILL, GL_LINE, GL_POINT
 
54
 
 
55
    Colors
 
56
    ------
 
57
    glColor[34][bsifd](r,g,b,a)         - setting color, values expected to be
 
58
                                        between 0.0 and 1.0
 
59
    glShadeModel (<mode>)               - shading mode
 
60
        GL_SMOOTH       color of one vertex of a primitive is duplicated across
 
61
                        all the primitive's vertices.
 
62
        GL_FLAT         color at each vertex is treated individually. the colors 
 
63
                        for the interior of the polygon are interpolated between
 
64
                        the vertex colors.
 
65
                                    
 
66
    Bit planes: GL_RED_BITS, GL_GREEN_BITS, GL_BLUE_BITS, GL_ALPHA_BITS, and
 
67
    GL_INDEX_BITS.
 
68
    
 
69
    - The alpha value (the A in RGBA) has no direct effect on the color 
 
70
    displayed on the screen. It can be used for many things, including blending
 
71
    and transparency, and it can have an effect on the values of R, G, and B 
 
72
    that are written.
 
73
    
 
74
    - Dithering: increasing amount of supported colors by mixing pixels of two
 
75
    different tones in checkboard manner. Depending on proportion of pixels of
 
76
    each color, a new combined tone would be seen by an user if hi is far away 
 
77
    from display and can't distinguish separate pixels.
 
78
        glEnable(GL_DITHER)             - enables dithering
 
79
 
 
80
    - Gamma correction: Color intensities on most computer screens aren't 
 
81
    perceived as linear by the human eye. The question is, does 0.5 look like 
 
82
    halfway between 0.0 and 1.0? 
 
83
     * To test this, write a program that draws alternate pixels in a 
 
84
    checkerboard pattern to intensities 0.0 and 1.0, and compare it with 
 
85
    a region drawn solidly in color 0.5. OpenGL assumes they're the same. 
 
86
     * Many systems have a table to adjust intensities so that 0.5 appears to 
 
87
    be halfway between 0.0 and 1.0. The mapping usually used is an exponential
 
88
    one, with the exponent referred to as gamma. 
 
89
 
 
90
 
 
91
    Display Lists
 
92
    -------------
 
93
    A display list is a group of OpenGL commands that have been stored for later
 
94
    execution. When a display list is invoked, the commands in it are executed 
 
95
    in the order in which they were issued.
 
96
    glNewList(<id>, GL_COMPILE);
 
97
        ... glBegin/glEnd blocks ... 
 
98
    glEndList()
 
99
    
 
100
    glCallList(<id>)                            - Execute List, id>=1
 
101
    
 
102
    - ID's should start from 1!
 
103
    - Some time it is wise to save-and-restore transformation matrixes and GL
 
104
    context:
 
105
        glPushMatrix();
 
106
        glPushAttrib(GL_CURRENT_BIT);
 
107
            ... list coomands
 
108
        glPopAttrib();
 
109
        glPopMatrix();
 
110
    - Nesting is allowed. The called threads should not be defined prior to 
 
111
    calls and may be defined later in the program (but, obvious, before call to
 
112
    encompassing list)
 
113
    - Other commands
 
114
        firstid = glGenList(<num>)      - allocates contiguous range of still
 
115
                                        unallocated list indecis
 
116
        glListBase(<firstid>)           - set display-list base, see glCallLists
 
117
                                        for example usage
 
118
        gCallLists(n, type, lists)      
 
119
            Executes 'n' display lists. The indices of the lists to be executed
 
120
            are computed by adding the offset indicated by the current 
 
121
            display-list base (specified with glListBase()) to the values in 
 
122
            the 'lists' array of type 'type.
 
123
            Types: GL_BYTE, GL_SHORT, GL_INT, GL_4_BYTES, GL_3_BYTES, ...
 
124
 
 
125
        glIsList(<id>)                  - is list existing
 
126
        glDeleteLists(...);             - delete lists
 
127
 
 
128
 
 
129
Viewing
 
130
=======
 
131
 [object coordintates] 
 
132
    -- Viewing Transformation (modelview) -->
 
133
 [eye coordinates]
 
134
    -- Projection Transformation (projection) -->
 
135
 [clip coordinates]
 
136
    -- Perespective Division -->
 
137
 [normolized device coordinates]
 
138
    -- Viewport Transofrmation
 
139
 [window coordinates]
 
140
 
 
141
 - Coordinate system (and default view):
 
142
        y^
 
143
         |
 
144
         |   x
 
145
         .--->
 
146
        / 
 
147
      z* 
 
148
        
 
149
 - Approach:
 
150
    * The camera is Initialy located at (0,0,0) and points at negative z-axis
 
151
    * Actually, all transformations are performed using 4 x 4 matrix (M), which
 
152
    is then multiplied by coordinates of each vertex (v): v' = Mv
 
153
    * Last transformation command called in your program is actually the first 
 
154
    one applied to the vertices.
 
155
 
 
156
 - Defining transformations:
 
157
    glMatrixMode(mode)          - Selecting  appropriate transofrmation matrix
 
158
        GL_PROJECTION, GL_MODELVIEW
 
159
    glLoadIdentity()            - Clear Matrix
 
160
    
 
161
    ... defining transformations ...
 
162
 
 
163
    ... adding objects ...
 
164
 
 
165
    ... defining additional transformations ...
 
166
 
 
167
    ... adding objects ...
 
168
 
 
169
    ......................
 
170
    
 
171
 - Enabling ray tracing (removing hiddent parts from screen)
 
172
    glEnable(GL_DEPTH_TEST);
 
173
 
 
174
 - Defining transformations:
 
175
    glLoadMatrix(arr)           - Defining transformation matrices
 
176
    glMultMatrix(arr)           - Adds transformation matrix to sequence
 
177
        arr - is 1D array defining matrix 4x4 (fastest indecis change on vert.)
 
178
    
 
179
    glPushMatrix()              - Saves current matrix in stack
 
180
    glPopMatrix()               - Popes matrix from stack
 
181
    
 
182
 - MODELVIEW transformations: 
 
183
    glTranslate[fd](x,y,z)      - moves camera by the specified vector
 
184
    glRotate[fd](angle,x,y,z)   - rotates object (counterclockwise) arround 
 
185
                                the ray from the origin through specified point
 
186
    glScale[fd](x,y,z)          - scale object along axis
 
187
 
 
188
    gluLookAt(fx,fy,fz,tx,ty,tz,vx,vy,vz);
 
189
        we are looking from (fx,fy,fz) to (tx,ty,tz) with an up vector (vx,vy,vz)
 
190
    
 
191
 - PROJECTION transformations:
 
192
    glFrustum(left,right,bottom,top,near,far)   - perespective projection
 
193
            left,right,bottom,top - defines sizes of near clipping plane
 
194
            near, far - defines distance to near and far planes
 
195
 
 
196
           /|
 
197
          / |far
 
198
        ./| |plan
 
199
         \| |
 
200
     near \ |
 
201
      plan \|
 
202
            
 
203
            only objects between near plan and far plan are displayed
 
204
 
 
205
 
 
206
    gluPerespective(fovy,aspect,zNear,zFar)
 
207
        fovy - field of view (degrees) in the 'y' direction
 
208
        aspect - x-y aspect ratio (of project planes)
 
209
        zNear - distance from viewer to the near clipping plane
 
210
        zFar - distance from viewer to the far clipping plane
 
211
 
 
212
 
 
213
    glOrtho(left,right,bottom,top,near,far)     - orthographic projection
 
214
    
 
215
 - Clipping planes
 
216
    glClipPlane(plane, equation)                - Defines additional planes, 
 
217
                                                clipping part of output
 
218
        * plane - is plane index, should be enabled or disabled by calling
 
219
            glEnable(GL_CLIP_PLANE<plane>);
 
220
            glDisable(GL_CLIP_PLANE<plane>);
 
221
        * equation is double array (a,b,c,d) defining plane ax+by+cz+d=0
 
222
        
 
223
 - VIEWPORT transformations:
 
224
    glViewport (x, y, w, h)     - in pixels
 
225
    glDepthRange(near, far)     - in pixels, must be within (0,1)
 
226
 
 
227
 - Perespective division:  (x,y,z,w) -> (x/w, y/w, z/w, 1)
 
228
 
 
229
 
 
230
Light
 
231
=====
 
232
    Theory
 
233
    ------
 
234
    - The OpenGL lighting model makes the approximation that a material's color 
 
235
    depends on the percentages of the incoming red, green, and blue light it 
 
236
    reflects. For example, a perfectly red ball reflects all the incoming red 
 
237
    light and absorbs all the green and blue light that strikes it. If you view
 
238
    such a ball in white light (composed of equal amounts of red, green, and 
 
239
    blue light), all the red is reflected, and you see a red ball. If the ball 
 
240
    is viewed in pure red light, it also appears to be red. 
 
241
    If, however, the red ball is viewed in pure green light, it appears black 
 
242
    (all the green is absorbed, and there's no incoming red, so no light is 
 
243
    reflected).
 
244
 
 
245
    - The light on the scene is a combination of global ambient light and light
 
246
    produced by each of light sources. The object on the scene do not act as
 
247
    a secondary light sources: The reflected light only defines a color of 
 
248
    object itself but not involved in lighting of other nearby objects.
 
249
    
 
250
    - The light source is defined by position, color and attenuation. Optionally,
 
251
    the direction (cone) may be specified (normally, it propogates spherically).
 
252
    
 
253
    - The OpenGL light subsystem assums that is that the normals it has are 
 
254
    vectors of length 1.0. However, if, for example, glScalef is used to resize
 
255
    primitives, the normals will be also resized. To automatically keep size
 
256
    of normals, the following command is used:
 
257
        glEnable(GL_NORMALIZE);
 
258
    
 
259
    Light - Matterial Interaction
 
260
    -----------------------------
 
261
    So, the color of each vertex on the scene is defined by its color 
 
262
    properties and light sources defined on the scene. OpenGL assumes what
 
263
    light of each source is consisting of three components: Ambient, Diffuse, 
 
264
    Specular. Each of these components may have a color associated (i.e. it is 
 
265
    posssible what diffuse and specular compoents had different colors).
 
266
    
 
267
    Correspondingly materials are characterized by ambient, diffuse and 
 
268
    specular reflectances. This defines percentage of light which is reflected 
 
269
    by surface. Following formula is used for computations: 
 
270
        (RR,RG,RB) = (LR*MR, LG*MG, LB*GB)
 
271
    where is Light(LR,LG,LB), Material(MR,MG,MB), Reflected(RR,RG,RB)
 
272
 
 
273
    Finally, the matterial may define "emmitted" light component. Which is 
 
274
    unnafected by light sources and adds directly to the matterial color (still
 
275
    it is not shining on other objects on the scene).
 
276
 
 
277
    Components: 
 
278
        Ambient         - just uniformly scattered light, comming from all 
 
279
                        directions and reflected equally in all directions
 
280
                        [������� ����]
 
281
        Diffuse         - the main component of light, it comes directly from
 
282
                        the light source and, then it hits surface, is scattered
 
283
                        equally in all directions
 
284
        Specular        - comes from the light source, and reflected off the 
 
285
                        surface in a certain direction [�����]
 
286
        Emitted         - originates from object and is unnaffected by any 
 
287
                        light source [���� ������� � �������]
 
288
 
 
289
    * In a real world ambient and diffuse components always have the same 
 
290
    colors and define a color of object. Specular reflectance is usually white 
 
291
    or gray, so that specular highlights end up being the color of the light 
 
292
    source's specular intensity. If you think of a white light shining on a 
 
293
    shiny red plastic sphere, most of the sphere appears red, but the shiny 
 
294
    highlight is white.
 
295
 
 
296
    * Light calculations don't take into account the possibility of one object 
 
297
    blocking light from another, so shadows aren't automatically created.
 
298
    
 
299
    Color computation
 
300
    -----------------
 
301
    All light sources are calculated independently. Then arriving on eyes every-
 
302
    thing is just summed up. Everything what is out of [0, 1] range is just 
 
303
    clamped to 1.
 
304
 
 
305
    - General formula is:    
 
306
     vertex color = the material emission at that vertex + the global ambient
 
307
     light scaled by the material's ambient property at that vertex + the 
 
308
     ambient, diffuse, and specular contributions from all the light sources, 
 
309
     properly attenuated
 
310
 
 
311
    - The colors of polygons are interpolated basing on vertex colors as usual.
 
312
    
 
313
    Lighting Model
 
314
    --------------
 
315
     glEnable(GL_LIGHTING)                      - Enabling lighting
 
316
 
 
317
     glLightModelfv(GL_LIGHT_MODEL_AMBIENT, {r,g,b,a})
 
318
        Adds constant ambient light to the system. It will be summed with
 
319
        ambient light emitted by each of sources.
 
320
 
 
321
     glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, GL_TRUE/GL_FALSE)
 
322
        Defines if viewer is somewhere arround or looking from infinity. It
 
323
        affects calculation of highlights produced by specular reflectance.
 
324
        When turned off, the position of viewer is not taken into the account
 
325
        which significantly optimizes calculation speed, but slightly decreasing
 
326
        precision.
 
327
 
 
328
    glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE/GL_FALSE);
 
329
        Enables special calculation of illumination for backfacing polygons. If
 
330
        turned on OpenGL reverses the surface normals for back-facing polygons;
 
331
        typically, this means that the surface normals of visible back- and 
 
332
        front-facing polygons face the viewer, rather than pointing away. 
 
333
        As a result, all polygons are illumnated correctly.
 
334
 
 
335
 
 
336
    Managing light sources
 
337
    -----------------------
 
338
    - All OpenGL implementations are mandatory supporting at least 8 light 
 
339
    sources. The particular implementation may support more but it's not
 
340
    required.
 
341
    
 
342
    The light sources are accessed by 'source ids' whiach are just a constansts
 
343
    in the form GL_LIGHT0, GL_LIGHT1, ...
 
344
     glEnable(GL_LIGHT0)                        - Enabling first light source
 
345
     glLight[if][v](<sid>, <propid>, value)     - Defining source properties
 
346
        GL_AMBIENT, GL_DIFFUSE, GL_SPECULAR = {r,g,b,a} - Setting source colors
 
347
 
 
348
    Light positioning
 
349
    -----------------
 
350
        There is two kinds of light: directional and positional. Directional,
 
351
        means what source of light is somewhere at infinitity and, hence, all
 
352
        rays of light are parallel and covering whole scene (Sun).
 
353
        The positional light is located near scene and propogates by default in 
 
354
        spherical form around this point (Lamp). 
 
355
            GL_POSITION={x,y,z,1}       - positional source,  (x,y,z) is point
 
356
            GL_POSITION={x,y,z,0}       - directional source, (x,y,z) is vector
 
357
        * The positional source location is transformed by the modelview matrix.
 
358
        
 
359
        * Alternatively, it is possible to configure connical positional light 
 
360
        source:
 
361
            GL_SPOT_DIRECTION={x,y,z}   - Vector defining the light direction
 
362
            GL_SPOT_CUTOFF=[0-90]       - Angle between axis of cone and a ray
 
363
                                        along the edge of cone (special value of 
 
364
                                        180 disables SPOT feature, default).
 
365
            GL_SPOT_EXPONENT=<value>    - Defines how concerated the light is.
 
366
                                        The light's intensity is highest in the 
 
367
                                        center of the cone. It's attenuated 
 
368
                                        toward the edges of the cone by the 
 
369
                                        cosine of the angle between the direction 
 
370
                                        of the light and the direction from the 
 
371
                                        light to the vertex being lighted, raised 
 
372
                                        to the power of the spot exponent.
 
373
        
 
374
        * Light attenuation (for positional sources) is calculated using 
 
375
        Constant (C), Linear (L), and Quadratic (Q) attenuation factors using 
 
376
        following formula:
 
377
            A = O / (C + L*d + Q*d*d)
 
378
        where, A - attenuated light intensity, O - light intensity at the source
 
379
        and d is distance to the source.
 
380
            GL_CONSTANT_ATTENUATION = value             - Factor
 
381
            GL_LINEAR_ATTENUATION = value               - Factor
 
382
            GL_QUADRATIC_ATTENUATION = value            - Factor
 
383
        
 
384
        * The colors across the face of a smooth-shaded polygon are determined 
 
385
        by the colors calculated for the vertices. Therefore, it's important to
 
386
        avoid using large polygons with local lights. Otherwise, if light is
 
387
        located near the middle of the polygon, the vertices might be too far 
 
388
        away to receive much light, so the whole polygon will look darker than 
 
389
        intended. 
 
390
        
 
391
    Matterial Properties
 
392
    --------------------
 
393
    glMaterial{if}[v](<face>, prop, value)              - Matterial properties
 
394
     face: GL_FRONT, GL_BACK, GL_FRONT_AND_BACK
 
395
     setting colors:
 
396
        props: GL_AMBIENT, GL_DIFFUSE, GL_AMBIENT_AND_DIFFUSE, GL_SPECULAR, 
 
397
        GL_EMISSION
 
398
        value: {r,g,b,a}
 
399
     setting specular light concentration: the higher the value, the smaller 
 
400
     and brighter (more focused) the highlight is:
 
401
        prop: GL_SHININESS
 
402
        value: exponent [0-128]
 
403
    
 
404
    glColorMaterial(<face>, <prop>);
 
405
        Causes the material properties to track the value of the current color 
 
406
        at all times. A change to the current color (using glColor*()) 
 
407
        immediately updates the specified material properties.
 
408
        Needs enabling: glEnable(GL_COLOR_MATERIAL)
 
409
        
 
410
        
 
411
Blending
 
412
========
 
413
 Definitions
 
414
    - "Source" is front object and "Destination" is back object.
 
415
    - (SR,SG,SB,SA) - source color, before blending
 
416
    - (DR,DG,DB,DA) - destination color, before blending
 
417
    - Blend factors are 4D vectors defining color mixing formula
 
418
    
 
419
  glEnable(GL_BLEND)                                    - Enable blending
 
420
  glBlndFunc(source_factor, destination_factor)         - Defining blend factors
 
421
    GL_ZERO                     (0,0,0,0)
 
422
    GL_ONE                      (1,1,1,1)
 
423
    GL_DST_COLOR                (DR,DG,DB,DA)           - src. factor only
 
424
    GL_SRC_COLOR                (SR,SG,SB,SA)           - dst. factor only
 
425
    GL_ONE_MINUS_DST_COLOR      (1-DR,1-DG,1-DB,1-DA)   - src. factor only
 
426
    GL_ONE_MINUS_SRC_COLOR      (1-SR,1-SG,1-SB,1-SA)   - dst. factor only
 
427
    GL_SRC_ALPHA                (SA,SA,SA,SA)
 
428
    GL_ONE_MINUS_SRC_ALPHA      (1-SA,1-SA,1-SA,1-SA)
 
429
    GL_DST_ALPHA                (DA,DA,DA,DA)
 
430
    GL_ONE_MINUS_DST_ALPHA      (1-DA,1-DA,1-DA,1-DA)
 
431
    GL_SRC_ALPHA_SATURATE       (f,f,f,1); f=min(SA,1-DA) - src. factor only
 
432
  Function:
 
433
   Let FS and FD be source and destination factors, then each component of 
 
434
   blended color could be calculated using: min(1,FS*S + FD*D)
 
435
  Standard Applications:
 
436
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)   - transparency
 
437
 
 
438
 Blending & Z-Buffer:
 
439
  - Since the order in which polygons are drawn greatly affects the blended 
 
440
  result, you can get different appearances depending on whether you draw the 
 
441
  polygons from back to front or from front to back. 
 
442
  
 
443
  - You also need to consider the effect of the depth buffer when determining 
 
444
  the correct order. The solution is to enable depth-buffering but make the 
 
445
  depth buffer read-only while drawing the translucent objects. 
 
446
   a) First you draw all the opaque objects, with the depth buffer in normal 
 
447
   operation. 
 
448
   b) Then, you preserve these depth values by making the depth buffer 
 
449
   read-only: glDepthMask(GL_FALSE)
 
450
   c) When the translucent objects are drawn, their depth values are still 
 
451
   compared to the values established by the opaque objects, so they aren't 
 
452
   drawn if they're behind the opaque ones. 
 
453
   If they're closer to the viewpoint, however, they don't eliminate the opaque 
 
454
   objects, since the depth-buffer values can't change. Instead, they're blended
 
455
   with the opaque objects. 
 
456
 
 
457
 - Another consideration is different matterials properties. For example, if
 
458
 GL_EMMISION is used to color object and GL_AMBIENT_AND_DIFFUSE is 0. Still,
 
459
 alfa value of AMBIENT_AND_DIFFUSE is taken into the consideration while
 
460
 blending.
 
461
 
 
462
Antialiasing
 
463
------------
 
464
    Since the pixels are not ideal points, most of stright lines are drawn 
 
465
 jagged. OpenGL may perform antialising (����������) of these lines to neglect 
 
466
 such visual effect. 
 
467
 
 
468
. In fact, when performing antialiasing, OpenGL calculates a coverage value for each fragment based on the fraction of the pixel square on the screen that it would cover.
 
469
OpenGL multiplies the fragment's alpha value by its coverage. You can then use the resulting alpha value to blend the fragment with the corresponding pixel already in the framebuffer.
 
470
 
 
471
 Enabling:
 
472
    a) glEnable(GL_POINT_SMOOTH) 
 
473
    b) glEnable(GL_LINE_SMOOTH) 
 
474
    c) glEnable(GL_POLYGON_SMOOTH)
 
475
    d) Blending should be enabled, with following factors
 
476
        for lines: GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA
 
477
        polygons in GL_FILL mode: GL_SRC_ALPHA_SATURATE, GL_ONE
 
478
 
 
479
Fog
 
480
---
 
481
 Hides objects which are to far away from the viewer.
 
482
    glEnable(GL_FOG)
 
483
    glFog{if}{v}(<prop>, <value>);
 
484
 Properties:
 
485
    GL_FOG_MODE = <mode>        - selects mode: GL_LINEAR, GL_EXP, or GL_EXP2
 
486
    GL_FOG_DENSITY, GL_FOG_START, GL_FOG_END = <value> - mode parameters
 
487
    GL_FOG_COLOR {r,g,b,a}      - sets fog color
 
488
 
 
489
 formula 
 
490
  GL_LINEAR:  f = (end - z) / (end - start)
 
491
  GL_EXP: f = exp(-density*z)
 
492
  GL_EXP2: f = exp(-(density*z)^2)
 
493
  
 
494
  Here 'z' is is distance between viewer and fragment center. Then using 'f'
 
495
  coefficient the each result color component is calculated by formula:
 
496
     f * C + (1 - f ) * F
 
497
  here 'C' is unfogged color, and F is color of FOG
 
498
 
 
499
 
 
500
Bitmaps, Images
 
501
===============
 
502
 Getting / Setting current raster position
 
503
    glRasterPos{234}{sifd}{v}(x,y,z,w)          - Sets current raster position
 
504
    glGetFloatv(GL_CURRENT_RASTER_POSITION, float v[4]) - Get current position
 
505
     - All transformations which are applied to the vertices, are also applied 
 
506
     to the raster positions.
 
507
 Drawing bitmap:
 
508
    glBitmap (width, height, xbo, ybo, xbi, ybi, GLubyte *bitmap)
 
509
        - (xbo, ybo) are added to the current raster position and that would
 
510
        be lower-left corner of bitmap. (xbi, ybi) are added to the current
 
511
        raster position after bitmap is placed.
 
512
        - each pixel of bitmap is encoded by bits of bitmap array (there is no
 
513
        byte sharing between rows. If width is not multiple of 8, unused bits
 
514
        of last byte of each row is just ignored)
 
515
        - The bitmap just specifies positions where the pixels are set, the 
 
516
        color of pixels are defined by current glColor.
 
517
 Drawing/Reading images:
 
518
  glReadPixels(x,y,width,height,target,data_type,pixels)
 
519
    * Reads pixel data from the framebuffer rectangle whose lower left corner
 
520
    is at (x, y) and whose dimensions are width and height, and stores it in 
 
521
    the array pointed to by 'pixels'.
 
522
  glDrawPixels(width, height, target, data_type, pixels)
 
523
    * The pixel rectangle is drawn with its lower left corner at the current 
 
524
    raster position.
 
525
  glCopyPixels(x,y,width,height,target)
 
526
    * Copies pixel data from the framebuffer rectangle whose lower left corner 
 
527
    is at (x, y) and whose dimensions are width and height. The data is copied 
 
528
    to a new position whose lower left corner is given by the current raster 
 
529
    position. 
 
530
 
 
531
  Targets for Read/Draw:
 
532
    GL_RGB, GL_RGBA     - red, green, blue, alpha color components. 3 or 4 
 
533
                        <datatype> values are returned (sequentially) per pixel.
 
534
    GL_RED, GL_GREEN, GL_BLUE, GL_ALPHA - single <datatype> per pixel
 
535
    GL_LUMINANCE
 
536
    GL_LUMINANCE_ALPHA  - two <datatype>'s per pixel
 
537
    GL_STENCIL_INDEX
 
538
    GL_DEPTH_COMPONENT  - z-index of pixel
 
539
  Targets for Copy:
 
540
    GL_COLOR            - color information
 
541
    GL_DEPTH            - z-buffer
 
542
    GL_STENCIL          - ?
 
543
  Data Types:
 
544
    GL_UNSIGNED_BYTE, GL_BYTE, GL_UNSIGNED_SHORT (16 bit), GL_SHORT, 
 
545
    GL_UNSIGNED_INT (32bit), GL_INT, GL_FLOAT
 
546
    GL_BITMAP - single bits in unsigned 8-bit integers (bit per pixel)
 
547
 
 
548
 Magnifying or Reducing an Image:
 
549
    glPixelZoom(zoomx, zoomy)
 
550
        Sets the magnification or reduction factors for pixel-write operations, 
 
551
        in the x- and y-dimensions. For example, If they're both 2.0, each 
 
552
        image pixel is drawn to 4 screen pixels.
 
553
        * Fractional magnification or reduction factors are allowed 
 
554
        
 
555
 Other commands:
 
556
    glPolygonStipple()
 
557
    
 
558
 Controlling data conversion:
 
559
    * glPixelStore*() - defines how pixel data is/should aligned, byte ordered, 
 
560
    and other things in that direction.
 
561
    * glPixelTransfer*() - defines transformations which would be applied while
 
562
    the data is moved from/to framebuffer.
 
563
    This includes: scaling, biasing, etc.
 
564
    * glPixelMap{isf}v(maptype, mapsize, values) - defines a lookup table which
 
565
    is used to modify color componetns, stencil indices, etc. before puting
 
566
    them into the memory.
 
567
 
 
568
 Textures
 
569
 --------
 
570
 - Texture mapping ensures that all the right things happen as the polygon is 
 
571
 transformed and rendered: When the wall is viewed in perspective, for example,
 
572
 the bricks decrease in size along with the wall as the wall gets farther from 
 
573
 the viewpoint.
 
574
 
 
575
 
 
576
 Using an advanced technique, called mipmapping, you can specify a single texture at many different resolutions; this allows you to avoid mapping a full-resolution image of a brick wall on a wall that's so far away from the viewer that it appears on the screen as a single pixel, for example.
 
577
 
 
578
 Enabling texturing
 
579
    glEnable(GL_TEXTURE_1D)
 
580
    glEnable(GL_TEXTURE_2D)
 
581
 
 
582
 Only single texture could be active at the same time. The basic proceeding is
 
583
 following.
 
584
    a) Enable texturing, load current texture, set properties.
 
585
    b) Apply texture to
 
586
 
 
587
 glTexImage2D(target, level, components, width, height, border, target_type, data_type, pixels)
 
588
    target = GL_TEXTURE_1D, GL_TEXTURE_2D
 
589
    level               - texture resolution level (for mipmapping),
 
590
                        0 - for single resolution textures
 
591
    components          - defines which color components are used for modulating
 
592
                        or blanding: 1 - L; 2 - L,A; 3 - R,G,B; 4 - R,G,B,A
 
593
                        L - is luminance
 
594
    border              - width of border (normally 0)
 
595
    width, height       - should be multiple of 2 and should include border
 
596
    target_type,data_type,pixels        - the same meaning as for glDrawPixels
 
597
                        glPixelStore*() calls are applicable as well
 
598
 - Maximal size of texture map depends on OpenGL implementation, but it should
 
599
 be at least 64x64 (66x66 with borders).
 
600
 
 
601
 glTexImage1D(target,level,components,width,border,target_type, data_type, pixels)
 
602
    Loading 1D texture, if all variations is in one direction only
 
603
 
 
604
 glGetTexImage(target, level, components, data_type, GLvoid *img)
 
605
    Get's currently set texture image
 
606
 
 
607
 glTexParameterf(target, prop, val)
 
608
    GL_TEXTURE_WRAP_S, GL_TEXTURE_WRAP_T = <mod> - defines computation to be
 
609
    applied if pixel outside of texture is requested
 
610
    'S' - defines how to extend texture horizontally and 'T' - vertically
 
611
        GL_REPEAT       - the texture is continiously repeating
 
612
        GL_CLAMP        - the texture border colors are used outside of texture
 
613
                    if texture have no border defined, GL_TEXTURE_BORDER_COLOR
 
614
                    is used (see next property, in this function description)
 
615
 
 
616
    [ABC]       [ABC][ABC][ABC]         [ABC]]]]]]]]]]]
 
617
    [DEF]       [DEF][DEF][DEF]         [DEF]]]]]]]]]]]
 
618
    [GIJ]       [GIJ][GIJ][GIJ]         [GIJ]]]]]]]]]]]
 
619
                    GL_REPEAT               GL_CLAMP
 
620
 
 
621
    GL_TEXTURE_BORDER_COLOR = {r,b,a}   - defines default color for GL_CLAMP
 
622
    GL_TEXTURE_MAG_FILTER = <filter>    - defines magnification filter
 
623
        GL_NEAREST (speed), GL_LINEAR (quality)
 
624
    GL_TEXTURE_MIN_FILTER = <filter>    - defines minification filter
 
625
        L_NEAREST, GL_LINEAR (mimaps are not used)
 
626
        GL_NEAREST_MIPMAP_NEAREST, GL_NEAREST_MIPMAP_LINEAR, 
 
627
        GL_LINEAR_MIPMAP_NEAREST, or GL_LINEAR_MIPMAP_LINEAR
 
628
    
 
629
 glTexEnv{if}{v}(target, prop, value)
 
630
    targets: GL_TEXTURE_ENV
 
631
    GL_TEXTURE_ENV_MODE = <mode>        - blending mode
 
632
        GL_DECAL                - texture is just drawn on the polygon,
 
633
                                no blending is performed (original (polygon)
 
634
                                alfa is used if 3 component texture is specifed)
 
635
        GL_MODULATE             - The original (polygon) color components are
 
636
                                multiplied by corespondent texture components.
 
637
                                In 1 and 2 component mode, the luminance is used 
 
638
                                in place of all color components, but alpha.
 
639
        GL_BLEND                COLOR = (1-L)*C + L*Ce, ALPHA = At*A
 
640
                                    L - texture luminance
 
641
                                    At - texture alpha or 1 (if not specified)
 
642
                                    Ce - color component assigned by call to
 
643
                                        GL_TEXTURE_ENV_COMPONENT
 
644
                                    C - original/untextured color
 
645
                                    A - original/untextured alpha
 
646
                                - only applicable to luminace texture modes
 
647
    GL_TEXTURE_ENV_COLOR = {r,g,b,a} - defines color to be used in GL_BLEND
 
648
                                blending mode
 
649
 
 
650
 glTexCoords{234}{sif}[v](s,t,r,q) - assigns texture coordinates, see below
 
651
    S,T,R,Q is standard terminology for texture coordinates and are used in 
 
652
    place of X,Y,Z,W in order to make it easy to distinguish between texture 
 
653
    and scene coordinates.
 
654
 
 
655
 Applying textures
 
656
 -----------------
 
657
    glTexCoord2f(s, q); glVertex3f(x,y,z) - sets correspondance between coors.
 
658
    of texture (s, q) and vertex. Such correspondance should be specified for
 
659
    all vertices of polygon.
 
660
    - If floating-point function call is used, then the whole texture is mapped
 
661
    to the [0,1]. This means [0,0] is address of left-botom corner of texture 
 
662
    and [1,1] - top right corner. However, if integer call is used, then the
 
663
    texture coordinates are not translated: [0,0] again is left-bottom corner,
 
664
    and right-up depends on texture height and width.
 
665
    - In exactly the same way that colors are interpolated between two vertices 
 
666
    of shaded polygons and lines, texture coordinates are linearly interpolated
 
667
    between vertices. 
 
668
 
 
669
 Auto-computed coordinates
 
670
 -------------------------
 
671
    glTexGen{ifd}{v}(coord, prop, value)
 
672
        coord: GL_S, GL_T, GL_R, GL_Q
 
673
        GL_TEXTURE_GEN_MODE = <mode>    - defines coordinate generation alg.
 
674
            GL_OBJECT_LINEAR: coordinate_value = p1*x + p2*y + p3*z + p4*w
 
675
                p1,p2,p3,p4 are defined by the GL_OBJECT_PLANE call, below
 
676
            GL_PLANE_LINEAR: coordinate_value = p1'*x + p2'*y + p3'*z + p4'*w
 
677
                (p1',p2',p3',p4') = (p1,p2,p3,p4)M^(-1), where M is MODELVIEW
 
678
                transformation matrix and p1,p2,p3,p4 are defined by the
 
679
                GL_EYE_PALNE call, below
 
680
                Similliar to the GL_OBJECT_LINEAR, but the x,y,z,w are supplied
 
681
                after applying MODELVIEW transformations (i.e. calculations 
 
682
                would be performed relative to the eye's coordinate system)
 
683
            GL_SPHERE_MAP
 
684
                Used to simulate reflections of shiny objects. Assumes that the
 
685
                 items in the environment are far away compared to the surfaces
 
686
                 of the shiny object. Hence, to find the color of a point on 
 
687
                 the surface, take the ray from the eye to the surface, and 
 
688
                 reflect the ray off the surface. The direction of the reflected 
 
689
                 ray completely determines the color to be painted there. 
 
690
                 Encoding a color for each direction on a flat texture map is 
 
691
                 equivalent to putting a polished perfect sphere in the middle 
 
692
                 of the environment and taking a picture of it with a camera that
 
693
                 has a lens with a very long focal length placed far away.
 
694
        GL_OBJECT_PLANE = {p1,p2,p3,p4} - parameters to coord. generation func.
 
695
        GL_EYE_PLANE = {p1,p2,p3,p4}    - parameters to coord. generation func.
 
696
 
 
697
    - GL_OBJECT_LINEAR, GL_PLANE_LINEAR is intended to draw contours using
 
698
    texture (normally 1D) and GL_SPHERE_MAP to simulate reflections.
 
699
 
 
700
    The coordinate generation should be enabled:
 
701
        glEnable(GL_TEXTURE_GEN_S);
 
702
        glEnable(GL_TEXTURE_GEN_T);
 
703
        glEnable(GL_TEXTURE_GEN_R);
 
704
        glEnable(GL_TEXTURE_GEN_Q);
 
705
 
 
706
 Mipmapping
 
707
 ----------
 
708
    - Textured objects can be viewed, like any other objects in a scene, at 
 
709
 different distances from the viewpoint. As a textured object moves farther 
 
710
 from the viewpoint, the texture map must decrease in size along with the size 
 
711
 of the projected image. Therefore, OpenGL has to filter the texture map down 
 
712
 to an appropriate size for mapping onto the object, without introducing 
 
713
 visually disturbing artifacts. To avoid such artifacts, you can specify a 
 
714
 series of prefiltered texture maps of decreasing resolutions, called mipmaps. 
 
715
    - Mipmapping requires some extra computation, but, when it's not used, 
 
716
 textures that are mapped onto smaller objects might shimmer and flash as the 
 
717
 objects move.
 
718
    - To use mipmapping, you provide all sizes of your texture in powers of 2 
 
719
 between the largest size and a 1x1 map. For example, if the highest-resolution
 
720
 map is 64x16, you must also provide maps of size: 
 
721
     32x8, 16x4, 8x2, 4x1, 2x1, and 1x1. 
 
722
    - Functions:
 
723
  * gluBuild1DMipmaps() and gluBuild2DMipmaps() functions from OpenGL Utility
 
724
  library may be used to construct pyramid of mipmaps from the original 
 
725
  (largest) image and to load them using glTexImage calls.
 
726
  * glTexImage1D, glTexImage2D - are called to load sequence of mipmaps. 
 
727
  Level = 0 should be used for the largest image, and, then, sequentially 
 
728
  increase by one for each smaller mipmap.
 
729
 
 
730
 Texture Transformations
 
731
 -----------------------
 
732
 Just as a model coordinates are transformed by a matrix before being rendered,
 
733
 texture coordinates are multiplied by a 4x4 matrix before any texture mapping 
 
734
 occurs. By default, the texture matrix is the identity, so the texture coords.
 
735
 (explicitly assigned or auto-generated) remain unchanged. 
 
736
 By modifying the texture matrix while redrawing an object, however, it is
 
737
 possible to get various effects, like: texture sliding over the surface, 
 
738
 rotation, stretching and shrinking, etc.
 
739
    glMatrixMode(GL_TEXTURE);
 
740
    glRotate(...); 
 
741
    ...
 
742
 
 
743
 Notes
 
744
 -----
 
745
 - In some cases, it isn't obvious whether magnification or minification is 
 
746
 called for. If the mipmap needs to be stretched (or shrunk) in both the x and 
 
747
 y directions, then magnification (or minification) is needed. If the mipmap 
 
748
 needs to be stretched in one direction and shrunk in the other, however, 
 
749
 OpenGL makes a choice between magnification and minification that in most 
 
750
 cases gives the best result possible. It's best to try to avoid these 
 
751
 situations by using texture coordinates that map without such distortion;
 
752
 
 
753
 
 
754
 Limiting draw area
 
755
 ------------------
 
756
    glStencilFunc(test, refval, mask)
 
757
    test: GL_NEVER, GL_LESS, GL_LEQUAL, GL_GREATER, GL_GEQUAL, GL_EQUAL, 
 
758
    GL_NOTEQUAL, and GL_ALWAYS
 
759
    refval: reference value, to compare with the data in the stencil buffer
 
760
    mask: is bitwise ANDed with both the reference value and the stored 
 
761
    stencil value
 
762
 
 
763
  You fill the stencil buffer, then render geometry and images, usingthe 
 
764
  stencil planes to mask out portions of the screen.  Stenciling is typically 
 
765
  usedin multipass rendering algorithms to achieve specialeffects, such as 
 
766
  decals, outlining, and constructive solid geometry rendering.
 
767
 
 
768
  Enabling: glEnable(GL_STENCIL_TEST)
 
769
  
 
770
  Example: GL_LEQUAL test, a pixel is drawn if (refval&mask)<(stencil&mask)
 
771
  
 
772
 - It is possible to modify data in stencil buffer depending on fail-or-success
 
773
 of test:
 
774
  void glStencilOp(GLenum fail, GLenum zfail, GLenum zpass)
 
775
    'fail' is applied if stencil test is failed
 
776
    'zfail' is applied if stencil test is passed and depth test is failed
 
777
    'zpass' is applied if both stencil and depth test are passed
 
778
   GL_KEEP, GL_ZERO, GL_REPLACE (with refval), GL_INCR, GL_DECR, or 
 
779
   GL_INVERT (bitwise)
 
780
 
 
781
 - Filling stencil buffer
 
782
    a) set stencil test to GL_ALWAYS
 
783
    b) set zpass to GL_REPLACE
 
784
    c) In the loop
 
785
        1) set refval
 
786
        2) draw into the color area where this refval should be used
 
787
  
 
788
 - glScissor(GLint x, GLint y, GLsizei width, GLsizei height)
 
789
    another to define the only (rectangular) area where the drawing is allowed
 
790
  
 
791
  Enabling: glEnable(GL_SCISSOR)
 
792
  
 
793
    
 
794
Frame buffers
 
795
=============
 
796
 * color buffers - there could be multiple color buffers. One is just contains
 
797
 color information for display, others may be used for image preparation, etc.
 
798
 * depth (z) buffer - used to skip objects beyond the scene
 
799
 * stencil buffer - restrict drawing to certain portions of the screen
 
800
 * accumulation buffer - is storing color information and is used to accumulate
 
801
 series of images to produce (after needed amount of images received) super-
 
802
 sampled image
 
803
 
 
804
 Clearing buffers (reinitializing to default values)
 
805
  - setting default values
 
806
    glClearColor(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha); 
 
807
    glClearDepth(GLclampd depth); 
 
808
    glClearStencil(GLint s);
 
809
    glClearAccum(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha);
 
810
 - issuing clear command
 
811
    glClear(GLbitfield mask)
 
812
        mask is combination of  GL_COLOR_BUFFER_BIT, GL_DEPTH_BUFFER_BIT, 
 
813
        GL_STENCIL_BUFFER_BIT, and GL_ACCUM_BUFFER_BIT bits
 
814
 
 
815
 Selecting current color buffers 
 
816
  glDrawBuffer(<buffer>)        - here the draw commands are sent
 
817
  glReadBuffer(<buffer>)        - the read commands are accessing this buffer
 
818
    GL_FRONT (on display), GL_BACK (if double buffering is supported buffer where
 
819
    we perepare data), sterescopic buffers (GL_RIGHT, GL_LEFT, GL_FRONT_RIGHT,
 
820
    GL_FRONT_LEFT, GL_BACK_RIGHT, GL_BACK_LEFT), auxiliary buffers (GL_AUX<i>)
 
821
    GL_FRONT_AND_BACK, GL_NONE
 
822
 
 
823
 Masking data prior to writing it to the buffers
 
824
    glColorMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha); 
 
825
    glDepthMask(GLboolean flag)
 
826
    glStencilMask(GLuint mask)
 
827
    - boolean flags just enables-or-disable writing, interger value (for stencil
 
828
    mask) allows to enable/disable wrtiting to the certain bits.
 
829
 
 
830
 Setting test functions
 
831
    glAlphaFunc()
 
832
    glDepthFunc(GLenum func);
 
833
    glStencilFunc(GLenum func, GLint ref, GLuint mask)
 
834
    functions: GL_NEVER, GL_ALWAYS, GL_LESS, GL_LEQUAL, GL_EQUAL, GL_GEQUAL, 
 
835
    GL_GREATER, or GL_NOTEQUAL
 
836
    
 
837
 Usage of accomulation buffer
 
838
    OpenGL graphics operations don't write directly into the accumulation 
 
839
    buffer. Typically, a series of images is generated in one of the standard 
 
840
    color buffers, and these are accumulated, one at a time, into the 
 
841
    accumulation buffer. When the accumulation is finished, the result is 
 
842
    copied back into a color buffer for viewing. To reduce rounding errors, 
 
843
    the accumulation buffer may have higher precision (more bits per color) 
 
844
    than the standard color buffers.
 
845
    
 
846
    glAccum(<operation>, <value>)
 
847
    operations:
 
848
     GL_ACCUM - reads data from the current ReadBuffer, multiplies the R, G, B,
 
849
     and Alpha values by 'value', and adds the result to the accumulation buffer
 
850
     GL_LOAD - the same but replaces values currently in the acc. buffer
 
851
     GL_RETURN - takes values from the accumulation buffer, multiplies them by 
 
852
     'value', and places the result in the current DrawBuffer
 
853
     GL_ADD, GL_MULT - add/multiply the value of each pixel in the accumulation 
 
854
     buffer by value
 
855
     
 
856
    Example usage:
 
857
    * Antialising: loop 'n' times through code that draws image in a slightly 
 
858
    different position, accumulating the data with glAccum(GL_ACCUM, 1.0/n)
 
859
    and then get result with: glAccum(GL_RETURN, 1.0)
 
860
    
 
861
 
 
862
Rendering Modes
 
863
===============
 
864
 glRenderMode(<mode>)
 
865
    GL_RENDER - Default mode, rendering scene in the frame buffer
 
866
    GL_SELECT - Mode to find out objects near the specified screen location
 
867
                + glSelectBuffer - should be called prior to setting this mode
 
868
    GL_FEEDBACK - Mode to perform calculations and get back results, without
 
869
                actually rendering them
 
870
                + glFeedbackBuffer - should be called prior to setting this mode
 
871
 
 
872
 - glRenderMode is returning amount of records placed in the Selection or
 
873
 Feedback buffer if called while OpenGL is in selection or feedback modes.
 
874
 
 
875
 Enumerating Objects (only working in selection mode)
 
876
 -------------------
 
877
    glInitNames()       - Clearing the name stack
 
878
 
 
879
    glLoadName(1);      - Setting ID of object to be rendered
 
880
    ... rendering primitives ...
 
881
 
 
882
    glLoadName(2);      - Setting ID of object to be rendered
 
883
    ... rendering primitives ...
 
884
    
 
885
    
 
886
    - Normally, all work is perfomed on the stack of objects, not just a single
 
887
    name. This allows to address items better, for example, the top object
 
888
    is robot, then goes hand of robot, and at the head of stack is finger
 
889
    of robot. The stack is used like that:
 
890
    
 
891
    glPushName(<id>)            - Setting ID of objects to render
 
892
      ... render primitives
 
893
    glPopName()                 - Restoring old ID
 
894
    
 
895
    The stack depth is  at least 64 different objects. Actual depth could be 
 
896
    obtained with glGetIntegerv(GL_NAME_STACK_DEPTH)
 
897
 
 
898
 
 
899
 Selection Mode
 
900
 --------------
 
901
    In the selection mode, the OpenGL engine instead of drawing primitives will
 
902
    return a list of objects (enumerated) which are visible in the current 
 
903
    viewpoint. The full name stack of
 
904
 
 
905
    * glSelectBuffer(GLsizei size, GLuint *buffer) - defines a buffer where the
 
906
    list of objects would be returned. Should be set before entering selection
 
907
    mode ('size' defines size of buffer in GLuint elements). 
 
908
    
 
909
        - Depth of name stack when hit occured [GLuint]
 
910
        - Minimum z-index of objects in view [GLuint]                 /|    
 
911
        - Maximum z-index of objects in view [GLuint]                / |far  
 
912
          * The z-coord of all objects is mapped to [0,1] where    ./| |plan
 
913
            0 - corresponds to the depth of near projection plane   \| |    
 
914
            1 - correspnds to the depth of far projection plane  near\ |
 
915
          then the resulting values are multiplied by MAXINT and  plan\|    
 
916
          minimum and maxumu is stored in provided buffer.
 
917
          * This allows to find closest and farest visible object.
 
918
        - The names stack, bottommost object first [array of GLuint]
 
919
     
 
920
 
 
921
    * Usage:
 
922
        selectBuf = malloc(BUFSIZE*sizeof(GLuint));     - Allocating buffer
 
923
        glSelectBuffer(BUFSIZE, selectBuf);     - Passing it to OpneGL
 
924
        glRenderMode(GL_SELECT);                - Entering selection mode
 
925
        ... Rendering objects ....
 
926
        
 
927
        hits = glRenderMode (GL_RENDER);        - Switching to rendering mode
 
928
                                        and obtaining number of records which 
 
929
                                        are placed in the selection buffer
 
930
 
 
931
        ... Processing hits in selectBuf (a selectBuf is only acccesable 
 
932
        after that point) ...
 
933
        
 
934
    - If only object near to mouse position (or whatever) are of interest, the
 
935
        gluPickMatrix(x,y,width,height, GLint viewport[4])
 
936
    may be ised to limit selection area.
 
937
        x,y - center of region
 
938
        width,height - rectangle dimensions
 
939
        viewport - indicates the current viewport boundaries and can be obtained
 
940
        by calling: glGetIntegerv(GL_VIEWPORT, GLint *viewport).
 
941
    This is done during configuration of Projection matrix:
 
942
        glLoadIdentity();
 
943
        gluPickMatrix();
 
944
        glFrustum();;
 
945
        ... Draw Commands ...
 
946
        
 
947
 Feedback Mode
 
948
 -------------
 
949
    In the selection mode, the OpenGL engine instead of rendering primitives 
 
950
    just applies all specified transformations and return information about
 
951
    resulting values.
 
952
    The information is returned about
 
953
        a) All primitves (vertix by vertix) defined in the glBegin, glEnd 
 
954
        sections
 
955
        b) Pixel regions created with 'glBitmap', 'glCopyPixels' calls
 
956
        c) Pass through markers specified using 'glPassThrough' function
 
957
 
 
958
    - Feedback occurs after transformations, lighting, polygon culling, and 
 
959
    interpretation of polygons by glPolygonMode(). It might also occur after 
 
960
    polygons with more than three edges are broken up into triangles (if your 
 
961
    particular OpenGL implementation renders polygons by performing this 
 
962
    decomposition).
 
963
 
 
964
 glFeedbackBuffer(size, type, GLfloat *buffer) 
 
965
    size - size of buffer in GLfloat's
 
966
    type - specifies which information will be returned in buffer for each 
 
967
           vertex:
 
968
            GL_2D: x,y [2]
 
969
            GL_3D: x,y,z [3]
 
970
            GL_3D_COLOR: x,y,z, r,g,b,a [7]
 
971
            GL_3D_COLOR_TEXTURE: x,y,z, r,g,b,a, s,t,r,q [11]
 
972
            GL_4D_COLOR_TEXTURE: x,y,z,w, r,g,b,a, s,t,r,q [12]
 
973
    buffer - allocated memory to return results in. The results are stored
 
974
    record by record. Each record consists of
 
975
        a) Primitive type [GLfloat]: 
 
976
            - GL_POINT_TOKEN                            - single vertix
 
977
            - GL_LINE_TOKEN, GL_LINE_RESET_TOKEN,       - two vertices
 
978
            - GL_POLYGON_TOKEN,                 - vertix count [GLfloat],followed 
 
979
                                                by appropriate number of vertices
 
980
            - GL_BITMAP_TOKEN, GL_DRAW_PIXEL_TOKEN, GL_COPY_PIXEL_TOKEN,
 
981
                                        - single vertix describing bitmap area,
 
982
                                        I think it is vertex on the left-bottom
 
983
                                        corner, but have not checked.
 
984
                
 
985
            - GL_PASS_THROUGH_TOKEN     - only a single GLfloat value, passed by 
 
986
                                        glPassThrough command, is stored in the 
 
987
                                        buffer for this record
 
988
 
 
989
        b) The record data, normally describing all vertices of primitive. So,
 
990
        the size of record is depending on feedback type and the primitive 
 
991
        described by record. For example, for GL_LINE_TOKEN primitive and GL_3D
 
992
        feedback type the 6 values (x1,y1,z1), (x2,y2,z2) reporting coordinates 
 
993
        of begining and end of the line will be stored in the buffer.
 
994
    
 
995
    - The primitives which are filtered out of view (by z-buffer, etc.) is not
 
996
    reported and not returned.
 
997
        
 
998
 glPassThrough(GLfloat token)
 
999
    This is quite difficult to distinguish the originating primitives of 
 
1000
    records in feedback buffer. The passthrough markers are inteneded to
 
1001
    help.
 
1002
    - Should not be called within glBegin/glEnd block
 
1003
 
 
1004
    
 
1005
 Usage:
 
1006
        feedBuf = malloc(BUFSIZE*sizeof(GLfloat));      - Allocating buffer
 
1007
        glFeedbackBuffer(BUFSIZE, <mode>, feedBuf);     - Passing it to OpneGL
 
1008
        glRenderMode(GL_FEEDBACK);              - Entering selection mode
 
1009
        ... Rendering objects ....
 
1010
        
 
1011
        recs = glRenderMode (GL_RENDER);        - Switching to rendering mode
 
1012
                                        and obtaining number of records which 
 
1013
                                        are placed in the selection buffer
 
1014
 
 
1015
        ... Processing information in feedBuf (a feedBuf is only acccesable 
 
1016
        after that point) ...
 
1017
 
 
1018
    
 
1019
Performance
 
1020
===========
 
1021
 glHint(<target>, <hint>)       - hints OpenGL engine about desired quality / 
 
1022
                                performance tradeoff 
 
1023
 Antialising: GL_POINT_SMOOTH_HINT, GL_LINE_SMOOTH_HINT, GL_POLYGON_SMOOTH_HINT
 
1024
 Fog: GL_FOG_HINT
 
1025
 Perespective: GL_PERSPECTIVE_CORRECTION_HINT
 
1026
 Tradeoffs: GL_NICEST, GL_FASTEST, GL_DONT_CARE
 
1027
 
 
1028
 
 
1029
Misc
 
1030
====
 
1031
 1. Skipps processing of front or back faces. Just nothing is drawn for 
 
1032
 correspondent face
 
1033
    glEnable(GL_CULL_FACE);
 
1034
    glCullFace(GL_BACK|GL_FRONT)
 
1035
 
 
1036
 2. Redefining front and back faces
 
1037
    glFrontFace(GL_CW|GL_CCW);
 
1038
        CW - clockwise
 
1039
        CCW - counter clockwise (default)           
 
1040
    
 
1041
 
 
 
b'\\ No newline at end of file'