2IV60 Computer graphics Graphics primitives and attributes Jack van Wijk TU/e.

Slides:



Advertisements
Similar presentations
Computer Graphics- SCC 342
Advertisements

COMP 175 | COMPUTER GRAPHICS Remco Chang1/6103b – Shapes Lecture 03b: Shapes COMP 175: Computer Graphics February 3, 2015.
Chapter 2: Graphics Programming
CHAPTER 3 2D GRAPHICS ALGORITHMS
CMPE 466 COMPUTER GRAPHICS
CS 450: COMPUTER GRAPHICS FILLING POLYGONS SPRING 2015 DR. MICHAEL J. REALE.
Informationsteknologi Wednesday, November 7, 2007Computer Graphics - Class 51 Today’s class Geometric objects and transformations.
Informationsteknologi Monday, October 29, 2007Computer Graphics - Class 21 Today’s class Graphics programming Color.
OpenGL (Graphics Library) Software Interface to graphics software Allows to create interactive programs that produce color images of moving 3D objects.
CSCE 441: Computer Graphics Scan Conversion of Polygons
Drawing Geometric Objects
1 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Programming with OpenGL Part 2: Complete Programs Ed Angel Professor of Computer Science,
1 Lecture 4 Graphical primitives Rasterization: algorithmic approach Rasterization: geometric approach 2D discrete lines, triangles Discrete planes 3D.
1 CSCE 441 Computer Graphics: Clipping Lines Jinxiang Chai.
OpenGL and WebGL Drawing Functions CSCI 440 Day Five.
CSC 461: Lecture 6 1 CSC461 Lecture 6: 2D Programming in OpenGL Objectives:  Fundamental OpenGL primitives  Attributes  Viewport.
Reference1. [OpenGL course slides by Rasmus Stenholt]
1 CSCE 441: Computer Graphics Scan Conversion of Polygons Jinxiang Chai.
GRAPHICS OUTPUT PRIMITIVES CA 302 Computer Graphics and Visual Programming Aydın Öztürk
CS 450: Computer Graphics REVIEW: OVERVIEW OF POLYGONS
Basics of Rendering Pipeline Based Rendering –Objects in the scene are rendered in a sequence of steps that form the Rendering Pipeline. Ray-Tracing –A.
COS 397 Computer Graphics Assoc. Prof. Svetla Boytcheva AUBG 2013 COS 397 Computer Graphics Practical Session №1 Introduction to OpenGL, GLFW and CG.
Basic OpenGL Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Wednesday, September 10, 2003.
Drawing Basic Graphics Primitives Lecture 4 Wed, Sep 3, 2003.
Part 6: Graphics Output Primitives (4) 1.  Another useful construct,besides points, straight line segments, and curves for describing components of a.
CSE 470: Computer Graphics. 10/15/ Defining a Vertex A 2D vertex: glVertex2f(GLfloat x, GLfloat y); 2D vertexfloating pointopenGL parameter type.
Introduction to Computer Graphics PPT2: Graphics Output Primitives
Computer Graphics CS 385 January 31, Fractals Some definitions Object which is self-similar at all scales. Regardless of scale the same level of.
State Management and Drawing Geometry Objects
1. OpenGL/GLU/GLUT  OpenGL v4.0 (latest) is the “core” library that is platform independent  GLUT v3.7 is an auxiliary library that handles window creation,
P RACTICING O PEN GL- P RIMITIVES. O PEN GL O UTPUT P RIMITIVES  Each geometric object is described by a set of vertices and the type of primitive to.
2D Output Primitives Points Lines Circles Ellipses Other curves Filling areas Text Patterns Polymarkers.
Representation. Objectives Introduce concepts such as dimension and basis Introduce coordinate systems for representing vectors spaces and frames for.
Computer Graphics Basic 3D Geometry CO2409 Computer Graphics Week 5-1.
Computer Graphics Bing-Yu Chen National Taiwan University.
Intro to OpenGL: Vertices and Drawing
UniS CS297 Graphics with Java and OpenGL State Management and Drawing Primative Geometric Objects.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
In the name of God Computer Graphics Bastanfard. Curve Function(2) Other method is approximate it using a poly-line. Just locate a set of points along.
1 CSCE 441 Lecture 2: Scan Conversion of Lines Jinxiang Chai.
What are Computer Graphics Basically anything that is on you Monitor – This includes the text that you will see Text isn’t Advanced Graphics But…. Understanding.
2D Output Primitives Points Lines Circles Ellipses Other curves Filling areas Text Patterns Polymarkers.
1 Programming with OpenGL Part 2: Complete Programs.
OpenGL API 2D Graphic Primitives Angel Angel: Interactive Computer Graphics5E © Addison-Wesley
1 E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012 Programming with OpenGL Part 4: Color and Attributes Isaac Gang University.
1 CSCE 441: Computer Graphics Scan Conversion of Polygons Jinxiang Chai.
1 Perception, Illusion and VR HNRS 299, Spring 2008 Lecture 15 Creating 3D Models.
Introduction to Meshes Lecture 22 Mon, Oct 20, 2003.
OpenGL: Introduction #include main() { OpenWindow() ; glClearColor(0.0, 0.0, 0.0, 0.0); glClear(GL_COLOR_BUFFER_BIT); glOrtho(-1.0, 1.0, -1.0, 1.0, -1.0,
2002 by Jim X. Chen: Drawing Geometric Models.1. Objectives –OpenGL drawing primitives and attributes –OpenGL polygon face.
Computer Graphics I, Fall Programming with OpenGL Part 2: Complete Programs.
Computer Graphics (Fall 2003) COMS 4160, Lecture 5: OpenGL 1 Ravi Ramamoorthi Many slides courtesy Greg Humphreys.
CSC Graphics Programming
Programming with OpenGL Part 2: Complete Programs
Materi Anatomi OpenGL Fungsi GLUT Posisi Kamera Proyeksi
OpenGL API 2D Graphic Primitives
Programming with OpenGL Part 2: Complete Programs
OpenGL (Open Graphics Library) Mr. B.A.Swamy Assistant Professor Dept of CSE.
Lab 3 Geometric Drawing Lab 3 Geometric Drawing.
Objectives OpenGL drawing primitives and attributes
Introduction to Computer Graphics with WebGL
Programming with OpenGL Part 4: Color and Attributes
CSE 411 Computer Graphics Lecture #3 Graphics Output Primitives
Primitive Objects Lecture 6 Wed, Sep 5, 2007.
CSCE 441 Computer Graphics: Clipping Polygons Jinxiang Chai
Programming with OpenGL Part 2: Complete Programs
Programming with OpenGL Part 2: Complete Programs
Programming with OpenGL Part 4: Color and Attributes
Programming with OpenGL Part 2: Complete Programs
Polygons.
Presentation transcript:

2IV60 Computer graphics Graphics primitives and attributes Jack van Wijk TU/e

Overview Basic graphics primitives: –points, lines, polygons Basic attributes –linewidth, color

OpenGL output functions glBegin(GL_LINES); // Specify what to draw, // here lines // Geometric info via vertices: glVertex*(); // 1 glVertex*(); // 2... //... glEnd; glVertex[234][isfd] [234]: 2D, 3D, 4D [isfd]: integer, short, float, double For instance: glVertex2i(100, 25); H&B 4-4:81-82

Point and Line primitives GL_POINTS : sequence of points GL_LINES : sequence of line segments GL_LINE_STRIP : polyline GL_LINE_LOOP : closed polyline H&B 4-4:

Fill-area primitives 1 Point, line and curve, fill area Usually polygons 2D shapes and boundary 3D objects H&B 4-6:83-84

Fill-area primitives 2 Approximation of curved surface: –Surface mesh or Surface tesselation –Face or facet (planar), patch (curved) H&B 4-6:83-84

Polygon Polygon: –Planar shape, defined by a sequence of three or more vertices, connected by line segments (edges or sides) –Standard or simple polygon: no crossing edges bowtie polygon H&B 4-7:84-94

Regular polygon Vertices uniformly distributed over a circle: r H&B 4-7:84-94

Convex vs. concave 1 Convex: –All interior angles < 180 graden, and –All line segments between 2 interior points in polygon, and –All points at the same side of line through edge, and –From each interior point complete boundary visible Concave: not convex H&B 4-7:84-94

Convex vs. concave 2 Puzzle: Given a planar polygon in 3D, with vertices P i, with i = 1, …, N. Give a recipe to determine if the polygon is convex or concave. H&B 4-7:84-94

Convex vs. concave 3 Puzzle: Given a planar polygon in 3D, with vertices P i, with i = 1, …, N. Give a recipe to determine if the polygon is convex or concave. Solution: (multiple solutions possible) H&B 4-7:84-94

Splitting concave polygons H&B 4-7:84-94

Convex polygon  triangles Puzzle: Which sequence of points to pick? Repeat Pick three succeeding points; Join the outside ones with a line; Remove the middle point Until three points are left over H&B 4-7:84-94

Inside / outside polygon 1 H&B 4-7:84-94

Inside / outside polygon 2 H&B 4-7:84-94

Inside / outside polygon 3 General: odd-even rule –Draw a line from C to a point far away. If the number of crossings with the boundary is odd, then C is inside the polygoon. H&B 4-7:84-94

Storage polygons 1 Mesh: –Vertices –Edges –Faces Operations –Draw all edges –Draw all faces –Move all vertices –Determine orientation –…–… H&B 4-7:84-94

Storage polygons 2 Simple: all polygons apart Faces: F 1 : V 1, V 2, V 3 Per vertex coordinates F 2 : V 1, V 3, V 4, V 5 H&B 4-7:84-94

More efficient: polygons and vertices apart Faces:Vertices: F 1 : 1,2,3V 1 : x 1, y 1, z 1 F 2 : 1,3,4,5V 2 : x 2, y 2, z 2 V 3 : x 3, y 3, z 3 V 4 : x 4, y 4, z 4 V 5 : x 5, y 5, z 5 V 6 : x 6, y 6, z 6 Storage polygons 3 H&B 4-7:84-94

Storage polygons 4 Also: polygons, edges and vertices apart Faces:Edges:Vertices: F 1 : 1,2,3E 1 : 1,2V 1 : x 1, y 1, z 1 F 2 : 3,4,5,6E 2 : 2,3V 2 : x 2, y 2, z 2 E 3 : 3,1V 3 : x 3, y 3, z 3 E 4 : 3,4V 4 : x 4, y 4, z 4 E 5 : 4,5V 5 : x 5, y 5, z 5 E 6 : 5,1V 6 : x 6, y 6, z 6 H&B 4-7:84-94

Or: keep list of neighboring faces per vertex Faces:Vertices:Neighbor faces: F 1 : 1,2,3V 1 : x 1, y 1, z 1 1, 2 F 2 : 1,3,4,5V 2 : x 2, y 2, z 2 1 V 3 : x 3, y 3, z 3 1, 2 V 4 : x 4, y 4, z 4 2 V 5 : x 5, y 5, z 5 2 V 6 : x 6, y 6, z 6 … Storage polygons 5 H&B 4-7:84-94

Storage polygons 6 Many other formats possible –See f.i. winged edge data structure Select/design storage format based on: –Operations on elements; –Efficiency (size and operations); –Simplicity –Maintainability –Consistency –… H&B 4-7:84-94

Polygons in space 1 3D flat polygon in (infinite) plane Equation plane: Ax + By + Cz + D = 0 x y z Plane: z=0 H&B 4-7:84-94

Polygons in space 2 Position point (x, y, z) w.r.t. plane: Ax + By + Cz + D > 0 : point in front of plane Ax + By + Cz + D < 0 : point behind plane x y z Plane: z=0 H&B 4-7:84-94

Polygons in space 3 Normal: vector N perpendicular to plane Unit normal: |N|=1 x y z Normal: (0, 0, 1) Vlak: z=0 In general: Normal: N=(A, B, C) for Plane: Ax + By + Cz + D = 0 Or N.X+D = 0 H&B 4-7:84-94

Polygons in space 4 x y z H&B 4-7:84-94

OpenGL Fill-Area Functions 1 glBegin(GL_POLYGON); // Specify what to draw, // a polygon // Geometric info via vertices: glVertex*(); // 1 glVertex*(); // 2... //... glEnd; glVertex[234][isfd] [234]: 2D, 3D, 4D [isfd]: integer, short, float, double For instance: glVertex2i(100, 25); H&B 4-4:81-82

OpenGL Fill-Area Functions 2 GL_POLYGON : convex polygon Concave polygons give unpredictable results H&B 4-8:94-99

OpenGL Fill-Area Functions 3 GL_TRIANGLES : sequence of triangles GL_TRIANGLE_STRIP : GL_TRIANGLE_FAN : H&B 4-8:94-99

OpenGL Fill-Area Functions 4 GL_QUADS : sequence of quadrilaterals GL_QUAD_STRIP : strip of quadrilaterals H&B 4-8:94-99

More efficiency Reduce the number of function calls: –OpenGL Vertex Arrays: pass arrays of vertices instead of single ones; Store information on GPU and do not resend: –OpenGL Display lists; –Vertex Buffer Objects. H&B App. C

OpenGL Display lists 1 Key idea: Collect a sequence of OpenGL commands in a structure, stored at the GPU, and reference it later on + Simple to program + Can give a boost + Useful for static scenes and hierarchical models  Not the most modern H&B

OpenGL Display lists 2 // Straightforward void drawRobot(); { // lots of glBegin, glVertex, glEnd calls } void drawScene(); { drawRobot(); glTranslate3f(1.0, 0.0, 0.0); drawRobot(); } H&B

OpenGL Display lists 3 void drawRobot(); { // lots of glBegin, glVertex, glEnd calls } int rl_id; void init(); { rl_id = glGenLists(1); // get id for list glNewList(rl_id, GL_COMPILE); // create new list drawRobot(); // draw your object glEndList(); } // end of list void drawScene(); { glCallList(rl_id); // draw list glTranslate3f(1.0, 0.0, 0.0); glCallList(rl_id); // and again } H&B

OpenGL Display lists 4 First, get an id. Either some fixed constant, or get a guaranteed unique one: rl_id = glGenLists(1); // get id for list Next, create a display list with this id: glNewList(rl_id, GL_COMPILE); // create new list drawing commands; // draw something glEndList(); // end of list Finally, “replay” the list. Change the list only when the scene is changed: glCallList(rl_id); // draw list H&B

Attributes 1 Attribute parameter: determines how a graphics primitive is displayed For instance for line: color, width, style OpenGL: simple state system –Current setting is maintained; –Setting can be changed with a function. H&B 5-1:130

Attributes 2 Example: glLineWidth(width); glEnable(GL_LINE_STIPPLE); glLineStipple(repeatfactor, pattern); // draw stippled lines... glDisable(GL_LINE_STIPPLE); Note: special features often must be enabled explicitly with glEnable(). H&B 5-7:

Color 1 RGB mode : color = (red, green, blue) glColor[34][bisf]: set color of vertex For example: –glColor4f(red, green, blue, alpha) –alpha : opacity (1  transparantie) H&B 5-2:

Color 2 RGB: hardware oriented model Dimensions are not natural (0, 0, 0): black; (1, 0, 0): red; (1, 1, 1) white H&B 5-2:

Color 3 HSV: Hue, Saturation (Chroma), Value More natural dimensions Hue: red-orange-yellow- green-blue- purple; Saturation: grey-pink-red; Value: dark-light H&B 19-7:

Color 4 HSL: Hue, Saturation (Chroma), Lightness More natural dimensions H&B 19-8:

Color 5 Color: big and complex topic Color: not physical, but perceptual AB

Color 6 Adelson checkerboard illusion

Color 6 Adelson checkerboard illusion

Next We now know how to draw polygons. How to model geometric objects?