Graphics Output Primitives Sang Il Park Sejong University
2D Fill-Area Primitives
Irregular curved fill region Fill-Area Primitives Circular fill region Irregular curved fill region Polygonal fill region Tessellation
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 )
Polygon Representation Using Tables: 1. Vertex table, edge table, surface table 2. Vertex table, surface table
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);
OpenGL polygon fill-area functions OpenGL에서의 그림 그리기는 다음과 같은 Begin-End 절로 표현 http://www.opengl.org/sdk/docs/man/xhtml/glBegin.xml 예) 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 ( );
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);
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);
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 }
OpenGL Pixel-Array Primitives Bitmap: using a bit for representing each pixel Pixmap: using several bytes for each pixel
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);
OpenGL Pixel-Array Primitives glDrawPixels: draw a pixmap on the screen glDrawPixels ( width, height, dataFormat, dataType, pixMap);
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
OpenGL Text Drawing Bitmap text: Ex) glutBitmapCharacter (font, char ) GLUT_BITMAP_8_BY_13 GLUT_BITMAP_9_BY_15 GLUT_BITMAP_TIMES_ROMAN_10 … http://www.opengl.org/resources/libraries/glut/spec3/node76.html char a[]=“abced”; glrasterPosition2i(100,100); for(int i=0;i<5;i++) glutBitmapCharacter (GLUT_BITMAP_8_BY_13, a[i]);
연습 교재 page 181~189 까지 직접 입력해서 실행해 보고, 그 내용을 분석해 볼 것
Ch.4. Attributes of Graphics Primitives
OpenGL State variables: Color Point attributes Line attributes Fill-Area attributes
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);
Point Attributes in OpenGL Size: Color : glPointSize ( size ); glColor* (values);
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);
Other Line Attributes Not in OpenGL Line Caps: Connecting: Butt cap Round cap Projecting square cap Miter join Round join Bevel join
Other Line Attributes Not in OpenGL Pen and Brush Options:
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);
Area Filling Scan line approach Seed Fill Algorithm
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
Area Filling (Scan line Approach) Take advantage of Edge coherence: edges intersected by scan line i are also intersected by scan line i+1
Area Filling (Scan line method)
Area Filling (Seed Fill Algorithm) basic idea Start at a pixel interior to a polygon Fill the others using connectivity seed
Seed Fill Algorithm (Cont’) 4-connected 8-connected Need a stack. Why?
Seed Fill Algorithm (Cont’) start position
Seed Fill Algorithm (Cont’) 8 6 4 2 0 2 4 6 8 10 0 2 4 6 8 10 8 6 4 2 interior-defined boundary-defined flood fill algorithm boundary fill algorithm
Seed Fill Algorithm (Cont’) 0 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 hole boundary pixel interior pixel seed pixel The stack may contain duplicated or unnecessary information !!!
Boundary Filling
Flood Filling : Start a point inside the figure, replace a specified interior color only.
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), 321-327
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
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
Aliasing in CG Which is the better?