CPT205 W3
This’s week we will discuss about Geometric Primitives
. (几何图元)
Applications Packages Tools –> API Library –> Algorithms Techniques
- Graphics Primitives
- Points
- Lines
- Polygons 多边形
- Line Algorithms
- Digital Differential Analyser (DDA)
- Bresenham Algorithm
- Circles
- Antialiasing 反锯齿
- Polygon Fill 多边形填充
- Graphics Primitives with OpenGL
- glBegin(GL_POINTS); glBegin(GL_LINES)
- glBegin(GL_POLYGON); glBEgin(GL_QUAD)
Lecture
“Good” discrete lines 离散线
- No gaps in adjacent pixels
- Pixels close to ideal line
- Consistent choices; same pixels in same situations
- Smooth looking
- Even brightness in all orientations
- Same line for P0P1 as for P1P0
- Double pixels stacked up?
Line algorithms
Drawing a hrizontal line from (x1,y) to (x2,y) are below
DDA
DDA is digital differential algorithm
Generation of circles
略过
Line
raster points 栅格点: 就是一般的点
jaggies 锯齿: 把点根据标准线连接在一起
pixel space 像素空间: 这条线所占据的像素格
Antialiasing by area averaging
通过面积平均反锯齿
Colour multiple pixels for each x depending on coverage by ideal line.
根据理想线的覆盖范围,为每个x的多个像素着色。
Geometric primitives 几何基本-多边形和三角形
- The basic graphics primitives are points, lines and polygons 基本的图形原语是点、线和多边形
- A polygon can be defined by an ordered set of vertices 一个多边形可以被定义为一组有序顶点的集合
- Graphics hardware is optimised for processing points 图形硬件优化处理点
- Complex objects are eventually divided into triangular polygons (a process called tessellation) 复杂的物体最终被分割成三角形的多边形
- Because triangular polygons are always flat 三角形的多边形总是平的
Scan conversion 自动转换
- also called rasterization 栅格化
- The 3D to 2D projection givens us 2D vertices (points).
Polygon fill 多边形填充
- Rasterize edges into framebuffer.
- Find a seed pixel inside the polygon.
- Visit neighbours recursively and colour if they are not edge pixels.
- When vertices lie on the scanlines, cases (a) and (b) must be treated differently when using odd-even fill definition
- Case (a): zero or two crossings
- Case (b): one edge crossing
Geometric primitives in OpenGL
glBegin (prametres)
- GL_POINTS: individual points
- GL_LINES: pairs of vertices interpreted as individual line segments
- GL_LINE_STRIP: series of connected line segments
- GL_LINE_LOOP: same as above, with a segment added between last and first vertices
- GL_TRIANGLES: triples of vertices interpreted as triangles
- GL_TRIANGLE_STRIP: linked strip of triangles
- GL_TRIANGLE_FAN: linked fan of triangles
- GL_QUADS: quadruples of vertices interpreted as four-sided polygons
- GL_QUAD_STRIP: linked strip of quadrilaterals
- GL_POLYGON: boundary of a simple, convex polygon
GL_POINTS
1 | // this code will draw a point located at (100,100) |
GL_LINES
1 | // this code will draw a line at starting and ending |
How to make lines efficient?
1 | // this code will draw two lines "at a time" to save the time it takes to call glBegin and glEnd |
Triangle in OpenGL
1 | glBegin(GL_TRIANGLES); |
glQuad_STRIP
Ordering of coordinates very important