Presentation is loading. Please wait.

Presentation is loading. Please wait.

Graphics Output Primitives

Similar presentations


Presentation on theme: "Graphics Output Primitives"— Presentation transcript:

1 Graphics Output Primitives
Sang Il Park Sejong University

2 2D Fill-Area Primitives

3 Irregular curved fill region
Fill-Area Primitives Circular fill region Irregular curved fill region Polygonal fill region Tessellation

4 POLYGON Polygon: a plane figure specified by a set of vertices connected with sequence of straight-line segments ex) triangles, rectangles, pentagons, octagons, ... How to represent: a sequence of the vertices ( vertex list )

5 Polygon Representation
Using Tables: 1. Vertex table, edge table, surface table 2. Vertex table, surface table

6 OpenGL polygon fill-area functions
Rectangular fill area: glRect* (x1,y1,x2,y2) glRecti (50, 50, 200, 200) int pt1 [] = {50, 50}; int pt2 [] = {200,200}; glRectiv (pt1, pt2);

7 OpenGL polygon fill-area functions
OpenGL에서의 그림 그리기는 다음과 같은 Begin-End 절로 표현 예) glBegin (종류); ……… glEnd ( ); GL_POLYGON GL_TRIANGLES GL_TRIANGLE_STRIP GL_TRIANGLE_FAN GL_QUADS GL_QUAD_STRIP glBegin (GL_POLYGONS); glVertex2iv (pt1); glVertex2iv (pt2); glVertex2iv (pt3); glVertex2iv (pt4); glVertex2iv (pt5); glEnd ( );

8 OpenGL Vertex Arrays An efficient way to send the vertex data
glEnableClientState (GL_VERTEX_ARRAY); glVertexPointer (2, GL_INT, 0, pt); GLubyte vertIndex [] = {1, 2, 3, 4, 4, 3, 5, 6}; glDrawElements (GL_QUADS,8, GL_UNSIGNED_BYTE, vertIndex);

9 OpenGL Display List An comvenient, efficient way to store an object
Execute a display list: glNewList (listID, listMode ); // your drawing routine glEndList(); listID: a unique name for the list (GLuint) Use glGenLists(1) to obtain a valid ID listMode: GL_COMPILE / GL_COMPILE_AND_EXECUTE glCallList(listID);

10 GLUT display reshape function
Reshape (or resize) callback: when changing the window size Registration: Implementation: glutReshapeFunc ( MyReshape ); void MyReshape (int w, int h) { // your reshaping code such as gluOrtho2D }

11 OpenGL Pixel-Array Primitives
Bitmap: using a bit for representing each pixel Pixmap: using several bytes for each pixel

12 OpenGL Pixel-Array Primitives
glBitmap: draw a bitmap on the screen Glubyte bitmap [20] = { 0x1c,0x00,0x1c,0x00,0x1c,0x00,0x1c,0x00, 0x1c,0x00,0xff,0x80,0x7f,0x00,0x3e,0x00, 0x1c,0x00,0x08,0x00}; glPixelStorei (GL_UNPACK_ALIGHMENT, 1); glRasterPos2i(30,40); glBitmap( 9, 10, 0.0, 0.0, 20.0, 15.0, bitmap);

13 OpenGL Pixel-Array Primitives
glDrawPixels: draw a pixmap on the screen glDrawPixels ( width, height, dataFormat, dataType, pixMap);

14 Text-Drawing Painting programs Drawing programs
bit-mapped representation e.g., Adobe Photoshop, bit-map fonts Drawing programs object-based representation e.g., Powerpoint, outline fonts

15 OpenGL Text Drawing Bitmap text: Ex) glutBitmapCharacter (font, char )
GLUT_BITMAP_8_BY_13 GLUT_BITMAP_9_BY_15 GLUT_BITMAP_TIMES_ROMAN_10 char a[]=“abced”; glrasterPosition2i(100,100); for(int i=0;i<5;i++) glutBitmapCharacter (GLUT_BITMAP_8_BY_13, a[i]);

16 연습 교재 page 181~189 까지 직접 입력해서 실행해 보고, 그 내용을 분석해 볼 것

17 Ch.4. Attributes of Graphics Primitives

18 OpenGL State variables:
Color Point attributes Line attributes Fill-Area attributes

19 Color in OpenGL Color buffer Setting: Setting the color value: Ex)
glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB) GLUT_RGBA GLUT_RGB GLUT_INDEX GLUT_SINGLE GLUT_DOUBLE glColor* (values); glColor3f (0.0, 1.0, 0.5); glColor3i ( 0, 255, 128);

20 Point Attributes in OpenGL
Size: Color : glPointSize ( size ); glColor* (values);

21 Line Attributes in OpenGL
Width: Line-Style : ex) Line-Style On/Off: glLineWidth ( width ); glLineStipple (repeatFactor, pattern); glLineStipple (1, 0x00FF); glLineStipple (1, 0x0101); glEnable (GL_LINE_STIPPLE); glDisable (GL_LINE_STIPPLE);

22 Other Line Attributes Not in OpenGL
Line Caps: Connecting: Butt cap Round cap Projecting square cap Miter join Round join Bevel join

23 Other Line Attributes Not in OpenGL
Pen and Brush Options:

24 Color in OpenGL Color buffer Setting: Setting the color value: Ex)
glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB) GLUT_RGBA GLUT_RGB GLUT_INDEX GLUT_SINGLE GLUT_DOUBLE glColor* (values); glColor3f (0.0, 1.0, 0.5); glColor3i ( 0, 255, 128);

25 Area Filling Scan line approach Seed Fill Algorithm

26 Area Filling (Scan line Approach)
For each scan line (1) Find intersections (the extrema of spans) Use Bresenham's line-scan algorithm (2) Sort intersections (increasing x order) (3) Fill in between pair of intersections

27 Area Filling (Scan line Approach)
Take advantage of Edge coherence: edges intersected by scan line i are also intersected by scan line i+1

28 Area Filling (Scan line method)

29 Area Filling (Seed Fill Algorithm)
basic idea Start at a pixel interior to a polygon Fill the others using connectivity seed

30 Seed Fill Algorithm (Cont’)
4-connected 8-connected Need a stack. Why?

31 Seed Fill Algorithm (Cont’)
start position

32 Seed Fill Algorithm (Cont’)
8 6 4 2 8 6 4 2 interior-defined boundary-defined flood fill algorithm boundary fill algorithm

33 Seed Fill Algorithm (Cont’)
1 2 3 4 5 6 7 1 2 3 4 5 6 7 hole boundary pixel interior pixel seed pixel The stack may contain duplicated or unnecessary information !!!

34 Boundary Filling

35 Flood Filling : Start a point inside the figure, replace a specified interior color only.

36 Scan Line Seed Fill scan line conversion seed filling +
Shani, U., “Filling Regions in Binary Raster Images: A Graph-Theoretic Approach”, Computer Graphics, 14, (1981),

37 Boundary Filling Efficiency in space!
finish the scan line containing the starting position process all lines below the start line process all lines above the start line

38 Problems of Filling Algorithm
What happens if a vertex is shared by more than one polygon, e.g. three triangles? What happens if the polygon intersects itself? What happens for a “sliver”? Solutions? Redefine what it means to be inside of a triangle Different routines for nasty little triangles

39 Aliasing in CG Which is the better?


Download ppt "Graphics Output Primitives"

Similar presentations


Ads by Google