Table of Contents Glide Programming Guide



Download 6.22 Mb.
Page34/106
Date03.02.2023
Size6.22 Mb.
#60547
1   ...   30   31   32   33   34   35   36   37   ...   106
GLIDEPGM
grColorCombine( GR_COMBINE_FUNCTION_SCALE_OTHER,
GR_COMBINE_FACTOR_ONE,
GR_COMBINE_LOCAL_ITERATED,
GR_COMBINE_OTHER_ITERATED
FXFALSE )

A series of examples follows.


Example Color and Lighting.1 Drawing a constant color triangle.


The code segment below draws a teal colored triangle by setting the constant color and directing the color combine unit to use it as cother.
GrVertex a, b, c;

/* set color to teal (assumes ARGB format) */


grConstantColorValue( (100<<8) + 150 );

/* configure color combine unit for constant color */


grColorCombine(GR_COMBINE_FUNCTION_SCALE_OTHER, GR_COMBINE_FACTOR_ONE, GR_COMBINE_LOCAL_NONE, GR_COMBINE_OTHER_CONSTANT, FXFALSE);

/* assumes that some coordinates have been assigned to a, b, and c */


grDrawTriangle(&a, &b, &c);


The code segment below will produce the same result as the one above, but it points clocal to the constant color.
GrVertex a, b, c;

/* set color to teal (assumes ARGB format) */


grConstantColorValue( (100<<8) + 150);

/* configure color combine unit for constant color */


grColorCombine(GR_COMBINE_FUNCTION_LOCAL, GR_COMBINE_FACTOR_NONE, GR_COMBINE_LOCAL_CONSTANT, GR_COMBINE_OTHER_NONE, FXFALSE);

/* assumes that some coordinates have been assigned to a, b, and c */


grDrawTriangle(&a, &b, &c);
Example Color and Lighting.2 Drawing a flat-shaded triangle.
The code segment below draws a flat-shaded triangle using the color for vertex A. It sets the constant color to the vertex color and proceeds as in the previous example.
GrVertex A, B, C;

/* set constant color to color of vertex A (assumes ARGB format) */


grConstantColorValue((((int)A.a)<<24)||(((int)A.r)<<16)||(((int)A.g)<<8)||(int) A.b);

/* configure color combine unit for constant color */


grColorCombine(GR_COMBINE_FUNCTION_LOCAL, GR_COMBINE_FACTOR_NONE, GR_COMBINE_LOCAL_CONSTANT, GR_COMBINE_OTHER_NONE, FXFALSE);

/* assumes that some coordinates have been assigned to a, b, and c */


grDrawTriangle(&A, &B, &C);


Alternatively, you could set the colors of all three vertices to the colors in Vertex A and proceed as in the next example.
GrVertex A, B, C;

/* set all vertices to same color */


B.a = C.a = A.a;
B.r = C.r = A.r;
B.g = C.g = A.g;
B.b = C.b = A.b;

/* configure color combine unit for iterated colors */


grColorCombine(GR_COMBINE_FUNCTION_LOCAL, GR_COMBINE_FACTOR_NONE, GR_COMBINE_LOCAL_ITERATED, GR_COMBINE_OTHER_NONE, FXFALSE);

/* assumes that some coordinates have been assigned to a, b, and c */


grDrawTriangle(&A, &B, &C);
Example Color and Lighting.3 Drawing a smooth-shaded triangle.
In this example, a Gouraud-shaded triangle will be drawn, with the color blending smoothly from vertex to vertex. The hardware automatically iterates the colors to achieve the smooth shading. The color combine unit is configured with clocal set to the iterated color components.
GrVertex a, b, c;

/* configure color combine unit for iterated color */


grColorCombine(GR_COMBINE_FUNCTION_LOCAL, GR_COMBINE_FACTOR_NONE, GR_COMBINE_LOCAL_ITERATED, GR_COMBINE_OTHER_NONE, FXFALSE);

/* assumes that some coordinates have been assigned to a, b, and c */


grDrawTriangle(&a, &b, &c);


Alternatively, cother can be directed at the iterated color components.
GrVertex a, b, c;

/* configure color combine unit for iterated color */


grColorCombine(GR_COMBINE_FUNCTION_SCALE_OTHER, GR_COMBINE_FACTOR_ONE, GR_COMBINE_LOCAL_NONE, GR_COMBINE_OTHER_ITERATED, FXFALSE);

/* assumes that some coordinates have been assigned to a, b, and c */


grDrawTriangle(&a, &b, &c);

Example Color and Lighting.4 Drawing a flat-shaded textured triangle.


The following code produces a textured flat-shaded triangle using the constant color.
GrVertex a, b, c;

/* set color to teal (assumes ARGB format) */


grConstantColorValue( (100<<8) + 150);

/* configure color combine unit for iterated color */


grColorCombine(GR_COMBINE_FUNCTION_SCALE_OTHER, GR_COMBINE_FACTOR_LOCAL, GR_COMBINE_LOCAL_CONSTANT, GR_COMBINE_OTHER_TEXTURE, FXFALSE);

/* assumes that some coordinates have been assigned to a, b, and c */


grDrawTriangle(&a, &b, &c);

Example Color and Lighting.5 Drawing a smooth-shaded textured triangle.


This example configures the color combine unit for a smoothly shaded textured triangle by directing clocal to the iterated color and cother to the output from the texture combine unit.
GrVertex a, b, c;

/* configure color combine unit for iterated color */


grColorCombine(GR_COMBINE_FUNCTION_SCALE_OTHER, GR_COMBINE_FACTOR_LOCAL, GR_COMBINE_LOCAL_ITERATED, GR_COMBINE_OTHER_TEXTURE, FXFALSE);

/* assumes that some coordinates have been assigned to a, b, and c */


grDrawTriangle(&a, &b, &c);

Example Color and Lighting.6 Drawing a smooth-shaded triangle with specular lighting.


This example produces a textured triangle with specular lighting provided by iterating the RGB color.
GrVertex a, b, c;

/* configure color combine unit for iterated color */


grColorCombine(GR_COMBINE_FUNCTION_SCALE_OTHER_ADD_LOCAL, GR_COMBINE_FACTOR_ONE, GR_COMBINE_LOCAL_ITERATED, GR_COMBINE_OTHER_TEXTURE, FXFALSE);

/* assumes that some coordinates have been assigned to a, b, and c */


grDrawTriangle(&a, &b, &c);
Example Color and Lighting.7 Drawing a smooth-shaded textured triangle with specular highlights.
By using the alpha component to model monochrome specular highlights, you can produce shiny, textured, smooth-shaded triangles ((texture RGB * iterated RGB) + iterated a).

GrVertex a, b, c;


/* configure color combine unit for iterated color */


grColorCombine(GR_COMBINE_FUNCTION_SCALE_OTHER_ADD_LOCAL_ALPHA, GR_COMBINE_FACTOR_LOCAL, GR_COMBINE_LOCAL_ITERATED, GR_COMBINE_OTHER_TEXTURE, FXFALSE);

/* assumes that some coordinates have been assigned to a, b, and c */


grDrawTriangle(&a, &b, &c);
Example Color and Lighting.8 Drawing a smooth-shaded triangle with monochrome diffuse and colored specular lighting.
Alternatively, monochrome diffuse lighting and colored specular lighting can be produced by using the alpha component to model monochrome diffuse lighting and iterated RGB to model colored specular lighting ((texture RGB * iterated a) + iterated RGB). Iterated alpha is chosen to be either alocal or aother with a call to grAlphaCombine() that is not shown here. In the first code segment, iterated alpha is assumed to be available as alocal.
GrVertex a, b, c;

/* configure color combine unit for iterated color */


grColorCombine(GR_COMBINE_FUNCTION_SCALE_OTHER_ADD_LOCAL, GR_COMBINE_FACTOR_LOCAL_ALPHA, GR_COMBINE_LOCAL_ITERATED, GR_COMBINE_OTHER_TEXTURE, FXFALSE);

/* assumes that some coordinates have been assigned to a, b, and c */


grDrawTriangle(&a, &b, &c);


Alternatively, iterated alpha can be specified for aother in grAlphaCombine(). In that case the following grColorCombine() configuration is needed.

GrVertex a, b, c;


/* configure color combine unit for iterated color */


grColorCombine(GR_COMBINE_FUNCTION_SCALE_OTHER_ADD_LOCAL, GR_COMBINE_FACTOR_OTHER_ALPHA, GR_COMBINE_LOCAL_ITERATED, GR_COMBINE_OTHER_TEXTURE, FXFALSE);

/* assumes that some coordinates have been assigned to a, b, and c */


grDrawTriangle(&a, &b, &c);



Download 6.22 Mb.

Share with your friends:
1   ...   30   31   32   33   34   35   36   37   ...   106




The database is protected by copyright ©ininet.org 2024
send message

    Main page