attributes.ppt
description
Transcript of attributes.ppt
Copyright @ 2002 by Jim X. Chen: [email protected]
• Pattern filling in scan-conversion• Antialiasing• Double-buffering and animation
.1.
ATTRIBUTESATTRIBUTES• Any parameter that affects a primitive
displayed is an attribute parameter.• Polygon Attributes
– pattern, color, anti-aliasing • Line Attributes
– type (solid, dashed, dotted), width, cap (butt, round, square), join (miter, round, etc.), color, grayscale, anti-aliasing
Copyright @ 2002 by Jim X. Chen: [email protected]
.2.
Copyright @ 2002 by Jim X. Chen: [email protected]
.3.
PATTERN FILLING (bitmap patterns)PATTERN FILLING (bitmap patterns)
The 1s & 0s select foreground and background color, respectively. For transparent mode, only 1s are written with foreground color.
Anchor the pattern at a vertex of a primitive; this choiceallows the pattern to move with the primitive
Generating patterns while scan-converting, or scan converting a primitive first into a rectangular work area, and then copy pixels from the rectangular bitmap to the appropriate space in the background.
Anchor the pattern at the corner of the drawing area; the pattern does not move with the primitive
Triangle PatternTriangle Pattern
• Generating color patterns on a span (horizontal line)
void span(int x2, int x1, int y) { double num = cnt; for (int x = x2; x<x1; x++) { gl.glColor3d(Math.sin(num*Math.PI/200), Math.cos(num*Math.PI/110), Math.sin(num*Math.PI/350)); gl.glPointSize(1); drawPoint(x, y); num++; } }
Copyright @ 2002 by Jim X. Chen: [email protected]
.4.
Copyright @ 2002 by Jim X. Chen: [email protected] : :
Drawing Geometric ModelsDrawing Geometric Models
.5.
Point and Line AttributesPoint and Line Attributes• void glPointSize(GLfloat size);
• void glLineWidth(GLfloat width);• glLineStipple(1, 0x3F07);
glEnable(GL_LINE_STIPPLE);• void glLineStipple(GLint factor, Glushort pattern);
Stippled LinesStippled Lines
Copyright @ 2002 by Jim X. Chen: [email protected]
Drawing Geometric ModelsDrawing Geometric Models
.6.
SPECIFYING A COLORSPECIFYING A COLOR
glColor3f(0.0, 0.0, 0.0);draw_object(A); draw_object(B); glColor3f(1.0, 0.0, 0.0); draw_object(C);
glColor3f(0.0, 0.0, 0.0); black glColor3f(1.0, 0.0, 0.0); red glColor3f(0.0, 1.0, 0.0); green glColor3f(1.0, 1.0, 0.0); yellow glColor3f(0.0, 0.0, 1.0); blue glColor3f(1.0, 0.0, 1.0); magenta glColor3f(0.0, 1.0, 1.0); cyan glColor3f(1.0, 1.0, 1.0); white
Copyright @ 2002 by Jim X. Chen: [email protected]
.7.
Line Anti-aliasingLine Anti-aliasing
AntialiasingAntialiasing
DemoDemo
Copyright @ 2002 by Jim X. Chen: [email protected]
.8.
Supersampling (postfiltering)Supersampling (postfiltering)•Increase sampling rate, each pixel area is
covered by a finer grid
We can then use multiple sample points in a pixel that is within a line to determine an appropriate intensity level for the pixel.
Supersampling algorithms often choose more weight to subpixels near the center of a pixel area: pixel-
wighting masks
121242121
Copyright @ 2002 by Jim X. Chen: [email protected]
.9.
Area sampling (prefiltering)Area sampling (prefiltering)Determine pixel intensity by calculating the areas of overlap of each pixel with the objects to be displayed
• Unweighted Area Samplingdetermines the pixel intensity by the overlap area only
• Weighted Area Samplingan area closer to the pixel’s center has greater influence on the pixel’s intensity than an equal area further away from the pixel’s center.
Copyright @ 2002 by Jim X. Chen: [email protected]
.10.
• Cone filter , Gaussian filter, Intensity table, etc.• A simple equation for 3-pixel wide line
Given the current pixel’s color (r, g, b), we can modify the intensity by: (r, g, b)*(1-D/1.5). When a pixel is exactly on the line (D=0), the pixel’s intensity is not changed. When a pixel is far away from the center of the line (D=1.5), the pixel’s intensity is modified to (0, 0, 0). Therefore, the pixels have different intensity levels depending on their distances from the center of the line. For a foreground color F and B, we can use: F*(1-D/1.5) + B*D/1.5. We can read the current pixel color from the framebuffer.
void glGetDoublev(GL_CURRENT_RASTER_COLOR, GLdouble *params );
How to calculate D?
FILTER FUNCTIONSFILTER FUNCTIONS
Copyright @ 2002 by Jim X. Chen: [email protected]
.11.
Antialiasing a straight line Antialiasing a straight line
DNE = DE – cos = D + sin – cos
Copyright @ 2002 by Jim X. Chen: [email protected]
.12.
void IntensifyPixel(int x,int y, double D){
float d, r1, g1, b1;
if (D<0) d = -D; else d = D;
r1=r*(1-d/1.5); g1=g*(1-d/1.5); b1=b*(1-d/1.5);
glColor3f(r1, g1, b1);writepixel(x,y);
}
AntialiasingAntialiasing
Example: J1_4_Line
Copyright @ 2002 by Jim X. Chen: [email protected]
.13.
void antialiasedLine(int x0,int y0,int xn,int yn){
int dx, dy, incrE, incrNE, d, x, y;float D=0, sin_a, cos_a, smc_a, Denom;
dy=yn-y0; dx=xn-x0; x=x0; y=y0; d=2*dy-dx; incrE=2*dy; incrNE=2*(dy-dx);
Denom = sqrt(dx*dx + dy*dy);sin_a = dy / Denom; cos_a = dx / Denom;smc_a = sin_a - cos_a;
while (x<xn+1) {IntensifyPixel(x,y,D); // current pixelIntensifyPixel(x,y+1,D-cos_a); // NorthIntensifyPixel(x,y-1,D+cos_a); // South
x++; if (d<=0) { D+=sin_a; d+=incrE; }
else { D+=smc_a; y++; d+=incrNE; };}
} /* AntiAliased Midpoint Algorithm */
AntialiasingAntialiasing
Frame Rate and Refresh RateFrame Rate and Refresh Rate
• If the display refreshes at 60 times per second (f/s), this means that the fastest image frame rate you can achieve is 60 f/s
• What often happens is that the frame is too complicated to draw in 1/60 second, so each frame is displayed more than once
• Notice the difference between the image frame rate and display refresh rate.
Copyright @ 2002 by Jim X. Chen: [email protected]
Copyright @ 2002 by Jim X. Chen: [email protected] : :
Drawing Geometric ModelsDrawing Geometric Models
.15.
Circle x
y
x
y
v1
v2
v3
v4
v1
v2v12
a) depth=0 b) depth=1
Drawing a circle by subdivision
• depth=0, draw 4 triangles. depth=1, each triangle is subdivided into two and we draw 8 triangles.
•consider v1, v2, and v12 as vectors. Then, v12 is in the direction of (v1 + v2)=(v1x+v2x, v1y+v2y, v1z+v2z) and |v1| = |v2| = |v12|.
• v12 = normalize(v1 + v2). Normalizing a vector is equivalent to scaling the vector to a unit vector.
•recursively subdivides depth times and draws 2depth triangles.
subdivideCircle(int radius, float[] v1, float[] v2, int depth) {float v11[] = new float[3]; float v22[] = new float[3];float v00[] = { 0, 0, 0 }; float v12[] = new float[3];if (depth == 0) {for (int i = 0; i < 3; i++) {v11[i] = v1[i] * radius; v22[i] = v2[i] * radius;}drawtriangle(v11, v22, v00);return;}v12[0] = v1[0]+v2[0]; v12[1] = v1[1]+v2[1]; v12[2] = v1[2]+v2[2];normalize(v12);
// subdivide a triangle recursively, and draw them
subdivideCircle(radius, v1, v12, depth - 1);subdivideCircle(radius, v12, v2, depth - 1);
}
Copyright @ 2002 by Jim X. Chen: [email protected]
Example: J1_5_Circle
Copyright @ 2002 by Jim X. Chen: [email protected]
Clipping; Jim Chen
HW1_8_Circle
• Draw a pentagon with antialiasing that rotates in a circle. Within the star there is a filled circle. The filled circle should be filled through subdivision with your own triangle function.
• The triangle should have a pattern of your choice. For example, random generated color. Clipping should be still in force.
Copyright @ 2006 by Jim X. Chen: [email protected]
18
HW3: 2012 Fall ClassHW3: 2012 Fall Class1. Modify from previous homework, so that the points
become small circles that bounces; (40%)2. The small circles bounce with one another as well;
(40%)3. Some circles are filled circles, some are not; (20%)