Drawing Geometric Objects

Slides:



Advertisements
Similar presentations
COMP 175 | COMPUTER GRAPHICS Remco Chang1/6103b – Shapes Lecture 03b: Shapes COMP 175: Computer Graphics February 3, 2015.
Advertisements

O a polygon is a plane figure specified by a set of three or more coordinate positions, called vertices, that are connected in sequence by straight-Line.
CMPE 466 COMPUTER GRAPHICS
Computer Graphics Programming: Matrices and Transformations CSE 3451 Matt Boggus.
2IV60 Computer graphics Graphics primitives and attributes Jack van Wijk TU/e.
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.
What is OpenGL The OpenGL graphics system is a software interface to graphics hardware. (The GL stands for Graphics Library.) It allows you to create interactive.
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.
CSC 461: Lecture 6 1 CSC461 Lecture 6: 2D Programming in OpenGL Objectives:  Fundamental OpenGL primitives  Attributes  Viewport.
Computer Graphics CS 385 February 7, Fundamentals of OpenGl and Glut Today we will go through the basics of a minimal OpenGl Glut project, explaining.
Curso: Graficación Prof. Gueorgi Khatchatourov
OpenGL Programming Guide (Red Book) State Management and Drawing Geometric Objects 고려대학교 그래픽스 연구실 강 신 진.
Computer Graphics: Programming, Problem Solving, and Visual Communication Steve Cunningham California State University Stanislaus and Grinnell College.
Polygon Shading. Assigning color to a shape to make graphical scenes look realistic, or artistic, or whatever effect we’re attempting to achieve But first.
CS 450: Computer Graphics REVIEW: OVERVIEW OF POLYGONS
JOGL in MS Windows GDI – Graphics Device Interface (Windows-specific) OpenGL Lib JOGL Commands GDI Processor Graphics Hardware JOGL Lib.
1 OpenGL Basics A Graphics Standard ©Mel Slater, Anthony Steed
Basic OpenGL Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Wednesday, September 10, 2003.
Using OpenGL. 2 What is OpenGL? A software interface to graphics hardware It is a Graphics Rendering API (Application Programmer’s Interface) that is.
Modeling. Geometric Models  2D and 3D objects  Triangles, quadrilaterals, polygons  Spheres, cones, boxes  Surface characteristics  Color  Texture.
Drawing Basic Graphics Primitives Lecture 4 Wed, Sep 3, 2003.
CSE 470: Computer Graphics. 10/15/ Defining a Vertex A 2D vertex: glVertex2f(GLfloat x, GLfloat y); 2D vertexfloating pointopenGL parameter type.
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
Ch 2 Graphics Programming page 1 CSC 367 Coordinate Systems (2.1.2) Device coordinates, or screen coordinates (pixels) put limitations on programmers and.
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.
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.
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.
Lecture 2 Review OpenGL Libraries Graphics Overview Rendering Pipeline OpenGL command structure.
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 Perception, Illusion and VR HNRS 299, Spring 2008 Lecture 15 Creating 3D Models.
31/1/2006Based on: Angel (4th Edition) & Akeine-Möller & Haines (2nd Edition)1 CSC345: Advanced Graphics & Virtual Environments Lecture 2: Introduction.
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.
CIS 681 Review: OpenGL. CIS 681 Command Syntax OpenGL commands start with a gl. This is followed by the base command such as Color. Followed by the number.
Computer Graphics I, Fall Programming with OpenGL Part 2: Complete Programs.
Computer Graphics Lecture 34. OpenGL Programming II Taqdees A. Siddiqi
OpenGL Programming Guide Chapter 2 Korea Univ. Graphics Labs. Ji Jun Yong Korea Univ. Graphics Labs. Ji Jun Yong.
Program Studi S-1 Teknik Informatika FMIPA Universitas Padjadjaran
CSC Graphics Programming
State Management and Drawing Geometric Objects
State Management and Drawing Geometric Objects
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.
Class 17 front and back lighting convex sets, convex hull
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
Drawing in the plane 455.
Lecture 13 Clipping & Scan Conversion
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
Class 18 front and back lighting convex sets, convex hull
Polygons.
Presentation transcript:

Drawing Geometric Objects

Drawing Primitives OpenGL sets three types of drawing primitives Points Lines Polygons, e.g, traingles All primitives are represented in terms of vertices that define the positions of the points themselves or the ends of line segments or the corners of polygons

Points Object of zero dimension (infinitely small) Specified by a set of floating-point numbers (coordinates) called a vertex Displayed as a single pixel on screen void glPointSize(Glfloat size); Sets the size of a rendered point in pixels

Specifying Vertices void glVertex{234}{sifd}[v](TYPE coords); Specifies a vertex for use in describing a geometric object glVertex2s(2,4); glVertex4f(2.3, 1.0, -2.2, 2.0); GLdouble dvect[3] = {5.0, 9.0, 4.0); glVertex3dv(dvect); OpenGL works in homogeneous coordinates vertex:: (x, y, z, w) w = 1 for default

Displaying Vertices Bracket a set of vertices between a call to glBegin() and a call to glEnd() pair The argument GL_POINTS passed to glBegin() means drawing vertices in the form of the points glBegin(GL_POINTS); glVertex2f(0.0, 0.0); glVertex2f(4.0, 0.0); glVertex2f(4.0, 4.0); glVertex2f(0.0, 4.0); glEnd(); Other drawing options for vertex-data list Lines (GL_LINES) Polygon (GL_POLYGON)

Lines The term line refers to a line segment Specified by the vertices at their endpoints Displayed solid and one pixel wide Smooth curves from line segments

Drawing Lines To draw a vertex-data list as lines GL_LINE_STRIP glBegin(GL_LINES); glVertex2f(0.0, 0.0); glVertex2f(4.0, 0.0); glVertex2f(4.0, 4.0); glVertex2f(0.0, 4.0); glEnd(); GL_LINE_STRIP A series of connected lines GL_LINE_LOOP A closed loop

Wide and Stippled Lines void glLineWidth(GLfloat width); Sets the width in pixels for rendered lines void glLineStipple(GLint factor, GLshort pattern); Sets the current stippling pattern (dashed or dotted) for lines Pattern is a 16-bit series of 0s and 1s 1 means one pixel drawing, and 0 not drawing Factor stretches the pattern multiplying each bit Trun on and off stippling glEnable(GL_LINE_STIPPLE) glDisable(GL_LINE_STIPPLE)

Example of Stippled Lines glLineStipple(1, 0x3F07); Pattern 0x3F07 translates to 0011111100000111 Line is drawn with 3 pixels on, 5 off, 6 on, and 2 off glLineStipple(2, 0x3F07); Factor is 2 Line is drawn with 6 pixels on, 10 off, 12 on, and 4 off

Polygon Areas enclosed by singled closed loops of line segments Specified by vertices at the corners Displayed as solid with the pixels in the interior filled in Examples: Triangle and Pentagon

Polygon Tessellation Simple and convex polygon Polygon tessellation Triangle Any three points always lie on a plane Polygon tessellation Nonsimple or nonconvex polygons can be represented in the form of triangles Curved surfaces can be approximated by polygons

Drawing Polygon Draw a vertex-data list as a polygon GL_TRIANGLES glBegin(GL_POLYGON); glVertex2f(0.0, 0.0); glVertex2f(4.0, 0.0); glVertex2f(4.0, 4.0); glVertex2f(0.0, 4.0); glEnd(); GL_TRIANGLES Draws first three vertices as a triangle GL_QUADS Quadilateral is a four-sided polygon

Drawing Polygons GL_TRIANGLE_STRIP GL_TRIANGLE_FAN GL_QUAD_STRIP v1 v3 GL_TRIANGLE_STRIP Draws a series of triangles using vertices in the order v0,v1,v2; v2,v1,v3 v2,v3,v4; v4,v3,v5 All triangles are drawn with the same orientation (clockwise order) GL_TRIANGLE_FAN One vertex is in common to all triangles Clockwise orientation GL_QUAD_STRIP Draws a series of quadrilaterals v5 v0 v2 v4 v1 v2 v3 v0 v4 v5

Polygons as Points and Outlines void glPolygonMode(GLenum face, Glenum mode); Controls the drawing mode for a polygon’s front and back faces glPolygonMode(GL_FRONT, GL_FILL); glPolygonMode(GL_BACK, GL_LINE); glPolygonMode(GL_FRONT_AND_BACK, GL_POINT); By convention, polygons whose vertices appear in counterclockwise order are front-facing GL_CCW

Deciding Front- or Back Facing Decision based the sign of the polygon’s area, a computed in window coordinates For GL_CCW, if a>0 means the polygon be front-facing, then a<0 means the back-facing For GL_CW, if a<0 for front-facing, then a>0 for back-facing

Reversing and Culling Polygons void glFrontFace(GLenum mode); Controls how front-facing polygons are determined Default mode is GL_CCW (vertices in counterclockwise order) Needs to be enabled void glCullFace(GLenum mode); Indicates which polygons (back-facing or front-facing) should be discarded (culled)

Stippling Polygons Void glPolygonStipple(const GLbyte *mask); Defines the current stipple pattern for the filled polygons The argument is a pointer to a 32x32 bitmap (a mask of 0s and 1s) Needs to be enabled and disabled glEnable(GL_POLYGON_STIPPLE); glDisable(GL_POLYGON_STIPPLE);

Normal Vectors Points in a direction that’s perpendicular to a surface The normal vectors are used in lighting calculations void glNormal3(bsidf)(TYPE nx, TYPE ny, TYPE nz); Sets the current normal vector as specified by the arguments void glNormal3(bsidf)v(const TYPE *v); Vector version supplying a single array v of three element

Finding Normal Vector Surfaces described with polygonal data Calculate normal vectors for each polygonal facet Average these normals for neighboring facets Use the averaged normal for the vertex that the neighboring facets have in common Using normal vectors in lighting model to make surface appear smooth rather than facet •

Finding Normal Vector Make two vectors from any three vertices v1, v2 and v3 P = v1 - v2; Q = v2 - v3 Cross product of these vectors is perpendicular to polygonal surface N = P x Q = [Px Py Pz] x [Qx Qy Qz] = [PyQz-QyPz) (QxPz-PxQz) (PxQy-QxPy] = [Nx Ny Nz] Normalize the vector n = [nx ny nz] = [Nx/L Ny/L Nz/L] where L is length of the vector [Nx Ny Nz] v3 v1 Q P v2

Building Polygonal Models of Surfaces You can approximate smooth surfaces by polygons Important points Polygon orientations consistency (all clockwise or all anticlockwise) Caution at non-triangular polygons Trade-off between display speed and image quality

Examples Building an icosahedron Polygonal approximation to a sphere