CPT205 W3

This’s week we will discuss about Geometric Primitives. (几何图元)
Applications Packages Tools –> API Library –> Algorithms Techniques

  1. Graphics Primitives
    • Points
    • Lines
    • Polygons 多边形
  2. Line Algorithms
    • Digital Differential Analyser (DDA)
    • Bresenham Algorithm
    • Circles
    • Antialiasing 反锯齿
  3. Polygon Fill 多边形填充
  4. 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
line algorithms

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
2
3
4
5
6
// this code will draw a point located at (100,100)
glBegin(GL_POINTS);
glVertex2f(100.0f, 100.0f);
...
// add more points if required
glEnd( );

GL_LINES

1
2
3
4
5
6
// this code will draw a line at starting and ending 
// coordinates specified by glVertex2f
glBegin(GL_LINES);
glVertex2f(100.0f, 100.0f); // origin of line
glVertex2f(200.0f, 140.0f); // end point of line
glEnd( );

How to make lines efficient?

1
2
3
4
5
6
7
// this code will draw two lines "at a time" to save the time it takes to call glBegin and glEnd
glBegin(GL_LINES);
glVertex2f(100.0f, 100.0f); // origin of the FIRST line
glVertex2f(200.0f, 140.0f); // end point of the FIRST line
glVertex2f(120.0f, 170.0f); // origin of the SECOND line
glVertex2f(240.0f, 120.0f); // end point of the SECOND line
glEnd( );

Triangle in OpenGL

1
2
3
4
5
glBegin(GL_TRIANGLES); 
glVertex2f(-0.5,-0.5);
glVertex2f(0.5,0.0);
glVertex2f(0.0,0.5);
glEnd();

glQuad_STRIP

Ordering of coordinates very important
glQuad_STRIP

作者

Felix Chen

发布于

2021-09-23

更新于

2021-09-23

许可协议

评论